// WortUhr03
unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
  ExtCtrls, Grids, LazUTF8;
  // LazUTF8 wegen Umlaut-Behandlung
type

  { TForm1 }

  TForm1 = class(TForm)
    ClockLabel: TLabel;
    Grid: TStringGrid;
    Label1: TLabel;
    Label2: TLabel;
    Timer1: TTimer;
    procedure FormClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private
    { private declarations }
  public
    { public declarations }
  end;

var
  Form1: TForm1;
  zeile : array [1..10] of string;
  es_ist : string;
  fuenfo : string;
  zehn_o : string;
  zwanzi : string;
  drei_o : string;
  vierte : string;
  vor___ : string;
  nach__ : string;
  halb__ : string;
  elf___ : string;
  fuenfu : string;
  ein___ : string;
  eins__ : string;
  zwei__ : string;
  drei_u : string;
  vier__ : string;
  sechs_ : string;
  acht__ : string;
  sieben : string;
  zwoelf : string;
  zehn_u : string;
  neun__ : string;
  uhr___ : string;
  spalte : integer;
  reihe : integer;
  m : string;
  minute : string;
  stunde : string;
  mn : integer;
  st : integer;
  an_aus : string;
  an_aus1 : string;
  an_aus2 : string;
  an_aus3 : string;
  mreihe1 : integer;
  mreihe2 : integer;
  mreihe3 : integer;
  sreihe : integer;
  leer : string;
  farben : integer;
implementation

{$R *.lfm}

{ TForm1 }

procedure TForm1.FormCreate(Sender: TObject);
begin
    zeile[1] := 'ES IST FÜNF';
    zeile[2] := 'ZEHNZWANZIG';
    zeile[3] := 'DREIVIERTEL';
    zeile[4] := 'VOR    NACH';
    zeile[5] := 'HALB ELFÜNF';
    zeile[6] := 'EINS   ZWEI';
    zeile[7] := 'DREI   VIER';
    zeile[8] := 'SECHS  ACHT';
    zeile[9] := 'SIEBENZWÖLF';
    zeile[10] := 'ZEHNEUN UHR';
    //         ----- Zeile, immer +1
    //         |
    //         |----------- 1=Buchstabe hervorgehoben, 0=verdeckt
    es_ist := '011011100000';
    fuenfo := '000000001111';
    zehn_o := '111110000000';
    zwanzi := '100001111111';
    drei_o := '211111111111';
    vierte := '200001111111';
    vor___ := '311100000000';
    nach__ := '300000001111';
    halb__ := '411110000000';
    elf___ := '400000111000';
    fuenfu := '400000001111';
    ein___ := '511100000000';
    eins__ := '511110000000';
    zwei__ := '500000001111';
    drei_u := '611110000000';
    vier__ := '600000001111';
    sechs_ := '711111000000';
    acht__ := '700000001111';
    sieben := '811111100000';
    zwoelf := '800000011111';
    zehn_u := '911110000000';
    neun__ := '900011110000';
    uhr___ := '900000000111';
    //
    leer := Char(32);
    With Grid do
    begin
    RowCount := 10;
    ColCount := 11;
    DefaultColWidth := 30;
    DefaultRowHeight := Grid.DefaultColWidth;
    FixedCols := 0;
    FixedRows := 0;
    Width := 335;
    Height := 305;
    Flat := True;
    GridLineWidth := 0;
    Font.Color := clWhite;
    Color := clBlack;
    BorderStyle := bsNone;
    end;
    farben := 0;
    //
    for reihe := 0 to Grid.RowCount-1 do
        begin
        for spalte := 0 to Grid.ColCount-1 do
            begin
            //Grid.Cells[spalte,reihe] := Copy (zeile[reihe+1],spalte+1,1);
            Grid.Cells[spalte,reihe] := LazUTF8.UTF8copy(zeile[reihe+1],spalte+1,1);
            //m := LazUTF8.UTF8copy(zeile[reihe+1],spalte+1,1);
            end;
        end;
end;

