aboutsummaryrefslogblamecommitdiffstats
path: root/Game/Code/Screens/UScreenPopup.pas
blob: e7d6ce00f6159f54877f968b0e3934be4988140f (plain) (tree)
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765



















                                                                                                          

                                                   



































                                                                                                          













































































































































































































                                                                                                            



                                                    
 



                                        























































                                                                                                           











                                         
















                                                                             
                                                                                                 












                                                                                             


                                   





































































































































































































































































































































































































                                                                                                                          
                                 

          
                                                               


















                                                              





                                                                                    


                                                              





                                                                                
                                                    





                                                                              




















                          

     
   
unit UScreenPopup;

interface

uses
  UMenu, SDL, UMusic, math, UFiles, SysUtils, UThemes, UHelp, gl, glu;

type
  TScreenPopupCheck = class(TMenu)
    public
      Visible: Boolean; //Whether the Menu should be Drawn

      constructor Create; override;
      function ParseInput(PressedKey: Cardinal; ScanCode: byte; PressedDown: Boolean): Boolean; override;
      procedure onShow; override;
      procedure ShowPopup(msg: String);
      function Draw: boolean; override;
  end;

  TScreenPopupError = class(TMenu)
    {private
      CurMenu: Byte; //Num of the cur. Shown Menu}
    public
      Visible: Boolean; //Whether the Menu should be Drawn

      constructor Create; override;
      function ParseInput(PressedKey: Cardinal; ScanCode: byte; PressedDown: Boolean): Boolean; override;
      procedure onShow; override;
      procedure onHide; override;
      procedure ShowPopup(msg: String);
      function Draw: boolean; override;
  end;

  TRect = record
    left, right, top, bottom: integer;
  end;

  TLine = record
    fX, fY, tX, tY: integer;
  end;

  TText = record
    X, Y:   integer;
    Style:  integer;
    Size:   real;
    Italic: boolean;
    text:   string;
  end;

  TResLine = record
    Y:      integer;
    H:      integer;
    lines:  array of TLine;
    texts:  array of TText;
  end;

  TScreenPopupHelp = class(TMenu)
    private
      TextsGFX:   array of TResLine;
      msg:        TTextResult;
      Rect:       TRect;

      max_high:   real;
      step:       double;
      barH:       double;

      procedure   DrawTable;
      procedure   DrawLine(line, index, Y: integer);
      procedure   DrawText(line, index, Y: integer);
      procedure   DrawScroll(X, Y, W, H: integer; pos, len: double);
    public
      Visible:    Boolean; //Whether the Menu should be Drawn

      constructor Create; override;
      function ParseInput(PressedKey: Cardinal; ScanCode: byte; PressedDown: Boolean): Boolean; override;
      procedure onShow; override;
      procedure onHide; override;
      procedure ShowPopup();
      function Draw: boolean; override;
  end;
var
//  ISelections: Array of String;
  SelectValue: Integer;


implementation

uses Classes, TextGL, UGraphic, UMain, UIni, UTexture, ULanguage, UParty, UPlaylist, UDisplay;

function TScreenPopupCheck.ParseInput(PressedKey: Cardinal; ScanCode: byte; PressedDown: Boolean): Boolean;
begin
  Result := true;
  If (PressedDown) Then
  begin // Key Down

    case PressedKey of
      SDLK_Q:
        begin
          Result := false;
        end;

      SDLK_ESCAPE,
      SDLK_BACKSPACE :
        begin
          Display.CheckOK:=False;
          Display.NextScreenWithCheck:=NIL;
          Visible:=False;
          Result := false;
        end;

      SDLK_RETURN:
        begin
          case Interaction of
          0: begin
               //Hack to Finish Singscreen correct on Exit with Q Shortcut
               if (Display.NextScreenWithCheck = NIL) then
               begin
                 if (Display.ActualScreen = @ScreenSing) then
                   ScreenSing.Finish
                 else if (Display.ActualScreen = @ScreenSingModi) then
                   ScreenSingModi.Finish;
               end;

               Display.CheckOK:=True;
             end;
          1: begin
               Display.CheckOK:=False;
               Display.NextScreenWithCheck:=NIL;
             end;
          end;
          Visible:=False;
          Result := false;
        end;

      SDLK_DOWN:    InteractNext;
      SDLK_UP:      InteractPrev;

      SDLK_RIGHT: InteractNext;
      SDLK_LEFT: InteractPrev;
    end;
  end;
end;

constructor TScreenPopupCheck.Create;
var
  I:    integer;
begin
  inherited Create;

  AddBackground(Theme.CheckPopup.Background.Tex);

  AddButton(Theme.CheckPopup.Button1);
  if (Length(Button[0].Text) = 0) then
    AddButtonText(14, 20, 'Button 1');

  AddButton(Theme.CheckPopup.Button2);
  if (Length(Button[1].Text) = 0) then
    AddButtonText(14, 20, 'Button 2');

  AddText(Theme.CheckPopup.TextCheck);

  for I := 0 to High(Theme.CheckPopup.Static) do
    AddStatic(Theme.CheckPopup.Static[I]);

  for I := 0 to High(Theme.CheckPopup.Text) do
    AddText(Theme.CheckPopup.Text[I]);

  Interaction := 0;
end;

function TScreenPopupCheck.Draw: boolean;
begin
  inherited Draw;
end;

procedure TScreenPopupCheck.onShow;
begin

end;

procedure TScreenPopupCheck.ShowPopup(msg: String);
begin
  Interaction := 0; //Reset Interaction
  Visible := True;  //Set Visible

  Text[0].Text := Language.Translate(msg);

  Button[0].Visible := True;
  Button[1].Visible := True;

  Button[0].Text[0].Text := Language.Translate('SONG_MENU_YES');
  Button[1].Text[0].Text := Language.Translate('SONG_MENU_NO');
end;

// error popup

function TScreenPopupError.ParseInput(PressedKey: Cardinal; ScanCode: byte; PressedDown: Boolean): Boolean;
begin
  Result := true;
  If (PressedDown) Then
  begin // Key Down

    case PressedKey of
      SDLK_Q:
        begin
          Result := false;
        end;

      SDLK_ESCAPE,
      SDLK_BACKSPACE :
        begin
          Visible:=False;
          Result := false;
        end;

      SDLK_RETURN:
        begin
          Visible:=False;
          Result := false;
        end;

      SDLK_DOWN:    InteractNext;
      SDLK_UP:      InteractPrev;

      SDLK_RIGHT: InteractNext;
      SDLK_LEFT: InteractPrev;
    end;
  end;
end;

constructor TScreenPopupError.Create;
var
  I:    integer;
begin
  inherited Create;

  AddBackground(Theme.CheckPopup.Background.Tex);

  AddButton(Theme.ErrorPopup.Button1);
  if (Length(Button[0].Text) = 0) then
    AddButtonText(14, 20, 'Button 1');

  AddText(Theme.ErrorPopup.TextError);

  for I := 0 to High(Theme.ErrorPopup.Static) do
    AddStatic(Theme.ErrorPopup.Static[I]);

  for I := 0 to High(Theme.ErrorPopup.Text) do
    AddText(Theme.ErrorPopup.Text[I]);

  Interaction := 0;
end;

function TScreenPopupError.Draw: boolean;
begin
  inherited Draw;
end;

procedure TScreenPopupError.onShow;
begin

end;

procedure TScreenPopupError.onHide;
begin
end;

procedure TScreenPopupError.ShowPopup(msg: String);

begin
  Interaction := 0; //Reset Interaction
  Visible := True;  //Set Visible

  Text[0].Text:=msg;

  Button[0].Visible := True;

  Button[0].Text[0].Text := 'OK';
end;

// Help popup

function TScreenPopupHelp.ParseInput(PressedKey: Cardinal; ScanCode: byte; PressedDown: Boolean): Boolean;
var
  pos:  double;
begin
  Result := true;
  If (PressedDown) Then
  begin // Key Down
    pos := Help.GetScrollPos();
    case PressedKey of
      SDLK_TAB,
      SDLK_ESCAPE,
      SDLK_BACKSPACE :
        begin
          Visible:=False;
          Result := false;
        end;

      SDLK_RETURN:
        begin
          Visible:=False;
          Result := false;
        end;

      SDLK_DOWN:
        begin
          InteractNext;
          if pos<(1-step) then
            Help.SetScrollPos(pos+step)
          else if pos>0 then
            Help.SetScrollPos(1);
        end;
      SDLK_UP:
        begin
          InteractPrev;
          if pos>step then
            Help.SetScrollPos(pos-step)
          else if pos>0 then
            Help.SetScrollPos(0);
        end;

      SDLK_RIGHT: InteractNext;
      SDLK_LEFT: InteractPrev;
    end;
  end;
end;

constructor TScreenPopupHelp.Create;
begin
  inherited Create;

  AddButton(Theme.HelpPopup.Button1);
  if (Length(Button[0].Text) = 0) then
    AddButtonText(14, 20, 'Button 1');
  Button[0].Visible := false;
  Interaction := 0;
end;

function TScreenPopupHelp.Draw: boolean;
var
  abs:  real;
begin
  inherited Draw;
  if step<1 then
    abs := 20
  else
    abs := 5;

  //Background:
  glEnable(GL_BLEND);
  glbegin(gl_quads);
    glColor4f(0.2, 0.2, 0.2, 0.8); glVertex2f(Rect.left-5, Rect.top-5);
    glColor4f(0.2, 0.2, 0.2, 0.8); glVertex2f(Rect.right+abs, Rect.top-5);
    glColor4f(0.2, 0.2, 0.2, 0.8); glVertex2f(Rect.right+abs, Rect.bottom+5);
    glColor4f(0.2, 0.2, 0.2, 0.8); glVertex2f(Rect.left-5, Rect.bottom+5);
  glEnd;
  glDisable(GL_BLEND);
  glScissor(Rect.left-1, ScreenH-Rect.bottom-1, Rect.right-Rect.left+2, Rect.bottom-Rect.top+2);
  glScissor(round((Rect.left-1)*(ScreenW/Screens)/RenderW+(ScreenW/Screens)*(ScreenAct-1)),
    round((RenderH-Rect.bottom-1)*ScreenH/RenderH),
    round((Rect.right-Rect.left+2)*(ScreenW/Screens)/RenderW),
    round((Rect.bottom-Rect.top+2)*ScreenH/RenderH));
  glEnable(GL_SCISSOR_TEST);
  DrawTable();
  glDisable(GL_SCISSOR_TEST);
  if step<1 then
    DrawScroll(Rect.right+5, Rect.top, 10, Rect.bottom-Rect.top, Help.GetScrollPos(), barH);
end;

procedure TScreenPopupHelp.onShow;
begin
end;

procedure TScreenPopupHelp.onHide;
begin
end;

procedure TScreenPopupHelp.ShowPopup();
var
  I, J, K:  integer;
  line:     integer;
  SL:       TStringList;
  tempStr:  String;
  KeyEnd:   integer;
  Style:    integer;
  Size:     real;
  Italic:   boolean;
  fieldh:   integer;
  tline:    integer;
  countline:integer;

  procedure AddLine(l, i, fX, fY, tX, tY: integer);
  begin
    TextsGFX[l].lines[i].fX := fX;
    TextsGFX[l].lines[i].fY := fY;
    TextsGFX[l].lines[i].tX := tX;
    TextsGFX[l].lines[i].tY := tY;
  end;

  procedure NewLine(h, lines: integer);
  begin
    inc(line);
    tline := -1;
    SetLength(TextsGFX, line+1);
    TextsGFX[line].H := h;
    TextsGFX[line].Y := TextsGFX[line-1].Y + TextsGFX[line-1].H;
    SetLength(TextsGFX[line].lines, lines);
  end;

  procedure NewText(X, Y: integer);
  begin
    inc(tline);
    SetLength(TextsGFX[line].texts, tline+1);
    TextsGFX[line].texts[tline].X := X;
    TextsGFX[line].texts[tline].Y := Y;
    TextsGFX[line].texts[tline].Style := Style;
    TextsGFX[line].texts[tline].Size := Size;
    TextsGFX[line].texts[tline].Italic := Italic;
  end;

begin
  Interaction := 0; //Reset Interaction
  Visible := True;  //Set Visible

  SetLength(TextsGFX, 0);
  line := 0;
  tline := -1;

  Style := 1;
  Size := 7;
  Italic := false;

  SetFontStyle(Style);
  SetFontSize(Size);
  SetFontItalic(Italic);


  Rect.left := 25;
  Rect.right := 770;
  Rect.top := 25;
  Rect.bottom := 575;

  KeyEnd := round((Rect.right - Rect.left)*0.4);
  fieldh := 22;

  msg := Help.GetHelpStr();

  //Title
  SetLength(TextsGFX, 1);
  TextsGFX[line].H := round(fieldh/4);
  TextsGFX[line].Y := Rect.top;
  SetLength(TextsGFX[line].lines, 3);

  AddLine(line, 0, Rect.left, TextsGFX[line].Y, Rect.right, TextsGFX[line].Y);
  AddLine(line, 1, Rect.left, TextsGFX[line].Y, Rect.left, TextsGFX[line].Y + TextsGFX[line].H);
  AddLine(line, 2, Rect.right, TextsGFX[line].Y, Rect.right, TextsGFX[line].Y + TextsGFX[line].H);

  NewLine(fieldh*2, 2);
  AddLine(line, 0, Rect.left, TextsGFX[line].Y, Rect.left, TextsGFX[line].Y + TextsGFX[line].H);
  AddLine(line, 1, Rect.right, TextsGFX[line].Y, Rect.right, TextsGFX[line].Y + TextsGFX[line].H);

  NewText(Rect.left + 5, TextsGFX[line].Y + 2);
  TextsGFX[line].texts[tline].Size:=12;
  TextsGFX[line].texts[tline].text := Language.Translate('MSG_HELP_TITLE') + ': ' + msg.Title;

  NewLine(round(fieldh/4), 3);
  AddLine(line, 0, Rect.left, TextsGFX[line].Y, Rect.right, TextsGFX[line].Y);
  AddLine(line, 1, Rect.left, TextsGFX[line].Y, Rect.left, TextsGFX[line].Y + TextsGFX[line].H);
  AddLine(line, 2, Rect.right, TextsGFX[line].Y, Rect.right, TextsGFX[line].Y + TextsGFX[line].H);

  //Description
  Style := 1;
  SetFontStyle(Style);
  SL:=TStringList.Create;
  try
    ExtractStrings([' '], [], PChar(msg.Description), SL);
    if SL.Count>0 then
    begin
      NewLine(round(fieldh/4), 3);
      AddLine(line, 0, Rect.left, TextsGFX[line].Y, Rect.right, TextsGFX[line].Y);
      AddLine(line, 1, Rect.left, TextsGFX[line].Y, Rect.left, TextsGFX[line].Y + TextsGFX[line].H);
      AddLine(line, 2, Rect.right, TextsGFX[line].Y, Rect.right, TextsGFX[line].Y + TextsGFX[line].H);

      NewLine(fieldh, 2);
      AddLine(line, 0, Rect.left, TextsGFX[line].Y, Rect.left, TextsGFX[line].Y + TextsGFX[line].H);
      AddLine(line, 1, Rect.right, TextsGFX[line].Y, Rect.right, TextsGFX[line].Y + TextsGFX[line].H);

      NewText(Rect.left + 5, TextsGFX[line].Y + 2);
    end;
    tempStr := '';
    for I := 0 to SL.Count-1 do
    begin
      if glTextWidth(PChar(tempStr + SL[I] + ' ')) <= (Rect.right - Rect.left - 10) then
      begin
        if I<SL.Count-1 then
          tempStr := tempStr + SL[I] + ' '
        else
          tempStr := tempStr + SL[I];
        TextsGFX[line].texts[tline].text := tempStr;
      end else
      begin
        TextsGFX[line].texts[tline].text := tempStr;
        NewLine(fieldh, 2);
        AddLine(line, 0, Rect.left, TextsGFX[line].Y, Rect.left, TextsGFX[line].Y + TextsGFX[line].H);
        AddLine(line, 1, Rect.right, TextsGFX[line].Y, Rect.right, TextsGFX[line].Y + TextsGFX[line].H);

        NewText(Rect.left + 5, TextsGFX[line].Y + 2);

        if I<SL.Count-1 then
          tempStr := SL[I] + ' '
        else
          tempStr := SL[I];
        TextsGFX[line].texts[tline].text := tempStr;
      end;
    end;
  Finally
    SL.Free;
    if Length(msg.Subs)<1 then
    begin
      NewLine(round(fieldh/4), 3);
      AddLine(line, 0, Rect.left, TextsGFX[line].Y + TextsGFX[line].H , Rect.right, TextsGFX[line].Y + TextsGFX[line].H);
      AddLine(line, 1, Rect.left, TextsGFX[line].Y, Rect.left, TextsGFX[line].Y + TextsGFX[line].H);
      AddLine(line, 2, Rect.right, TextsGFX[line].Y, Rect.right, TextsGFX[line].Y + TextsGFX[line].H);
    end else
    begin
      NewLine(round(fieldh/4), 2);
      AddLine(line, 0, Rect.left, TextsGFX[line].Y, Rect.left, TextsGFX[line].Y + TextsGFX[line].H);
      AddLine(line, 1, Rect.right, TextsGFX[line].Y, Rect.right, TextsGFX[line].Y + TextsGFX[line].H);
    end;
  end;

  //Subs
  for K := 0 to Length(msg.Subs) - 1 do
  begin
    //Sub title
    Style := 1;
    SetFontStyle(Style);
    Size := 7;
    SetFontSize(Size);

    tempStr := '';
    NewLine(round(fieldh/2), 2);
    AddLine(line, 0, Rect.left, TextsGFX[line].Y, Rect.left, TextsGFX[line].Y + TextsGFX[line].H);
    AddLine(line, 1, Rect.right, TextsGFX[line].Y, Rect.right, TextsGFX[line].Y + TextsGFX[line].H);

    NewLine(round(fieldh), 2);
    AddLine(line, 0, Rect.left, TextsGFX[line].Y, Rect.left, TextsGFX[line].Y + TextsGFX[line].H);
    AddLine(line, 1, Rect.right, TextsGFX[line].Y, Rect.right, TextsGFX[line].Y + TextsGFX[line].H);

    NewText(Rect.left+5, TextsGFX[line].Y + 2);
    TextsGFX[line].texts[tline].text := msg.Subs[K].title+':';

    //text
    Style := 1;
    SetFontStyle(Style);
    Size := 7;
    SetFontSize(Size);


    for J := 0 to length(msg.Subs[K].text) - 1 do
    begin
      NewLine(fieldh, 2);
      AddLine(line, 0, Rect.left, TextsGFX[line].Y, Rect.left, TextsGFX[line].Y + TextsGFX[line].H);
      AddLine(line, 1, Rect.right, TextsGFX[line].Y, Rect.right, TextsGFX[line].Y + TextsGFX[line].H);

      SL:=TStringList.Create;
      try
        ExtractStrings([' '], [], PChar(msg.Subs[K].text[J]), SL);

        NewText(Rect.left + 5, TextsGFX[line].Y + 2);
        tempStr := '';
        for I := 0 to SL.Count-1 do
        begin
          if glTextWidth(PChar(tempStr + SL[I] + ' ')) <= (Rect.right - Rect.left - 10) then
          begin
            if I<SL.Count-1 then
              tempStr := tempStr + SL[I] + ' '
            else
              tempStr := tempStr + SL[I];
            TextsGFX[line].texts[tline].text := tempStr;
          end else
          begin
            TextsGFX[line].texts[tline].text := tempStr;

            NewLine(fieldh, 2);
            AddLine(line, 0, Rect.left, TextsGFX[line].Y, Rect.left, TextsGFX[line].Y + TextsGFX[line].H);
            AddLine(line, 1, Rect.right, TextsGFX[line].Y, Rect.right, TextsGFX[line].Y + TextsGFX[line].H);

            NewText(Rect.left + 5, TextsGFX[line].Y + 2);

            if I<SL.Count-1 then
              tempStr := SL[I] + ' '
            else
              tempStr := SL[I];
            TextsGFX[line].texts[tline].text := tempStr;
          end;
        end;
      Finally
        SL.Free;
      end;
    end;

    if K<Length(msg.Subs) - 1 then
    begin
      NewLine(round(fieldh/4), 2);
      AddLine(line, 0, Rect.left, TextsGFX[line].Y, Rect.left, TextsGFX[line].Y + TextsGFX[line].H);
      AddLine(line, 1, Rect.right, TextsGFX[line].Y, Rect.right, TextsGFX[line].Y + TextsGFX[line].H);
    end else
    begin
      NewLine(round(fieldh/2), 3);
      AddLine(line, 0, Rect.left, TextsGFX[line].Y + TextsGFX[line].H , Rect.right, TextsGFX[line].Y + TextsGFX[line].H);
      AddLine(line, 1, Rect.left, TextsGFX[line].Y, Rect.left, TextsGFX[line].Y + TextsGFX[line].H);
      AddLine(line, 2, Rect.right, TextsGFX[line].Y, Rect.right, TextsGFX[line].Y + TextsGFX[line].H);
    end;
  end;

  //Sections
  for K := 0 to Length(msg.Sections) - 1 do
  begin
    //Section title
    Style := 1;
    SetFontStyle(Style);
    Size := 9;
    SetFontSize(Size);

    tempStr := '';
    NewLine(round(fieldh/2), 2);
    AddLine(line, 0, Rect.left, TextsGFX[line].Y, Rect.left, TextsGFX[line].Y + TextsGFX[line].H);
    AddLine(line, 1, Rect.right, TextsGFX[line].Y, Rect.right, TextsGFX[line].Y + TextsGFX[line].H);

    NewLine(round(fieldh*1.4), 2);
    AddLine(line, 0, Rect.left, TextsGFX[line].Y, Rect.left, TextsGFX[line].Y + TextsGFX[line].H);
    AddLine(line, 1, Rect.right, TextsGFX[line].Y, Rect.right, TextsGFX[line].Y + TextsGFX[line].H);

    tempStr := msg.Sections[K].name;
    NewText(Rect.left + round((Rect.right - Rect.left - 10)/2 - glTextWidth((PChar(tempStr)))/2), TextsGFX[line].Y + 2);
    TextsGFX[line].texts[tline].text := tempStr;

    NewLine(round(fieldh/2), 3);
    AddLine(line, 0, Rect.left, TextsGFX[line].Y + TextsGFX[line].H , Rect.right, TextsGFX[line].Y + TextsGFX[line].H);
    AddLine(line, 1, Rect.left, TextsGFX[line].Y, Rect.left, TextsGFX[line].Y + TextsGFX[line].H);
    AddLine(line, 2, Rect.right, TextsGFX[line].Y, Rect.right, TextsGFX[line].Y + TextsGFX[line].H);

    Style := 1;
    SetFontStyle(Style);
    Size := 7;
    SetFontSize(Size);
    //keys
    for J := 0 to Length(msg.Sections[K].Keys) - 1 do
    begin
      NewLine(fieldh, 3);
      AddLine(line, 0, Rect.left, TextsGFX[line].Y, Rect.left, TextsGFX[line].Y + TextsGFX[line].H);
      AddLine(line, 1, KeyEnd, TextsGFX[line].Y, KeyEnd, TextsGFX[line].Y + TextsGFX[line].H);
      AddLine(line, 2, Rect.right, TextsGFX[line].Y, Rect.right, TextsGFX[line].Y + TextsGFX[line].H);

      countline := 1;
      NewText(Rect.left + 5, TextsGFX[line].Y + 2);
      tempStr := '';
      for I := 0 to Length(msg.Sections[K].Keys[J].Key) - 1 do
      begin
        if glTextWidth(PChar(tempStr + msg.Sections[K].Keys[J].Key[I] + '+')) <= (KeyEnd - Rect.left - 10) then
        begin
          if I<Length(msg.Sections[K].Keys[J].Key)-1 then
            tempStr := tempStr + msg.Sections[K].Keys[J].Key[I] + '+'
          else
            tempStr := tempStr + msg.Sections[K].Keys[J].Key[I];
          TextsGFX[line].texts[tline].text := tempStr;
        end else
        begin
          TextsGFX[line].texts[tline].text := tempStr;
          NewLine(fieldh, 3);
          AddLine(line, 0, Rect.left, TextsGFX[line].Y, Rect.left, TextsGFX[line].Y + TextsGFX[line].H);
          AddLine(line, 1, KeyEnd, TextsGFX[line].Y, KeyEnd, TextsGFX[line].Y + TextsGFX[line].H);
          AddLine(line, 2, Rect.right, TextsGFX[line].Y, Rect.right, TextsGFX[line].Y + TextsGFX[line].H);

          NewText(Rect.left + 5, TextsGFX[line].Y + 2);

          if I<Length(msg.Sections[K].Keys[J].Key)-1 then
            tempStr := msg.Sections[K].Keys[J].Key[I] + '+'
          else
            tempStr := msg.Sections[K].Keys[J].Key[I];
          TextsGFX[line].texts[tline].text := tempStr;
          inc(countline);
        end;
      end;

      //key-description
      SL:=TStringList.Create;
      try
        ExtractStrings([' '], [], PChar(msg.Sections[K].KeyDescription[J]), SL);
        line := line - countline + 1;
        tline := Length(TextsGFX[line].texts) -1;

        NewText(KeyEnd + 5, TextsGFX[line].Y + 2);
        tempStr := '';
        for I := 0 to SL.Count-1 do
        begin
          if glTextWidth(PChar(tempStr + SL[I] + ' ')) <= (Rect.right - KeyEnd - 10) then
          begin
            if I<SL.Count-1 then
              tempStr := tempStr + SL[I] + ' '
            else
              tempStr := tempStr + SL[I];
            TextsGFX[line].texts[tline].text := tempStr;
          end else
          begin
            TextsGFX[line].texts[tline].text := tempStr;
            if countline<2 then
            begin
              NewLine(fieldh, 3);
              AddLine(line, 0, Rect.left, TextsGFX[line].Y, Rect.left, TextsGFX[line].Y + TextsGFX[line].H);
              AddLine(line, 1, KeyEnd, TextsGFX[line].Y, KeyEnd, TextsGFX[line].Y + TextsGFX[line].H);
              AddLine(line, 2, Rect.right, TextsGFX[line].Y, Rect.right, TextsGFX[line].Y + TextsGFX[line].H);
            end else
            begin
              dec(countline);
              inc(line);
              tline := Length(TextsGFX[line].texts) -1;
            end;

            NewText(KeyEnd + 5, TextsGFX[line].Y + 2);

            if I<SL.Count-1 then
              tempStr := SL[I] + ' '
            else
              tempStr := SL[I];
            TextsGFX[line].texts[tline].text := tempStr;
          end;
        end;
      Finally
        SL.Free;
        line := line + countline -1;
        NewLine(round(fieldh/4), 4);
        AddLine(line, 0, Rect.left, TextsGFX[line].Y, Rect.left, TextsGFX[line].Y + TextsGFX[line].H);
        AddLine(line, 1, KeyEnd, TextsGFX[line].Y, KeyEnd, TextsGFX[line].Y + TextsGFX[line].H);
        AddLine(line, 2, Rect.right, TextsGFX[line].Y, Rect.right, TextsGFX[line].Y + TextsGFX[line].H);
        AddLine(line, 3, Rect.left, TextsGFX[line].Y+TextsGFX[line].H, Rect.right, TextsGFX[line].Y + TextsGFX[line].H);
      end;
    end;
  end;

  max_high := (TextsGFX[Length(TextsGFX)-1].Y + TextsGFX[Length(TextsGFX)-1].H);

  if max_high=0 then
    max_high:=1.0; //TODO error.log!
  if max_high<=Rect.bottom-Rect.top then
  begin
    barH := 1;
    step := 1;
  end
  else
  begin
    barH := (Rect.bottom-Rect.top)/max_high;
    step := barH/(1/barH);
  end;
end;

procedure TScreenPopupHelp.DrawTable();
var
  I, J:integer;
  maxh:   integer;
  h, offset:      integer;
begin

  maxh := 2*RenderH+Rect.Bottom;
  h := 0;

  offset := round(Help.GetScrollPos()*(max_high-Rect.Bottom));

  I := 0;
  while (I<Length(TextsGFX)) and (h<maxh) do
  begin
    if (TextsGFX[I].Y >= offset-20) then
    begin
      for J := 0 to Length(TextsGFX[I].lines) - 1 do
        DrawLine(I, J, offset);
      for J := 0 to Length(TextsGFX[I].texts) - 1 do
        DrawText(I, J, offset);

      h := h + TextsGFX[I].H;
    end;
    inc(I);
  end;
end;

procedure TScreenPopupHelp.DrawLine(line, index, Y: integer);
begin
  glColor4f(1, 1, 1, 1);
  glLineWidth(2);
  glBegin(GL_LINES);
    glVertex2f(TextsGFX[line].lines[index].fX, TextsGFX[line].lines[index].fY - Y);
    glVertex2f(TextsGFX[line].lines[index].tX, TextsGFX[line].lines[index].tY - Y);
  glEnd;
end;

procedure TScreenPopupHelp.DrawText(line, index, Y: integer);
begin
  glColor4f(1, 1, 1, 1);
  SetFontStyle(TextsGFX[line].texts[index].Style);
  SetFontItalic(TextsGFX[line].texts[index].Italic);
  SetFontSize(TextsGFX[line].texts[index].Size);
  SetFontPos (TextsGFX[line].texts[index].X, TextsGFX[line].texts[index].Y - Y);
  glPrint(PChar(TextsGFX[line].texts[index].text));
end;

procedure TScreenPopupHelp.DrawScroll(X, Y, W, H: integer; pos, len: double);
var
  fY, tY: double;
begin
  glColor4f(1, 1, 1, 1);

  glLineWidth(1);
  glBegin(GL_LINE_LOOP);
    glVertex2f(X, Y);
    glVertex2f(X+W, Y);
    glVertex2f(X+W, Y+H);
    glVertex2f(X, Y+H);
  glEnd;

  fY := Y+(H-H*len)*Pos;
  tY := fY+H*len;
  if tY+0.001>=Y+H then
    tY := Y+H;

  glBegin(GL_QUADS);
    glVertex2f(X, fY);
    glVertex2f(X+W, fY);
    glVertex2f(X+W, tY);
    glVertex2f(X, tY);
  glEnd;
end;

end.