DEADSOFTWARE

Holmes: gxlib API change
[d2df-sdl.git] / src / gx / gh_ui.pas
index a8593adacd9a4111c9e29fe2d9ae5b162094f131..85a4a5ff67af8b0dfc792556119c218d9fbbb749 100644 (file)
@@ -37,6 +37,7 @@ type
 
   private
     mParent: THControl;
+    mId: AnsiString;
     mX, mY: Integer;
     mWidth, mHeight: Integer;
     mFrameWidth, mFrameHeight: Integer;
@@ -72,12 +73,13 @@ type
     procedure blurred (); virtual;
 
     //WARNING! do not call scissor functions outside `.draw*()` API!
-    // reset scissor to whole control
-    procedure resetScissor ();
-    // set scissor to this internal rect (in local coords)
+    // set scissor to this rect (in local coords)
     procedure setScissor (lx, ly, lw, lh: Integer);
+    // reset scissor to whole control
+    procedure resetScissor (fullArea: Boolean); inline; // "full area" means "with frame"
 
     // DO NOT USE!
+    // set scissor to this rect (in global coords)
     procedure setScissorGLInternal (x, y, w, h: Integer);
 
   public
@@ -143,6 +145,7 @@ type
     function parseAnyAlign (par: TTextParser): Integer;
     function parseHAlign (par: TTextParser): Integer;
     function parseVAlign (par: TTextParser): Integer;
+    function parseOrientation (const prname: AnsiString; par: TTextParser): Boolean;
     procedure parseTextAlign (par: TTextParser; var h, v: Integer);
     procedure parseChildren (par: TTextParser); // par should be on '{'; final '}' is eaten
 
@@ -159,15 +162,14 @@ type
 
   public
     constructor Create ();
-    constructor Create (aparent: THControl);
-    constructor Create (ax, ay, aw, ah: Integer; aparent: THControl=nil);
+    constructor Create (ax, ay, aw, ah: Integer);
     destructor Destroy (); override;
 
     // `sx` and `sy` are screen coordinates
-    procedure drawControl (sx, sy: Integer); virtual;
+    procedure drawControl (gx, gy: Integer); virtual;
 
     // called after all children drawn
-    procedure drawControlPost (sx, sy: Integer); virtual;
+    procedure drawControlPost (gx, gy: Integer); virtual;
 
     procedure draw (); virtual;
 
@@ -175,7 +177,9 @@ type
 
     // returns `true` if global coords are inside this control
     function toLocal (var x, y: Integer): Boolean;
+    function toLocal (gx, gy: Integer; out x, y: Integer): Boolean; inline;
     procedure toGlobal (var x, y: Integer);
+    procedure toGlobal (lx, ly: Integer; out x, y: Integer); inline;
 
     // x and y are global coords
     function controlAtXY (x, y: Integer): THControl;
@@ -191,6 +195,7 @@ type
     procedure appendChild (ctl: THControl); virtual;
 
   public
+    property id: AnsiString read mId;
     property x0: Integer read mX;
     property y0: Integer read mY;
     property height: Integer read mHeight;
@@ -226,8 +231,8 @@ type
     procedure centerInScreen ();
 
     // `sx` and `sy` are screen coordinates
-    procedure drawControl (sx, sy: Integer); override;
-    procedure drawControlPost (sx, sy: Integer); override;
+    procedure drawControl (gx, gy: Integer); override;
+    procedure drawControlPost (gx, gy: Integer); override;
 
     function keyEvent (var ev: THKeyEvent): Boolean; override; // returns `true` if event was eaten
     function mouseEvent (var ev: THMouseEvent): Boolean; override; // returns `true` if event was eaten
@@ -250,12 +255,12 @@ type
     mItems: array of TItem;
 
   public
-    constructor Create (ax, ay: Integer; aparent: THControl=nil);
+    constructor Create (ax, ay: Integer);
     destructor Destroy (); override;
 
     procedure appendItem (const atext: AnsiString; acentered: Boolean=false; ahline: Boolean=false);
 
-    procedure drawControl (sx, sy: Integer); override;
+    procedure drawControl (gx, gy: Integer); override;
 
     function mouseEvent (var ev: THMouseEvent): Boolean; override;
     function keyEvent (var ev: THKeyEvent): Boolean; override;
@@ -276,12 +281,12 @@ type
     mCurIndex: Integer;
 
   public
-    constructor Create (ax, ay: Integer; aparent: THControl=nil);
+    constructor Create (ax, ay: Integer);
     destructor Destroy (); override;
 
     procedure appendItem (const atext: AnsiString; bv: PBoolean; aaction: TActionCB=nil);
 
-    procedure drawControl (sx, sy: Integer); override;
+    procedure drawControl (gx, gy: Integer); override;
 
     function mouseEvent (var ev: THMouseEvent): Boolean; override;
     function keyEvent (var ev: THKeyEvent): Boolean; override;
@@ -294,12 +299,11 @@ type
     mCaption: AnsiString;
 
   public
