split painter and context classes in nvwidgets.pas into separate source file
fixed compilation example.pp renamed context and painter source files to be more clear git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2248 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
parent
8e9a5d48b4
commit
6a43b61d2c
@ -6,7 +6,7 @@ program example;
|
||||
uses
|
||||
Classes, SysUtils,
|
||||
GLut, GL, GLu,
|
||||
nvWidgets, nvGlutWidgets;
|
||||
nvTypes, nvGlutContext, nvGLPainter, GLFreeTypeFont;
|
||||
|
||||
type
|
||||
UIOption = (
|
||||
@ -169,6 +169,8 @@ begin
|
||||
glutCreateWindow('UI example');
|
||||
|
||||
ui := GlutUIContext.Create;
|
||||
ui.Painter := GLUIPainter.Create;
|
||||
ui.Painter.Font := TGLFreeTypeFont.Create('Ubuntu-R.ttf', 10);
|
||||
|
||||
if not ui.init(win_w, win_h) then
|
||||
begin
|
||||
|
@ -12,7 +12,6 @@
|
||||
<MainUnit Value="0"/>
|
||||
<ResourceType Value="res"/>
|
||||
<UseXPManifest Value="True"/>
|
||||
<Icon Value="0"/>
|
||||
</General>
|
||||
<LazDoc Paths="..\doc"/>
|
||||
<i18n>
|
||||
@ -34,17 +33,42 @@
|
||||
<FormatVersion Value="1"/>
|
||||
</local>
|
||||
</RunParams>
|
||||
<Units Count="2">
|
||||
<Units Count="7">
|
||||
<Unit0>
|
||||
<Filename Value="widget_test.pp"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="widget_test"/>
|
||||
</Unit0>
|
||||
<Unit1>
|
||||
<Filename Value="..\src\nvWidgets.pas"/>
|
||||
<Filename Value="..\src\nvwidgets.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="nvWidgets"/>
|
||||
</Unit1>
|
||||
<Unit2>
|
||||
<Filename Value="..\src\gl\glfreetypefont.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="GLFreeTypeFont"/>
|
||||
</Unit2>
|
||||
<Unit3>
|
||||
<Filename Value="..\src\nvbasefont.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="nvBaseFont"/>
|
||||
</Unit3>
|
||||
<Unit4>
|
||||
<Filename Value="..\src\glut\nvglutwidgets.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="nvGlutWidgets"/>
|
||||
</Unit4>
|
||||
<Unit5>
|
||||
<Filename Value="..\src\glut\glutbitmapfont.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="GLUTBitmapFont"/>
|
||||
</Unit5>
|
||||
<Unit6>
|
||||
<Filename Value="..\src\nvtypes.pas"/>
|
||||
<IsPartOfProject Value="True"/>
|
||||
<UnitName Value="nvTypes"/>
|
||||
</Unit6>
|
||||
</Units>
|
||||
</ProjectOptions>
|
||||
<CompilerOptions>
|
||||
@ -55,7 +79,7 @@
|
||||
</Target>
|
||||
<SearchPaths>
|
||||
<IncludeFiles Value="$(ProjOutDir)"/>
|
||||
<OtherUnitFiles Value="..\src\;..\src\gl\;..\src\glut\"/>
|
||||
<OtherUnitFiles Value="..\src;..\src\gl;..\src\glut"/>
|
||||
<UnitOutputDirectory Value="lib\$(TargetCPU)-$(TargetOS)"/>
|
||||
</SearchPaths>
|
||||
<Other>
|
||||
|
@ -3,9 +3,8 @@ program widget_test;
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
uses
|
||||
Classes, SysUtils,
|
||||
GLut, GL, GLu,
|
||||
nvWidgets, nvGLWidgets, nvBaseFont, nvGlutWidgets, GLFreeTypeFont, GLUTBitmapFont;
|
||||
Classes, SysUtils, GLut, GL, GLu, nvGLPainter,
|
||||
nvGlutContext, GLFreeTypeFont, GLUTBitmapFont, nvTypes;
|
||||
|
||||
var
|
||||
ui: GlutUIContext;
|
||||
|
@ -10,8 +10,7 @@ unit GLFreeType;
|
||||
interface
|
||||
|
||||
uses
|
||||
SysUtils, freetypeh, GL, GLu,
|
||||
nvBaseFont;
|
||||
SysUtils, freetypeh, GL, GLu;
|
||||
|
||||
//This holds all of the information related to any
|
||||
//freetype font that we want to create.
|
||||
|
@ -7,14 +7,14 @@
|
||||
//
|
||||
// Copyright (c) NVIDIA Corporation. All rights reserved.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
unit nvGLWidgets;
|
||||
unit nvGLPainter;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, nvWidgets,
|
||||
Classes, nvPainter, nvTypes,
|
||||
GL, ftFont, FPCanvas;
|
||||
|
||||
const
|
@ -11,14 +11,14 @@
|
||||
//
|
||||
// Copyright (c) NVIDIA Corporation. All rights reserved.
|
||||
////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
unit nvGlutWidgets;
|
||||
unit nvGlutContext;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
SysUtils, nvWidgets;
|
||||
SysUtils, nvContext, nvTypes;
|
||||
|
||||
type
|
||||
|
@ -7,208 +7,17 @@
|
||||
//
|
||||
// Copyright (c) NVIDIA Corporation. All rights reserved.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
unit nvWidgets;
|
||||
unit nvContext;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, nvBaseFont;
|
||||
Classes, SysUtils, nvTypes, nvPainter, nvBaseFont;
|
||||
|
||||
type
|
||||
|
||||
{ Point }
|
||||
|
||||
Point = object
|
||||
x, y: integer;
|
||||
|
||||
constructor Point;
|
||||
constructor Point(ix, iy: integer);
|
||||
constructor Point(const p: Point);
|
||||
end;
|
||||
|
||||
function SetPoint(x, y: integer): Point;
|
||||
|
||||
type
|
||||
{ Rect }
|
||||
|
||||
Rect = object
|
||||
x, y, w, h: integer;
|
||||
|
||||
constructor Rect;
|
||||
constructor Rect(const p: TPoint);
|
||||
constructor Rect(ix, iy: integer; iw: integer = 0; ih: integer = 0);
|
||||
constructor Rect(const r: Rect);
|
||||
end;
|
||||
|
||||
function SetRect(x, y: integer): Rect;
|
||||
function SetRect(x, y, w, h: integer): Rect;
|
||||
|
||||
const
|
||||
ButtonFlags_Off = $0;
|
||||
ButtonFlags_On = $1;
|
||||
ButtonFlags_Begin = $2;
|
||||
ButtonFlags_End = $4;
|
||||
ButtonFlags_Shift = $8;
|
||||
ButtonFlags_Alt = $10;
|
||||
ButtonFlags_Ctrl = $20;
|
||||
|
||||
type
|
||||
ButtonState = record
|
||||
state: integer;
|
||||
time: TDateTime;
|
||||
cursor: Point;
|
||||
end;
|
||||
|
||||
const
|
||||
// An enum to identify the mouse buttons
|
||||
MouseButton_Left = 1;
|
||||
MouseButton_Middle = 2;
|
||||
MouseButton_Right = 3;
|
||||
|
||||
// An enum to identify the special key buttons not translated with ASCII codes
|
||||
Key_F1 = 128;
|
||||
Key_F2 = 129;
|
||||
Key_F3 = 130;
|
||||
Key_F4 = 131;
|
||||
Key_F5 = 132;
|
||||
Key_F6 = 133;
|
||||
Key_F7 = 134;
|
||||
Key_F8 = 135;
|
||||
Key_F9 = 136;
|
||||
Key_F10 = 137;
|
||||
Key_F11 = 138;
|
||||
Key_F12 = 139;
|
||||
|
||||
Key_Left = 140;
|
||||
Key_Up = 141;
|
||||
Key_Right = 142;
|
||||
Key_Down = 143;
|
||||
Key_PageUp = 144;
|
||||
Key_PageDown = 145;
|
||||
Key_Home = 146;
|
||||
Key_End = 147;
|
||||
Key_Insert = 148;
|
||||
|
||||
// The various flags to modify the behavior of the groups
|
||||
|
||||
// Layout behavior flags
|
||||
GroupFlags_LayoutNone = $01;
|
||||
GroupFlags_LayoutVertical = $02;
|
||||
GroupFlags_LayoutHorizontal = $04;
|
||||
GroupFlags_LayoutMask = $07;
|
||||
GroupFlags_LayoutXMask = $ffff xor GroupFlags_LayoutMask;
|
||||
|
||||
// Alignment flags for the widgets inserted in the group
|
||||
GroupFlags_AlignLeft = $10;
|
||||
GroupFlags_AlignRight = $20;
|
||||
GroupFlags_AlignTop = $40;
|
||||
GroupFlags_AlignBottom = $80;
|
||||
GroupFlags_AlignMask = $f0;
|
||||
GroupFlags_AlignXMask = $ffff xor GroupFlags_AlignMask;
|
||||
|
||||
// Start flags defining the starting origin of the group
|
||||
GroupFlags_StartLeft = $100;
|
||||
GroupFlags_StartRight = $200;
|
||||
GroupFlags_StartTop = $400;
|
||||
GroupFlags_StartBottom = $800;
|
||||
GroupFlags_StartMask = $f00;
|
||||
GroupFlags_StartXMask = $ffff xor GroupFlags_StartMask;
|
||||
|
||||
// Optional flags
|
||||
GroupFlags_LayoutForce = $8000;
|
||||
GroupFlags_LayoutDefault = $4000;
|
||||
GroupFlags_LayoutNoMargin = $2000;
|
||||
GroupFlags_LayoutNoSpace = $1000;
|
||||
GroupFlags_GrowRightFromBottom = GroupFlags_LayoutHorizontal or GroupFlags_StartLeft or GroupFlags_AlignLeft or GroupFlags_StartBottom or GroupFlags_AlignBottom;
|
||||
|
||||
// Predefined configurations
|
||||
GroupFlags_GrowRightFromTop = GroupFlags_LayoutHorizontal or GroupFlags_StartLeft or GroupFlags_AlignLeft or GroupFlags_StartTop or GroupFlags_AlignTop;
|
||||
GroupFlags_GrowLeftFromBottom = GroupFlags_LayoutHorizontal or GroupFlags_StartRight or GroupFlags_AlignRight or GroupFlags_StartBottom or GroupFlags_AlignBottom;
|
||||
GroupFlags_GrowLeftFromTop = GroupFlags_LayoutHorizontal or GroupFlags_StartRight or GroupFlags_AlignRight or GroupFlags_StartTop or GroupFlags_AlignTop;
|
||||
GroupFlags_GrowUpFromLeft = GroupFlags_LayoutVertical or GroupFlags_StartBottom or GroupFlags_AlignBottom or GroupFlags_StartLeft or GroupFlags_AlignLeft;
|
||||
GroupFlags_GrowUpFromRight = GroupFlags_LayoutVertical or GroupFlags_StartBottom or GroupFlags_AlignBottom or GroupFlags_StartRight or GroupFlags_AlignRight;
|
||||
GroupFlags_GrowDownFromLeft = GroupFlags_LayoutVertical or GroupFlags_StartTop or GroupFlags_AlignTop or GroupFlags_StartLeft or GroupFlags_AlignLeft;
|
||||
GroupFlags_GrowDownFromRight = GroupFlags_LayoutVertical or GroupFlags_StartTop or GroupFlags_AlignTop or GroupFlags_StartRight or GroupFlags_AlignRight;
|
||||
GroupFlags_LayoutDefaultFallback = GroupFlags_GrowDownFromLeft;
|
||||
|
||||
type
|
||||
Group = record
|
||||
bounds: Rect; //anchor point + width and height of the region
|
||||
flags: integer; //group behavior
|
||||
margin: integer; //border
|
||||
space: integer; //interior
|
||||
end;
|
||||
PGroup = ^Group;
|
||||
|
||||
//*************************************************************************
|
||||
// UIPainter
|
||||
|
||||
UIPainter = class(TObject)
|
||||
private
|
||||
FFont: TnvBaseFont;
|
||||
procedure SetFont(AValue: TnvBaseFont);
|
||||
public
|
||||
constructor Create;
|
||||
|
||||
procedure _begin(const window: Rect); virtual;
|
||||
procedure _end; virtual;
|
||||
|
||||
// These methods should be called between begin/end
|
||||
|
||||
procedure drawFrame(const r: Rect; margin: integer; style: integer); virtual; abstract;
|
||||
|
||||
function getLabelRect(const r: Rect; const Text: string; out rt: Rect; out nbLines: integer): Rect; virtual; abstract;
|
||||
procedure drawLabel(const r: Rect; const Text: string; const rt: Rect; const nbLines: integer; isHover: boolean; style: integer); virtual; abstract;
|
||||
|
||||
function getButtonRect(const r: Rect; const Text: string; out rt: Rect): Rect; virtual; abstract;
|
||||
procedure drawButton(const r: Rect; const Text: string; const rt: Rect; isDown: boolean; isHover: boolean; isFocus: boolean; style: integer); virtual; abstract;
|
||||
|
||||
function getCheckRect(const r: Rect; const Text: string; out rt: Rect; out rc: Rect): Rect; virtual; abstract;
|
||||
procedure drawCheckButton(const r: Rect; const Text: string; const rt: Rect; const rr: Rect; isChecked: boolean; isHover: boolean; isFocus: boolean; style: integer); virtual; abstract;
|
||||
|
||||
function getRadioRect(const r: Rect; const Text: string; out rt: Rect; out rr: Rect): Rect; virtual; abstract;
|
||||
procedure drawRadioButton(const r: Rect; const Text: string; const rt: Rect; const rr: Rect; isOn: boolean; isHover: boolean; isFocus: boolean; style: integer); virtual; abstract;
|
||||
|
||||
function getHorizontalSliderRect(const r: Rect; out rs: Rect; v: double; out rc: Rect): Rect; virtual; abstract;
|
||||
procedure drawHorizontalSlider(const r: Rect; rs: Rect; v: double; rc: Rect; isHover: boolean; style: integer); virtual; abstract;
|
||||
|
||||
function getItemRect(const r: Rect; const Text: string; out rt: Rect): Rect; virtual; abstract;
|
||||
procedure drawListItem(const r: Rect; const Text: string; const rt: Rect; isSelected: boolean; isHover: boolean; style: integer); virtual; abstract;
|
||||
|
||||
function getListRect(const r: Rect; numOptions: integer; const options: array of string; out ri: Rect; out rt: Rect): Rect; virtual; abstract;
|
||||
procedure drawListBox(const r: Rect; numOptions: integer; const options: array of string; const ri: Rect; const rt: Rect; selected: integer; hovered: integer; style: integer); virtual; abstract;
|
||||
|
||||
function getComboRect(const r: Rect; numOptions: integer; const options: array of string; selected: integer; out rt: Rect; out ra: Rect): Rect; virtual; abstract;
|
||||
function getComboOptionsRect(const rCombo: Rect; numOptions: integer; const options: array of string; out ri: Rect; out rit: Rect): Rect; virtual; abstract;
|
||||
procedure drawComboBox(const rect: Rect; numOptions: integer; const options: array of string; const rt: Rect; const ra: Rect; selected: integer; isHover: boolean; isFocus: boolean; style: integer); virtual; abstract;
|
||||
procedure drawComboOptions(const rect: Rect; numOptions: integer; const options: array of string; const ri: Rect; const rit: Rect; selected: integer; hovered: integer; isHover: boolean; isFocus: boolean; style: integer); virtual; abstract;
|
||||
|
||||
function getLineEditRect(const r: Rect; const Text: string; out rt: Rect): Rect; virtual; abstract;
|
||||
procedure drawLineEdit(const r: Rect; const Text: string; const rt: Rect; caretPos: integer; isSelected: boolean; isHover: boolean; style: integer); virtual; abstract;
|
||||
|
||||
function getPanelRect(const r: Rect; const Text: string; out rt: Rect; out ra: Rect): Rect; virtual; abstract;
|
||||
procedure drawPanel(const rect: Rect; const Text: string; const rt: Rect; const ra: Rect; isUnfold: boolean; isHover: boolean; isFocus: boolean; style: integer); virtual; abstract;
|
||||
|
||||
function getTextureViewRect(const rect: Rect; out rt: Rect): Rect; virtual; abstract;
|
||||
procedure drawTextureView(const rect: Rect; const texID: integer; const rt: Rect; const rz: Rect; mipLevel: integer; texelScale: double; texelOffset: double; r: integer; g: integer; b: integer; a: integer; style: integer); virtual; abstract;
|
||||
|
||||
// Eval widget dimensions
|
||||
function getCanvasMargin: integer; virtual;
|
||||
function getCanvasSpace: integer; virtual;
|
||||
function getFontHeight: integer; virtual;
|
||||
function getTextLineWidth(const Text: string): integer; virtual;
|
||||
function getTextSize(const Text: string; out nbLines: integer): integer; virtual;
|
||||
function getPickedCharNb(const Text: string; const at: Point): integer; virtual;
|
||||
|
||||
procedure drawDebugRect(const r: Rect); virtual; abstract;
|
||||
|
||||
procedure init; virtual; abstract;
|
||||
published
|
||||
property Font: TnvBaseFont read FFont write SetFont;
|
||||
end;
|
||||
|
||||
{ UIContext }
|
||||
|
||||
UIContext = class(TObject)
|
||||
@ -428,75 +237,6 @@ begin
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
{ Point }
|
||||
|
||||
constructor Point.Point;
|
||||
begin
|
||||
x := 0;
|
||||
y := 0;
|
||||
end;
|
||||
|
||||
constructor Point.Point(ix, iy: integer);
|
||||
begin
|
||||
x := ix;
|
||||
y := iy;
|
||||
end;
|
||||
|
||||
constructor Point.Point(const p: Point);
|
||||
begin
|
||||
x := p.x;
|
||||
y := p.y;
|
||||
end;
|
||||
|
||||
{ Rect }
|
||||
|
||||
constructor Rect.Rect;
|
||||
begin
|
||||
x := 0;
|
||||
y := 0;
|
||||
w := 0;
|
||||
h := 0;
|
||||
end;
|
||||
|
||||
constructor Rect.Rect(const p: TPoint);
|
||||
begin
|
||||
x := p.x;
|
||||
y := p.y;
|
||||
w := 0;
|
||||
h := 0;
|
||||
end;
|
||||
|
||||
constructor Rect.Rect(ix, iy: integer; iw: integer; ih: integer);
|
||||
begin
|
||||
x := ix;
|
||||
y := iy;
|
||||
w := iw;
|
||||
h := ih;
|
||||
end;
|
||||
|
||||
constructor Rect.Rect(const r: Rect);
|
||||
begin
|
||||
x := r.x;
|
||||
y := r.y;
|
||||
w := r.w;
|
||||
h := r.h;
|
||||
end;
|
||||
|
||||
function SetPoint(x, y: integer): Point;
|
||||
begin
|
||||
Result.Point(x, y);
|
||||
end;
|
||||
|
||||
function SetRect(x, y: integer): Rect;
|
||||
begin
|
||||
Result.Rect(x, y);
|
||||
end;
|
||||
|
||||
function SetRect(x, y, w, h: integer): Rect;
|
||||
begin
|
||||
Result.Rect(x, y, w, h);
|
||||
end;
|
||||
|
||||
{ UIContext }
|
||||
|
||||
constructor UIContext.Create;
|
||||
@ -1375,58 +1115,5 @@ begin
|
||||
Result := aRect;
|
||||
end;
|
||||
|
||||
{ UIPainter }
|
||||
|
||||
procedure UIPainter.SetFont(AValue: TnvBaseFont);
|
||||
begin
|
||||
if FFont=AValue then Exit;
|
||||
FFont:=AValue;
|
||||
end;
|
||||
|
||||
constructor UIPainter.Create;
|
||||
begin
|
||||
inherited;
|
||||
end;
|
||||
|
||||
procedure UIPainter._begin(const window: Rect);
|
||||
begin
|
||||
init;
|
||||
end;
|
||||
|
||||
procedure UIPainter._end;
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
function UIPainter.getCanvasMargin: integer;
|
||||
begin
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
function UIPainter.getCanvasSpace: integer;
|
||||
begin
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
function UIPainter.getFontHeight: integer;
|
||||
begin
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
function UIPainter.getTextLineWidth(const Text: string): integer;
|
||||
begin
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
function UIPainter.getTextSize(const Text: string; out nbLines: integer): integer;
|
||||
begin
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
function UIPainter.getPickedCharNb(const Text: string; const at: Point): integer;
|
||||
begin
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
154
components/nvidia-widgets/src/nvpainter.pas
Normal file
154
components/nvidia-widgets/src/nvpainter.pas
Normal file
@ -0,0 +1,154 @@
|
||||
//
|
||||
// nvWidgets.h - User Interface library
|
||||
//
|
||||
//
|
||||
// Author: Ignacio Castano, Samuel Gateau, Evan Hart
|
||||
// Email: sdkfeedback@nvidia.com
|
||||
//
|
||||
// Copyright (c) NVIDIA Corporation. All rights reserved.
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
unit nvPainter;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, nvBaseFont, nvTypes;
|
||||
|
||||
type
|
||||
|
||||
UIPainter = class(TObject)
|
||||
private
|
||||
FFont: TnvBaseFont;
|
||||
procedure SetFont(AValue: TnvBaseFont);
|
||||
public
|
||||
constructor Create;
|
||||
|
||||
procedure _begin(const window: Rect); virtual;
|
||||
procedure _end; virtual;
|
||||
|
||||
// These methods should be called between begin/end
|
||||
|
||||
procedure drawFrame(const r: Rect; margin: integer; style: integer); virtual; abstract;
|
||||
|
||||
function getLabelRect(const r: Rect; const Text: string; out rt: Rect; out nbLines: integer): Rect; virtual; abstract;
|
||||
procedure drawLabel(const r: Rect; const Text: string; const rt: Rect; const nbLines: integer; isHover: boolean; style: integer); virtual; abstract;
|
||||
|
||||
function getButtonRect(const r: Rect; const Text: string; out rt: Rect): Rect; virtual; abstract;
|
||||
procedure drawButton(const r: Rect; const Text: string; const rt: Rect; isDown: boolean; isHover: boolean; isFocus: boolean; style: integer); virtual; abstract;
|
||||
|
||||
function getCheckRect(const r: Rect; const Text: string; out rt: Rect; out rc: Rect): Rect; virtual; abstract;
|
||||
procedure drawCheckButton(const r: Rect; const Text: string; const rt: Rect; const rr: Rect; isChecked: boolean; isHover: boolean; isFocus: boolean; style: integer); virtual; abstract;
|
||||
|
||||
function getRadioRect(const r: Rect; const Text: string; out rt: Rect; out rr: Rect): Rect; virtual; abstract;
|
||||
procedure drawRadioButton(const r: Rect; const Text: string; const rt: Rect; const rr: Rect; isOn: boolean; isHover: boolean; isFocus: boolean; style: integer); virtual; abstract;
|
||||
|
||||
function getHorizontalSliderRect(const r: Rect; out rs: Rect; v: double; out rc: Rect): Rect; virtual; abstract;
|
||||
procedure drawHorizontalSlider(const r: Rect; rs: Rect; v: double; rc: Rect; isHover: boolean; style: integer); virtual; abstract;
|
||||
|
||||
function getItemRect(const r: Rect; const Text: string; out rt: Rect): Rect; virtual; abstract;
|
||||
procedure drawListItem(const r: Rect; const Text: string; const rt: Rect; isSelected: boolean; isHover: boolean; style: integer); virtual; abstract;
|
||||
|
||||
function getListRect(const r: Rect; numOptions: integer; const options: array of string; out ri: Rect; out rt: Rect): Rect; virtual; abstract;
|
||||
procedure drawListBox(const r: Rect; numOptions: integer; const options: array of string; const ri: Rect; const rt: Rect; selected: integer; hovered: integer; style: integer); virtual; abstract;
|
||||
|
||||
function getComboRect(const r: Rect; numOptions: integer; const options: array of string; selected: integer; out rt: Rect; out ra: Rect): Rect; virtual; abstract;
|
||||
function getComboOptionsRect(const rCombo: Rect; numOptions: integer; const options: array of string; out ri: Rect; out rit: Rect): Rect; virtual; abstract;
|
||||
procedure drawComboBox(const rect: Rect; numOptions: integer; const options: array of string; const rt: Rect; const ra: Rect; selected: integer; isHover: boolean; isFocus: boolean; style: integer); virtual; abstract;
|
||||
procedure drawComboOptions(const rect: Rect; numOptions: integer; const options: array of string; const ri: Rect; const rit: Rect; selected: integer; hovered: integer; isHover: boolean; isFocus: boolean; style: integer); virtual; abstract;
|
||||
|
||||
function getLineEditRect(const r: Rect; const Text: string; out rt: Rect): Rect; virtual; abstract;
|
||||
procedure drawLineEdit(const r: Rect; const Text: string; const rt: Rect; caretPos: integer; isSelected: boolean; isHover: boolean; style: integer); virtual; abstract;
|
||||
|
||||
function getPanelRect(const r: Rect; const Text: string; out rt: Rect; out ra: Rect): Rect; virtual; abstract;
|
||||
procedure drawPanel(const rect: Rect; const Text: string; const rt: Rect; const ra: Rect; isUnfold: boolean; isHover: boolean; isFocus: boolean; style: integer); virtual; abstract;
|
||||
|
||||
function getTextureViewRect(const rect: Rect; out rt: Rect): Rect; virtual; abstract;
|
||||
procedure drawTextureView(const rect: Rect; const texID: integer; const rt: Rect; const rz: Rect; mipLevel: integer; texelScale: double; texelOffset: double; r: integer; g: integer; b: integer; a: integer; style: integer); virtual; abstract;
|
||||
|
||||
// Eval widget dimensions
|
||||
function getCanvasMargin: integer; virtual;
|
||||
function getCanvasSpace: integer; virtual;
|
||||
function getFontHeight: integer; virtual;
|
||||
function getTextLineWidth(const Text: string): integer; virtual;
|
||||
function getTextSize(const Text: string; out nbLines: integer): integer; virtual;
|
||||
function getPickedCharNb(const Text: string; const at: Point): integer; virtual;
|
||||
|
||||
procedure drawDebugRect(const r: Rect); virtual; abstract;
|
||||
|
||||
procedure init; virtual; abstract;
|
||||
published
|
||||
property Font: TnvBaseFont read FFont write SetFont;
|
||||
end;
|
||||
|
||||
function EvalBool(b: boolean): byte;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
Math;
|
||||
|
||||
function EvalBool(b: boolean): byte;
|
||||
begin
|
||||
if b then
|
||||
Result := 1
|
||||
else
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
{ UIPainter }
|
||||
|
||||
procedure UIPainter.SetFont(AValue: TnvBaseFont);
|
||||
begin
|
||||
if FFont=AValue then Exit;
|
||||
FFont:=AValue;
|
||||
end;
|
||||
|
||||
constructor UIPainter.Create;
|
||||
begin
|
||||
inherited;
|
||||
end;
|
||||
|
||||
procedure UIPainter._begin(const window: Rect);
|
||||
begin
|
||||
init;
|
||||
end;
|
||||
|
||||
procedure UIPainter._end;
|
||||
begin
|
||||
|
||||
end;
|
||||
|
||||
function UIPainter.getCanvasMargin: integer;
|
||||
begin
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
function UIPainter.getCanvasSpace: integer;
|
||||
begin
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
function UIPainter.getFontHeight: integer;
|
||||
begin
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
function UIPainter.getTextLineWidth(const Text: string): integer;
|
||||
begin
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
function UIPainter.getTextSize(const Text: string; out nbLines: integer): integer;
|
||||
begin
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
function UIPainter.getPickedCharNb(const Text: string; const at: Point): integer;
|
||||
begin
|
||||
Result := 0;
|
||||
end;
|
||||
|
||||
end.
|
||||
|
208
components/nvidia-widgets/src/nvtypes.pas
Normal file
208
components/nvidia-widgets/src/nvtypes.pas
Normal file
@ -0,0 +1,208 @@
|
||||
unit nvTypes;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils;
|
||||
|
||||
type
|
||||
|
||||
{ Point }
|
||||
|
||||
Point = object
|
||||
x, y: integer;
|
||||
|
||||
constructor Point;
|
||||
constructor Point(ix, iy: integer);
|
||||
constructor Point(const p: Point);
|
||||
end;
|
||||
|
||||
function SetPoint(x, y: integer): Point;
|
||||
|
||||
type
|
||||
{ Rect }
|
||||
|
||||
Rect = object
|
||||
x, y, w, h: integer;
|
||||
|
||||
constructor Rect;
|
||||
constructor Rect(const p: TPoint);
|
||||
constructor Rect(ix, iy: integer; iw: integer = 0; ih: integer = 0);
|
||||
constructor Rect(const r: Rect);
|
||||
end;
|
||||
|
||||
function SetRect(x, y: integer): Rect;
|
||||
function SetRect(x, y, w, h: integer): Rect;
|
||||
|
||||
const
|
||||
ButtonFlags_Off = $0;
|
||||
ButtonFlags_On = $1;
|
||||
ButtonFlags_Begin = $2;
|
||||
ButtonFlags_End = $4;
|
||||
ButtonFlags_Shift = $8;
|
||||
ButtonFlags_Alt = $10;
|
||||
ButtonFlags_Ctrl = $20;
|
||||
|
||||
type
|
||||
ButtonState = record
|
||||
state: integer;
|
||||
time: TDateTime;
|
||||
cursor: Point;
|
||||
end;
|
||||
|
||||
const
|
||||
// An enum to identify the mouse buttons
|
||||
MouseButton_Left = 1;
|
||||
MouseButton_Middle = 2;
|
||||
MouseButton_Right = 3;
|
||||
|
||||
// An enum to identify the special key buttons not translated with ASCII codes
|
||||
Key_F1 = 128;
|
||||
Key_F2 = 129;
|
||||
Key_F3 = 130;
|
||||
Key_F4 = 131;
|
||||
Key_F5 = 132;
|
||||
Key_F6 = 133;
|
||||
Key_F7 = 134;
|
||||
Key_F8 = 135;
|
||||
Key_F9 = 136;
|
||||
Key_F10 = 137;
|
||||
Key_F11 = 138;
|
||||
Key_F12 = 139;
|
||||
|
||||
Key_Left = 140;
|
||||
Key_Up = 141;
|
||||
Key_Right = 142;
|
||||
Key_Down = 143;
|
||||
Key_PageUp = 144;
|
||||
Key_PageDown = 145;
|
||||
Key_Home = 146;
|
||||
Key_End = 147;
|
||||
Key_Insert = 148;
|
||||
|
||||
// The various flags to modify the behavior of the groups
|
||||
|
||||
// Layout behavior flags
|
||||
GroupFlags_LayoutNone = $01;
|
||||
GroupFlags_LayoutVertical = $02;
|
||||
GroupFlags_LayoutHorizontal = $04;
|
||||
GroupFlags_LayoutMask = $07;
|
||||
GroupFlags_LayoutXMask = $ffff xor GroupFlags_LayoutMask;
|
||||
|
||||
// Alignment flags for the widgets inserted in the group
|
||||
GroupFlags_AlignLeft = $10;
|
||||
GroupFlags_AlignRight = $20;
|
||||
GroupFlags_AlignTop = $40;
|
||||
GroupFlags_AlignBottom = $80;
|
||||
GroupFlags_AlignMask = $f0;
|
||||
GroupFlags_AlignXMask = $ffff xor GroupFlags_AlignMask;
|
||||
|
||||
// Start flags defining the starting origin of the group
|
||||
GroupFlags_StartLeft = $100;
|
||||
GroupFlags_StartRight = $200;
|
||||
GroupFlags_StartTop = $400;
|
||||
GroupFlags_StartBottom = $800;
|
||||
GroupFlags_StartMask = $f00;
|
||||
GroupFlags_StartXMask = $ffff xor GroupFlags_StartMask;
|
||||
|
||||
// Optional flags
|
||||
GroupFlags_LayoutForce = $8000;
|
||||
GroupFlags_LayoutDefault = $4000;
|
||||
GroupFlags_LayoutNoMargin = $2000;
|
||||
GroupFlags_LayoutNoSpace = $1000;
|
||||
GroupFlags_GrowRightFromBottom = GroupFlags_LayoutHorizontal or GroupFlags_StartLeft or GroupFlags_AlignLeft or GroupFlags_StartBottom or GroupFlags_AlignBottom;
|
||||
|
||||
// Predefined configurations
|
||||
GroupFlags_GrowRightFromTop = GroupFlags_LayoutHorizontal or GroupFlags_StartLeft or GroupFlags_AlignLeft or GroupFlags_StartTop or GroupFlags_AlignTop;
|
||||
GroupFlags_GrowLeftFromBottom = GroupFlags_LayoutHorizontal or GroupFlags_StartRight or GroupFlags_AlignRight or GroupFlags_StartBottom or GroupFlags_AlignBottom;
|
||||
GroupFlags_GrowLeftFromTop = GroupFlags_LayoutHorizontal or GroupFlags_StartRight or GroupFlags_AlignRight or GroupFlags_StartTop or GroupFlags_AlignTop;
|
||||
GroupFlags_GrowUpFromLeft = GroupFlags_LayoutVertical or GroupFlags_StartBottom or GroupFlags_AlignBottom or GroupFlags_StartLeft or GroupFlags_AlignLeft;
|
||||
GroupFlags_GrowUpFromRight = GroupFlags_LayoutVertical or GroupFlags_StartBottom or GroupFlags_AlignBottom or GroupFlags_StartRight or GroupFlags_AlignRight;
|
||||
GroupFlags_GrowDownFromLeft = GroupFlags_LayoutVertical or GroupFlags_StartTop or GroupFlags_AlignTop or GroupFlags_StartLeft or GroupFlags_AlignLeft;
|
||||
GroupFlags_GrowDownFromRight = GroupFlags_LayoutVertical or GroupFlags_StartTop or GroupFlags_AlignTop or GroupFlags_StartRight or GroupFlags_AlignRight;
|
||||
GroupFlags_LayoutDefaultFallback = GroupFlags_GrowDownFromLeft;
|
||||
|
||||
type
|
||||
Group = record
|
||||
bounds: Rect; //anchor point + width and height of the region
|
||||
flags: integer; //group behavior
|
||||
margin: integer; //border
|
||||
space: integer; //interior
|
||||
end;
|
||||
PGroup = ^Group;
|
||||
|
||||
implementation
|
||||
|
||||
{ Point }
|
||||
|
||||
constructor Point.Point;
|
||||
begin
|
||||
x := 0;
|
||||
y := 0;
|
||||
end;
|
||||
|
||||
constructor Point.Point(ix, iy: integer);
|
||||
begin
|
||||
x := ix;
|
||||
y := iy;
|
||||
end;
|
||||
|
||||
constructor Point.Point(const p: Point);
|
||||
begin
|
||||
x := p.x;
|
||||
y := p.y;
|
||||
end;
|
||||
|
||||
{ Rect }
|
||||
|
||||
constructor Rect.Rect;
|
||||
begin
|
||||
x := 0;
|
||||
y := 0;
|
||||
w := 0;
|
||||
h := 0;
|
||||
end;
|
||||
|
||||
constructor Rect.Rect(const p: TPoint);
|
||||
begin
|
||||
x := p.x;
|
||||
y := p.y;
|
||||
w := 0;
|
||||
h := 0;
|
||||
end;
|
||||
|
||||
constructor Rect.Rect(ix, iy: integer; iw: integer; ih: integer);
|
||||
begin
|
||||
x := ix;
|
||||
y := iy;
|
||||
w := iw;
|
||||
h := ih;
|
||||
end;
|
||||
|
||||
constructor Rect.Rect(const r: Rect);
|
||||
begin
|
||||
x := r.x;
|
||||
y := r.y;
|
||||
w := r.w;
|
||||
h := r.h;
|
||||
end;
|
||||
|
||||
function SetPoint(x, y: integer): Point;
|
||||
begin
|
||||
Result.Point(x, y);
|
||||
end;
|
||||
|
||||
function SetRect(x, y: integer): Rect;
|
||||
begin
|
||||
Result.Rect(x, y);
|
||||
end;
|
||||
|
||||
function SetRect(x, y, w, h: integer): Rect;
|
||||
begin
|
||||
Result.Rect(x, y, w, h);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
Loading…
Reference in New Issue
Block a user