DEADSOFTWARE

HolmesUI: ortholine control; fixed expanding of controls without maxsize
[d2df-sdl.git] / src / gx / gh_ui.pas
index 812fae7bda427e97be0ca26ab906b99376b0e464..8875f7dd1c82e2102055260da504faf3fd6e4530 100644 (file)
@@ -145,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
 
@@ -318,7 +319,35 @@ type
     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;
@@ -327,7 +356,8 @@ type
 
   public
     constructor Create (const atext: AnsiString);
-    //destructor Destroy (); override;
+
+    procedure AfterConstruction (); override; // so it will be correctly initialized when created from parser
 
     function parseProperty (const prname: AnsiString; par: TTextParser): Boolean; override;
 
@@ -714,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;
 
@@ -823,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
@@ -876,8 +921,13 @@ begin
   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;
@@ -1369,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;
 
@@ -1775,19 +1818,13 @@ constructor THCtlBox.Create (ahoriz: Boolean);
 begin
   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);
@@ -1798,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);
+    mDefSize := TLaySize.Create(Length(mCaption)*8+3, 8);
     result := true;
     exit;
   end;
@@ -1827,9 +1864,9 @@ begin
   if (Length(mCaption) > 0) then
   begin
     setScissor(mFrameWidth+1, 0, mWidth-mFrameWidth-2, 8);
-    tx := gx+((mWidth-Length(mCaption)*8) div 2)-1;
-    if mHasFrame then fillRect(tx, gy, Length(mCaption)*8+2, 8, 0, 0, 128);
-    drawText8(tx+1, gy, mCaption, r, g, b);
+    tx := gx+((mWidth-Length(mCaption)*8) div 2);
+    if mHasFrame then fillRect(tx-2, gy, Length(mCaption)*8+3, 8, 0, 0, 128);
+    drawText8(tx, gy, mCaption, r, g, b);
   end;
 end;
 
@@ -1866,19 +1903,91 @@ procedure THCtlVBox.AfterConstruction ();
 begin
   inherited AfterConstruction();
   mHoriz := false;
+  mCanFocus := false;
 end;
 
+
+// ////////////////////////////////////////////////////////////////////////// //
+procedure THCtlSpan.AfterConstruction ();
+begin
+  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, 255, 255, 255);
+  end
+  else
+  begin
+    drawVLine(gx+(mWidth div 2), gy, mHeight, 255, 255, 255);
+  end;
+  //fillRect(gx, gy, mWidth, mHeight, 255, 0, 0);
+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();
-  mHAlign := -1;
-  mVAlign := 0;
   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
@@ -1940,8 +2049,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.