-    constructor Create (ahoriz: Boolean; aparent: THControl=nil);
-    //destructor Destroy (); override;
+    constructor Create (ahoriz: Boolean);
 
     function parseProperty (const prname: AnsiString; par: TTextParser): Boolean; override;
 
-    procedure drawControl (sx, sy: Integer); override;
+    procedure drawControl (gx, gy: Integer); override;
 
     function mouseEvent (var ev: THMouseEvent): Boolean; override;
     function keyEvent (var ev: THKeyEvent): Boolean; override;
@@ -307,15 +311,43 @@ type
 
   THCtlHBox = class(THCtlBox)
   public
-    constructor Create (aparent: THControl=nil);
+    procedure AfterConstruction (); override; // so it will be correctly initialized when created from parser
   end;
 
   THCtlVBox = class(THCtlBox)
   public
-    constructor Create (aparent: THControl=nil);
+    procedure AfterConstruction (); override; // so it will be correctly initialized when created from parser
+  end;
+
+  // ////////////////////////////////////////////////////////////////////// //
+  THCtlSpan = class(THControl)
+  public
+    procedure AfterConstruction (); override; // so it will be correctly initialized when created from parser
+
+    function parseProperty (const prname: AnsiString; par: TTextParser): Boolean; override;
+
+    procedure drawControl (gx, gy: Integer); override;
+  end;
+
+  // ////////////////////////////////////////////////////////////////////// //
+  THCtlLine = class(THControl)
+  public
+    function parseProperty (const prname: AnsiString; par: TTextParser): Boolean; override;
+
+    procedure drawControl (gx, gy: Integer); override;
+  end;
+
+  THCtlHLine = class(THCtlLine)
+  public
+    procedure AfterConstruction (); override; // so it will be correctly initialized when created from parser
   end;
 
+  THCtlVLine = class(THCtlLine)
+  public
+    procedure AfterConstruction (); override; // so it will be correctly initialized when created from parser
+  end;
 
+  // ////////////////////////////////////////////////////////////////////// //
   THCtlTextLabel = class(THControl)
   private
     mText: AnsiString;
@@ -323,12 +355,13 @@ type
     mVAlign: Integer; // -1: top; 0: center; 1: bottom; default: center
 
   public
-    constructor Create (const atext: AnsiString; aparent: THControl=nil);
-    //destructor Destroy (); override;
+    constructor Create (const atext: AnsiString);
+
+    procedure AfterConstruction (); override; // so it will be correctly initialized when created from parser
 
     function parseProperty (const prname: AnsiString; par: TTextParser): Boolean; override;
 
-    procedure drawControl (sx, sy: Integer); override;
+    procedure drawControl (gx, gy: Integer); override;
 
     function mouseEvent (var ev: THMouseEvent): Boolean; override;
     function keyEvent (var ev: THKeyEvent): Boolean; override;
@@ -412,11 +445,9 @@ begin
     lay.setup(ctl);
     //lay.layout();
 
-    writeln('============================');
-    lay.dumpFlat();
+    //writeln('============================'); lay.dumpFlat();
 
-    writeln('=== initial ===');
-    lay.dump();
+    //writeln('=== initial ==='); lay.dump();
 
     //lay.calcMaxSizeInternal(0);
     {
@@ -430,8 +461,7 @@ begin
     }
 
     lay.layout();
-    writeln('=== final ===');
-    lay.dump();
+    //writeln('=== final ==='); lay.dump();
 
   finally
     FreeAndNil(lay);
@@ -459,9 +489,7 @@ begin
   begin
     for f := High(uiTopList) downto 0 do
     begin
-      lx := ev.x;
-      ly := ev.y;
-      if uiTopList[f].toLocal(lx, ly) then
+      if uiTopList[f].toLocal(ev.x, ev.y, lx, ly) then
       begin
         result := true;
         if uiTopList[f].mEnabled and (f <> High(uiTopList)) then
@@ -605,7 +633,8 @@ begin
   mDrawShadow := false;
   actionCB := nil;
   // layouter interface
-  mDefSize := TLaySize.Create(64, 8); // default size
+  //mDefSize := TLaySize.Create(64, 8); // default size
+  mDefSize := TLaySize.Create(0, 0); // default size
   mMaxSize := TLaySize.Create(-1, -1); // maximum size
   mFlex := 0;
   mHoriz := true;
@@ -618,9 +647,9 @@ begin
 end;
 
 
-constructor THControl.Create (ax, ay, aw, ah: Integer; aparent: THControl=nil);
+constructor THControl.Create (ax, ay, aw, ah: Integer);
 begin
-  Create(aparent);
+  Create();
   mX := ax;
   mY := ay;
   mWidth := aw;
@@ -628,13 +657,6 @@ begin
 end;
 
 
-constructor THControl.Create (aparent: THControl);
-begin
-  Create();
-  mParent := aparent;
-end;
-
-
 destructor THControl.Destroy ();
 var
   f, c: Integer;