procedure TForm1.FormClick(Sender: TObject);
begin
     farben := farben +1;
     if farben = 2 then farben := 0;
     if farben = 0 then
        begin
             Grid.Font.Color := clWhite;
             Grid.Color := clBlack;
             Form1.Color := clBlack;
             // Auch dieses Verfahren geht:
             //Form1.Canvas.Brush.Color := clBlack;
             //Form1.Canvas.FillRect(0,0,Form1.Width,Form1.Height);
        end;
     if farben = 1 then
        begin
             Grid.Font.Color := clBlack;
             Grid.Color := clWhite;
             Form1.Color := clWhite;
             // Auch dieses Verfahren geht:
             //Form1.Canvas.Brush.Color := clWhite;
             //Form1.Canvas.FillRect(0,0,Form1.Width,Form1.Height);
        end;
end;

procedure TForm1.Timer1Timer(Sender: TObject);
var s: string;
begin
      // DateTimetoString(s,'dd.mm.yyyy   hh:mm',now);
      // formatiert datum + zeit, ohne sekunden
      DateTimetoString(s,'hh:mm:ss',now);
      Form1.Caption := 'Die Wortuhr sagt '+s + ' Uhr';
      minute := Copy (s,4,2);
      mn := StrToInt(minute); mn := mn div 5;
      stunde := Copy (s,1,2);
      st := StrToInt (stunde);
      if st = 0 Then st := 12;
      If mn >= 5 Then st := st + 1;
      If st > 12 Then st := st - 12;
      sreihe := 99;
      mreihe1 := 99;
      mreihe2 := 99;
      mreihe3 := 99;
      //Zuordnungen der Stundenanzeige
      if st = 1 then
      begin
           if mn = 0 then an_aus := ein___;
           if mn <> 0 then an_aus := eins__;
      end;
      if st = 2 then an_aus := zwei__;
      if st = 3 then an_aus := drei_u;
      if st = 4 then an_aus := vier__;
      if st = 5 then an_aus := fuenfu;
      if st = 6 then an_aus := sechs_;
      if st = 7 then an_aus := sieben;
      if st = 8 then an_aus := acht__;
      if st = 9 then an_aus := neun__;
      if st = 10 then an_aus := zehn_u;
      if st = 11 then an_aus := elf___;
      if st = 12 then an_aus := zwoelf;
      sreihe := StrToInt(Copy (an_aus,1,1));
      //Zuordnungen der Minutenanzeige
      if mn = 0 then
      begin
         an_aus1 := uhr___; mreihe1 := StrToInt(Copy (an_aus1,1,1));
         an_aus2 := ''; mreihe2 := 99;
         an_aus3 := ''; mreihe3 := 99;
      end;
      if mn = 1 then
      begin
           an_aus1 := fuenfo; mreihe1 := StrToInt(Copy (an_aus1,1,1));
           an_aus2 := nach__; mreihe2 := StrToInt(Copy (an_aus2,1,1));
           an_aus3 := ''; mreihe3 := 99;
      end;
      if mn = 2 then
      begin
           an_aus1 := zehn_o; mreihe1 := StrToInt(Copy (an_aus1,1,1));
           an_aus2 := nach__; mreihe2 := StrToInt(Copy (an_aus2,1,1));
           an_aus3 := ''; mreihe3 := 99;
      end;
      if mn = 3 then
      begin
           an_aus1 := vierte; mreihe1 := StrToInt(Copy (an_aus1,1,1));
           an_aus2 := nach__; mreihe2 := StrToInt(Copy (an_aus2,1,1));
           an_aus3 := ''; mreihe3 := 99;
      end;
      if mn = 4 then
      begin
           an_aus1 := zwanzi; mreihe1 := StrToInt(Copy (an_aus1,1,1));
           an_aus2 := nach__; mreihe2 := StrToInt(Copy (an_aus2,1,1));
           an_aus3 := ''; mreihe3 := 99;
      end;
      if mn = 5 then
      begin
           an_aus1 := fuenfo; mreihe1 := StrToInt(Copy (an_aus1,1,1));
           an_aus2 := vor___; mreihe2 := StrToInt(Copy (an_aus2,1,1));
           an_aus3 := halb__; mreihe3 := StrToInt(Copy (an_aus3,1,1));
      end;
      if mn = 6 then
      begin
           an_aus1 := halb__; mreihe1 := StrToInt(Copy (an_aus1,1,1));
           an_aus2 := ''; mreihe2 := 99;
           an_aus3 := ''; mreihe3 := 99;
      end;
      if mn = 7 then
      begin
           an_aus1 := fuenfo; mreihe1 := StrToInt(Copy (an_aus1,1,1));
           an_aus2 := nach__; mreihe2 := StrToInt(Copy (an_aus2,1,1));
           an_aus3 := halb__; mreihe3 := StrToInt(Copy (an_aus3,1,1));
      end;
      if mn = 8 then
      begin
           an_aus1 := zehn_o; mreihe1 := StrToInt(Copy (an_aus1,1,1));
           an_aus2 := nach__; mreihe2 := StrToInt(Copy (an_aus2,1,1));
           an_aus3 := halb__; mreihe3 := StrToInt(Copy (an_aus3,1,1));
      end;
      if mn = 9 then
      begin
           an_aus1 := drei_o; mreihe1 := StrToInt(Copy (an_aus1,1,1));
           an_aus2 := ''; mreihe2 := 99;
           an_aus3 := ''; mreihe3 := 99;
      end;
      if mn = 10 then
      begin
           an_aus1 := zehn_o; mreihe1 := StrToInt(Copy (an_aus1,1,1));
           an_aus2 := vor___; mreihe2 := StrToInt(Copy (an_aus2,1,1));
           an_aus3 := ''; mreihe3 := 99;
      end;
      if mn = 11 then
      begin
           an_aus1 := fuenfo; mreihe1 := StrToInt(Copy (an_aus1,1,1));
           an_aus2 := vor___; mreihe2 := StrToInt(Copy (an_aus2,1,1));
           an_aus3 := ''; mreihe3 := 99;
      end;
      // Grid mit Leerzeichen füllen
      for reihe := 0 to Grid.RowCount-1 do
          begin
          for spalte := 0 to Grid.ColCount-1 do
              begin
              Grid.Cells[spalte,reihe] := leer;
              end;
          end;
      // Minuten
      if mreihe1 < 99 then
      begin
           reihe := mreihe1;
           for spalte := 0 to Grid.ColCount-1 do
           begin
                m := Copy (an_aus1,spalte+2,1);
                if m = '1' then Grid.Cells[spalte,reihe] := LazUTF8.UTF8copy(zeile[reihe+1],spalte+1,1);
            end;
      end;
      if mreihe2 < 99 then
      begin
           reihe := mreihe2;
           for spalte := 0 to Grid.ColCount-1 do
           begin
                m := Copy (an_aus2,spalte+2,1);
                if m = '1' then Grid.Cells[spalte,reihe] := LazUTF8.UTF8copy(zeile[reihe+1],spalte+1,1);
           end;
      end;
      if mreihe3 < 99 then
      begin
           reihe := mreihe3;
           for spalte := 0 to Grid.ColCount-1 do
           begin
                m := Copy (an_aus3,spalte+2,1);
                if m = '1' then Grid.Cells[spalte,reihe] := LazUTF8.UTF8copy(zeile[reihe+1],spalte+1,1);
            end;
      end;
      //Stunden
      for spalte := 0 to Grid.ColCount-1 do
      begin
           m := Copy (an_aus,spalte+2,1);
           if m = '1' then Grid.Cells[spalte,sreihe] := LazUTF8.UTF8copy(zeile[sreihe+1],spalte+1,1);
      end;
      //Es ist
      for spalte := 0 to 5 do
      begin
           m := Copy (es_ist,spalte+2,1);
           if m = '1' then Grid.Cells[spalte,0] := LazUTF8.UTF8copy(zeile[1],spalte+1,1);
       end;
      (*
      Sleep(1000);
      clocklabel.Caption := an_aus1;
      label1.caption := an_aus2;
      label2.caption := an_aus3;
      clocklabel.caption := IntToStr(mreihe1);
      label1.caption := inttostr(mreihe2);
      label2.caption := inttostr(mn);
      *)
end;
end.