summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: fe568f3)
raw | patch | inline | side by side (parent: fe568f3)
author | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Sun, 24 Sep 2017 21:18:39 +0000 (00:18 +0300) | ||
committer | Ketmar Dark <ketmar@ketmar.no-ip.org> | |
Sun, 24 Sep 2017 21:19:37 +0000 (00:19 +0300) |
src/gx/gh_flexlay.pas | patch | blob | history | |
src/gx/gh_ui.pas | patch | blob | history | |
src/gx/glgfx.pas | patch | blob | history | |
src/shared/xparser.pas | patch | blob | history |
diff --git a/src/gx/gh_flexlay.pas b/src/gx/gh_flexlay.pas
index f9487028524e56367082f0211caa8a5805af6d98..79c6a5c578b8fc3a858d34eb5cc966f8a4a691c7 100644 (file)
--- a/src/gx/gh_flexlay.pas
+++ b/src/gx/gh_flexlay.pas
grp: PLayGroup;
maxsz: Integer;
cidx: LayControlIdx;
+ ct: PLayControl;
mr: TLayMargins;
begin
// reset all 'laywrap' flags for controls, set initial 'startsize'
for c := 0 to High(grp.ctls) do
begin
cidx := grp.ctls[c];
- if (maxsz < ctlist[cidx].startsize[gtype]) then maxsz := ctlist[cidx].startsize[gtype];
+ ct := @ctlist[cidx];
+ if (maxsz < ct.startsize[gtype]) then maxsz := ct.startsize[gtype];
end;
for c := 0 to High(grp.ctls) do
begin
cidx := grp.ctls[c];
- if (maxsz <> ctlist[cidx].startsize[gtype]) then
+ ct := @ctlist[cidx];
+ if (maxsz <> ct.startsize[gtype]) then
begin
needRecalcMaxSize := true;
- ctlist[cidx].startsize[gtype] := maxsz;
+ ct.startsize[gtype] := maxsz;
end;
end;
end;
// expand or align
if (lc.expand) then lc.desiredsize.w := nmin(lc.maxsize.w, me.desiredsize.w-me.margins.vert) // expand
else if (lc.aligndir > 0) then lc.desiredpos.x := me.desiredsize.w-me.margins.right-lc.desiredsize.w // right align
- else if (lc.aligndir = 0) then lc.desiredpos.x := (me.desiredsize.w-me.margins.horiz-lc.desiredsize.w) div 2; // center
+ else if (lc.aligndir = 0) then lc.desiredpos.x := (me.desiredsize.w-lc.desiredsize.w) div 2; // center
if (not osz.equals(lc.desiredsize)) then
begin
if (lc.inGroup) then groupElementChanged := true;
end;
for c := 0 to 1 do
begin
- if (ct.maxsize[c] <= 0) then continue;
+ if (ct.maxsize[c] < 0) then continue;
if (ct.desiredsize[c] > ct.maxsize[c]) then
begin
//writeln('ctl #', f, '; dimension #', c, ': desired=', ctlist[f].desiredsize[c], '; max=', ctlist[f].maxsize[c]);
diff --git a/src/gx/gh_ui.pas b/src/gx/gh_ui.pas
index a8593adacd9a4111c9e29fe2d9ae5b162094f131..a467408ab04b93ff6da97e1f97f0e532a725c793 100644 (file)
--- a/src/gx/gh_ui.pas
+++ b/src/gx/gh_ui.pas
private
mParent: THControl;
+ mId: AnsiString;
mX, mY: Integer;
mWidth, mHeight: Integer;
mFrameWidth, mFrameHeight: Integer;
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 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;
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);
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);
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;
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;
mVAlign: Integer; // -1: top; 0: center; 1: bottom; default: center
public
- constructor Create (const atext: AnsiString; aparent: THControl=nil);
+ constructor Create (const atext: AnsiString);
//destructor Destroy (); override;
function parseProperty (const prname: AnsiString; par: TTextParser): Boolean; override;
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;
end;
-constructor THControl.Create (aparent: THControl);
-begin
- Create();
- mParent := aparent;
-end;
-
-
destructor THControl.Destroy ();
var
f, c: Integer;
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;
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
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
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;
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.setScissor (lx, ly, lw, lh: Integer);
var
x, y: Integer;
+ //ox, oy, ow, oh: Integer;
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;
+ //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;
x := lx;
y := ly;
toGlobal(x, y);
procedure THControl.drawControlPost (sx, sy: Integer);
begin
+ // shadow
if mDrawShadow and (mWidth > 0) and (mHeight > 0) then
begin
setScissorGLInternal(sx+8, sy+8, mWidth, mHeight);
// ////////////////////////////////////////////////////////////////////////// //
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;
// ////////////////////////////////////////////////////////////////////////// //
-constructor THCtlSimpleText.Create (ax, ay: Integer; aparent: THControl=nil);
+constructor THCtlSimpleText.Create (ax, ay: Integer);
begin
mItems := nil;
inherited Create(ax, ay, 4, 4);
// ////////////////////////////////////////////////////////////////////////// //
-constructor THCtlCBListBox.Create (ax, ay: Integer; aparent: THControl=nil);
+constructor THCtlCBListBox.Create (ax, ay: Integer);
begin
mItems := nil;
mCurIndex := -1;
// ////////////////////////////////////////////////////////////////////////// //
-constructor THCtlBox.Create (ahoriz: Boolean; aparent: THControl=nil);
+constructor THCtlBox.Create (ahoriz: Boolean);
begin
- inherited Create(aparent);
+ inherited Create();
mHoriz := ahoriz;
end;
end;
end;
+
function THCtlBox.mouseEvent (var ev: THMouseEvent): Boolean;
var
lx, ly: Integer;
// ////////////////////////////////////////////////////////////////////////// //
-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;
end;
-
// ////////////////////////////////////////////////////////////////////////// //
-constructor THCtlTextLabel.Create (const atext: AnsiString; aparent: THControl=nil);
+constructor THCtlTextLabel.Create (const atext: AnsiString);
begin
- inherited Create(aparent);
+ inherited Create();
mHAlign := -1;
mVAlign := 0;
mText := atext;
diff --git a/src/gx/glgfx.pas b/src/gx/glgfx.pas
index d6f8763b401724947277acb25e5b7c79d28beb8a..61fa5f6278474d08943b9c2193f7860c7d52c4f6 100644 (file)
--- a/src/gx/glgfx.pas
+++ b/src/gx/glgfx.pas
procedure restore ();
// set new scissor rect, bounded by the saved scissor rect
- procedure setRect (x, y, w, h: Integer);
+ procedure combineRect (x, y, w, h: Integer);
end;
if wassc then glEnable(GL_SCISSOR_TEST) else glDisable(GL_SCISSOR_TEST);
end;
-procedure TScissorSave.setRect (x, y, w, h: Integer);
+procedure TScissorSave.combineRect (x, y, w, h: Integer);
+//var ox, oy, ow, oh: Integer;
begin
if (w < 1) or (h < 1) then begin glScissor(0, 0, 0, 0); exit; end;
y := gScrHeight-(y+h);
- if not intersectRect(x, y, w, h, scxywh[0], scxywh[1], scxywh[2], scxywh[3]) then glScissor(0, 0, 0, 0) else glScissor(x, y, w, h);
+ //ox := x; oy := y; ow := w; oh := h;
+ if not intersectRect(x, y, w, h, scxywh[0], scxywh[1], scxywh[2], scxywh[3]) then
+ begin
+ //writeln('oops: COMBINE: old=(', ox, ',', oy, ')-(', ox+ow-1, ',', oy+oh-1, '); sci: (', scxywh[0], ',', scxywh[1], ')-(', scxywh[0]+scxywh[2]-1, ',', scxywh[1]+scxywh[3]-1, ')');
+ glScissor(0, 0, 0, 0);
+ end
+ else
+ begin
+ glScissor(x, y, w, h);
+ end;
end;
//TODO: overflow checks
result := false;
if (w0 < 1) or (h0 < 1) or (w1 < 1) or (h1 < 1) then exit;
// check for intersection
- if (x0+w0 <= x1) or (y0+h0 <= y1) or (x1+w1 <= x0) or (y1+h1 <= y0) then exit;
- if (x0 >= x1+w1) or (y0 >= y1+h1) or (x1 >= x0+h0) or (y1 >= y0+h0) then exit;
- // ok, intersects
ex0 := x0+w0;
ey0 := y0+h0;
+ if (ex0 <= x1) or (ey0 <= y1) or (x1+w1 <= x0) or (y1+h1 <= y0) then exit;
+ if (x0 >= x1+w1) or (y0 >= y1+h1) or (x1 >= ex0) or (y1 >= ey0) then exit;
+ // ok, intersects
if (x0 < x1) then x0 := x1;
if (y0 < y1) then y0 := y1;
if (ex0 > x1+w1) then ex0 := x1+w1;
diff --git a/src/shared/xparser.pas b/src/shared/xparser.pas
index b985f1a30a781724b03a058c5b644621b9d0c851..0f2c2ece5b06731f2a18d6c4a46dcf15e445f7d3 100644 (file)
--- a/src/shared/xparser.pas
+++ b/src/shared/xparser.pas
function skipToken1 (): Boolean;
{$ENDIF}
+ function isIdOrStr (): Boolean; inline;
+
function expectId (): AnsiString;
procedure expectId (const aid: AnsiString; caseSens: Boolean=true);
function eatId (const aid: AnsiString; caseSens: Boolean=true): Boolean;
end;
+function TTextParser.isIdOrStr (): Boolean; inline;
+begin
+ result := (mTokType = TTId) or (mTokType = TTStr);
+end;
+
+
function TTextParser.expectId (): AnsiString;
begin
if (mTokType <> TTId) then raise Exception.Create('identifier expected');