@@ -685,6 +707,7 @@ begin
 end;
 
 procedure THControl.setActualSizePos (constref apos: TLayPos; constref asize: TLaySize); inline; begin
+  //writeln(self.className, '; pos=', apos.toString, '; size=', asize.toString);
   if (mParent <> nil) then
   begin
     mX := apos.x;
@@ -721,10 +744,10 @@ var
   ech: AnsiChar = ')';
 begin
   if (par.eatDelim('[')) then ech := ']' else par.expectDelim('(');
-  result.h := par.expectInt();
-  par.eatDelim(','); // optional comma
   result.w := par.expectInt();
   par.eatDelim(','); // optional comma
+  result.h := par.expectInt();
+  par.eatDelim(','); // optional comma
   par.expectDelim(ech);
 end;
 
@@ -830,6 +853,21 @@ begin
   if not wasV and not wasH then par.error('invalid align value');
 end;
 
+function THControl.parseOrientation (const prname: AnsiString; par: TTextParser): Boolean;
+begin
+  if (strEquCI1251(prname, 'orientation')) or (strEquCI1251(prname, 'orient')) then
+  begin
+         if (par.eatIdOrStr('horizontal', false)) or (par.eatIdOrStr('horiz', false)) then mHoriz := true
+    else if (par.eatIdOrStr('vertical', false)) or (par.eatIdOrStr('vert', false)) then mHoriz := false
+    else par.error('`horizontal` or `vertical` expected');
+    result := true;
+  end
+  else
+  begin
+    result := false;
+  end;
+end;
+
 // par should be on '{'; final '}' is eaten
 procedure THControl.parseProperties (par: TTextParser);
 var
@@ -838,7 +876,7 @@ begin
   if (not par.eatDelim('{')) then exit;
   while (not par.eatDelim('}')) do
   begin
-    if (par.tokType <> par.TTId) and (par.tokType <> par.TTStr) then par.error('property name expected');
+    if (not par.isIdOrStr) then par.error('property name expected');
     pn := par.tokStr;
     par.skipToken();
     par.eatDelim(':'); // optional
@@ -856,13 +894,14 @@ begin
   par.expectDelim('{');
   while (not par.eatDelim('}')) do
   begin
-    if (par.tokType <> par.TTId) then par.error('control name expected');
+    if (not par.isIdOrStr) then par.error('control name expected');
     cc := findCtlClass(par.tokStr);
     if (cc = nil) then par.errorfmt('unknown control name: ''%s''', [par.tokStr]);
     //writeln('children for <', par.tokStr, '>: <', cc.className, '>');
     par.skipToken();
     par.eatDelim(':'); // optional
-    ctl := cc.Create(nil);
+    ctl := cc.Create();
+    //writeln('  mHoriz=', ctl.mHoriz);
     try
       ctl.parseProperties(par);
     except
@@ -879,10 +918,16 @@ end;
 function THControl.parseProperty (const prname: AnsiString; par: TTextParser): Boolean;
 begin
   result := true;
+  if (strEquCI1251(prname, 'id')) then begin mId := par.expectStrOrId(true); exit; end; // allow empty strings
   if (strEquCI1251(prname, 'flex')) then begin flex := par.expectInt(); exit; end;
   // sizes
-  if (strEquCI1251(prname, 'defsize')) then begin mDefSize := parseSize(par); exit; end;
+  if (strEquCI1251(prname, 'defsize')) or (strEquCI1251(prname, 'size')) then begin mDefSize := parseSize(par); exit; end;
   if (strEquCI1251(prname, 'maxsize')) then begin mMaxSize := parseSize(par); exit; end;
+  if (strEquCI1251(prname, 'defwidth')) or (strEquCI1251(prname, 'width')) then begin mDefSize.w := par.expectInt(); exit; end;
+  if (strEquCI1251(prname, 'defheight')) or (strEquCI1251(prname, 'height')) then begin mDefSize.h := par.expectInt(); exit; end;
+  if (strEquCI1251(prname, 'maxwidth')) then begin mMaxSize.w := par.expectInt(); exit; end;
+  if (strEquCI1251(prname, 'maxheight')) then begin mMaxSize.h := par.expectInt(); exit; end;
+  // flags
   if (strEquCI1251(prname, 'wrap')) then begin mCanWrap := parseBool(par); exit; end;
   if (strEquCI1251(prname, 'linestart')) then begin mLineStart := parseBool(par); exit; end;
   if (strEquCI1251(prname, 'expand')) then begin mExpand := parseBool(par); exit; end;
@@ -1002,6 +1047,12 @@ begin
   result := (x >= 0) and (y >= 0) and (x < mWidth) and (y < mHeight);
 end;
 
+function THControl.toLocal (gx, gy: Integer; out x, y: Integer): Boolean; inline;
+begin
+  x := gx;
+  y := gy;
+  result := toLocal(x, y);
+end;
 
 procedure THControl.toGlobal (var x, y: Integer);
 var
@@ -1016,6 +1067,13 @@ begin
   end;
 end;
 
