From: Ketmar Dark Date: Fri, 22 Sep 2017 22:06:13 +0000 (+0300) Subject: added "common" module for Holmes UI (preparation for layout manager) X-Git-Url: https://deadsoftware.ru/gitweb?a=commitdiff_plain;h=9bca9a6ab02b578db654863d557691e3edbcf0ca;p=d2df-sdl.git added "common" module for Holmes UI (preparation for layout manager) --- diff --git a/src/game/Doom2DF.dpr b/src/game/Doom2DF.dpr index 67dcc03..7daaaea 100644 --- a/src/game/Doom2DF.dpr +++ b/src/game/Doom2DF.dpr @@ -113,6 +113,7 @@ uses ImagingUtility, sdlcarcass in '../gx/sdlcarcass.pas', glgfx in '../gx/glgfx.pas', + gh_ui_common in '../gx/gh_ui_common.pas', gh_ui in '../gx/gh_ui.pas'; {$IFDEF WINDOWS} diff --git a/src/gx/gh_ui.pas b/src/gx/gh_ui.pas index aa94e62..f67757a 100644 --- a/src/gx/gh_ui.pas +++ b/src/gx/gh_ui.pas @@ -21,6 +21,7 @@ interface uses SysUtils, Classes, GL, GLExt, SDL2, + gh_ui_common, sdlcarcass, glgfx; @@ -78,6 +79,43 @@ type public actionCB: TActionCB; + private + mSize: TLaySize; // default size + mMaxSize: TLaySize; // maximum size + mActSize: TLaySize; // actual (calculated) size + mActPos: TLayPos; // actual (calculated) position + mFlex: Integer; + mHoriz: Boolean; + mCanWrap: Boolean; + mLineStart: Boolean; + mHGroup: AnsiString; + mVGroup: AnsiString; + + public + // layouter interface + function getSize (): TLaySize; inline; // default size; <0: use max size + procedure setSize (constref sz: TLaySize); inline; // default size; <0: use max size + function getMaxSize (): TLaySize; inline; // max size; <0: set to some huge value + procedure setMaxSize (constref sz: TLaySize); inline; // max size; <0: set to some huge value + function getFlex (): Integer; inline; // <=0: not flexible + function isHorizBox (): Boolean; inline; // horizontal layout for children? + procedure setHorizBox (v: Boolean); inline; // horizontal layout for children? + function canWrap (): Boolean; inline; // for horizontal boxes: can wrap children? for child: `false` means 'nonbreakable at *next* ctl' + procedure setCanWrap (v: Boolean); inline; // for horizontal boxes: can wrap children? for child: `false` means 'nonbreakable at *next* ctl' + function isLineStart (): Boolean; inline; // `true` if this ctl should start a new line; ignored for vertical boxes + procedure setLineStart (v: Boolean); inline; // `true` if this ctl should start a new line; ignored for vertical boxes + procedure setActualSizePos (constref apos: TLayPos; constref asize: TLaySize); inline; + function getHGroup (): AnsiString; inline; // empty: not grouped + procedure setHGroup (const v: AnsiString); inline; // empty: not grouped + function getVGroup (): AnsiString; inline; // empty: not grouped + procedure setVGroup (const v: AnsiString); inline; // empty: not grouped + function hasSibling (): Boolean; inline; + //function nextSibling (): THControl; inline; + function hasChildren (): Boolean; inline; + //function firstChild (): THControl; inline; + + property flex: Integer read mFlex write mFlex; + public constructor Create (ax, ay, aw, ah: Integer; aparent: THControl=nil); destructor Destroy (); override; @@ -376,6 +414,17 @@ begin scallowed := false; mDrawShadow := false; actionCB := nil; + // layouter interface + mSize := TLaySize.Create(64, 10); // default size + mMaxSize := TLaySize.Create(-1, -1); // maximum size + mActSize := TLaySize.Create(0, 0); // actual (calculated) size + mActPos := TLayPos.Create(0, 0); // actual (calculated) position + mFlex := 0; + mHoriz := true; + mCanWrap := false; + mLineStart := false; + mHGroup := ''; + mVGroup := ''; end; @@ -404,6 +453,28 @@ begin end; +function THControl.getSize (): TLaySize; inline; begin result := mSize; end; +procedure THControl.setSize (constref sz: TLaySize); inline; begin mSize := sz; end; +function THControl.getMaxSize (): TLaySize; inline; begin result := mMaxSize; end; +procedure THControl.setMaxSize (constref sz: TLaySize); inline; begin mMaxSize := sz; end; +function THControl.getFlex (): Integer; inline; begin result := mFlex; end; +function THControl.isHorizBox (): Boolean; inline; begin result := mHoriz; end; +procedure THControl.setHorizBox (v: Boolean); inline; begin mHoriz := v; end; +function THControl.canWrap (): Boolean; inline; begin result := mCanWrap; end; +procedure THControl.setCanWrap (v: Boolean); inline; begin mCanWrap := v; end; +function THControl.isLineStart (): Boolean; inline; begin result := mLineStart; end; +procedure THControl.setLineStart (v: Boolean); inline; begin mLineStart := v; end; +procedure THControl.setActualSizePos (constref apos: TLayPos; constref asize: TLaySize); inline; begin mActPos := apos; mActSize := asize; end; +function THControl.getHGroup (): AnsiString; inline; begin result := mHGroup; end; +procedure THControl.setHGroup (const v: AnsiString); inline; begin mHGroup := v; end; +function THControl.getVGroup (): AnsiString; inline; begin result := mVGroup; end; +procedure THControl.setVGroup (const v: AnsiString); inline; begin mVGroup := v; end; +function THControl.hasSibling (): Boolean; inline; begin result := (nextSibling <> nil) end; +//function THControl.nextSibling (): THControl; inline; begin result := nextSibling; end; +function THControl.hasChildren (): Boolean; inline; begin result := (firstChild <> nil); end; +//function THControl.firstChild (): THControl; inline; begin result := firstChild; end; + + procedure THControl.activated (); begin end; diff --git a/src/gx/gh_ui_common.pas b/src/gx/gh_ui_common.pas new file mode 100644 index 0000000..7143501 --- /dev/null +++ b/src/gx/gh_ui_common.pas @@ -0,0 +1,82 @@ +(* Copyright (C) DooM 2D:Forever Developers + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + *) +{$INCLUDE ../shared/a_modes.inc} +unit gh_ui_common; + +interface + + +// ////////////////////////////////////////////////////////////////////////// // +type + TLaySize = record + public + w, h: Integer; + + private + function getIdx (idx: Integer): Integer; inline; + procedure setIdx (idx, v: Integer); inline; + + public + constructor Create (aw, ah: Integer); + + function toString (): AnsiString; + + function equals (constref a: TLaySize): Boolean; inline; + public + property item[idx: Integer]: Integer read getIdx write setIdx; default; + end; + + TLayPos = record + public + x, y: Integer; + + private + function getIdx (idx: Integer): Integer; inline; + procedure setIdx (idx, v: Integer); inline; + + public + constructor Create (ax, ay: Integer); + + function toString (): AnsiString; + + function equals (constref a: TLayPos): Boolean; inline; + + public + property item[idx: Integer]: Integer read getIdx write setIdx; default; + end; + + +implementation + +uses + utils; + + +// ////////////////////////////////////////////////////////////////////////// // +constructor TLaySize.Create (aw, ah: Integer); begin w := aw; h := ah; end; +function TLaySize.getIdx (idx: Integer): Integer; inline; begin if (idx = 0) then result := w else if (idx = 1) then result := h else result := -1; end; +procedure TLaySize.setIdx (idx, v: Integer); inline; begin if (idx = 0) then w := v else if (idx = 1) then h := v; end; +function TLaySize.toString (): AnsiString; begin result := formatstrf('[%d,%d]', [w, h]); end; +function TLaySize.equals (constref a: TLaySize): Boolean; inline; begin result := (w = a.w) and (h = a.h); end; + +constructor TLayPos.Create (ax, ay: Integer); begin x := ax; y := ay; end; +function TLayPos.getIdx (idx: Integer): Integer; inline; begin if (idx = 0) then result := x else if (idx = 1) then result := y else result := -1; end; +procedure TLayPos.setIdx (idx, v: Integer); inline; begin if (idx = 0) then x := v else if (idx = 1) then y := v; end; +function TLayPos.toString (): AnsiString; begin result := formatstrf('(%d,%d)', [x, y]); end; +function TLayPos.equals (constref a: TLayPos): Boolean; inline; begin result := (x = a.x) and (y = a.y); end; + + +end.