| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638 |
- //
- // The graphics engine GLScene https://github.com/glscene
- //
- unit GLS.Windows;
- (* OpenGL windows management classes and structures *)
- interface
- {$I GLScene.Defines.inc}
- uses
- Winapi.OpenGL,
- Winapi.Windows,
- System.Classes,
- System.SysUtils,
- System.Math,
- Vcl.StdCtrls,
- Vcl.Controls,
- Vcl.Graphics,
- GLScene.OpenGLTokens,
- GLS.PersistentClasses,
- GLScene.Strings,
- GLS.Coordinates,
- GLScene.VectorTypes,
- GLS.Objects,
- GLS.State,
- GLScene.Utils,
- GLS.Scene,
- GLS.HudObjects,
- GLS.Material,
- GLS.Context,
- GLS.BitmapFont,
- GLS.WindowsFont,
- GLScene.VectorGeometry,
- GLS.Gui,
- GLS.Color,
- GLS.ImageUtils,
- GLS.Texture,
- GLS.RenderContextInfo,
- GLS.BaseClasses;
- type
- TGLBaseComponent = class(TGLBaseGuiObject)
- private
- FGUIRedraw: Boolean;
- FGuiLayout: TGLGuiLayout;
- FGuiLayoutName: TGLGuiComponentName;
- FGuiComponent: TGLGuiComponent;
- FReBuildGui: Boolean;
- FRedrawAtOnce: Boolean;
- MoveX, MoveY: TGLFloat;
- FRenderStatus: TGUIDrawResult;
- FAlphaChannel: Single;
- FRotation: TGLFloat;
- FNoZWrite: Boolean;
- BlockRendering: Boolean;
- RenderingCount: Integer;
- BlockedCount: Integer;
- GuiDestroying: Boolean;
- FDoChangesOnProgress: Boolean;
- FAutosize: Boolean;
- procedure SetGUIRedraw(value: Boolean);
- procedure SetDoChangesOnProgress(const Value: Boolean);
- procedure SetAutosize(const Value: Boolean);
- protected
- procedure RenderHeader(var rci: TGLRenderContextInfo; renderSelf, renderChildren: Boolean);
- procedure RenderFooter(var rci: TGLRenderContextInfo; renderSelf, renderChildren: Boolean);
- procedure SetGuiLayout(NewGui: TGLGuiLayout); virtual;
- procedure SetGuiLayoutName(const NewName: TGLGuiComponentName);
- procedure Notification(AComponent: TComponent; Operation: TOperation); override;
- procedure SetRotation(const val: TGLFloat);
- procedure SetAlphaChannel(const val: Single);
- function StoreAlphaChannel: Boolean;
- procedure SetNoZWrite(const val: Boolean);
- public
- procedure BlockRender;
- procedure UnBlockRender;
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- procedure NotifyChange(Sender: TObject); override;
- procedure DoChanges; virtual;
- procedure MoveGUI(XRel, YRel: Single);
- procedure PlaceGUI(XPos, YPos: Single);
- procedure DoProgress(const progressTime: TGLProgressTimes); override;
- procedure DoRender(var rci: TGLRenderContextInfo; renderSelf, renderChildren: Boolean); override;
- procedure InternalRender(var rci: TGLRenderContextInfo; renderSelf, renderChildren: Boolean); virtual;
- property GUIRedraw: Boolean read FGUIRedraw write SetGUIRedraw;
- property ReBuildGui: Boolean read FReBuildGui write FReBuildGui;
- published
- property Autosize: Boolean read FAutosize write SetAutosize;
- property RedrawAtOnce: Boolean read FRedrawAtOnce write FRedrawAtOnce;
- property GuiLayout: TGLGuiLayout read FGuiLayout write SetGuiLayout;
- property GuiLayoutName: TGLGuiComponentName read FGuiLayoutName write SetGuiLayoutName;
- // This the ON-SCREEN rotation of the GuiComponent. Rotatation=0 is handled faster.
- property Rotation: TGLFloat read FRotation write SetRotation;
- // If different from 1, this value will replace that of Diffuse.Alpha
- property AlphaChannel: Single read FAlphaChannel write SetAlphaChannel stored StoreAlphaChannel;
- // If True, GuiComponent will not write to Z-Buffer. GuiComponent will be maskable by ZBuffer test STILL.
- property NoZWrite: Boolean read FNoZWrite write SetNoZWrite;
- property DoChangesOnProgress: Boolean read FDoChangesOnProgress write SetDoChangesOnProgress;
- property Visible;
- property Width;
- property Height;
- property Left;
- property Top;
- property Position;
- end;
- TGLFocusControl = class;
- TGLBaseControl = class;
- TGLMouseAction = (ma_mouseup, ma_mousedown, ma_mousemove);
- TGLAcceptMouseQuery = procedure(Sender: TGLBaseControl; Shift: TShiftState;
- Action: TGLMouseAction; Button: TMouseButton; X, Y: Integer; var Accept: boolean) of object;
- TGLBaseControl = class(TGLBaseComponent)
- private
- FOnMouseDown: TMouseEvent;
- FOnMouseMove: TMouseMoveEvent;
- FOnMouseUp: TMouseEvent;
- FKeepMouseEvents: Boolean;
- FActiveControl: TGLBaseControl;
- FFocusedControl: TGLFocusControl;
- FOnAcceptMouseQuery: TGLAcceptMouseQuery;
- FOnMouseLeave: TNotifyEvent;
- FOnMouseEnter: TNotifyEvent;
- FEnteredControl: TGLBaseControl;
- protected
- procedure InternalMouseDown(Shift: TShiftState; Button: TMouseButton; X, Y: Integer); virtual;
- procedure InternalMouseUp(Shift: TShiftState; Button: TMouseButton; X, Y: Integer); virtual;
- procedure InternalMouseMove(Shift: TShiftState; X, Y: Integer); virtual;
- procedure SetActiveControl(NewControl: TGLBaseControl);
- procedure SetFocusedControl(NewControl: TGLFocusControl);
- function FindFirstGui: TGLBaseControl;
- procedure Notification(AComponent: TComponent; Operation: TOperation); override;
- procedure DoMouseEnter;
- procedure DoMouseLeave;
- public
- function MouseDown(Sender: TObject; Button: TMouseButton; Shift:
- TShiftState; X, Y: Integer): Boolean; virtual;
- function MouseUp(Sender: TObject; Button: TMouseButton; Shift:
- TShiftState; X, Y: Integer): Boolean; virtual;
- function MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer): Boolean; virtual;
- procedure KeyPress(Sender: TObject; var Key: Char); virtual;
- procedure KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); virtual;
- procedure KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); virtual;
- property ActiveControl: TGLBaseControl read FActiveControl write SetActiveControl;
- property KeepMouseEvents: Boolean read FKeepMouseEvents write FKeepMouseEvents default false;
- published
- property FocusedControl: TGLFocusControl read FFocusedControl write SetFocusedControl;
- property OnMouseDown: TMouseEvent read FOnMouseDown write FOnMouseDown;
- property OnMouseMove: TMouseMoveEvent read FOnMouseMove write FOnMouseMove;
- property OnMouseUp: TMouseEvent read FOnMouseUp write FOnMouseUp;
- property OnMouseEnter: TNotifyEvent read FOnMouseEnter write FOnMouseEnter;
- property OnMouseLeave: TNotifyEvent read FOnMouseLeave write FOnMouseLeave;
- property OnAcceptMouseQuery: TGLAcceptMouseQuery read FOnAcceptMouseQuery write FOnAcceptMouseQuery;
- end;
- TGLBaseFontControl = class(TGLBaseControl)
- private
- FBitmapFont: TGLCustomBitmapFont;
- FDefaultColor: TGLColorVector;
- protected
- function GetDefaultColor: TColor;
- procedure SetDefaultColor(value: TColor);
- procedure SetBitmapFont(NewFont: TGLCustomBitmapFont);
- function GetBitmapFont: TGLCustomBitmapFont;
- procedure WriteTextAt(var rci: TGLRenderContextInfo; const X, Y: TGLFloat;
- const Data: UnicodeString; const Color: TGLColorVector); overload;
- procedure WriteTextAt(var rci: TGLRenderContextInfo; const X1, Y1, X2, Y2:
- TGLFloat; const Data: UnicodeString; const Color: TGLColorVector); overload;
- function GetFontHeight: Integer;
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- procedure Notification(AComponent: TComponent; Operation: TOperation); override;
- published
- property BitmapFont: TGLCustomBitmapFont read GetBitmapFont write SetBitmapFont;
- property DefaultColor: TColor read GetDefaultColor write SetDefaultColor;
- end;
- TGLBaseTextControl = class(TGLBaseFontControl)
- private
- FCaption: UnicodeString;
- protected
- procedure SetCaption(const NewCaption: UnicodeString);
- public
- published
- property Caption: UnicodeString read FCaption write SetCaption;
- end;
- TGLFocusControl = class(TGLBaseTextControl)
- private
- FRootControl: TGLBaseControl;
- FFocused: Boolean;
- FOnKeyDown: TKeyEvent;
- FOnKeyUp: TKeyEvent;
- FOnKeyPress: TKeyPressEvent;
- FShiftState: TShiftState;
- FFocusedColor: TGLColorVector;
- protected
- procedure InternalKeyPress(var Key: Char); virtual;
- procedure InternalKeyDown(var Key: Word; Shift: TShiftState); virtual;
- procedure InternalKeyUp(var Key: Word; Shift: TShiftState); virtual;
- procedure SetFocused(Value: Boolean); virtual;
- function GetRootControl: TGLBaseControl;
- function GetFocusedColor: TColor;
- procedure SetFocusedColor(const Val: TColor);
- public
- destructor Destroy; override;
- procedure NotifyHide; override;
- procedure MoveTo(newParent: TGLBaseSceneObject); override;
- procedure ReGetRootControl;
- procedure SetFocus;
- procedure PrevControl;
- procedure NextControl;
- procedure KeyPress(Sender: TObject; var Key: Char); override;
- procedure KeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); override;
- procedure KeyUp(Sender: TObject; var Key: Word; Shift: TShiftState); override;
- published
- property RootControl: TGLBaseControl read GetRootControl;
- property Focused: Boolean read FFocused write SetFocused;
- property FocusedColor: TColor read GetFocusedColor write SetFocusedColor;
- property OnKeyDown: TKeyEvent read FOnKeyDown write FOnKeyDown;
- property OnKeyUp: TKeyEvent read FOnKeyUp write FOnKeyUp;
- property OnKeyPress: TKeyPressEvent read FOnKeyPress write FOnKeyPress;
- end;
- TGLCustomControl = class;
- TGLCustomRenderEvent = procedure(Sender: TGLCustomControl; Bitmap: TBitmap) of object;
- TGLCustomControl = class(TGLFocusControl)
- private
- FCustomData: Pointer;
- FCustomObject: TObject;
- FOnRender: TGLCustomRenderEvent;
- FMaterial: TGLMaterial;
- FBitmap: TBitmap;
- FInternalBitmap: TBitmap;
- FBitmapChanged: Boolean;
- FXTexCoord: Single;
- FYTexCoord: Single;
- FInvalidRenderCount: Integer;
- FMaxInvalidRenderCount: Integer;
- FCentered: Boolean;
- procedure SetCentered(const Value: Boolean);
- protected
- procedure OnBitmapChanged(Sender: TObject);
- procedure SetBitmap(ABitmap: TBitmap);
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- procedure InternalRender(var rci: TGLRenderContextInfo; renderSelf,
- renderChildren: Boolean); override;
- procedure SetMaterial(AMaterial: TGLMaterial);
- property CustomData: Pointer read FCustomData write FCustomData;
- property CustomObject: TObject read FCustomObject write FCustomObject;
- published
- property OnRender: TGLCustomRenderEvent read FOnRender write FOnRender;
- property Centered: Boolean read FCentered write SetCentered;
- property Material: TGLMaterial read FMaterial write SetMaterial;
- property Bitmap: TBitmap read FBitmap write SetBitmap;
- property MaxInvalidRenderCount: Integer read FMaxInvalidRenderCount
- write FMaxInvalidRenderCount;
- end;
- TGLPopupMenu = class;
- TGLPopupMenuClick = procedure(Sender: TGLPopupMenu; index: Integer; const MenuItemText: string) of object;
- TGLPopupMenu = class(TGLFocusControl)
- private
- FOnClick: TGLPopupMenuClick;
- FMenuItems: TStrings;
- FSelIndex: Integer;
- FMarginSize: Single;
- NewHeight: Single;
- protected
- procedure SetFocused(Value: Boolean); override;
- procedure SetMenuItems(Value: TStrings);
- procedure SetMarginSize(const val: Single);
- procedure SetSelIndex(const val: Integer);
- procedure InternalMouseDown(Shift: TShiftState; Button: TMouseButton; X, Y: Integer); override;
- procedure InternalMouseMove(Shift: TShiftState; X, Y: Integer); override;
- procedure OnStringListChange(Sender: TObject);
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- procedure PopUp(Px, Py: Integer);
- procedure InternalRender(var rci: TGLRenderContextInfo; renderSelf,
- renderChildren: Boolean); override;
- procedure DoRender(var rci: TGLRenderContextInfo; renderSelf, renderChildren:
- Boolean); override;
- function MouseDown(Sender: TObject; Button: TMouseButton; Shift:
- TShiftState; X, Y: Integer): Boolean; override;
- published
- property MenuItems: TStrings read FMenuItems write SetMenuItems;
- property OnClick: TGLPopupMenuClick read FOnClick write FOnClick;
- property MarginSize: Single read FMarginSize write SetMarginSize;
- property SelIndex: Integer read FSelIndex write SetSelIndex;
- end;
- TGLForm = class;
- TGLFormCanRequest = procedure(Sender: TGLForm; var Can: Boolean) of object;
- TGLFormCloseOptions = (co_Hide, co_Ignore, co_Destroy);
- TGLFormCanClose = procedure(Sender: TGLForm; var CanClose: TGLFormCloseOptions) of object;
- TGLFormNotify = procedure(Sender: TGLForm) of object;
- TGLFormMove = procedure(Sender: TGLForm; var Left, Top: Single) of object;
- TGLForm = class(TGLBaseTextControl)
- private
- FOnCanMove: TGLFormCanRequest;
- FOnCanResize: TGLFormCanRequest;
- FOnCanClose: TGLFormCanClose;
- FOnShow: TGLFormNotify;
- FOnHide: TGLFormNotify;
- FOnMoving: TGLFormMove;
- Moving: Boolean;
- OldX: Integer;
- OldY: Integer;
- FTitleColor: TGLColorVector;
- FTitleOffset: Single;
- protected
- procedure InternalMouseDown(Shift: TShiftState; Button: TMouseButton; X, Y: Integer); override;
- procedure InternalMouseUp(Shift: TShiftState; Button: TMouseButton; X, Y: Integer); override;
- procedure InternalMouseMove(Shift: TShiftState; X, Y: Integer); override;
- function GetTitleColor: TColor;
- procedure SetTitleColor(value: TColor);
- public
- constructor Create(AOwner: TComponent); override;
- procedure Close;
- procedure NotifyShow; override;
- procedure NotifyHide; override;
- function MouseUp(Sender: TObject; Button: TMouseButton; Shift:
- TShiftState; X, Y: Integer): Boolean; override;
- function MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer): Boolean; override;
- procedure InternalRender(var rci: TGLRenderContextInfo; renderSelf, renderChildren: Boolean); override;
- published
- property TitleColor: TColor read GetTitleColor write SetTitleColor;
- property OnCanMove: TGLFormCanRequest read FOnCanMove write FOnCanMove;
- property OnCanResize: TGLFormCanRequest read FOnCanResize write FOnCanResize;
- property OnCanClose: TGLFormCanClose read FOnCanClose write FOnCanClose;
- property OnShow: TGLFormNotify read FOnShow write FOnShow;
- property OnHide: TGLFormNotify read FOnHide write FOnHide;
- property OnMoving: TGLFormMove read FOnMoving write FOnMoving;
- property TitleOffset: Single read FTitleOffset write FTitleOffset;
- end;
- TGLPanel = class(TGLBaseControl)
- end;
- TGLCheckBox = class(TGLBaseControl)
- private
- FChecked: Boolean;
- FOnChange: TNotifyEvent;
- FGuiLayoutNameChecked: TGLGuiComponentName;
- FGuiCheckedComponent: TGLGuiComponent;
- FGroup: Integer;
- protected
- procedure SetChecked(NewChecked: Boolean);
- procedure InternalMouseDown(Shift: TShiftState; Button: TMouseButton; X, Y: Integer); override;
- procedure InternalMouseUp(Shift: TShiftState; Button: TMouseButton; X, Y: Integer); override;
- procedure SetGuiLayoutNameChecked(const newName: TGLGuiComponentName);
- procedure SetGuiLayout(NewGui: TGLGuiLayout); override;
- procedure SetGroup(const val: Integer);
- public
- constructor Create(AOwner: TComponent); override;
- procedure InternalRender(var rci: TGLRenderContextInfo; renderSelf,
- renderChildren: Boolean); override;
- procedure NotifyChange(Sender: TObject); override;
- published
- property Group: Integer read FGroup write SetGroup;
- property Checked: Boolean read FChecked write SetChecked;
- property OnChange: TNotifyEvent read FOnChange write FOnChange;
- property GuiLayoutNameChecked: TGLGuiComponentName read FGuiLayoutNameChecked
- write SetGuiLayoutNameChecked;
- end;
- TGLButton = class(TGLFocusControl)
- private
- FPressed : Boolean;
- FOnButtonClick : TNotifyEvent;
- FGuiLayoutNamePressed : TGLGuiComponentName;
- FGuiPressedComponent : TGLGuiComponent;
- FBitBtn : TGLMaterial;
- FGroup : Integer;
- FLogicWidth : Single;
- FLogicHeight : Single;
- FXOffSet : Single;
- FYOffSet : Single;
- FAllowUp : Boolean;
- protected
- procedure SetPressed(NewPressed: Boolean);
- procedure InternalMouseDown(Shift: TShiftState; Button: TMouseButton; X, Y: Integer); override;
- procedure InternalMouseUp(Shift: TShiftState; Button: TMouseButton; X, Y: Integer); override;
- procedure InternalKeyDown(var Key: Word; Shift: TShiftState); override;
- procedure InternalKeyUp(var Key: Word; Shift: TShiftState); override;
- procedure SetFocused(Value: Boolean); override;
- procedure SetGuiLayoutNamePressed(const newName: TGLGuiComponentName);
- procedure SetGuiLayout(NewGui: TGLGuiLayout); override;
- procedure SetBitBtn(AValue: TGLMaterial);
- procedure DestroyHandle; override;
- procedure SetGroup(const val: Integer);
- procedure SetLogicWidth(const val: single);
- procedure SetLogicHeight(const val: single);
- procedure SetXOffset(const val: single);
- procedure SetYOffset(const val: single);
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- procedure InternalRender(var rci: TGLRenderContextInfo; renderSelf, renderChildren: Boolean); override;
- published
- property Group: Integer read FGroup write SetGroup;
- property BitBtn: TGLMaterial read FBitBtn write SetBitBtn;
- property Pressed: Boolean read FPressed write SetPressed;
- property OnButtonClick: TNotifyEvent read FOnButtonClick write FOnButtonClick;
- property GuiLayoutNamePressed: TGLGuiComponentName read FGuiLayoutNamePressed write SetGuiLayoutNamePressed;
- property LogicWidth: Single read FLogicWidth write SetLogicWidth;
- property LogicHeight: Single read FLogicHeight write SetLogicHeight;
- property XOffset: Single read FXOffset write SetXOffset;
- property YOffset: Single read FYOffset write SetYOffset;
- property AllowUp: Boolean read FAllowUp write FAllowUp;
- end;
- TGLEdit = class(TGLFocusControl)
- private
- FOnChange: TNotifyEvent;
- FSelStart: Integer;
- FReadOnly: Boolean;
- FEditChar: string;
- protected
- procedure InternalMouseDown(Shift: TShiftState; Button: TMouseButton; X, Y: Integer); override;
- procedure InternalKeyPress(var Key: Char); override;
- procedure InternalKeyDown(var Key: Word; Shift: TShiftState); override;
- procedure InternalKeyUp(var Key: Word; Shift: TShiftState); override;
- procedure SetFocused(Value: Boolean); override;
- procedure SetSelStart(const Value: Integer);
- procedure SetEditChar(const Value: string);
- public
- constructor Create(AOwner: TComponent); override;
- procedure InternalRender(var rci: TGLRenderContextInfo; renderSelf,
- renderChildren: Boolean); override;
- published
- property EditChar: string read FEditChar write SetEditChar;
- property ReadOnly: Boolean read FReadOnly write FReadOnly default False;
- property OnChange: TNotifyEvent read FOnChange write FOnChange;
- property SelStart: Integer read FSelStart write SetSelStart;
- end;
- TGLLabel = class(TGLBaseTextControl)
- private
- FAlignment: TAlignment;
- FTextLayout: TTextLayout;
- procedure SetAlignment(const Value: TAlignment);
- procedure SetTextLayout(const Value: TTextLayout);
- protected
- public
- constructor Create(AOwner: TComponent); override;
- procedure InternalRender(var rci: TGLRenderContextInfo; renderSelf, renderChildren: Boolean); override;
- published
- property Alignment: TAlignment read FAlignment write SetAlignment;
- property TextLayout: TTextLayout read FTextLayout write SetTextLayout;
- end;
- TGLAdvancedLabel = class(TGLFocusControl)
- private
- protected
- public
- procedure InternalRender(var rci: TGLRenderContextInfo; renderSelf, renderChildren: Boolean); override;
- published
- end;
- TGLScrollbar = class(TGLFocusControl)
- private
- FMin: Single;
- FMax: Single;
- FStep: Single;
- FPos: Single;
- FPageSize: Single;
- FOnChange: TNotifyEvent;
- FGuiLayoutKnobName: TGLGuiComponentName;
- FGuiKnobComponent: TGLGuiComponent;
- FKnobRenderStatus: TGUIDrawResult;
- FScrollOffs: Single;
- FScrolling: Boolean;
- FHorizontal: Boolean;
- FLocked: Boolean;
- protected
- procedure SetMin(const val: Single);
- procedure SetMax(const val: Single);
- procedure SetPos(const val: Single);
- procedure SetPageSize(const val: Single);
- procedure SetHorizontal(const val: Boolean);
- procedure SetGuiLayoutKnobName(const newName: TGLGuiComponentName);
- procedure SetGuiLayout(NewGui: TGLGuiLayout); override;
- function GetScrollPosY(ScrollPos: Single): Single;
- function GetYScrollPos(Y: Single): Single;
- function GetScrollPosX(ScrollPos: Single): Single;
- function GetXScrollPos(X: Single): Single;
- procedure InternalMouseDown(Shift: TShiftState; Button: TMouseButton; X, Y: Integer); override;
- procedure InternalMouseUp(Shift: TShiftState; Button: TMouseButton; X, Y: Integer); override;
- procedure InternalMouseMove(Shift: TShiftState; X, Y: Integer); override;
- public
- constructor Create(AOwner: TComponent); override;
- procedure StepUp;
- procedure StepDown;
- procedure PageUp;
- procedure PageDown;
- function MouseUp(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer): Boolean; override;
- function MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer): Boolean; override;
- procedure InternalRender(var rci: TGLRenderContextInfo; renderSelf, renderChildren: Boolean); override;
- published
- property Horizontal: Boolean read FHorizontal write SetHorizontal;
- property Pos: Single read FPos write SetPos;
- property Min: Single read FMin write SetMin;
- property Max: Single read FMax write SetMax;
- property Step: Single read FStep write FStep;
- property PageSize: Single read FPageSize write SetPageSize;
- property OnChange: TNotifyEvent read FOnChange write FOnChange;
- property GuiLayoutKnobName: TGLGuiComponentName read FGuiLayoutKnobName write SetGuiLayoutKnobName;
- property Locked: Boolean read FLocked write FLocked default False;
- end;
- TGLStringGrid = class(TGLFocusControl)
- private
- FSelCol, FSelRow: Integer;
- FRowSelect: Boolean;
- FColSelect: Boolean;
- FColumns: TStrings;
- FRows: TList;
- FHeaderColor: TGLColorVector;
- FMarginSize: Integer;
- FColumnSize: Integer;
- FRowHeight: Integer;
- FScrollbar: TGLScrollbar;
- FDrawHeader: Boolean;
- protected
- function GetCell(X, Y: Integer; out oCol, oRow: Integer): Boolean;
- procedure InternalMouseDown(Shift: TShiftState; Button: TMouseButton; X, Y: Integer); override;
- procedure SetColumns(const val: TStrings);
- procedure SetColSelect(const val: Boolean);
- function GetRow(index: Integer): TStringList;
- procedure SetRow(index: Integer; const val: TStringList);
- function GetRowCount: Integer;
- procedure SetRowCount(const val: Integer);
- procedure SetSelCol(const val: Integer);
- procedure SetSelRow(const val: Integer);
- procedure SetRowSelect(const val: Boolean);
- procedure SetDrawHeader(const val: Boolean);
- function GetHeaderColor: TColor;
- procedure SetHeaderColor(const val: TColor);
- procedure SetMarginSize(const val: Integer);
- procedure SetColumnSize(const val: Integer);
- procedure SetRowHeight(const val: Integer);
- procedure SetScrollbar(const val: TGLScrollbar);
- procedure SetGuiLayout(NewGui: TGLGuiLayout); override;
- public
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- procedure Clear;
- function Add(const Data: array of string): Integer; overload;
- function Add(const Data: string): Integer; overload;
- procedure SetText(Data: string);
- procedure Notification(AComponent: TComponent; Operation: TOperation); override;
- procedure NotifyChange(Sender: TObject); override;
- procedure InternalRender(var rci: TGLRenderContextInfo; renderSelf, renderChildren: Boolean); override;
- procedure OnStringListChange(Sender: TObject);
- property Row[index: Integer]: TStringList read GetRow write SetRow;
- published
- property HeaderColor: TColor read GetHeaderColor write SetHeaderColor;
- property Columns: TStrings read FColumns write SetColumns;
- property MarginSize: Integer read FMarginSize write SetMarginSize;
- property ColumnSize: Integer read FColumnSize write SetColumnSize;
- property RowHeight: Integer read FRowHeight write SetRowHeight;
- property RowCount: Integer read GetRowCount write SetRowCount;
- property SelCol: Integer read FSelCol write SetSelCol;
- property SelRow: Integer read FSelRow write SetSelRow;
- property RowSelect: Boolean read FRowSelect write SetRowSelect;
- property ColSelect: Boolean read FColSelect write SetColSelect;
- property DrawHeader: Boolean read FDrawHeader write SetDrawHeader;
- property Scrollbar: TGLScrollbar read FScrollbar write SetScrollbar;
- end;
- function UnpressGroup(CurrentObject: TGLBaseSceneObject; AGroupID: Integer): Boolean;
- //--------------------------------------------------------------------------
- implementation
- //--------------------------------------------------------------------------
- function UnpressGroup(CurrentObject: TGLBaseSceneObject; AGroupID: Integer): Boolean;
- var
- XC: Integer;
- begin
- Result := False;
- if CurrentObject is TGLButton then
- with CurrentObject as TGLButton do
- begin
- if Group = AGroupID then
- if Pressed then
- begin
- Pressed := False;
- Result := True;
- Exit;
- end;
- end;
- if CurrentObject is TGLCheckBox then
- with CurrentObject as TGLCheckBox do
- begin
- if Group = AGroupID then
- if Checked then
- begin
- Checked := False;
- Result := True;
- Exit;
- end;
- end;
- for XC := 0 to CurrentObject.Count - 1 do
- begin
- if UnpressGroup(CurrentObject.Children[XC], AGroupID) then
- begin
- Result := True;
- Exit;
- end;
- end;
- end;
- procedure TGLBaseComponent.SetGUIRedraw(value: Boolean);
- begin
- FGUIRedraw := Value;
- if Value then
- begin
- if csDestroying in ComponentState then
- Exit;
- if (FRedrawAtOnce) or (csDesigning in ComponentState) then
- begin
- FGUIRedraw := False;
- StructureChanged;
- end;
- end;
- end;
- procedure TGLBaseComponent.BlockRender;
- begin
- while BlockedCount <> 0 do
- Sleep(1);
- BlockRendering := True;
- while RenderingCount <> BlockedCount do
- Sleep(1);
- end;
- procedure TGLBaseComponent.UnBlockRender;
- begin
- BlockRendering := False;
- end;
- procedure TGLBaseComponent.RenderHeader(var rci: TGLRenderContextInfo; renderSelf,
- renderChildren: Boolean);
- var
- f: Single;
- begin
- FGuiLayout.Material.Apply(rci);
- if AlphaChannel <> 1 then
- rci.GLStates.SetGLMaterialAlphaChannel(GL_FRONT, AlphaChannel);
- // Prepare matrices
- gl.MatrixMode(GL_MODELVIEW);
- gl.PushMatrix;
- gl.LoadMatrixf(@TGLSceneBuffer(rci.buffer).BaseProjectionMatrix);
- if rci.renderDPI = 96 then
- f := 1
- else
- f := rci.renderDPI / 96;
- gl.Scalef(f * 2 / rci.viewPortSize.cx, f * 2 / rci.viewPortSize.cy, 1);
- gl.Translatef(f * Position.X - rci.viewPortSize.cx * 0.5,
- rci.viewPortSize.cy * 0.5 - f * Position.Y, 0);
- if Rotation <> 0 then
- gl.Rotatef(Rotation, 0, 0, 1);
- gl.MatrixMode(GL_PROJECTION);
- gl.PushMatrix;
- gl.LoadIdentity;
- rci.GLStates.Disable(stDepthTest);
- rci.GLStates.DepthWriteMask := False;
- end;
- procedure TGLBaseComponent.RenderFooter(var rci: TGLRenderContextInfo; renderSelf, renderChildren: Boolean);
- begin
- gl.PopMatrix;
- gl.MatrixMode(GL_MODELVIEW);
- gl.PopMatrix;
- FGuiLayout.Material.UnApply(rci);
- end;
- procedure TGLBaseComponent.SetGuiLayout(NewGui: TGLGuiLayout);
- begin
- if FGuiLayout <> NewGui then
- begin
- if Assigned(FGuiLayout) then
- begin
- FGuiLayout.RemoveGuiComponent(Self);
- end;
- FGuiComponent := nil;
- FGuiLayout := NewGui;
- if Assigned(FGuiLayout) then
- if FGuiLayoutName <> '' then
- FGuiComponent := FGuiLayout.GuiComponents.FindItem(FGuiLayoutName);
- // in effect this code have been moved...
- if Assigned(FGuiLayout) then
- FGuiLayout.AddGuiComponent(Self);
- NotifyChange(Self);
- end;
- end;
- procedure TGLBaseComponent.SetGuiLayoutName(const NewName: TGLGuiComponentName);
- begin
- if FGuiLayoutName <> NewName then
- begin
- FGuiComponent := nil;
- FGuiLayoutName := NewName;
- if FGuiLayoutName <> '' then
- if Assigned(FGuiLayout) then
- begin
- FGuiComponent := FGuiLayout.GuiComponents.FindItem(FGuiLayoutName);
- end;
- NotifyChange(Self);
- end;
- end;
- procedure TGLBaseComponent.Notification(AComponent: TComponent; Operation: TOperation);
- begin
- if Operation = opRemove then
- begin
- if AComponent = FGuiLayout then
- begin
- BlockRender;
- GuiLayout := nil;
- UnBlockRender;
- end;
- end;
- inherited;
- end;
- procedure TGLBaseComponent.SetRotation(const val: TGLFloat);
- begin
- if FRotation <> val then
- begin
- FRotation := val;
- NotifyChange(Self);
- end;
- end;
- procedure TGLBaseComponent.SetAlphaChannel(const val: Single);
- begin
- if val <> FAlphaChannel then
- begin
- if val < 0 then
- FAlphaChannel := 0
- else if val > 1 then
- FAlphaChannel := 1
- else
- FAlphaChannel := val;
- NotifyChange(Self);
- end;
- end;
- procedure TGLBaseComponent.SetAutosize(const Value: Boolean);
- var
- MarginLeft, MarginCenter, MarginRight: TGLFloat;
- MarginTop, MarginMiddle, MarginBottom: TGLFloat;
- MaxWidth: TGLFloat;
- MaxHeight: TGLFloat;
- i: integer;
- begin
- if FAutosize <> Value then
- begin
- FAutosize := Value;
- if FAutosize and Assigned(FGuiComponent) then
- begin
- MarginLeft := 0;
- MarginCenter := 0;
- MarginRight := 0;
- MarginTop := 0;
- MarginMiddle := 0;
- MarginBottom := 0;
- for i := 0 to FGuiComponent.Elements.Count - 1 do
- with FGuiComponent.Elements[i] do
- begin
- case Align of
- GLAlTopLeft, GLAlLeft, GLAlBottomLeft:
- begin
- MarginLeft := Max(MarginLeft, abs(BottomRight.X - TopLeft.X) *
- Scale.X);
- end;
- GLAlTop, GLAlCenter, GLAlBottom:
- begin
- MarginCenter := Max(MarginCenter, abs(BottomRight.X - TopLeft.X)
- * Scale.X);
- end;
- GLAlTopRight, GLAlRight, GLAlBottomRight:
- begin
- MarginRight := Max(MarginRight, abs(BottomRight.X - TopLeft.X) *
- Scale.X);
- end;
- end;
- end;
- for i := 0 to FGuiComponent.Elements.Count - 1 do
- with FGuiComponent.Elements[i] do
- begin
- case Align of
- GLAlTopLeft, GLAlTop, GLAlTopRight:
- begin
- MarginTop := Max(MarginTop, abs(BottomRight.Y - TopLeft.Y) *
- Scale.Y);
- end;
- GLAlLeft, GLAlCenter, GLAlRight:
- begin
- MarginMiddle := Max(MarginMiddle, abs(BottomRight.Y - TopLeft.Y)
- * Scale.Y);
- end;
- GLAlBottomLeft, GLAlBottom, GLAlBottomRight:
- begin
- MarginBottom := Max(MarginBottom, abs(BottomRight.Y - TopLeft.Y)
- * Scale.Y);
- end;
- end;
- end;
- MaxWidth := MarginLeft + MarginCenter + MarginRight;
- MaxHeight := MarginTop + MarginMiddle + MarginBottom;
- if MaxWidth > 0 then
- Width := MaxWidth;
- if MaxHeight > 0 then
- Height := MaxHeight;
- end;
- end;
- end;
- function TGLBaseComponent.StoreAlphaChannel: Boolean;
- begin
- Result := (FAlphaChannel <> 1);
- end;
- procedure TGLBaseComponent.SetNoZWrite(const val: Boolean);
- begin
- FNoZWrite := val;
- NotifyChange(Self);
- end;
- constructor TGLBaseComponent.Create(AOwner: TComponent);
- begin
- inherited;
- FGuiLayout := nil;
- FGuiComponent := nil;
- BlockRendering := False;
- BlockedCount := 0;
- RenderingCount := 0;
- Width := 50;
- Height := 50;
- FReBuildGui := True;
- GuiDestroying := False;
- FAlphaChannel := 1;
- end;
- destructor TGLBaseComponent.Destroy;
- begin
- GuiDestroying := True;
- while RenderingCount > 0 do
- Sleep(1);
- GuiLayout := nil;
- inherited;
- end;
- procedure TGLBaseComponent.NotifyChange(Sender: TObject);
- begin
- if Sender = FGuiLayout then
- begin
- if (FGuiLayoutName <> '') and (GuiLayout <> nil) then
- begin
- BlockRender;
- FGuiComponent := GuiLayout.GuiComponents.FindItem(FGuiLayoutName);
- ReBuildGui := True;
- GUIRedraw := True;
- UnBlockRender;
- end
- else
- begin
- BlockRender;
- FGuiComponent := nil;
- ReBuildGui := True;
- GUIRedraw := True;
- UnBlockRender;
- end;
- end;
- if Sender = Self then
- begin
- ReBuildGui := True;
- GUIRedraw := True;
- end;
- inherited;
- end;
- procedure TGLBaseComponent.MoveGUI(XRel, YRel: Single);
- var
- XC: Integer;
- begin
- if RedrawAtOnce then
- begin
- BeginUpdate;
- try
- MoveX := MoveX + XRel;
- MoveY := MoveY + YRel;
- for XC := 0 to Count - 1 do
- if Children[XC] is TGLBaseComponent then
- begin
- (Children[XC] as TGLBaseComponent).MoveGUI(XRel, YRel);
- end;
- GUIRedraw := True;
- DoChanges;
- finally
- Endupdate;
- end;
- end
- else
- begin
- MoveX := MoveX + XRel;
- MoveY := MoveY + YRel;
- for XC := 0 to Count - 1 do
- if Children[XC] is TGLBaseComponent then
- begin
- (Children[XC] as TGLBaseComponent).MoveGUI(XRel, YRel);
- end;
- GUIRedraw := True;
- end;
- end;
- procedure TGLBaseComponent.PlaceGUI(XPos, YPos: Single);
- begin
- MoveGUI(XPos - Position.X, YPos - Position.Y);
- end;
- procedure TGLBaseComponent.DoChanges;
- var
- XC: Integer;
- begin
- if GUIRedraw then
- begin
- GUIRedraw := False;
- BeginUpdate;
- try
- if MoveX <> 0 then
- Position.X := Position.X + MoveX;
- if MoveY <> 0 then
- Position.Y := Position.Y + MoveY;
- MoveX := 0;
- MoveY := 0;
- for XC := 0 to Count - 1 do
- if Children[XC] is TGLBaseComponent then
- begin
- (Children[XC] as TGLBaseComponent).DoChanges;
- end;
- finally
- EndUpdate;
- end;
- end
- else
- begin
- for XC := 0 to Count - 1 do
- if Children[XC] is TGLBaseComponent then
- begin
- (Children[XC] as TGLBaseComponent).DoChanges;
- end;
- end;
- end;
- procedure TGLBaseComponent.InternalRender(var rci: TGLRenderContextInfo;
- renderSelf, renderChildren: Boolean);
- begin
- if Assigned(FGuiComponent) then
- begin
- try
- FGuiComponent.RenderToArea(0, 0, Width, Height, FRenderStatus,
- FReBuildGui);
- except
- on E: Exception do
- GLOKMessageBox(E.Message,
- 'Exception in GuiComponents InternalRender function');
- end;
- end;
- end;
- procedure TGLBaseComponent.DoRender(var rci: TGLRenderContextInfo; renderSelf,
- renderChildren: Boolean);
- var
- B: Boolean;
- begin
- Inc(RenderingCount);
- B := BlockRendering;
- if B then
- begin
- Inc(BlockedCount);
- while BlockRendering do
- sleep(1);
- Dec(BlockedCount);
- end;
- if not GuiDestroying then
- if RenderSelf then
- if FGuiLayout <> nil then
- begin
- RenderHeader(rci, renderSelf, renderChildren);
- InternalRender(rci, RenderSelf, RenderChildren);
- RenderFooter(rci, renderSelf, renderChildren);
- FReBuildGui := False;
- end;
- if renderChildren then
- if Count > 0 then
- Self.RenderChildren(0, Count - 1, rci);
- Dec(RenderingCount);
- end;
- procedure TGLBaseControl.InternalMouseDown(Shift: TShiftState; Button:
- TMouseButton; X, Y: Integer);
- begin
- if Assigned(FOnMouseDown) then
- FOnMouseDown(Self, Button, Shift, X, Y);
- end;
- procedure TGLBaseControl.InternalMouseUp(Shift: TShiftState; Button:
- TMouseButton; X, Y: Integer);
- begin
- if Assigned(FOnMouseUp) then
- FOnMouseUp(Self, Button, Shift, X, Y);
- end;
- procedure TGLBaseControl.InternalMouseMove(Shift: TShiftState; X, Y: Integer);
- begin
- if Assigned(FOnMouseMove) then
- FOnMouseMove(Self, Shift, X, Y);
- end;
- procedure TGLBaseControl.SetActiveControl(NewControl: TGLBaseControl);
- begin
- FActiveControl := NewControl;
- end;
- procedure TGLBaseControl.SetFocusedControl(NewControl: TGLFocusControl);
- begin
- if NewControl <> FFocusedControl then
- begin
- if Assigned(FFocusedControl) then
- FFocusedControl.Focused := False;
- FFocusedControl := NewControl;
- if Assigned(FFocusedControl) then
- FFocusedControl.Focused := True;
- end;
- end;
- function TGLBaseControl.FindFirstGui: TGLBaseControl;
- var
- tmpFirst: TGLBaseControl;
- TmpRoot: TGLBaseSceneObject;
- begin
- tmpFirst := Self;
- TmpRoot := Self;
- while (TmpRoot is TGLBaseComponent) do
- begin
- if Assigned(TmpRoot.parent) then
- begin
- if TmpRoot.parent is TGLBaseComponent then
- begin
- TmpRoot := TmpRoot.parent as TGLBaseComponent;
- if TmpRoot is TGLBaseControl then
- tmpFirst := TmpRoot as TGLBaseControl;
- end
- else
- Break;
- end
- else
- Break;
- end;
- Result := tmpFirst;
- end;
- procedure TGLBaseControl.Notification(AComponent: TComponent;
- Operation: TOperation);
- begin
- if Operation = opRemove then
- begin
- if FEnteredControl <> nil then
- begin
- FEnteredControl.DoMouseLeave;
- FEnteredControl := nil;
- end;
- end;
- inherited;
- end;
- function TGLBaseControl.MouseDown(Sender: TObject; Button: TMouseButton;
- Shift: TShiftState; X, Y: Integer): Boolean;
- var
- Xc: Integer;
- AcceptMouseEvent: Boolean;
- begin
- Result := False;
- AcceptMouseEvent := RecursiveVisible and ((Position.X <= X) and (Position.X +
- Width > X) and (Position.Y <= Y) and (Position.Y + Height > Y));
- if Assigned(OnAcceptMouseQuery) then
- OnAcceptMouseQuery(Self, shift, ma_mousedown, Button, X, Y,
- AcceptMouseEvent);
- if AcceptMouseEvent then
- begin
- Result := True;
- if not FKeepMouseEvents then
- begin
- if Assigned(FActiveControl) then
- if FActiveControl.MouseDown(Sender, Button, Shift, X, Y) then
- Exit;
- for XC := count - 1 downto 0 do
- if FActiveControl <> Children[XC] then
- begin
- if Children[XC] is TGLBaseControl then
- begin
- if (Children[XC] as TGLBaseControl).MouseDown(Sender, button, shift,
- x, y) then
- Exit;
- end;
- end;
- end;
- InternalMouseDown(Shift, Button, X, Y);
- end;
- end;
- function TGLBaseControl.MouseUp(Sender: TObject; Button: TMouseButton; Shift:
- TShiftState; X, Y: Integer): Boolean;
- var
- Xc: Integer;
- AcceptMouseEvent: Boolean;
- begin
- Result := False;
- AcceptMouseEvent := RecursiveVisible and ((Position.X <= X) and (Position.X +
- Width > X) and (Position.Y <= Y) and (Position.Y + Height > Y));
- if Assigned(OnAcceptMouseQuery) then
- OnAcceptMouseQuery(Self, shift, ma_mouseup, Button, X, Y, AcceptMouseEvent);
- if AcceptMouseEvent then
- begin
- Result := True;
- if not FKeepMouseEvents then
- begin
- if Assigned(FActiveControl) then
- if FActiveControl.MouseUp(Sender, button, shift, x, y) then
- Exit;
- for XC := count - 1 downto 0 do
- if FActiveControl <> Children[XC] then
- begin
- if Children[XC] is TGLBaseControl then
- begin
- if (Children[XC] as TGLBaseControl).MouseUp(Sender, button, shift,
- x, y) then
- Exit;
- end;
- end;
- end;
- InternalMouseUp(Shift, Button, X, Y);
- end;
- end;
- function TGLBaseControl.MouseMove(Sender: TObject; Shift: TShiftState; X, Y:
- Integer): Boolean;
- var
- Xc: Integer;
- AcceptMouseEvent: Boolean;
- begin
- Result := False;
- AcceptMouseEvent := RecursiveVisible and ((Position.X <= X) and (Position.X +
- Width > X) and (Position.Y <= Y) and (Position.Y + Height > Y));
- if Assigned(OnAcceptMouseQuery) then
- OnAcceptMouseQuery(Self, shift, ma_mousemove, mbMiddle, X, Y,
- AcceptMouseEvent);
- if AcceptMouseEvent then
- begin
- Result := True;
- if not FKeepMouseEvents then
- begin
- if Assigned(FActiveControl) then
- if FActiveControl.MouseMove(Sender, shift, x, y) then
- Exit;
- for XC := count - 1 downto 0 do
- if FActiveControl <> Children[XC] then
- begin
- if Children[XC] is TGLBaseControl then
- begin
- if (Children[XC] as TGLBaseControl).MouseMove(Sender, shift, x, y)
- then
- begin
- if FEnteredControl <> (Children[XC] as TGLBaseControl) then
- begin
- if FEnteredControl <> nil then
- begin
- FEnteredControl.DoMouseLeave;
- end;
- FEnteredControl := (Children[XC] as TGLBaseControl);
- if FEnteredControl <> nil then
- begin
- FEnteredControl.DoMouseEnter;
- end;
- end;
- Exit;
- end;
- end;
- end;
- end;
- if FEnteredControl <> nil then
- begin
- FEnteredControl.DoMouseLeave;
- FEnteredControl := nil;
- end;
- InternalMouseMove(Shift, X, Y);
- end;
- end;
- procedure TGLBaseControl.KeyDown(Sender: TObject; var Key: Word; Shift:
- TShiftState);
- begin
- if Assigned(FFocusedControl) then
- begin
- FFocusedControl.KeyDown(Sender, Key, Shift);
- end;
- end;
- procedure TGLBaseControl.KeyUp(Sender: TObject; var Key: Word; Shift:
- TShiftState);
- begin
- if Assigned(FFocusedControl) then
- begin
- FFocusedControl.KeyUp(Sender, Key, Shift);
- end;
- end;
- procedure TGLBaseControl.KeyPress(Sender: TObject; var Key: Char);
- begin
- if Assigned(FFocusedControl) then
- begin
- FFocusedControl.KeyPress(Sender, Key);
- end;
- end;
- procedure TGLFocusControl.InternalKeyPress(var Key: Char);
- begin
- if assigned(FOnKeyPress) then
- FOnKeyPress(Self, Key);
- end;
- procedure TGLFocusControl.InternalKeyDown(var Key: Word; Shift: TShiftState);
- begin
- if assigned(FOnKeyDown) then
- FOnKeyDown(Self, Key, shift);
- end;
- procedure TGLFocusControl.InternalKeyUp(var Key: Word; Shift: TShiftState);
- begin
- if assigned(FOnKeyUp) then
- FOnKeyUp(Self, Key, shift);
- end;
- procedure TGLBaseControl.DoMouseEnter;
- begin
- if Assigned(OnMouseEnter) then
- OnMouseEnter(Self);
- end;
- procedure TGLBaseControl.DoMouseLeave;
- begin
- //leave all child controls
- if FEnteredControl <> nil then
- begin
- FEnteredControl.DoMouseLeave;
- FEnteredControl := nil;
- end;
- if Assigned(OnMouseLeave) then
- OnMouseLeave(Self);
- end;
- procedure TGLFocusControl.SetFocused(Value: Boolean);
- begin
- if Value <> FFocused then
- begin
- FFocused := Value;
- GUIRedraw := True;
- end;
- end;
- function TGLFocusControl.GetRootControl: TGLBaseControl;
- begin
- if not Assigned(FRootControl) then
- begin
- FRootControl := FindFirstGui;
- end;
- Result := FRootControl;
- end;
- procedure TGLFocusControl.NotifyHide;
- begin
- inherited;
- if (RootControl.FFocusedControl = Self) and (self.focused) then
- begin
- RootControl.FocusedControl.PrevControl;
- end;
- end;
- procedure TGLFocusControl.ReGetRootControl;
- begin
- FRootControl := FindFirstGui;
- end;
- function TGLFocusControl.GetFocusedColor: TColor;
- begin
- Result := ConvertColorVector(FFocusedColor);
- end;
- procedure TGLFocusControl.SetFocusedColor(const Val: TColor);
- begin
- FFocusedColor := ConvertWinColor(val);
- GUIRedraw := True;
- end;
- procedure TGLFocusControl.SetFocus;
- begin
- RootControl.FocusedControl := Self;
- end;
- procedure TGLFocusControl.NextControl;
- var
- Host: TGLBaseComponent;
- Index: Integer;
- IndexedChild: TGLBaseComponent;
- RestartedLoop: Boolean;
- begin
- RestartedLoop := False;
- if Parent is TGLBaseComponent then
- begin
- Host := Parent as TGLBaseComponent;
- Index := Host.IndexOfChild(Self);
- while not Host.RecursiveVisible do
- begin
- if Host.Parent is TGLBaseComponent then
- begin
- IndexedChild := Host;
- Host := Host.Parent as TGLBaseComponent;
- Index := Host.IndexOfChild(IndexedChild);
- end
- else
- begin
- RootControl.FocusedControl := nil;
- Exit;
- end;
- end;
- while true do
- begin
- if Index > 0 then
- begin
- Dec(Index);
- if Host.Children[Index] is TGLFocusControl then
- begin
- with (Host.Children[Index] as TGLFocusControl) do
- if RecursiveVisible then
- begin
- SetFocus;
- Exit;
- end;
- end
- else
- begin
- if Host.Children[Index] is TGLBaseComponent then
- begin
- IndexedChild := Host.Children[Index] as TGLBaseComponent;
- if IndexedChild.RecursiveVisible then
- begin
- Host := IndexedChild;
- Index := Host.Count;
- end;
- end;
- end;
- end
- else
- begin
- if Host.Parent is TGLBaseComponent then
- begin
- Index := Host.Parent.IndexOfChild(Host);
- Host := Host.Parent as TGLBaseComponent;
- end
- else
- begin
- if RestartedLoop then
- begin
- SetFocus;
- Exit;
- end;
- Index := Host.Count;
- RestartedLoop := True;
- end;
- end;
- end;
- end;
- end;
- procedure TGLFocusControl.PrevControl;
- var
- Host: TGLBaseComponent;
- Index: Integer;
- IndexedChild: TGLBaseComponent;
- RestartedLoop: Boolean;
- begin
- RestartedLoop := False;
- if Parent is TGLBaseComponent then
- begin
- Host := Parent as TGLBaseComponent;
- Index := Host.IndexOfChild(Self);
- while not Host.RecursiveVisible do
- begin
- if Host.Parent is TGLBaseComponent then
- begin
- IndexedChild := Host;
- Host := Host.Parent as TGLBaseComponent;
- Index := Host.IndexOfChild(IndexedChild);
- end
- else
- begin
- RootControl.FocusedControl := nil;
- Exit;
- end;
- end;
- while true do
- begin
- Inc(Index);
- if Index < Host.Count then
- begin
- if Host.Children[Index] is TGLFocusControl then
- begin
- with (Host.Children[Index] as TGLFocusControl) do
- if RecursiveVisible then
- begin
- SetFocus;
- Exit;
- end;
- end;
- if Host.Children[Index] is TGLBaseComponent then
- begin
- IndexedChild := Host.Children[Index] as TGLBaseComponent;
- if IndexedChild.RecursiveVisible then
- begin
- Host := IndexedChild;
- Index := -1;
- end;
- end;
- end
- else
- begin
- if Host.Parent is TGLBaseComponent then
- begin
- IndexedChild := Host;
- Host := Host.Parent as TGLBaseComponent;
- Index := Host.IndexOfChild(IndexedChild);
- end
- else
- begin
- if RestartedLoop then
- begin
- RootControl.FocusedControl := nil;
- Exit;
- end;
- Index := -1;
- RestartedLoop := True;
- end;
- end;
- end;
- end;
- end;
- procedure TGLFocusControl.KeyPress(Sender: TObject; var Key: Char);
- begin
- InternalKeyPress(Key);
- if Key = #9 then
- begin
- if ssShift in FShiftState then
- begin
- PrevControl;
- end
- else
- begin
- NextControl;
- end;
- end;
- end;
- procedure TGLFocusControl.KeyDown(Sender: TObject; var Key: Word; Shift:
- TShiftState);
- begin
- FShiftState := Shift;
- InternalKeyDown(Key, Shift);
- if Key = VK_TAB then
- begin
- if ssShift in FShiftState then
- begin
- PrevControl;
- end
- else
- begin
- NextControl;
- end;
- end;
- end;
- procedure TGLFocusControl.KeyUp(Sender: TObject; var Key: Word; Shift:
- TShiftState);
- begin
- FShiftState := Shift;
- InternalKeyUp(Key, Shift);
- if Key = VK_TAB then
- begin
- if ssShift in FShiftState then
- begin
- PrevControl;
- end
- else
- begin
- NextControl;
- end;
- end;
- end;
- //------------------------
- // base font control
- //------------------------
- constructor TGLBaseFontControl.Create(AOwner: TComponent);
- begin
- inherited;
- FBitmapFont := nil;
- FDefaultColor := clrBlack;
- end;
- destructor TGLBaseFontControl.Destroy;
- begin
- inherited;
- BitmapFont := nil;
- end;
- procedure TGLBaseFontControl.SetBitmapFont(NewFont: TGLCustomBitmapFont);
- begin
- if NewFont <> FBitmapFont then
- begin
- if Assigned(FBitmapFont) then
- begin
- FBitmapFont.RemoveFreeNotification(Self);
- FBitmapFont.UnRegisterUser(Self);
- end;
- FBitmapFont := NewFont;
- if Assigned(FBitmapFont) then
- begin
- FBitmapFont.RegisterUser(Self);
- FBitmapFont.FreeNotification(Self);
- end;
- GUIRedraw := True;
- end;
- end;
- function TGLBaseFontControl.GetBitmapFont: TGLCustomBitmapFont;
- begin
- Result := nil;
- if Assigned(FBitmapFont) then
- Result := FBitmapFont
- else if Assigned(GuiLayout) then
- if Assigned(GuiLayout.BitmapFont) then
- begin
- if not (csDesigning in ComponentState) then
- begin
- if not GuiDestroying then
- begin
- BitmapFont := GuiLayout.BitmapFont;
- Result := FBitmapFont;
- end;
- end
- else
- Result := GuiLayout.BitmapFont;
- end;
- end;
- function TGLBaseFontControl.GetDefaultColor: TColor;
- begin
- Result := ConvertColorVector(FDefaultColor);
- end;
- procedure TGLBaseFontControl.SetDefaultColor(value: TColor);
- begin
- FDefaultColor := ConvertWinColor(value);
- GUIRedraw := True;
- NotifyChange(Self);
- end;
- procedure TGLBaseFontControl.Notification(AComponent: TComponent; Operation:
- TOperation);
- begin
- if (Operation = opRemove) and (AComponent = FBitmapFont) then
- begin
- BlockRender;
- BitmapFont := nil;
- UnBlockRender;
- end;
- inherited;
- end;
- //----------------------------------
- // GLBaseTextControl
- //----------------------------------
- procedure TGLBaseTextControl.SetCaption(const NewCaption: UnicodeString);
- begin
- FCaption := NewCaption;
- GuiRedraw := True;
- end;
- procedure TGLBaseFontControl.WriteTextAt(var rci: TGLRenderContextInfo; const X,
- Y: TGLFloat; const Data: UnicodeString; const Color: TGLColorVector);
- var
- Position: TGLVector;
- begin
- if Assigned(BitmapFont) then
- begin
- Position.X := Round(X);
- Position.Y := Round(Y);
- Position.Z := 0;
- Position.W := 0;
- BitmapFont.RenderString(rci, Data, taLeftJustify, tlTop, Color, @Position);
- end;
- end;
- procedure TGLBaseFontControl.WriteTextAt(var rci: TGLRenderContextInfo; const X1,
- Y1, X2, Y2: TGLFloat; const Data: UnicodeString; const Color: TGLColorVector);
- var
- Position: TGLVector;
- begin
- if Assigned(BitmapFont) then
- begin
- Position.X := Round(((X2 + X1 -
- BitmapFont.CalcStringWidth(Data)) * 0.5));
- Position.Y := Round(-((Y2 + Y1 - GetFontHeight) * 0.5)) + 2;
- Position.Z := 0;
- Position.W := 0;
- BitmapFont.RenderString(rci, Data, taLeftJustify, tlTop, Color, @Position);
- end;
- end;
- function TGLBaseFontControl.GetFontHeight: Integer;
- begin
- if Assigned(BitmapFont) then
- if BitmapFont is TGLWindowsBitmapFont then
- Result := Abs((BitmapFont as TGLWindowsBitmapFont).Font.Height)
- else
- Result := BitmapFont.CharHeight
- else
- Result := -1;
- end;
- //----------------------------------
- // GLBaseCustomControl
- //----------------------------------
- constructor TGLCustomControl.Create(AOwner: TComponent);
- begin
- inherited;
- FMaterial := TGLMaterial.create(Self);
- FBitmap := TBitmap.create;
- FBitmap.OnChange := OnBitmapChanged;
- FInternalBitmap := nil;
- FInvalidRenderCount := 0;
- FXTexCoord := 1;
- FYTexCoord := 1;
- end;
- destructor TGLCustomControl.Destroy;
- begin
- if Assigned(FInternalBitmap) then
- FInternalBitmap.Free;
- Bitmap.Free;
- FMaterial.Free;
- inherited;
- end;
- procedure TGLCustomControl.SetCentered(const Value: Boolean);
- begin
- FCentered := Value;
- end;
- procedure TGLCustomControl.OnBitmapChanged(Sender: TObject);
- begin
- FBitmapChanged := True;
- end;
- procedure TGLCustomControl.SetBitmap(ABitmap: TBitmap);
- begin
- FBitmap.Assign(ABitmap);
- end;
- procedure TGLCustomControl.InternalRender(var rci: TGLRenderContextInfo;
- renderSelf, renderChildren: Boolean);
- var
- X1, X2, Y1, Y2: Single;
- begin
- if Assigned(OnRender) then
- OnRender(self, FBitmap);
- if FBitmapChanged then
- if FInvalidRenderCount >= FMaxInvalidRenderCount then
- begin
- FInvalidRenderCount := 0;
- if not Assigned(FInternalBitmap) then
- FInternalBitmap := TBitmap.Create;
- FInternalBitmap.PixelFormat := FBitmap.PixelFormat;
- FInternalBitmap.Width := RoundUpToPowerOf2(FBitmap.Width);
- FInternalBitmap.Height := RoundUpToPowerOf2(FBitmap.Height);
- FInternalBitmap.Canvas.CopyRect(FBitmap.Canvas.ClipRect, FBitmap.Canvas,
- FBitmap.Canvas.ClipRect);
- FBitmapChanged := False;
- with Material.GetActualPrimaryTexture do
- begin
- Disabled := False;
- Image.Assign(FInternalBitmap);
- end;
- FXTexCoord := FBitmap.Width / FInternalBitmap.Width;
- FYTexCoord := FBitmap.Height / FInternalBitmap.Height;
- end
- else
- Inc(FInvalidRenderCount);
- if Assigned(FGuiComponent) then
- begin
- try
- if Centered then
- FGuiComponent.RenderToArea(-Width / 2, -Height / 2, Width, Height,
- FRenderStatus, FReBuildGui)
- else
- FGuiComponent.RenderToArea(0, 0, Width, Height, FRenderStatus,
- FReBuildGui);
- except
- on E: Exception do
- GLOKMessageBox(E.Message,
- 'Exception in TGLCustomControl InternalRender function');
- end;
- X1 := FRenderStatus[GLAlCenter].X1;
- X2 := FRenderStatus[GLAlCenter].X2;
- Y1 := -FRenderStatus[GLAlCenter].Y2;
- Y2 := -FRenderStatus[GLAlCenter].Y1;
- end
- else
- begin
- if Centered then
- begin
- X2 := Width / 2;
- Y1 := -Height / 2;
- X1 := -X2;
- Y2 := -Y1;
- end
- else
- begin
- X2 := Width;
- Y2 := -Height;
- X1 := 0;
- Y1 := 0;
- end;
- end;
- GuiLayout.Material.UnApply(rci);
- Material.Apply(rci);
- gl.Begin_(GL_QUADS);
- gl.TexCoord2f(FXTexCoord, -FYTexCoord);
- gl.Vertex2f(X2, Y2);
- gl.TexCoord2f(FXTexCoord, 0);
- gl.Vertex2f(X2, Y1);
- gl.TexCoord2f(0, 0);
- gl.Vertex2f(X1, Y1);
- gl.TexCoord2f(0, -FYTexCoord);
- gl.Vertex2f(X1, Y2);
- gl.End_();
- Material.UnApply(rci);
- GuiLayout.Material.Apply(rci);
- end;
- procedure TGLCustomControl.SetMaterial(AMaterial: TGLMaterial);
- begin
- FMaterial.Assign(AMaterial);
- end;
- //----------------------------------
- // GLPopupMenu
- //----------------------------------
- procedure TGLPopupMenu.SetFocused(Value: Boolean);
- begin
- inherited;
- if not (csDesigning in ComponentState) then
- if not FFocused then
- Visible := False;
- end;
- procedure TGLPopupMenu.SetMenuItems(Value: TStrings);
- begin
- FMenuItems.Assign(Value);
- NotifyChange(Self);
- end;
- procedure TGLPopupMenu.SetMarginSize(const val: Single);
- begin
- if FMarginSize <> val then
- begin
- FMarginSize := val;
- NotifyChange(Self);
- end;
- end;
- procedure TGLPopupMenu.SetSelIndex(const val: Integer);
- begin
- if FSelIndex <> val then
- begin
- FSelIndex := val;
- NotifyChange(Self);
- end;
- end;
- procedure TGLPopupMenu.InternalMouseDown(Shift: TShiftState; Button:
- TMouseButton; X, Y: Integer);
- var
- ClickIndex: Integer;
- Tx: Single;
- Ty: Single;
- begin
- Tx := X - Position.X;
- Ty := Y - Position.Y;
- if Button = mbLeft then
- if IsInRect(fRenderStatus[glAlCenter], Tx, Ty) then
- if Assigned(BitmapFont) then
- begin
- ClickIndex := Round(Int((Ty - fRenderStatus[glAlCenter].y1) /
- BitmapFont.CharHeight));
- if (ClickIndex >= 0) and (ClickIndex < FMenuItems.Count) then
- begin
- if Assigned(OnClick) then
- OnClick(Self, ClickIndex, FMenuItems[ClickIndex]);
- Visible := False;
- end;
- end;
- end;
- procedure TGLPopupMenu.InternalMouseMove(Shift: TShiftState; X, Y: Integer);
- var
- Tx: Single;
- Ty: Single;
- begin
- Tx := X - Position.X;
- Ty := Y - Position.Y;
- if IsInRect(fRenderStatus[glAlCenter], Tx, Ty) then
- if Assigned(BitmapFont) then
- begin
- SelIndex := Round(Int((Ty - fRenderStatus[glAlCenter].y1) /
- BitmapFont.CharHeight));
- end;
- end;
- procedure TGLPopupMenu.OnStringListChange(Sender: TObject);
- var
- CenterHeight: Single;
- TextHeight: Single;
- begin
- if not FReBuildGui then
- begin
- if Assigned(BitmapFont) then
- with FRenderStatus[GLalCenter] do
- begin
- CenterHeight := Y2 - Y1;
- CenterHeight := Round(CenterHeight + 0.499);
- TextHeight := BitmapFont.CharHeight * FMenuItems.Count;
- if CenterHeight <> TextHeight then // allways round up!
- begin
- Height := Height + TextHeight - CenterHeight;
- end;
- end;
- end;
- end;
- constructor TGLPopupMenu.Create(AOwner: TComponent);
- begin
- inherited;
- FOnClick := nil;
- FMenuItems := TStringList.Create;
- (FMenuItems as TStringList).OnChange := OnStringListChange;
- FSelIndex := 0;
- NewHeight := -1;
- end;
- destructor TGLPopupMenu.Destroy;
- begin
- inherited;
- FMenuItems.Free;
- end;
- procedure TGLPopupMenu.PopUp(Px, Py: Integer);
- begin
- Position.X := PX;
- Position.Y := PY;
- Visible := True;
- SetFocus;
- RootControl.ActiveControl := Self;
- end;
- procedure TGLPopupMenu.InternalRender(var rci: TGLRenderContextInfo; renderSelf,
- renderChildren: Boolean);
- var
- CenterHeight: Single;
- TextHeight: Single;
- YPos: Single;
- XPos: Single;
- XC: Integer;
- changedHeight: single;
- begin
- if Assigned(FGuiComponent) then
- begin
- try
- if NewHeight <> -1 then
- FGuiComponent.RenderToArea(0, 0, Width, NewHeight, FRenderStatus,
- FReBuildGui)
- else
- FGuiComponent.RenderToArea(0, 0, Width, Height, FRenderStatus,
- FReBuildGui);
- except
- on E: Exception do
- GLOKMessageBox(E.Message,
- 'Exception in GuiComponents InternalRender function');
- end;
- end;
- if Assigned(BitmapFont) and (FMenuItems.Count > 0) then
- with FRenderStatus[GLalCenter] do
- begin
- CenterHeight := Y2 - Y1;
- CenterHeight := Round(CenterHeight + 0.499);
- TextHeight := BitmapFont.CharHeight * FMenuItems.Count;
- if CenterHeight <> TextHeight then // allways round up!
- begin
- changedHeight := Height + TextHeight - CenterHeight;
- if changedHeight <> newHeight then
- begin
- newHeight := changedHeight;
- InternalRender(rci, RenderSelf, RenderChildren);
- end;
- end
- else
- begin
- YPos := -Y1;
- XPos := X1 + MarginSize;
- for XC := 0 to FMenuItems.count - 1 do
- begin
- if FSelIndex = XC then
- WriteTextAt(rci, XPos, YPos, FMenuItems[XC], FFocusedColor)
- else
- WriteTextAt(rci, XPos, YPos, FMenuItems[XC], FDefaultColor);
- YPos := YPos - BitmapFont.CharHeight;
- end;
- end;
- end;
- end;
- procedure TGLPopupMenu.DoRender(var rci: TGLRenderContextInfo; renderSelf,
- renderChildren: Boolean);
- begin
- inherited;
- // to avoid gui render-block deadlock!
- if NewHeight <> -1 then
- begin
- Height := NewHeight;
- NewHeight := -1;
- end;
- end;
- function TGLPopupMenu.MouseDown(Sender: TObject; Button: TMouseButton; Shift:
- TShiftState; X, Y: Integer): Boolean;
- begin
- Result := inherited MouseDown(Sender, Button, Shift, X, Y);
- if (not Result) and (RootControl.ActiveControl = Self) then
- begin
- RootControl.ActiveControl := nil;
- NextControl;
- end;
- end;
- //----------------------------------
- // GLForm
- //----------------------------------
- procedure TGLForm.InternalMouseDown(Shift: TShiftState; Button: TMouseButton;
- X, Y: Integer);
- var
- CanMove: Boolean;
- YHere: TGLFloat;
- begin
- YHere := Y - Position.Y;
- if YHere < FRenderStatus[GLALTop].Y2 then
- begin
- if Button = mbLeft then
- begin
- (* If contains(Width-22,Width-6,XHere) and contains(8,24,YHere) then
- Begin
- Close;
- End else(**)
- begin
- CanMove := True;
- if Assigned(FOnCanMove) then
- FOnCanMove(Self, CanMove);
- if CanMove then
- begin
- OldX := X;
- OldY := Y;
- Moving := True;
- if Parent is TGLFocusControl then
- (Parent as TGLFocusControl).ActiveControl := Self;
- end;
- end;
- end;
- end
- else
- inherited;
- end;
- procedure TGLForm.InternalMouseUp(Shift: TShiftState; Button: TMouseButton; X,
- Y: Integer);
- begin
- if (Button = mbLeft) and Moving then
- begin
- Moving := False;
- if Parent is TGLFocusControl then
- (Parent as TGLFocusControl).ActiveControl := nil;
- Exit;
- end;
- if Y - Position.Y < 27 then
- begin
- end
- else
- inherited;
- end;
- procedure TGLForm.InternalMouseMove(Shift: TShiftState; X, Y: Integer);
- var
- XRel, YRel: Single;
- begin
- if Moving then
- begin
- if (X <> OldX) or (Y <> OldY) then
- begin
- XRel := X - OldX;
- YRel := Y - OldY;
- XRel := XRel + Position.X;
- YRel := YRel + Position.Y;
- if Assigned(OnMoving) then
- OnMoving(Self, XRel, YRel);
- XRel := XRel - Position.X;
- YRel := YRel - Position.Y;
- MoveGUI(XRel, YRel);
- OldX := X;
- OldY := Y;
- end;
- end
- else if Y - Position.Y < 27 then
- begin
- //
- end
- else
- inherited;
- end;
- function TGLForm.GetTitleColor: TColor;
- begin
- Result := ConvertColorVector(FTitleColor);
- end;
- procedure TGLForm.SetTitleColor(value: TColor);
- begin
- FTitleColor := ConvertWinColor(value);
- GUIRedraw := True;
- end;
- constructor TGLForm.Create(AOwner: TComponent);
- begin
- inherited;
- FTitleOffset := 2;
- end;
- procedure TGLForm.Close;
- var
- HowClose: TGLFormCloseOptions;
- begin
- HowClose := co_hide;
- if Assigned(FOnCanClose) then
- FOnCanClose(Self, HowClose);
- case HowClose of
- co_hide: Visible := False;
- co_ignore: ;
- co_Destroy: Free;
- end;
- end;
- procedure TGLForm.NotifyShow;
- begin
- inherited;
- if Assigned(FOnShow) then
- FOnShow(Self);
- end;
- procedure TGLForm.NotifyHide;
- begin
- inherited;
- if Assigned(FOnHide) then
- FOnHide(Self);
- end;
- function TGLForm.MouseUp(Sender: TObject; Button: TMouseButton; Shift:
- TShiftState; X, Y: Integer): Boolean;
- begin
- if (Button = mbLeft) and (Moving) then
- begin
- Result := True;
- InternalMouseUp(Shift, Button, X, Y);
- end
- else
- Result := inherited MouseUp(Sender, Button, Shift, X, Y);
- end;
- function TGLForm.MouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer):
- Boolean;
- begin
- if (Moving) then
- begin
- Result := True;
- InternalMouseMove(Shift, X, Y);
- end
- else
- Result := inherited MouseMove(Sender, Shift, X, Y);
- end;
- procedure TGLForm.InternalRender(var rci: TGLRenderContextInfo; renderSelf,
- renderChildren: Boolean);
- var
- ATitleColor: TGLColorVector;
- begin
- if Assigned(FGuiComponent) then
- begin
- FGuiComponent.RenderToArea(0, 0, Width, Height, FRenderStatus, FReBuildGui);
- ATitleColor := FTitleColor;
- ATitleColor.W := AlphaChannel;
- WriteTextAt(rci, ((FRenderStatus[GLAlTop].X2 + FRenderStatus[GLAlTop].X1 -
- BitmapFont.CalcStringWidth(Caption)) * 0.5),
- -((FRenderStatus[GLAlTop].Y2 + FRenderStatus[GLAlTop].Y1 - GetFontHeight) *
- 0.5) + TitleOffset, Caption, ATitleColor);
- end;
- end;
- procedure TGLCheckBox.SetChecked(NewChecked: Boolean);
- begin
- if NewChecked <> FChecked then
- begin
- BlockRender;
- try
- if NewChecked then
- if Group >= 0 then
- UnpressGroup(FindFirstGui, Group);
- FChecked := NewChecked;
- finally
- UnBlockRender;
- end;
- NotifyChange(Self);
- if Assigned(FOnChange) then
- FOnChange(Self);
- end;
- end;
- procedure TGLCheckBox.InternalMouseDown(Shift: TShiftState; Button:
- TMouseButton; X, Y: Integer);
- begin
- Checked := not Checked;
- inherited;
- end;
- procedure TGLCheckBox.InternalMouseUp(Shift: TShiftState; Button:
- TMouseButton; X, Y: Integer);
- begin
- inherited;
- end;
- procedure TGLCheckBox.SetGuiLayoutNameChecked(const newName: TGLGuiComponentName);
- begin
- if FGuiLayoutNameChecked <> NewName then
- begin
- FGuiCheckedComponent := nil;
- FGuiLayoutNameChecked := NewName;
- if Assigned(FGuiLayout) then
- begin
- FGuiCheckedComponent :=
- FGuiLayout.GuiComponents.FindItem(FGuiLayoutNameChecked);
- FReBuildGui := True;
- GUIRedraw := True;
- end;
- end;
- end;
- procedure TGLCheckBox.SetGuiLayout(NewGui: TGLGuiLayout);
- begin
- FGuiCheckedComponent := nil;
- inherited;
- if Assigned(FGuiLayout) then
- begin
- FGuiCheckedComponent :=
- FGuiLayout.GuiComponents.FindItem(FGuiLayoutNameChecked);
- FReBuildGui := True;
- GUIRedraw := True;
- end;
- end;
- procedure TGLCheckBox.SetGroup(const val: Integer);
- begin
- FGroup := val;
- if Checked then
- begin
- BlockRender;
- FChecked := False;
- UnpressGroup(FindFirstGui, val);
- FChecked := true;
- UnBlockRender;
- end;
- end;
- constructor TGLCheckBox.Create(AOwner: TComponent);
- begin
- inherited;
- FChecked := False;
- FGroup := -1;
- end;
- procedure TGLCheckBox.InternalRender(var rci: TGLRenderContextInfo; renderSelf,
- renderChildren: Boolean);
- begin
- if Checked then
- begin
- if Assigned(FGuiCheckedComponent) then
- begin
- FGuiCheckedComponent.RenderToArea(0, 0, Width, Height, FRenderStatus,
- FReBuildGui);
- end;
- end
- else
- begin
- if Assigned(FGuiComponent) then
- begin
- FGuiComponent.RenderToArea(0, 0, Width, Height, FRenderStatus,
- FReBuildGui);
- end;
- end;
- end;
- procedure TGLCheckBox.NotifyChange(Sender: TObject);
- begin
- if Sender = FGuiLayout then
- begin
- if (FGuiLayoutNameChecked <> '') and (GuiLayout <> nil) then
- begin
- BlockRender;
- FGuiCheckedComponent :=
- GuiLayout.GuiComponents.FindItem(FGuiLayoutNameChecked);
- ReBuildGui := True;
- GUIRedraw := True;
- UnBlockRender;
- end
- else
- begin
- BlockRender;
- FGuiCheckedComponent := nil;
- ReBuildGui := True;
- GUIRedraw := True;
- UnBlockRender;
- end;
- end;
- inherited;
- end;
- procedure TGLButton.SetPressed(NewPressed: Boolean);
- begin
- if FPressed <> NewPressed then
- begin
- BlockRender;
- try
- if NewPressed then
- if Group >= 0 then
- UnpressGroup(RootControl, Group);
- FPressed := NewPressed;
- finally
- UnBlockRender;
- end;
- if FPressed then
- if Assigned(FOnButtonClick) then
- FOnButtonClick(Self);
- NotifyChange(Self);
- end;
- end;
- procedure TGLButton.InternalMouseDown(Shift: TShiftState; Button:
- TMouseButton; X, Y: Integer);
- begin
- SetFocus;
- inherited;
- if Button = mbLeft then
- if AllowUp then
- Pressed := not Pressed
- else
- Pressed := True;
- end;
- procedure TGLButton.InternalMouseUp(Shift: TShiftState; Button: TMouseButton;
- X, Y: Integer);
- begin
- if (Button = mbLeft) and (Group < 0) then
- Pressed := False;
- inherited;
- end;
- procedure TGLButton.InternalKeyDown(var Key: Word; Shift: TShiftState);
- begin
- inherited;
- if Key = VK_SPACE then
- begin
- Pressed := True;
- end;
- if Key = VK_RETURN then
- begin
- Pressed := True;
- end;
- end;
- procedure TGLButton.InternalKeyUp(var Key: Word; Shift: TShiftState);
- begin
- if ((Key = VK_SPACE) or (Key = VK_RETURN)) and (Group < 0) then
- begin
- Pressed := False;
- end;
- inherited;
- end;
- procedure TGLButton.SetFocused(Value: Boolean);
- begin
- inherited;
- if (not FFocused) and (Group < 0) then
- Pressed := False;
- end;
- procedure TGLButton.SetGuiLayoutNamePressed(const newName: TGLGuiComponentName);
- begin
- if FGuiLayoutNamePressed <> NewName then
- begin
- FGuiPressedComponent := nil;
- FGuiLayoutNamePressed := NewName;
- if Assigned(FGuiLayout) then
- begin
- FGuiPressedComponent :=
- FGuiLayout.GuiComponents.FindItem(FGuiLayoutNamePressed);
- FReBuildGui := True;
- GUIRedraw := True;
- end;
- end;
- end;
- procedure TGLButton.SetGuiLayout(NewGui: TGLGuiLayout);
- begin
- FGuiPressedComponent := nil;
- inherited;
- if Assigned(FGuiLayout) then
- begin
- FGuiPressedComponent :=
- FGuiLayout.GuiComponents.FindItem(FGuiLayoutNamePressed);
- FReBuildGui := True;
- GUIRedraw := True;
- end;
- end;
- procedure TGLButton.SetBitBtn(AValue: TGLMaterial);
- begin
- FBitBtn.Assign(AValue);
- NotifyChange(Self);
- end;
- procedure TGLButton.DestroyHandle;
- begin
- inherited;
- FBitBtn.DestroyHandles;
- end;
- procedure TGLButton.SetGroup(const val: Integer);
- begin
- FGroup := val;
- if Pressed then
- begin
- BlockRender;
- FPressed := False;
- UnpressGroup(RootControl, Group);
- FPressed := True;
- UnBlockRender;
- end;
- end;
- procedure TGLButton.SetLogicWidth(const val: single);
- begin
- FLogicWidth := val;
- NotifyChange(Self);
- end;
- procedure TGLButton.SetLogicHeight(const val: single);
- begin
- FLogicHeight := val;
- NotifyChange(Self);
- end;
- procedure TGLButton.SetXOffset(const val: single);
- begin
- FXOffSet := val;
- NotifyChange(Self);
- end;
- procedure TGLButton.SetYOffset(const val: single);
- begin
- FYOffSet := val;
- NotifyChange(Self);
- end;
- constructor TGLButton.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- FBitBtn := TGLMaterial.Create(Self);
- FGroup := -1;
- FPressed := False;
- end;
- destructor TGLButton.Destroy;
- begin
- inherited Destroy;
- FBitBtn.Free;
- end;
- procedure TGLButton.InternalRender(var rci: TGLRenderContextInfo; renderSelf,
- renderChildren: Boolean);
- var
- B: Boolean;
- TexWidth: Integer;
- TexHeight: Integer;
- Material: TGLMaterial;
- LibMaterial: TGLLibMaterial;
- TextColor: TGLColorVector;
- begin
- if Pressed then
- begin
- if Assigned(FGuiPressedComponent) then
- begin
- FGuiPressedComponent.RenderToArea(0, 0, Width, Height, FRenderStatus,
- FReBuildGui);
- end;
- end
- else
- begin
- if Assigned(FGuiComponent) then
- begin
- FGuiComponent.RenderToArea(0, 0, Width, Height, FRenderStatus,
- FReBuildGui);
- end;
- end;
- B := not BitBtn.Texture.Disabled;
- Material := nil;
- if not B then
- begin
- if (BitBtn.MaterialLibrary <> nil) and (BitBtn.MaterialLibrary is
- TGLMaterialLibrary) then
- begin
- LibMaterial :=
- TGLMaterialLibrary(BitBtn.MaterialLibrary).Materials.GetLibMaterialByName(BitBtn.LibMaterialName);
- if LibMaterial <> nil then
- begin
- Material := LibMaterial.Material;
- B := True;
- end;
- end;
- end
- else
- begin
- Material := BitBtn;
- end;
- if B then
- with FRenderStatus[GLAlCenter] do
- begin
- GuiLayout.Material.UnApply(rci);
- BitBtn.Apply(rci);
- TexWidth := Material.Texture.TexWidth;
- if TexWidth = 0 then
- TexWidth := Material.Texture.Image.Width;
- TexHeight := Material.Texture.TexHeight;
- if TexHeight = 0 then
- TexHeight := Material.Texture.Image.Height;
- gl.Begin_(GL_QUADS);
- gl.TexCoord2f(0, 0);
- gl.Vertex2f(X1 - XOffSet, -Y1 + YOffSet);
- gl.TexCoord2f(0, -(LogicHeight - 1) / TexHeight);
- gl.Vertex2f(X1 - XOffSet, -Y1 + YOffset - LogicHeight + 1);
- gl.TexCoord2f((LogicWidth - 1) / TexWidth, -(LogicHeight - 1) /
- TexHeight);
- gl.Vertex2f(X1 - XOffSet + LogicWidth - 1, -Y1 + YOffset - LogicHeight +
- 1);
- gl.TexCoord2f((LogicWidth - 1) / TexWidth, 0);
- gl.Vertex2f(X1 - XOffSet + LogicWidth - 1, -Y1 + YOffSet);
- gl.End_();
- BitBtn.UnApply(rci);
- GuiLayout.Material.Apply(rci);
- end;
- if Assigned(BitmapFont) then
- begin
- if FFocused then
- begin
- TextColor := FFocusedColor;
- end
- else
- begin
- TextColor := FDefaultColor;
- end;
- TextColor.W := AlphaChannel;
- WriteTextAt(rci, FRenderStatus[GLALCenter].X1,
- FRenderStatus[GLALCenter].Y1,
- FRenderStatus[GLALCenter].X2,
- FRenderStatus[GLALCenter].Y2,
- Caption,
- TextColor);
- end;
- end;
- procedure TGLEdit.InternalMouseDown(Shift: TShiftState; Button: TMouseButton;
- X, Y: Integer);
- begin
- if not FReadOnly then
- SetFocus;
- inherited;
- end;
- procedure TGLEdit.InternalKeyPress(var Key: Char);
- begin
- if FReadOnly then
- exit;
- inherited;
- case Key of
- #8:
- begin
- if FSelStart > 1 then
- begin
- system.Delete(FCaption, FSelStart - 1, 1);
- Dec(FSelStart);
- GUIRedraw := True;
- end;
- end;
- else
- begin
- if Key >= #32 then
- begin
- system.Insert(Key, FCaption, SelStart);
- inc(FSelStart);
- GUIRedraw := True;
- end;
- end;
- end;
- end;
- procedure TGLEdit.InternalKeyDown(var Key: Word; Shift: TShiftState);
- begin
- if FReadOnly then
- exit;
- inherited;
- case Key of
- VK_DELETE:
- begin
- if FSelStart <= Length(Caption) then
- begin
- System.Delete(FCaption, FSelStart, 1);
- GUIRedraw := True;
- end;
- end;
- VK_LEFT:
- begin
- if FSelStart > 1 then
- begin
- Dec(FSelStart);
- GUIRedraw := True;
- end;
- end;
- VK_RIGHT:
- begin
- if FSelStart < Length(Caption) + 1 then
- begin
- Inc(FSelStart);
- GUIRedraw := True;
- end;
- end;
- VK_HOME:
- begin
- if FSelStart > 1 then
- begin
- FSelStart := 1;
- GUIRedraw := True;
- end;
- end;
- VK_END:
- begin
- if FSelStart < Length(Caption) + 1 then
- begin
- FSelStart := Length(Caption) + 1;
- GUIRedraw := True;
- end;
- end;
- end;
- end;
- procedure TGLEdit.InternalKeyUp(var Key: Word; Shift: TShiftState);
- begin
- inherited;
- end;
- procedure TGLEdit.SetFocused(Value: Boolean);
- begin
- inherited;
- if Value then
- SelStart := Length(Caption) + 1;
- end;
- procedure TGLEdit.SetSelStart(const Value: Integer);
- begin
- FSelStart := Value;
- GUIRedraw := True;
- end;
- procedure TGLEdit.SetEditChar(const Value: string);
- begin
- FEditChar := Value;
- GUIRedraw := True;
- end;
- constructor TGLEdit.Create(AOwner: TComponent);
- begin
- inherited;
- FEditChar := '*';
- end;
- procedure TGLEdit.InternalRender(var rci: TGLRenderContextInfo; renderSelf,
- renderChildren: Boolean);
- var
- Tekst: UnicodeString;
- pBig: Integer;
- begin
- // Renders the background
- if Assigned(FGuiComponent) then
- begin
- FGuiComponent.RenderToArea(0, 0, Width, Height, FRenderStatus, FReBuildGui);
- end;
- // Renders the text
- if Assigned(FBitmapFont) then
- begin
- Tekst := Caption;
- if FFocused then
- begin
- // First put in the edit character where it should be.
- system.insert(FEditChar, Tekst, SelStart);
- // Next figure out if the string is too long.
- if FBitmapFont.CalcStringWidth(Tekst) > Width - 2 then
- begin
- // if it is then we need to check to see where SelStart is
- if SelStart >= Length(Tekst) - 1 then
- begin
- // SelStart is within close proximity of the end of the string
- // Calculate the % of text that we can use and return it against the length of the string.
- pBig := Trunc(Int(((Width - 2) /
- FBitmapFont.CalcStringWidth(Tekst)) * Length(Tekst)));
- dec(pBig);
- Tekst := Copy(Tekst, Length(Tekst) - pBig + 1, pBig);
- end
- else
- begin
- // SelStart is within close proximity of the end of the string
- // Calculate the % of text that we can use and return it against the length of the string.
- pBig := Trunc(Int(((Width - 2) /
- FBitmapFont.CalcStringWidth(Tekst)) * Length(Tekst)));
- dec(pBig);
- if SelStart + pBig < Length(Tekst) then
- Tekst := Copy(Tekst, SelStart, pBig)
- else
- Tekst := Copy(Tekst, Length(Tekst) - pBig + 1, pBig);
- end;
- end;
- end
- else
- { if FFocused then } if FBitmapFont.CalcStringWidth(Tekst) >
- Width - 2 then
- begin
- // The while loop should never execute more then once, but just in case its here.
- while FBitmapFont.CalcStringWidth(Tekst) > Width - 2 do
- begin
- // Calculate the % of text that we can use and return it against the length of the string.
- pBig := Trunc(Int(((Width - 2) /
- FBitmapFont.CalcStringWidth(Tekst)) * Length(Tekst)));
- Tekst := Copy(Tekst, 1, pBig);
- end;
- end;
- if FFocused then
- begin
- WriteTextAt(rci, FRenderStatus[GLAlLeft].X1, FRenderStatus[GLAlCenter].Y1,
- FRenderStatus[GLALCenter].X2, FRenderStatus[GLALCenter].Y2, Tekst,
- FFocusedColor);
- end
- else
- begin
- WriteTextAt(rci, FRenderStatus[GLAlLeft].X1, FRenderStatus[GLAlCenter].Y1,
- FRenderStatus[GLALCenter].X2, FRenderStatus[GLALCenter].Y2, Tekst,
- FDefaultColor);
- end;
- end;
- end;
- constructor TGLLabel.Create(AOwner: TComponent);
- begin
- inherited;
- FTextLayout := tlCenter;
- end;
- procedure TGLLabel.InternalRender(var rci: TGLRenderContextInfo; renderSelf,
- renderChildren: Boolean);
- var
- TekstPos: TGLVector;
- Tekst: UnicodeString;
- TextColor: TGLColorVector;
- begin
- if Assigned(BitmapFont) then
- begin
- case Alignment of
- taLeftJustify:
- TekstPos.X := 0;
- taCenter:
- TekstPos.X := Width / 2;
- taRightJustify:
- TekstPos.X := Width;
- end;
- case TextLayout of
- tlTop:
- TekstPos.Y := 0;
- tlCenter:
- TekstPos.Y := Round(-Height / 2);
- tlBottom:
- TekstPos.Y := -Height;
- end;
- TekstPos.Z := 0;
- TekstPos.W := 0;
- Tekst := Caption;
- TextColor := FDefaultColor;
- TextColor.W := AlphaChannel;
- BitmapFont.RenderString(rci, Tekst, FAlignment, FTextLayout, TextColor,
- @TekstPos);
- end;
- end;
- procedure TGLLabel.SetAlignment(const Value: TAlignment);
- begin
- if FAlignment <> Value then
- begin
- FAlignment := Value;
- NotifyChange(Self);
- end;
- end;
- procedure TGLLabel.SetTextLayout(const Value: TTextLayout);
- begin
- if FTextLayout <> Value then
- begin
- FTextLayout := Value;
- NotifyChange(Self);
- end;
- end;
- procedure TGLAdvancedLabel.InternalRender(var rci: TGLRenderContextInfo;
- renderSelf, renderChildren: Boolean);
- begin
- if Assigned(BitmapFont) then
- begin
- if Focused then
- begin
- WriteTextAt(rci, 8, -((Height - GetFontHeight) / 2) + 1, Caption,
- FFocusedColor);
- end
- else
- begin
- WriteTextAt(rci, 8, -((Height - GetFontHeight) / 2) + 1, Caption,
- FDefaultColor);
- end;
- end;
- end;
- procedure TGLScrollbar.SetMin(const val: Single);
- begin
- if FMin <> val then
- begin
- FMin := val;
- if FPos < FMin then
- Pos := FMin;
- NotifyChange(Self);
- end;
- end;
- procedure TGLScrollbar.SetMax(const val: Single);
- begin
- if FMax <> val then
- begin
- FMax := val;
- if FMax < FMin then
- FMax := FMin;
- if FPos > (FMax - FPageSize + 1) then
- Pos := (FMax - FPageSize + 1);
- NotifyChange(Self);
- end;
- end;
- procedure TGLScrollbar.SetPos(const val: Single);
- begin
- if FPos <> val then
- begin
- FPos := val;
- if FPos < FMin then
- FPos := FMin;
- if FPos > (FMax - FPageSize + 1) then
- FPos := (FMax - FPageSize + 1);
- NotifyChange(Self);
- if Assigned(FOnChange) then
- FOnChange(Self);
- end;
- end;
- procedure TGLScrollbar.SetPageSize(const val: Single);
- begin
- if FPageSize <> val then
- begin
- FPageSize := val;
- if FPos > (FMax - FPageSize + 1) then
- Pos := (FMax - FPageSize + 1);
- NotifyChange(Self);
- end;
- end;
- procedure TGLScrollbar.SetHorizontal(const val: Boolean);
- begin
- if FHorizontal <> val then
- begin
- FHorizontal := val;
- NotifyChange(Self);
- end;
- end;
- procedure TGLScrollbar.SetGuiLayoutKnobName(const newName: TGLGuiComponentName);
- begin
- if newName <> FGuiLayoutKnobName then
- begin
- FGuiKnobComponent := nil;
- FGuiLayoutKnobName := NewName;
- if Assigned(FGuiLayout) then
- begin
- FGuiKnobComponent :=
- FGuiLayout.GuiComponents.FindItem(FGuiLayoutKnobName);
- FReBuildGui := True;
- GUIRedraw := True;
- end;
- end;
- end;
- procedure TGLScrollbar.SetGuiLayout(NewGui: TGLGuiLayout);
- begin
- FGuiKnobComponent := nil;
- inherited;
- if Assigned(FGuiLayout) then
- begin
- FGuiKnobComponent := FGuiLayout.GuiComponents.FindItem(FGuiLayoutKnobName);
- FReBuildGui := True;
- GUIRedraw := True;
- end;
- end;
- function TGLScrollbar.GetScrollPosY(ScrollPos: Single): Single;
- begin
- with FRenderStatus[GLAlCenter] do
- begin
- Result := (ScrollPos - FMin) / (FMax - FMin) * (Y2 - Y1) + Y1;
- end;
- end;
- function TGLScrollbar.GetYScrollPos(Y: Single): Single;
- begin
- with FRenderStatus[GLAlCenter] do
- begin
- Result := (Y - Y1) / (Y2 - Y1) * (FMax - FMin) + FMin;
- end;
- end;
- function TGLScrollbar.GetScrollPosX(ScrollPos: Single): Single;
- begin
- with FRenderStatus[GLAlCenter] do
- begin
- Result := (ScrollPos - FMin) / (FMax - FMin) * (X2 - X1) + X1;
- end;
- end;
- function TGLScrollbar.GetXScrollPos(X: Single): Single;
- begin
- with FRenderStatus[GLAlCenter] do
- begin
- Result := (X - X1) / (X2 - X1) * (FMax - FMin) + FMin;
- end;
- end;
- procedure TGLScrollbar.InternalMouseDown(Shift: TShiftState; Button:
- TMouseButton; X, Y: Integer);
- var
- Tx, Ty: Single;
- begin
- if (Button = mbLeft)
- and not FLocked then
- begin
- Tx := x - Position.X;
- Ty := y - Position.Y;
- // is in mid area ?
- if IsInRect(FRenderStatus[GLAlCenter], Tx, Ty) then
- begin
- if FHorizontal then
- begin
- Tx := GetxScrollPos(Tx);
- if Tx < FPos then
- PageUp
- else if Tx > FPos + FPageSize - 1 then
- PageDown
- else
- begin
- fScrolling := True;
- FScrollOffs := Tx - FPos;
- RootControl.ActiveControl := Self;
- end;
- end
- else
- begin
- Ty := GetYScrollPos(Ty);
- if Ty < FPos then
- PageUp
- else if Ty > FPos + FPageSize - 1 then
- PageDown
- else
- begin
- fScrolling := True;
- FScrollOffs := Ty - FPos;
- RootControl.ActiveControl := Self;
- end;
- end;
- end
- else
- begin
- // if not, is at end buttons ?
- if horizontal then
- begin
- if IsInRect(FRenderStatus[GLAlLeft], Tx, Ty) then
- StepUp;
- if IsInRect(FRenderStatus[GLAlRight], Tx, Ty) then
- StepDown;
- end
- else
- begin
- if IsInRect(FRenderStatus[GLAlTop], Tx, Ty) then
- StepUp;
- if IsInRect(FRenderStatus[GLAlBottom], Tx, Ty) then
- StepDown;
- end;
- end;
- end;
- inherited;
- end;
- procedure TGLScrollbar.InternalMouseUp(Shift: TShiftState; Button:
- TMouseButton; X, Y: Integer);
- begin
- if fScrolling then
- begin
- fScrolling := False;
- RootControl.ActiveControl := nil;
- end;
- inherited;
- end;
- procedure TGLScrollbar.InternalMouseMove(Shift: TShiftState; X, Y: Integer);
- var
- Tx: Single;
- Ty: Single;
- begin
- if fScrolling then
- if FHorizontal then
- begin
- Tx := GetXScrollPos(x - Position.X) - FScrollOffs;
- Pos := Round(Tx);
- end
- else
- begin
- Ty := GetYScrollPos(y - Position.Y) - FScrollOffs;
- Pos := Round(Ty);
- end;
- inherited;
- end;
- constructor TGLScrollbar.Create(AOwner: TComponent);
- begin
- inherited;
- FGuiKnobComponent := nil;
- FMin := 1;
- FMax := 10;
- FPos := 1;
- FStep := 1;
- FPageSize := 3;
- FOnChange := nil;
- FGuiLayoutKnobName := '';
- FScrollOffs := 0;
- FScrolling := False;
- FHorizontal := False;
- end;
- procedure TGLScrollbar.StepUp;
- begin
- Pos := Pos - FStep;
- end;
- procedure TGLScrollbar.StepDown;
- begin
- Pos := Pos + FStep;
- end;
- procedure TGLScrollbar.PageUp;
- begin
- Pos := Pos - FPageSize;
- end;
- procedure TGLScrollbar.PageDown;
- begin
- Pos := Pos + FPageSize;
- end;
- function TGLScrollbar.MouseUp(Sender: TObject; Button: TMouseButton; Shift:
- TShiftState; X, Y: Integer): Boolean;
- begin
- if (Button = mbLeft) and (FScrolling) then
- begin
- Result := True;
- InternalMouseUp(Shift, Button, X, Y);
- end
- else
- Result := inherited MouseUp(Sender, Button, Shift, X, Y);
- end;
- function TGLScrollbar.MouseMove(Sender: TObject; Shift: TShiftState; X, Y:
- Integer): Boolean;
- begin
- if (FScrolling) then
- begin
- Result := True;
- InternalMouseMove(Shift, X, Y);
- end
- else
- Result := inherited MouseMove(Sender, Shift, X, Y);
- end;
- procedure TGLScrollbar.InternalRender(var rci: TGLRenderContextInfo; renderSelf,
- renderChildren: Boolean);
- var
- Start, Size: Integer;
- begin
- if Assigned(FGuiComponent) then
- begin
- try
- FGuiComponent.RenderToArea(0, 0, Width, Height, FRenderStatus,
- FReBuildGui);
- except
- on E: Exception do
- GLOKMessageBox(E.Message,
- 'Exception in GuiComponents InternalRender function');
- end;
- end;
- if Assigned(FGuiKnobComponent) then
- begin
- try
- with FRenderStatus[GLAlCenter] do
- begin
- if FHorizontal then
- begin
- Start := Round(GetScrollPosX(FPos));
- if FPageSize + FPos > FMax + 1 then
- Size := Round(GetScrollPosX(FMax) - X1)
- else
- Size := Round(GetScrollPosX(FPageSize) - X1);
- FGuiKnobComponent.RenderToArea(Start, Y1, Start + Size, Y2,
- FKnobRenderStatus, True);
- // Tag := start;
- // tagfloat := size;
- end
- else
- begin
- Start := Round(GetScrollPosY(FPos));
- if FPageSize + FPos > FMax + 1 then
- Size := Round(GetScrollPosY(FMax) - Y1)
- else
- Size := Round(GetScrollPosY(FPageSize) - Y1);
- FGuiKnobComponent.RenderToArea(X1, Start, X2, Start + Size,
- FKnobRenderStatus, True);
- // Tag := start;
- // tagfloat := size;
- end;
- end;
- except
- on E: Exception do
- GLOKMessageBox(E.Message,
- 'Exception in GuiComponents InternalRender function');
- end;
- end;
- end;
- function TGLStringGrid.GetCell(X, Y: Integer; out oCol, oRow: Integer): Boolean;
- var
- ClientRect: TRectangle;
- XPos: Integer;
- YPos: Integer;
- XC, YC: Integer;
- begin
- Result := False;
- if Assigned(BitmapFont) then
- begin
- if Assigned(FGuiComponent) then
- begin
- ClientRect.Left := Round(FRenderStatus[GLAlCenter].X1);
- ClientRect.Top := Round(FRenderStatus[GLAlCenter].Y1);
- ClientRect.Width := Round(FRenderStatus[GLAlCenter].X2);
- ClientRect.Height := Round(FRenderStatus[GLAlCenter].Y2);
- end
- else
- begin
- ClientRect.Left := 0;
- ClientRect.Top := 0;
- ClientRect.Width := Round(Width);
- ClientRect.Height := Round(Height);
- end;
- YPos := ClientRect.Top;
- if FDrawHeader then
- YPos := YPos + RowHeight;
- XPos := ClientRect.Left;
- if y < YPos then
- Exit;
- if x < XPos then
- Exit;
- XPos := XPos + MarginSize;
- for XC := 0 to Columns.Count - 1 do
- begin
- XPos := XPos + Integer(Columns.Objects[XC]);
- if x > XPos then
- continue;
- for YC := 0 to RowCount - 1 do
- begin
- YPos := YPos + RowHeight;
- if y < YPos then
- begin
- Result := True;
- if Assigned(Scrollbar) then
- oRow := YC + Round(Scrollbar.Pos) - 1
- else
- oRow := YC;
- oCol := XC;
- Exit;
- end;
- end;
- end;
- end;
- end;
- procedure TGLStringGrid.InternalMouseDown(Shift: TShiftState; Button:
- TMouseButton; X, Y: Integer);
- var
- tRow, tCol: Integer;
- begin
- SetFocus;
- if GetCell(Round(X - Position.X), Round(Y - Position.Y), tCol, tRow) then
- begin
- SelCol := tCol;
- SelRow := tRow;
- end;
- inherited;
- end;
- procedure TGLStringGrid.SetColumns(const val: TStrings);
- var
- XC: Integer;
- begin
- FColumns.Assign(val);
- for XC := 0 to Columns.Count - 1 do
- Columns.Objects[XC] := TObject(ColumnSize);
- end;
- procedure TGLStringGrid.SetColSelect(const val: Boolean);
- begin
- FColSelect := Val;
- NotifyChange(Self);
- end;
- function TGLStringGrid.GetRow(index: Integer): TStringList;
- begin
- if (index >= 0) and (index < FRows.Count) then
- Result := TStringList(FRows[index])
- else
- Result := nil;
- end;
- procedure TGLStringGrid.SetRow(index: Integer; const val: TStringList);
- begin
- if (index >= 0) then
- begin
- if (index >= RowCount) then
- RowCount := index + 1;
- TStringList(FRows[index]).Assign(val);
- end;
- end;
- function TGLStringGrid.GetRowCount: Integer;
- begin
- Result := FRows.count;
- end;
- procedure TGLStringGrid.SetRowCount(const val: Integer);
- var
- XC: Integer;
- begin
- XC := FRows.count;
- if val <> XC then
- begin
- if val > XC then
- begin
- FRows.count := val;
- for XC := XC to val - 1 do
- begin
- FRows[XC] := TStringList.Create;
- TStringList(FRows[XC]).OnChange := OnStringListChange;
- end;
- end
- else
- begin
- for XC := XC - 1 downto val do
- begin
- TStringList(FRows[XC]).Free;
- end;
- FRows.count := val;
- end;
- if Assigned(Scrollbar) then
- Scrollbar.FMax := FRows.Count;
- NotifyChange(Self);
- end;
- end;
- procedure TGLStringGrid.SetSelCol(const val: Integer);
- begin
- if FSelCol <> Val then
- begin
- FSelCol := Val;
- NotifyChange(Self);
- end;
- end;
- procedure TGLStringGrid.SetSelRow(const val: Integer);
- begin
- if FSelRow <> Val then
- begin
- FSelRow := Val;
- NotifyChange(Self);
- end;
- end;
- procedure TGLStringGrid.SetRowSelect(const val: Boolean);
- begin
- FRowSelect := Val;
- NotifyChange(Self);
- end;
- procedure TGLStringGrid.SetDrawHeader(const val: Boolean);
- begin
- FDrawHeader := Val;
- NotifyChange(Self);
- end;
- function TGLStringGrid.GetHeaderColor: TColor;
- begin
- Result := ConvertColorVector(FHeaderColor);
- end;
- procedure TGLStringGrid.SetHeaderColor(const val: TColor);
- begin
- FHeaderColor := ConvertWinColor(val);
- GUIRedraw := True;
- end;
- procedure TGLStringGrid.SetMarginSize(const val: Integer);
- begin
- if FMarginSize <> val then
- begin
- FMarginSize := val;
- GUIRedraw := True;
- end;
- end;
- procedure TGLStringGrid.SetColumnSize(const val: Integer);
- var
- XC: Integer;
- begin
- if FColumnSize <> val then
- begin
- FColumnSize := val;
- for XC := 0 to Columns.Count - 1 do
- Columns.Objects[XC] := TObject(ColumnSize);
- GUIRedraw := True;
- end;
- end;
- procedure TGLStringGrid.SetRowHeight(const val: Integer);
- begin
- if FRowHeight <> val then
- begin
- FRowHeight := val;
- GUIRedraw := True;
- end;
- end;
- procedure TGLStringGrid.SetScrollbar(const val: TGLScrollbar);
- begin
- if FScrollbar <> Val then
- begin
- if Assigned(FScrollbar) then
- FScrollbar.RemoveFreeNotification(Self);
- FScrollbar := Val;
- if Assigned(FScrollbar) then
- FScrollbar.FreeNotification(Self);
- end;
- end;
- procedure TGLStringGrid.SetGuiLayout(NewGui: TGLGuiLayout);
- begin
- inherited;
- if Assigned(Scrollbar) then
- if Scrollbar.GuiLayout <> nil then
- Scrollbar.GuiLayout := NewGui;
- end;
- constructor TGLStringGrid.Create(AOwner: TComponent);
- begin
- inherited;
- FRows := TList.Create;
- FColumns := TStringList.Create;
- TStringList(FColumns).OnChange := OnStringListChange;
- FSelCol := 0;
- FSelRow := 0;
- FRowSelect := True;
- FScrollbar := nil;
- FDrawHeader := True;
- end;
- destructor TGLStringGrid.Destroy;
- begin
- Scrollbar := nil;
- inherited;
- Clear;
- FRows.Free;
- FColumns.Free;
- end;
- procedure TGLStringGrid.Clear;
- begin
- RowCount := 0;
- end;
- procedure TGLStringGrid.Notification(AComponent: TComponent; Operation:
- TOperation);
- begin
- if (AComponent = FScrollbar) and (Operation = opRemove) then
- begin
- FScrollbar := nil;
- end;
- inherited;
- end;
- procedure TGLStringGrid.NotifyChange(Sender: TObject);
- begin
- if Sender = Scrollbar then
- begin
- ReBuildGui := True;
- GUIRedraw := True;
- end;
- inherited;
- end;
- procedure TGLStringGrid.InternalRender(var rci: TGLRenderContextInfo; renderSelf,
- renderChildren: Boolean);
- function CellSelected(X, Y: Integer): Boolean;
- begin
- if (RowSelect and ColSelect) then
- Result := (Y = SelRow) or (x = SelCol)
- else if RowSelect then
- Result := Y = SelRow
- else if ColSelect then
- Result := X = SelCol
- else
- Result := (Y = SelRow) and (x = SelCol);
- end;
- function CellText(X, Y: Integer): string;
- begin
- with Row[y] do
- if (X >= 0) and (X < Count) then
- Result := strings[x]
- else
- Result := '';
- end;
- var
- ClientRect: TRectangle;
- XPos: Integer;
- YPos: Integer;
- XC, YC: Integer;
- From, Till: Integer;
- begin
- if Assigned(FGuiComponent) then
- begin
- try
- FGuiComponent.RenderToArea(0, 0, Width, Height, FRenderStatus,
- FReBuildGui);
- ClientRect.Left := Round(FRenderStatus[GLAlCenter].X1);
- ClientRect.Top := Round(FRenderStatus[GLAlCenter].Y1);
- ClientRect.Width := Round(FRenderStatus[GLAlCenter].X2);
- ClientRect.Height := Round(FRenderStatus[GLAlCenter].Y2);
- except
- on E: Exception do
- GLOKMessageBox(E.Message,
- 'Exception in GuiComponents InternalRender function');
- end;
- end
- else
- begin
- ClientRect.Left := 0;
- ClientRect.Top := 0;
- ClientRect.Width := Round(Width);
- ClientRect.Height := Round(Height);
- end;
- if Assigned(BitmapFont) then
- begin
- XPos := ClientRect.Left + MarginSize;
- if Assigned(Scrollbar) then
- begin
- Scrollbar.Position.X := Position.X + FRenderStatus[GLAlCenter].X2 -
- Scrollbar.Width;
- Scrollbar.Position.Y := Position.Y + FRenderStatus[GLAlCenter].Y1;
- Scrollbar.Height := FRenderStatus[GLAlCenter].Y2 -
- FRenderStatus[GLAlCenter].Y1;
- XC := (ClientRect.Height - ClientRect.Top);
- if FDrawHeader then
- YC := (XC div RowHeight) - 1
- else
- YC := (XC div RowHeight);
- Scrollbar.PageSize := YC;
- From := Round(Scrollbar.pos - 1);
- Till := Round(Scrollbar.pageSize + From - 1);
- if Till > RowCount - 1 then
- Till := RowCount - 1;
- end
- else
- begin
- From := 0;
- Till := RowCount - 1;
- end;
- for XC := 0 to Columns.Count - 1 do
- begin
- YPos := -ClientRect.Top;
- if FDrawHeader then
- begin
- WriteTextAt(rci, XPos, YPos, Columns[XC], FHeaderColor);
- YPos := YPos - RowHeight;
- end;
- for YC := From to Till do
- begin
- if CellSelected(XC, YC) then
- WriteTextAt(rci, XPos, YPos, CellText(XC, YC), FFocusedColor)
- else
- WriteTextAt(rci, XPos, YPos, CellText(XC, YC), FDefaultColor);
- YPos := YPos - RowHeight;
- end;
- XPos := XPos + Integer(Columns.Objects[XC]);
- end;
- end;
- end;
- procedure TGLStringGrid.OnStringListChange(Sender: TObject);
- begin
- NotifyChange(Self);
- end;
- function TGLStringGrid.Add(const Data: array of string): Integer;
- var
- XC: Integer;
- begin
- Result := RowCount;
- RowCount := RowCount + 1;
- for XC := 0 to Length(Data) - 1 do
- Row[Result].Add(Data[XC]);
- end;
- function TGLStringGrid.Add(const Data: string): Integer;
- begin
- Result := Add([Data]);
- if Assigned(Scrollbar) then
- begin
- if Result > Round(Scrollbar.pageSize + Scrollbar.pos - 2) then
- Scrollbar.pos := Result - Scrollbar.pageSize + 2;
- end;
- end;
- procedure TGLStringGrid.SetText(Data: string);
- var
- Posi: Integer;
- begin
- Clear;
- while Data <> '' do
- begin
- Posi := Pos(#13#10, Data);
- if Posi > 0 then
- begin
- Add(Copy(Data, 1, Posi - 1));
- Delete(Data, 1, Posi + 1);
- end
- else
- begin
- Add(Data);
- Data := '';
- end;
- end;
- end;
- destructor TGLFocusControl.Destroy;
- begin
- if Focused then
- RootControl.FocusedControl := nil;
- inherited;
- end;
- procedure TGLBaseComponent.DoProgress(const progressTime: TGLProgressTimes);
- begin
- inherited;
- if FDoChangesOnProgress then
- DoChanges;
- end;
- procedure TGLBaseComponent.SetDoChangesOnProgress(const Value: Boolean);
- begin
- FDoChangesOnProgress := Value;
- end;
- procedure TGLFocusControl.MoveTo(newParent: TGLBaseSceneObject);
- begin
- inherited;
- ReGetRootControl;
- end;
- //--------------------------------------------
- initialization
- //--------------------------------------------
- RegisterClasses([TGLBaseControl, TGLPopupMenu, TGLForm, TGLPanel, TGLButton,
- TGLCheckBox, TGLEdit, TGLLabel, TGLAdvancedLabel, TGLScrollbar, TGLStringGrid,
- TGLCustomControl]);
- end.
|