+procedure THControl.toGlobal (lx, ly: Integer; out x, y: Integer); inline;
+begin
+  x := lx;
+  y := ly;
+  toGlobal(x, y);
+end;
+
 
 // x and y are global coords
 function THControl.controlAtXY (x, y: Integer): THControl;
@@ -1025,9 +1083,7 @@ var
 begin
   result := nil;
   if (not mEnabled) or (mWidth < 1) or (mHeight < 1) then exit;
-  lx := x;
-  ly := y;
-  if not toLocal(lx, ly) then exit;
+  if not toLocal(x, y, lx, ly) then exit;
   for f := High(mChildren) downto 0 do
   begin
     result := mChildren[f].controlAtXY(x, y);
@@ -1172,6 +1228,7 @@ begin
 end;
 
 
+// ////////////////////////////////////////////////////////////////////////// //
 procedure THControl.setScissorGLInternal (x, y, w, h: Integer);
 begin
   if not scallowed then exit;
@@ -1179,81 +1236,83 @@ begin
   y := trunc(y*gh_ui_scale);
   w := trunc(w*gh_ui_scale);
   h := trunc(h*gh_ui_scale);
-  //y := gWinSizeY-(y+h);
-  scis.setRect(x, y, w, h);
+  scis.combineRect(x, y, w, h);
 end;
 
-
-procedure THControl.resetScissor ();
+procedure THControl.setScissor (lx, ly, lw, lh: Integer);
 var
-  x, y: Integer;
+  gx, gy: Integer;
+  //ox, oy, ow, oh: Integer;
 begin
   if not scallowed then exit;
-  x := 0;
-  y := 0;
-  toGlobal(x, y);
-  setScissorGLInternal(x, y, mWidth, mHeight);
+  //ox := lx; oy := ly; ow := lw; oh := lh;
+  if not intersectRect(lx, ly, lw, lh, 0, 0, mWidth, mHeight) then
+  begin
+    //writeln('oops: <', self.className, '>: old=(', ox, ',', oy, ')-[', ow, ',', oh, ']');
+    glScissor(0, 0, 0, 0);
+    exit;
+  end;
+  toGlobal(lx, ly, gx, gy);
+  setScissorGLInternal(gx, gy, lw, lh);
 end;
 
-
-procedure THControl.setScissor (lx, ly, lw, lh: Integer);
-var
-  x, y: Integer;
+procedure THControl.resetScissor (fullArea: Boolean); inline;
 begin
   if not scallowed then exit;
-  if not intersectRect(lx, ly, lw, lh, 0, 0, mWidth, mHeight) then begin glScissor(0, 0, 0, 0); exit; end;
-  x := lx;
-  y := ly;
-  toGlobal(x, y);
-  setScissorGLInternal(x, y, lw, lh);
+  if (fullArea) then
+  begin
+    setScissor(0, 0, mWidth, mHeight);
+  end
+  else
+  begin
+    setScissor(mFrameWidth, mFrameHeight, mWidth-mFrameWidth*2, mHeight-mFrameHeight*2);
+  end;
 end;
 
 
+// ////////////////////////////////////////////////////////////////////////// //
 procedure THControl.draw ();
 var
   f: Integer;
-  x, y: Integer;
+  gx, gy: Integer;
 begin
   if (mWidth < 1) or (mHeight < 1) then exit;
-  x := 0;
-  y := 0;
-  toGlobal(x, y);
+  toGlobal(0, 0, gx, gy);
   //conwritefln('[%s]: (%d,%d)-(%d,%d)  (%d,%d)', [ClassName, mX, mY, mWidth, mHeight, x, y]);
 
   scis.save(true); // scissoring enabled
   try
-    //glEnable(GL_SCISSOR_TEST);
     scallowed := true;
-    resetScissor();
-    drawControl(x, y);
-    if (mFrameWidth <> 0) or (mFrameHeight <> 0) then setScissor(mFrameWidth, mFrameHeight, mWidth-mFrameWidth*2, mHeight-mFrameHeight*2);
+    resetScissor(true); // full area
+    drawControl(gx, gy);
+    resetScissor(false); // client area
     for f := 0 to High(mChildren) do mChildren[f].draw();
-    if (mFrameWidth <> 0) or (mFrameHeight <> 0) then resetScissor();
-    drawControlPost(x, y);
+    resetScissor(true); // full area
+    drawControlPost(gx, gy);
   finally
     scis.restore();
     scallowed := false;
   end;
 end;
 
-
-procedure THControl.drawControl (sx, sy: Integer);
+procedure THControl.drawControl (gx, gy: Integer);
 begin
-  if (mParent = nil) then darkenRect(sx, sy, mWidth, mHeight, 64);
+  if (mParent = nil) then darkenRect(gx, gy, mWidth, mHeight, 64);
 end;
 
-
-procedure THControl.drawControlPost (sx, sy: Integer);
+procedure THControl.drawControlPost (gx, gy: Integer);
 begin
+  // shadow
   if mDrawShadow and (mWidth > 0) and (mHeight > 0) then
   begin
-    setScissorGLInternal(sx+8, sy+8, mWidth, mHeight);
-    darkenRect(sx+mWidth, sy+8, 8, mHeight, 128);
-    darkenRect(sx+8, sy+mHeight, mWidth-8, 8, 128);
+    setScissorGLInternal(gx+8, gy+8, mWidth, mHeight);
+    darkenRect(gx+mWidth, gy+8, 8, mHeight, 128);
+    darkenRect(gx+8, gy+mHeight, mWidth-8, 8, 128);
   end;
 end;
 
 
+// ////////////////////////////////////////////////////////////////////////// //
 function THControl.mouseEvent (var ev: THMouseEvent): Boolean;
 var
   ctl: THControl;
@@ -1328,7 +1387,7 @@ end;
 // ////////////////////////////////////////////////////////////////////////// //
 constructor THTopWindow.Create (const atitle: AnsiString; ax, ay: Integer; aw: Integer=-1; ah: Integer=-1);
 begin
-  inherited Create(ax, ay, aw, ah, nil);
+  inherited Create(ax, ay, aw, ah);
   mFrameWidth := 8;
   mFrameHeight := 8;
   mTitle := atitle;
@@ -1360,14 +1419,7 @@ begin
     result := true;
     exit;
   end;
-  if (strEquCI1251(prname, 'orientation')) or (strEquCI1251(prname, 'orient')) then
-  begin
-         if (par.eatIdOrStr('horizontal', false)) or (par.eatIdOrStr('horiz', false)) then mHoriz := true
-    else if (par.eatIdOrStr('vertical', false)) or (par.eatIdOrStr('vert', false)) then mHoriz := false
-    else par.error('`horizontal` or `vertical` expected');
-    result := true;
-    exit;
-  end;
+  if (parseOrientation(prname, par)) then begin result := true; exit; end;
   result := inherited parseProperty(prname, par);
 end;
 
@@ -1382,13 +1434,13 @@ begin
 end;
 
 
-procedure THTopWindow.drawControl (sx, sy: Integer);
+procedure THTopWindow.drawControl (gx, gy: Integer);
 begin
-  fillRect(sx, sy, mWidth, mHeight, 0, 0, 128);
+  fillRect(gx, gy, mWidth, mHeight, TGxRGBA.Create(0, 0, 128));
 end;
 
 
-procedure THTopWindow.drawControlPost (sx, sy: Integer);
+procedure THTopWindow.drawControlPost (gx, gy: Integer);
 const r = 255;
 const g = 255;
 const b = 255;
@@ -1397,26 +1449,26 @@ var
 begin
   if mDragging then
   begin
-    drawRectUI(mX+4, mY+4, mWidth-8, mHeight-8, r, g, b);
+    drawRectUI(mX+4, mY+4, mWidth-8, mHeight-8, TGxRGBA.Create(r, g, b));
   end
   else
   begin
-    drawRectUI(mX+3, mY+3, mWidth-6, mHeight-6, r, g, b);
-    drawRectUI(mX+5, mY+5, mWidth-10, mHeight-10, r, g, b);
+    drawRectUI(mX+3, mY+3, mWidth-6, mHeight-6, TGxRGBA.Create(r, g, b));
+    drawRectUI(mX+5, mY+5, mWidth-10, mHeight-10, TGxRGBA.Create(r, g, b));
     setScissor(mFrameWidth, 0, 3*8, 8);
-    fillRect(mX+mFrameWidth, mY, 3*8, 8, 0, 0, 128);
-    drawText8(mX+mFrameWidth, mY, '[ ]', r, g, b);
-    if mInClose then drawText8(mX+mFrameWidth+7, mY, '#', 0, 255, 0)
-    else drawText8(mX+mFrameWidth+7, mY, '*', 0, 255, 0);
+    fillRect(mX+mFrameWidth, mY, 3*8, 8, TGxRGBA.Create(0, 0, 128));
+    drawText8(mX+mFrameWidth, mY, '[ ]', TGxRGBA.Create(r, g, b));
+    if mInClose then drawText8(mX+mFrameWidth+7, mY, '#', TGxRGBA.Create(0, 255, 0))
+    else drawText8(mX+mFrameWidth+7, mY, '*', TGxRGBA.Create(0, 255, 0));
   end;
   if (Length(mTitle) > 0) then
   begin
     setScissor(mFrameWidth+3*8, 0, mWidth-mFrameWidth*2-3*8, 8);
     tx := (mX+3*8)+((mWidth-3*8)-Length(mTitle)*8) div 2;
-    fillRect(tx-3, mY, Length(mTitle)*8+3+2, 8, 0, 0, 128);
-    drawText8(tx, mY, mTitle, r, g, b);
+    fillRect(tx-3, mY, Length(mTitle)*8+3+2, 8, TGxRGBA.Create(0, 0, 128));
+    drawText8(tx, mY, mTitle, TGxRGBA.Create(r, g, b));
   end;
-  inherited drawControlPost(sx, sy);
+  inherited drawControlPost(gx, gy);
 end;
 
 
@@ -1461,9 +1513,7 @@ begin
     exit;
   end;
 
-  lx := ev.x;
-  ly := ev.y;
-  if toLocal(lx, ly) then
+  if toLocal(ev.x, ev.y, lx, ly) then
   begin
     if (ev.press) then
     begin
@@ -1527,7 +1577,7 @@ end;
 
 
 // ////////////////////////////////////////////////////////////////////////// //
-constructor THCtlSimpleText.Create (ax, ay: Integer; aparent: THControl=nil);
+constructor THCtlSimpleText.Create (ax, ay: Integer);
 begin
   mItems := nil;
   inherited Create(ax, ay, 4, 4);
@@ -1555,7 +1605,7 @@ begin
 end;
 
 
-procedure THCtlSimpleText.drawControl (sx, sy: Integer);
+procedure THCtlSimpleText.drawControl (gx, gy: Integer);
 var
   f, tx: Integer;
   it: PItem;
@@ -1564,26 +1614,26 @@ begin
   for f := 0 to High(mItems) do
   begin
     it := @mItems[f];
-    tx := sx;
+    tx := gx;
     r := 255;
     g := 255;
     b := 0;
-    if it.centered then begin b := 255; tx := sx+(mWidth-Length(it.title)*8) div 2; end;
+    if it.centered then begin b := 255; tx := gx+(mWidth-Length(it.title)*8) div 2; end;
     if it.hline then
     begin
       b := 255;
       if (Length(it.title) = 0) then
       begin
-        drawHLine(sx+4, sy+3, mWidth-8, r, g, b);
+        drawHLine(gx+4, gy+3, mWidth-8, TGxRGBA.Create(r, g, b));
       end
-      else if (tx-3 > sx+4) then
+      else if (tx-3 > gx+4) then
       begin
-        drawHLine(sx+4, sy+3, tx-3-(sx+3), r, g, b);
-        drawHLine(tx+Length(it.title)*8, sy+3, mWidth-4, r, g, b);
+        drawHLine(gx+4, gy+3, tx-3-(gx+3), TGxRGBA.Create(r, g, b));
+        drawHLine(tx+Length(it.title)*8, gy+3, mWidth-4, TGxRGBA.Create(r, g, b));
       end;
     end;
-    drawText8(tx, sy, it.title, r, g, b);
-    Inc(sy, 8);
+    drawText8(tx, gy, it.title, TGxRGBA.Create(r, g, b));
+    Inc(gy, 8);
   end;
 end;
 
@@ -1593,9 +1643,7 @@ var
   lx, ly: Integer;
 begin
   result := inherited mouseEvent(ev);
-  lx := ev.x;
-  ly := ev.y;
-  if not result and toLocal(lx, ly) then
+  if not result and toLocal(ev.x, ev.y, lx, ly) then
   begin
     result := true;
   end;
@@ -1609,7 +1657,7 @@ end;
 
 
 // ////////////////////////////////////////////////////////////////////////// //
-constructor THCtlCBListBox.Create (ax, ay: Integer; aparent: THControl=nil);
+constructor THCtlCBListBox.Create (ax, ay: Integer);
 begin
   mItems := nil;
   mCurIndex := -1;
@@ -1639,7 +1687,7 @@ begin
 end;
 
 
-procedure THCtlCBListBox.drawControl (sx, sy: Integer);
+procedure THCtlCBListBox.drawControl (gx, gy: Integer);
 var
   f, tx: Integer;
   it: PItem;
@@ -1647,27 +1695,27 @@ begin
   for f := 0 to High(mItems) do
   begin
     it := @mItems[f];
-    if (mCurIndex = f) then fillRect(sx, sy, mWidth, 8, 0, 128, 0);
+    if (mCurIndex = f) then fillRect(gx, gy, mWidth, 8, TGxRGBA.Create(0, 128, 0));
     if (it.varp <> nil) then
     begin
-      if it.varp^ then drawText8(sx, sy, '[x]', 255, 255, 255) else drawText8(sx, sy, '[ ]', 255, 255, 255);
-      drawText8(sx+3*8+2, sy, it.title, 255, 255, 0);
+      if it.varp^ then drawText8(gx, gy, '[x]', TGxRGBA.Create(255, 255, 255)) else drawText8(gx, gy, '[ ]', TGxRGBA.Create(255, 255, 255));
+      drawText8(gx+3*8+2, gy, it.title, TGxRGBA.Create(255, 255, 0));
     end
     else if (Length(it.title) > 0) then
     begin
-      tx := sx+(mWidth-Length(it.title)*8) div 2;
-      if (tx-3 > sx+4) then
+      tx := gx+(mWidth-Length(it.title)*8) div 2;
+      if (tx-3 > gx+4) then
       begin
-        drawHLine(sx+4, sy+3, tx-3-(sx+3), 255, 255, 255);
-        drawHLine(tx+Length(it.title)*8, sy+3, mWidth-4, 255, 255, 255);
+        drawHLine(gx+4, gy+3, tx-3-(gx+3), TGxRGBA.Create(255, 255, 255));
+        drawHLine(tx+Length(it.title)*8, gy+3, mWidth-4, TGxRGBA.Create(255, 255, 255));
       end;
-      drawText8(tx, sy, it.title, 255, 255, 255);
+      drawText8(tx, gy, it.title, TGxRGBA.Create(255, 255, 255));
     end
     else
     begin
-      drawHLine(sx+4, sy+3, mWidth-8, 255, 255, 255);
+      drawHLine(gx+4, gy+3, mWidth-8, TGxRGBA.Create(255, 255, 255));
     end;
-    Inc(sy, 8);
+    Inc(gy, 8);
   end;
 end;
 
@@ -1678,9 +1726,7 @@ var
   it: PItem;
 begin
   result := inherited mouseEvent(ev);
-  lx := ev.x;
-  ly := ev.y;
-  if not result and toLocal(lx, ly) then
+  if not result and toLocal(ev.x, ev.y, lx, ly) then
   begin
     result := true;
     if (ev = 'lmb') then
@@ -1768,23 +1814,17 @@ end;
 
 
 // ////////////////////////////////////////////////////////////////////////// //
-constructor THCtlBox.Create (ahoriz: Boolean; aparent: THControl=nil);
+constructor THCtlBox.Create (ahoriz: Boolean);
 begin
-  inherited Create(aparent);
+  inherited Create();
   mHoriz := ahoriz;
+  mCanFocus := false;
 end;
 
 
 function THCtlBox.parseProperty (const prname: AnsiString; par: TTextParser): Boolean;
 begin
-  if (strEquCI1251(prname, 'orientation')) or (strEquCI1251(prname, 'orient')) then
-  begin
-         if (par.eatIdOrStr('horizontal', false)) or (par.eatIdOrStr('horiz', false)) then mHoriz := true
-    else if (par.eatIdOrStr('vertical', false)) or (par.eatIdOrStr('vert', false)) then mHoriz := false
-    else par.error('`horizontal` or `vertical` expected');
-    result := true;
-    exit;
-  end;
+  if (parseOrientation(prname, par)) then begin result := true; exit; end;
   if (strEquCI1251(prname, 'frame')) then
   begin
     mHasFrame := parseBool(par);
@@ -1795,7 +1835,7 @@ begin
   if (strEquCI1251(prname, 'title')) or (strEquCI1251(prname, 'caption')) then
   begin
     mCaption := par.expectStrOrId(true);
-    mDefSize := TLaySize.Create(Length(mCaption)*8+2+8*2, 8*2+2);
+    mDefSize := TLaySize.Create(Length(mCaption)*8+3, 8);
     result := true;
     exit;
   end;
@@ -1809,7 +1849,7 @@ begin
 end;
 
 
-procedure THCtlBox.drawControl (sx, sy: Integer);
+procedure THCtlBox.drawControl (gx, gy: Integer);
 var
   r, g, b: Integer;
   tx: Integer;
@@ -1818,25 +1858,25 @@ begin
   if mHasFrame then
   begin
     // draw frame
-    drawRectUI(mX+3, mY+3, mWidth-6, mHeight-6, r, g, b);
+    drawRectUI(gx+3, gy+3, mWidth-6, mHeight-6, TGxRGBA.Create(r, g, b));
   end;
+  // draw caption
   if (Length(mCaption) > 0) then
   begin
     setScissor(mFrameWidth+1, 0, mWidth-mFrameWidth-2, 8);
-    tx := mX+((mWidth-Length(mCaption)*8) div 2)-1;
-    if mHasFrame then fillRect(tx, mY, Length(mCaption)*8+2, 8, 0, 0, 128);
-    drawText8(tx+1, mY, mCaption, r, g, b);
+    tx := gx+((mWidth-Length(mCaption)*8) div 2);
+    if mHasFrame then fillRect(tx-2, gy, Length(mCaption)*8+3, 8, TGxRGBA.Create(0, 0, 128));
+    drawText8(tx, gy, mCaption, TGxRGBA.Create(r, g, b));
   end;
 end;
 
+
 function THCtlBox.mouseEvent (var ev: THMouseEvent): Boolean;
 var
   lx, ly: Integer;
 begin
   result := inherited mouseEvent(ev);
-  lx := ev.x;
-  ly := ev.y;
-  if not result and toLocal(lx, ly) then
+  if not result and toLocal(ev.x, ev.y, lx, ly) then
   begin
     result := true;
   end;
@@ -1851,30 +1891,102 @@ end;
 
 
 // ////////////////////////////////////////////////////////////////////////// //
-constructor THCtlHBox.Create (aparent: THControl=nil);
+procedure THCtlHBox.AfterConstruction ();
 begin
-  inherited Create(true, aparent);
+  inherited AfterConstruction();
+  mHoriz := true;
 end;
 
 
 // ////////////////////////////////////////////////////////////////////////// //
-constructor THCtlVBox.Create (aparent: THControl=nil);
+procedure THCtlVBox.AfterConstruction ();
 begin
-  inherited Create(false, aparent);
+  inherited AfterConstruction();
+  mHoriz := false;
+  mCanFocus := false;
 end;
 
 
 // ////////////////////////////////////////////////////////////////////////// //
-constructor THCtlTextLabel.Create (const atext: AnsiString; aparent: THControl=nil);
+procedure THCtlSpan.AfterConstruction ();
 begin
-  inherited Create(aparent);
-  mHAlign := -1;
-  mVAlign := 0;
+  inherited AfterConstruction();
+  mExpand := true;
+  mCanFocus := false;
+end;
+
+
+function THCtlSpan.parseProperty (const prname: AnsiString; par: TTextParser): Boolean;
+begin
+  if (parseOrientation(prname, par)) then begin result := true; exit; end;
+  result := inherited parseProperty(prname, par);
+end;
+
+
+procedure THCtlSpan.drawControl (gx, gy: Integer);
+begin
+end;
+
+
+// ////////////////////////////////////////////////////////////////////// //
+function THCtlLine.parseProperty (const prname: AnsiString; par: TTextParser): Boolean;
+begin
+  if (parseOrientation(prname, par)) then begin result := true; exit; end;
+  result := inherited parseProperty(prname, par);
+end;
+
+
+procedure THCtlLine.drawControl (gx, gy: Integer);
+begin
+  if mHoriz then
+  begin
+    drawHLine(gx, gy+(mHeight div 2), mWidth, TGxRGBA.Create(255, 255, 255));
+  end
+  else
+  begin
+    drawVLine(gx+(mWidth div 2), gy, mHeight, TGxRGBA.Create(255, 255, 255));
+  end;
+end;
+
+
+// ////////////////////////////////////////////////////////////////////////// //
+procedure THCtlHLine.AfterConstruction ();
+begin
+  mHoriz := true;
+  mExpand := true;
+  mDefSize.h := 1;
+end;
+
+
+// ////////////////////////////////////////////////////////////////////////// //
+procedure THCtlVLine.AfterConstruction ();
+begin
+  mHoriz := false;
+  mExpand := true;
+  mDefSize.w := 1;
+  //mDefSize.h := 8;
+end;
+
+
+// ////////////////////////////////////////////////////////////////////////// //
+constructor THCtlTextLabel.Create (const atext: AnsiString);
+begin
+  inherited Create();
   mText := atext;
   mDefSize := TLaySize.Create(Length(atext)*8, 8);
 end;
 
 
+procedure THCtlTextLabel.AfterConstruction ();
+begin
+  inherited AfterConstruction();
+  mHAlign := -1;
+  mVAlign := 0;
+  mCanFocus := false;
+  if (mDefSize.h <= 0) then mDefSize.h := 8;
+end;
+
+
 function THCtlTextLabel.parseProperty (const prname: AnsiString; par: TTextParser): Boolean;
 begin
   if (strEquCI1251(prname, 'title')) or (strEquCI1251(prname, 'caption')) then
@@ -1894,13 +2006,13 @@ begin
 end;
 
 
-procedure THCtlTextLabel.drawControl (sx, sy: Integer);
+procedure THCtlTextLabel.drawControl (gx, gy: Integer);
 var
   xpos, ypos: Integer;
 begin
   // debug
-  fillRect(sx, sy, mWidth, mHeight, 96, 96, 0);
-  drawRectUI(sx, sy, mWidth, mHeight, 96, 96, 96);
+  fillRect(gx, gy, mWidth, mHeight, TGxRGBA.Create(96, 96, 0));
+  drawRectUI(gx, gy, mWidth, mHeight, TGxRGBA.Create(96, 96, 96));
 
   if (Length(mText) > 0) then
   begin
@@ -1912,7 +2024,7 @@ begin
     else if (mVAlign > 0) then ypos := mHeight-8
     else ypos := (mHeight-8) div 2;
 
-    drawText8(sx+xpos, sy+ypos, mText, 255, 255, 255);
+    drawText8(gx+xpos, gy+ypos, mText, TGxRGBA.Create(255, 255, 255));
   end;
 end;
 
@@ -1922,9 +2034,7 @@ var
   lx, ly: Integer;
 begin
   result := inherited mouseEvent(ev);
-  lx := ev.x;
-  ly := ev.y;
-  if not result and toLocal(lx, ly) then
+  if not result and toLocal(ev.x, ev.y, lx, ly) then
   begin
     result := true;
   end;
@@ -1938,8 +2048,10 @@ end;
 
 
 initialization
-  registerCtlClass(THCtlBox, 'box');
   registerCtlClass(THCtlHBox, 'hbox');
   registerCtlClass(THCtlVBox, 'vbox');
+  registerCtlClass(THCtlSpan, 'span');
+  registerCtlClass(THCtlHLine, 'hline');
+  registerCtlClass(THCtlVLine, 'vline');
   registerCtlClass(THCtlTextLabel, 'label');
 end.