You've already forked lazarus-ccr
added font sources to documentation
painter and fonts are now user creatable properties added font option to fpmake implemented font styles for gl freetype started work on glut font class clean-up of nvglutwidgets class git-svn-id: https://svn.code.sf.net/p/lazarus-ccr/svn@2243 8e941d3f-bd1b-0410-a28a-d453659cc2b4
This commit is contained in:
@@ -2,6 +2,7 @@ type
|
||||
//add more here
|
||||
NV_CONTEXT = (GLUT);
|
||||
NV_PAINTER = (GL);
|
||||
NV_FONT = (GLFREETYPE, GLUTBITMAP);
|
||||
|
||||
const
|
||||
NV_DEBUG = True;
|
||||
@@ -15,4 +16,7 @@ var
|
||||
NV_ACTIVE_CONTEXT: NV_CONTEXT = GLUT;
|
||||
|
||||
//choose the painter
|
||||
NV_ACTIVE_PAINTER: NV_PAINTER = GL;
|
||||
NV_ACTIVE_PAINTER: NV_PAINTER = GL;
|
||||
|
||||
//choose the font
|
||||
NV_ACTIVE_FONT: NV_FONT = GLFREETYPE;
|
||||
@@ -35,6 +35,18 @@ begin
|
||||
|
||||
write('package ', P.Name, ' configured for ');
|
||||
|
||||
//select font class
|
||||
case NV_ACTIVE_FONT of
|
||||
GLFREETYPE: begin
|
||||
write('FreeType font ');
|
||||
P.Targets.AddUnit('./gl/glfreetypefont.pas');
|
||||
end;
|
||||
GLUTBITMAP: begin
|
||||
write('GLUT font ');
|
||||
P.Targets.AddUnit('./glut/glutbitmapfont.pas');
|
||||
end;
|
||||
end;
|
||||
|
||||
//context units
|
||||
case NV_ACTIVE_CONTEXT of
|
||||
GLUT: begin
|
||||
|
||||
@@ -17,25 +17,11 @@ uses
|
||||
//freetype font that we want to create.
|
||||
type
|
||||
|
||||
{ TGLFreeTypeFont }
|
||||
{ TGLFreeType }
|
||||
|
||||
TGLFreeTypeFont = object //class(TNVBaseFont)
|
||||
TGLFreeType = object
|
||||
textures: pGLuint; //< Holds the texture id's
|
||||
list_base: GLuint; //< Holds the first display list id
|
||||
{ public
|
||||
constructor Create(AName: string; ASize: integer); override;
|
||||
|
||||
//text metrics
|
||||
function TextHeight(Text: string): integer; override;
|
||||
function TextWidth(Text: string): integer; override;
|
||||
procedure TextSize(Text: string; var w, h: integer); override;
|
||||
|
||||
//printing function
|
||||
procedure TextOut(x, y: double; Text: string); override;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Height: cardinal; //< Holds the height of the font.
|
||||
|
||||
//The init function will create a font of
|
||||
@@ -202,7 +188,7 @@ begin
|
||||
FT_Done_Glyph(glyph);
|
||||
end;
|
||||
|
||||
procedure TGLFreeTypeFont.Init(const fname: string; AHeight: cardinal);
|
||||
procedure TGLFreeType.Init(const fname: string; AHeight: cardinal);
|
||||
var
|
||||
library_: PFT_Library = nil;
|
||||
face: PFT_Face = nil; //The object in which Freetype holds information on a given font is called a "face".
|
||||
@@ -247,7 +233,7 @@ begin
|
||||
FT_Done_FreeType(library_);
|
||||
end;
|
||||
|
||||
procedure TGLFreeTypeFont.Clean;
|
||||
procedure TGLFreeType.Clean;
|
||||
begin
|
||||
glDeleteLists(list_base, CHAR_NUM);
|
||||
glDeleteTextures(CHAR_NUM, textures);
|
||||
@@ -282,7 +268,7 @@ end;
|
||||
|
||||
//Much like Nehe's glPrint function, but modified to work
|
||||
//with freetype fonts.
|
||||
procedure TGLFreeTypeFont.Print(x, y: double; Text: string);
|
||||
procedure TGLFreeType.Print(x, y: double; Text: string);
|
||||
var
|
||||
font: GLuint;
|
||||
modelview_matrix: array [0..15] of double;
|
||||
@@ -327,7 +313,7 @@ begin
|
||||
pop_projection_matrix;
|
||||
end;
|
||||
|
||||
function TGLFreeTypeFont.TextWidth(const Text: string): integer;
|
||||
function TGLFreeType.TextWidth(const Text: string): integer;
|
||||
var
|
||||
i: Integer;
|
||||
begin
|
||||
|
||||
136
components/nvidia-widgets/src/gl/glfreetypefont.pas
Normal file
136
components/nvidia-widgets/src/gl/glfreetypefont.pas
Normal file
@@ -0,0 +1,136 @@
|
||||
unit GLFreeTypeFont;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
SysUtils, GLFreeType,
|
||||
nvBaseFont;
|
||||
|
||||
type
|
||||
TFontStyles = record
|
||||
Name: string;
|
||||
Bold: boolean;
|
||||
Italic: boolean;
|
||||
StrikeTrough: boolean;
|
||||
Underline: boolean;
|
||||
Font: TGLFreeType;
|
||||
end;
|
||||
|
||||
{ TGLFreeTypeFont }
|
||||
|
||||
TGLFreeTypeFont = class(TNVBaseFont)
|
||||
private
|
||||
FFontList: array of TFontStyles;
|
||||
FCount: integer;
|
||||
FActiveFont: integer;
|
||||
procedure FindStylizedFont;
|
||||
protected
|
||||
procedure SetFlags(AIndex: integer; AValue: boolean); override;
|
||||
public
|
||||
constructor Create(AName: string; ASize: integer); override;
|
||||
destructor Destroy; override;
|
||||
|
||||
//add stylized fonts
|
||||
procedure Add(AName: string; ABold, AItalic, AStrikeTrough, AUnderline: boolean); override;
|
||||
|
||||
//text metrics
|
||||
function TextHeight(Text: string): integer; override;
|
||||
function TextWidth(Text: string): integer; override;
|
||||
|
||||
//printing function
|
||||
procedure TextOut(x, y: double; Text: string); override;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
{ TGLFreeTypeFont }
|
||||
|
||||
procedure TGLFreeTypeFont.FindStylizedFont;
|
||||
var
|
||||
item: TFontStyles;
|
||||
i: integer;
|
||||
begin
|
||||
//if more fonts defined then find stylized font
|
||||
if FCount > 1 then
|
||||
for i := 0 to FCount - 1 do
|
||||
begin
|
||||
item := FFontList[i];
|
||||
|
||||
if (item.Bold = Bold) and
|
||||
(item.Italic = Italic) and
|
||||
(item.StrikeTrough = StrikeTrough) and
|
||||
(item.Underline = Underline) then
|
||||
begin
|
||||
FActiveFont := i;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
//no font found, select default one
|
||||
FActiveFont := 0;
|
||||
end;
|
||||
|
||||
procedure TGLFreeTypeFont.SetFlags(AIndex: integer; AValue: boolean);
|
||||
begin
|
||||
inherited SetFlags(AIndex, AValue);
|
||||
|
||||
FindStylizedFont;
|
||||
end;
|
||||
|
||||
constructor TGLFreeTypeFont.Create(AName: string; ASize: integer);
|
||||
begin
|
||||
inherited Create(AName, ASize);
|
||||
|
||||
FCount := 0;
|
||||
FSize := ASize;
|
||||
Add(AName, False, False, False, False);
|
||||
end;
|
||||
|
||||
destructor TGLFreeTypeFont.Destroy;
|
||||
var
|
||||
i: integer;
|
||||
begin
|
||||
for i := 0 to FCount - 1 do
|
||||
FFontList[i].Font.Clean;
|
||||
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TGLFreeTypeFont.Add(AName: string; ABold, AItalic, AStrikeTrough, AUnderline: boolean);
|
||||
begin
|
||||
Inc(FCount);
|
||||
SetLength(FFontList, FCount);
|
||||
|
||||
with FFontList[FCount - 1] do
|
||||
begin
|
||||
Font.Init(AName, Size);
|
||||
Name := AName;
|
||||
Bold := ABold;
|
||||
Italic := AItalic;
|
||||
StrikeTrough := AStrikeTrough;
|
||||
Underline := AUnderline;
|
||||
end;
|
||||
|
||||
FindStylizedFont;
|
||||
end;
|
||||
|
||||
function TGLFreeTypeFont.TextHeight(Text: string): integer;
|
||||
begin
|
||||
Result := Size;
|
||||
end;
|
||||
|
||||
function TGLFreeTypeFont.TextWidth(Text: string): integer;
|
||||
begin
|
||||
//only one font available or style not found then show default
|
||||
Result := FFontList[FActiveFont].Font.TextWidth(Text);
|
||||
end;
|
||||
|
||||
procedure TGLFreeTypeFont.TextOut(x, y: double; Text: string);
|
||||
begin
|
||||
FFontList[FActiveFont].Font.Print(x, y, Text);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
@@ -15,7 +15,7 @@ interface
|
||||
|
||||
uses
|
||||
Classes, nvWidgets,
|
||||
GL, ftFont, FPCanvas, GLFreeType;
|
||||
GL, ftFont, FPCanvas;
|
||||
|
||||
const
|
||||
cBase = 0;
|
||||
@@ -196,8 +196,6 @@ type
|
||||
|
||||
procedure init; override;
|
||||
private
|
||||
Font: TGLFreeTypeFont;
|
||||
|
||||
m_setupStateDL: integer;
|
||||
m_restoreStateDL: integer;
|
||||
m_foregroundDL: integer;
|
||||
@@ -256,13 +254,11 @@ begin
|
||||
m_texelScaleUniform := 0;
|
||||
m_texelOffsetUniform := 0;
|
||||
m_texelSwizzlingUniform := 0;
|
||||
|
||||
Font.Init('Ubuntu-R.ttf', 10);
|
||||
end;
|
||||
|
||||
destructor GLUIPainter.Destroy;
|
||||
begin
|
||||
Font.Clean;
|
||||
Font.Free;
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
@@ -797,7 +793,7 @@ end;
|
||||
|
||||
function GLUIPainter.getFontHeight: integer;
|
||||
begin
|
||||
Result := Font.Height + 4;
|
||||
Result := Font.TextHeight('X') + 4;
|
||||
end;
|
||||
|
||||
function GLUIPainter.getTextLineWidth(const Text: string): integer;
|
||||
@@ -925,7 +921,7 @@ end;
|
||||
|
||||
procedure GLUIPainter.drawString(x: integer; y: integer; Text: string; nbLines: integer);
|
||||
begin
|
||||
Font.Print(x, y + 2, Text);
|
||||
Font.TextOut(x, y + 2, Text);
|
||||
end;
|
||||
|
||||
procedure GLUIPainter.drawRect(aRect: Rect; fillColorId: integer; borderColorId: integer);
|
||||
|
||||
135
components/nvidia-widgets/src/glut/glutbitmapfont.pas
Normal file
135
components/nvidia-widgets/src/glut/glutbitmapfont.pas
Normal file
@@ -0,0 +1,135 @@
|
||||
unit GLUTBitmapFont;
|
||||
|
||||
{$mode objfpc}{$H+}
|
||||
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils, GLut, nvBaseFont;
|
||||
|
||||
type
|
||||
TFontStyles = record
|
||||
Name: string;
|
||||
Bold: boolean;
|
||||
Italic: boolean;
|
||||
StrikeTrough: boolean;
|
||||
Underline: boolean;
|
||||
Font: pointer;
|
||||
end;
|
||||
|
||||
{ TGLUTFreeTypeFont }
|
||||
|
||||
TGLUTFreeTypeFont = class(TNVBaseFont)
|
||||
private
|
||||
FFontList: array of TFontStyles;
|
||||
FCount: integer;
|
||||
FActiveFont: integer;
|
||||
procedure FindStylizedFont;
|
||||
protected
|
||||
procedure SetFlags(AIndex: integer; AValue: boolean); override;
|
||||
public
|
||||
constructor Create(AName: string; ASize: integer); override;
|
||||
destructor Destroy; override;
|
||||
|
||||
//add stylized fonts
|
||||
procedure Add(AName: string; ABold, AItalic, AStrikeTrough, AUnderline: boolean); override;
|
||||
|
||||
//text metrics
|
||||
function TextHeight(Text: string): integer; override;
|
||||
function TextWidth(Text: string): integer; override;
|
||||
|
||||
//printing function
|
||||
procedure TextOut(x, y: double; Text: string); override;
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
{ TGLUTFreeTypeFont }
|
||||
|
||||
procedure TGLUTFreeTypeFont.FindStylizedFont;
|
||||
var
|
||||
item: TFontStyles;
|
||||
i: integer;
|
||||
begin
|
||||
//if more fonts defined then find stylized font
|
||||
if FCount > 1 then
|
||||
for i := 0 to FCount - 1 do
|
||||
begin
|
||||
item := FFontList[i];
|
||||
|
||||
if (item.Bold = Bold) and
|
||||
(item.Italic = Italic) and
|
||||
(item.StrikeTrough = StrikeTrough) and
|
||||
(item.Underline = Underline) then
|
||||
begin
|
||||
FActiveFont := i;
|
||||
exit;
|
||||
end;
|
||||
end;
|
||||
|
||||
//no font found, select default one
|
||||
FActiveFont := 0;
|
||||
end;
|
||||
|
||||
procedure TGLUTFreeTypeFont.SetFlags(AIndex: integer; AValue: boolean);
|
||||
begin
|
||||
inherited SetFlags(AIndex, AValue);
|
||||
|
||||
FindStylizedFont;
|
||||
end;
|
||||
|
||||
constructor TGLUTFreeTypeFont.Create(AName: string; ASize: integer);
|
||||
begin
|
||||
inherited Create(AName, ASize);
|
||||
|
||||
FSize := ASize;
|
||||
Add(AName, False, False, False, False);
|
||||
FActiveFont := 0;
|
||||
end;
|
||||
|
||||
destructor TGLUTFreeTypeFont.Destroy;
|
||||
var
|
||||
i: integer;
|
||||
begin
|
||||
//for i := 0 to FCount - 1 do
|
||||
// FFontList[i].Font.Clean;
|
||||
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure TGLUTFreeTypeFont.Add(AName: string; ABold, AItalic, AStrikeTrough, AUnderline: boolean);
|
||||
begin
|
||||
Inc(FCount);
|
||||
SetLength(FFontList, FCount);
|
||||
|
||||
with FFontList[FCount - 1] do
|
||||
begin
|
||||
//Font.Init(AName, Size);
|
||||
Name := AName;
|
||||
Bold := ABold;
|
||||
Italic := AItalic;
|
||||
StrikeTrough := AStrikeTrough;
|
||||
Underline := AUnderline;
|
||||
end;
|
||||
|
||||
FindStylizedFont;
|
||||
end;
|
||||
|
||||
function TGLUTFreeTypeFont.TextHeight(Text: string): integer;
|
||||
begin
|
||||
Result := Size;
|
||||
end;
|
||||
|
||||
function TGLUTFreeTypeFont.TextWidth(Text: string): integer;
|
||||
begin
|
||||
//only one font available or style not found then show default
|
||||
//Result := FFontList[FActiveFont].Font.TextWidth(Text)
|
||||
end;
|
||||
|
||||
procedure TGLUTFreeTypeFont.TextOut(x, y: double; Text: string);
|
||||
begin
|
||||
//FFontList[FActiveFont].Font.Print(x, y, Text);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
@@ -28,27 +28,6 @@ type
|
||||
|
||||
public
|
||||
|
||||
//
|
||||
// Default UI constructor
|
||||
//
|
||||
// Creates private OpenGL painter
|
||||
//////////////////////////////////////////////////////////////////
|
||||
constructor Create;
|
||||
|
||||
//
|
||||
// Alternate UI constructor
|
||||
//
|
||||
// Allows for overriding the standard painter
|
||||
//////////////////////////////////////////////////////////////////
|
||||
constructor Create(painter: UIPainter);
|
||||
|
||||
//
|
||||
// UI destructor
|
||||
//
|
||||
// Destroy painter if it is private
|
||||
//////////////////////////////////////////////////////////////////
|
||||
destructor Destroy; override;
|
||||
|
||||
//
|
||||
// One time initialization
|
||||
//
|
||||
@@ -72,47 +51,19 @@ type
|
||||
procedure specialKeyboard(k, x, y: integer);
|
||||
|
||||
private
|
||||
m_ownPainter: boolean;
|
||||
|
||||
//
|
||||
// Translate non-ascii keys from GLUT to nvWidgets
|
||||
//////////////////////////////////////////////////////////////////
|
||||
function translateKey(k: integer): byte;
|
||||
|
||||
end;
|
||||
|
||||
implementation
|
||||
|
||||
uses
|
||||
GLut, GLext, nvGLWidgets;
|
||||
GLut, GLext;
|
||||
|
||||
{ GlutUIContext }
|
||||
|
||||
constructor GlutUIContext.Create;
|
||||
begin
|
||||
inherited Create(GLUIPainter.Create);
|
||||
m_ownPainter := True;
|
||||
end;
|
||||
|
||||
constructor GlutUIContext.Create(painter: UIPainter);
|
||||
begin
|
||||
inherited Create(painter);
|
||||
m_ownPainter := False;
|
||||
end;
|
||||
|
||||
destructor GlutUIContext.Destroy;
|
||||
var
|
||||
painter: UIPainter;
|
||||
begin
|
||||
if m_ownPainter then
|
||||
begin
|
||||
painter := getPainter;
|
||||
FreeAndNil(painter);
|
||||
end;
|
||||
|
||||
inherited;
|
||||
end;
|
||||
|
||||
function GlutUIContext.init(w, h: integer): boolean;
|
||||
begin
|
||||
Result := False;
|
||||
|
||||
@@ -16,15 +16,19 @@ type
|
||||
FAngle: double;
|
||||
FFlags: word;
|
||||
FName: string;
|
||||
FSize: integer;
|
||||
|
||||
function GetFlags(AIndex: integer): boolean;
|
||||
procedure SetFlags(AIndex: integer; AValue: boolean);
|
||||
protected
|
||||
FSize: integer;
|
||||
|
||||
procedure SetAngle(AValue: double); virtual;
|
||||
procedure SetFlags(AIndex: integer; AValue: boolean); virtual;
|
||||
public
|
||||
constructor Create(AName: string; ASize: integer); virtual;
|
||||
|
||||
//add stylized fonts
|
||||
procedure Add(AName: string; ABold, AItalic, AStrikeTrough, AUnderline: boolean); virtual; abstract;
|
||||
|
||||
//font characteristics
|
||||
property Name: string read FName;
|
||||
property Size: integer read FSize;
|
||||
@@ -32,7 +36,7 @@ type
|
||||
//text metrics
|
||||
function TextHeight(Text: string): integer; virtual; abstract;
|
||||
function TextWidth(Text: string): integer; virtual; abstract;
|
||||
procedure TextSize(Text: string; var w, h: integer); virtual; abstract;
|
||||
procedure TextSize(Text: string; var w, h: integer); virtual;
|
||||
|
||||
//font flags <<possibly not implemented for all font classes>>
|
||||
property Angle: double read FAngle write SetAngle;
|
||||
@@ -77,5 +81,11 @@ begin
|
||||
FSize := ASize;
|
||||
end;
|
||||
|
||||
procedure TNVBaseFont.TextSize(Text: string; var w, h: integer);
|
||||
begin
|
||||
w := TextWidth(Text);
|
||||
h := TextHeight(Text);
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ unit nvWidgets;
|
||||
interface
|
||||
|
||||
uses
|
||||
Classes, SysUtils;
|
||||
Classes, SysUtils, nvBaseFont;
|
||||
|
||||
type
|
||||
|
||||
@@ -146,6 +146,9 @@ type
|
||||
// UIPainter
|
||||
|
||||
UIPainter = class(TObject)
|
||||
private
|
||||
FFont: TnvBaseFont;
|
||||
procedure SetFont(AValue: TnvBaseFont);
|
||||
public
|
||||
constructor Create;
|
||||
|
||||
@@ -202,13 +205,16 @@ type
|
||||
procedure drawDebugRect(const r: Rect); virtual; abstract;
|
||||
|
||||
procedure init; virtual; abstract;
|
||||
published
|
||||
property Font: TnvBaseFont read FFont write SetFont;
|
||||
end;
|
||||
|
||||
{ UIContext }
|
||||
|
||||
UIContext = class(TObject)
|
||||
public
|
||||
constructor Create(painter: UIPainter);
|
||||
constructor Create;
|
||||
destructor Destroy; override;
|
||||
|
||||
// UI method for processing window size events
|
||||
//////////////////////////////////////////////////////////////////
|
||||
@@ -376,18 +382,21 @@ type
|
||||
function window: Rect;
|
||||
|
||||
private
|
||||
FPainter: UIPainter;
|
||||
procedure setCursor(x: integer; y: integer);
|
||||
|
||||
function overlap(const aRect: Rect; const p: Point): boolean;
|
||||
|
||||
function hasFocus(const aRect: Rect): boolean;
|
||||
function isHover(const aRect: Rect): boolean;
|
||||
procedure SetPainter(AValue: UIPainter);
|
||||
protected
|
||||
function placeRect(const r: Rect): Rect;
|
||||
|
||||
protected
|
||||
m_painter: UIPainter;
|
||||
published
|
||||
property Painter: UIPainter read FPainter write SetPainter;
|
||||
|
||||
protected
|
||||
m_groupIndex: integer;
|
||||
m_groupStack: array [0..63] of Group;
|
||||
|
||||
@@ -490,13 +499,20 @@ end;
|
||||
|
||||
{ UIContext }
|
||||
|
||||
constructor UIContext.Create(painter: UIPainter);
|
||||
constructor UIContext.Create;
|
||||
begin
|
||||
m_painter := painter;
|
||||
m_twoStepFocus := False;
|
||||
m_focusCaretPos := -1;
|
||||
end;
|
||||
|
||||
destructor UIContext.Destroy;
|
||||
begin
|
||||
if Assigned(Painter) then
|
||||
Painter.Free;
|
||||
|
||||
inherited Destroy;
|
||||
end;
|
||||
|
||||
procedure UIContext.reshape(w, h: integer);
|
||||
begin
|
||||
m_window.x := 0;
|
||||
@@ -558,12 +574,12 @@ end;
|
||||
|
||||
procedure UIContext._begin;
|
||||
begin
|
||||
m_painter._begin(m_window);
|
||||
Painter._begin(m_window);
|
||||
|
||||
m_groupIndex := 0;
|
||||
m_groupStack[m_groupIndex].flags := GroupFlags_LayoutNone;
|
||||
m_groupStack[m_groupIndex].margin := m_painter.getCanvasMargin;
|
||||
m_groupStack[m_groupIndex].space := m_painter.getCanvasSpace;
|
||||
m_groupStack[m_groupIndex].margin := Painter.getCanvasMargin;
|
||||
m_groupStack[m_groupIndex].space := Painter.getCanvasSpace;
|
||||
m_groupStack[m_groupIndex].bounds := m_window;
|
||||
end;
|
||||
|
||||
@@ -571,7 +587,7 @@ procedure UIContext._end;
|
||||
var
|
||||
i: integer;
|
||||
begin
|
||||
m_painter._end;
|
||||
Painter._end;
|
||||
|
||||
// Release focus.
|
||||
if (m_mouseButton[0].state and ButtonFlags_End) > 0 then
|
||||
@@ -597,8 +613,8 @@ var
|
||||
nbLines: integer;
|
||||
aRect: Rect;
|
||||
begin
|
||||
aRect := placeRect(m_painter.getLabelRect(r, Text, rt, nbLines));
|
||||
m_painter.drawLabel(aRect, Text, rt, nbLines, isHover(aRect), style);
|
||||
aRect := placeRect(Painter.getLabelRect(r, Text, rt, nbLines));
|
||||
Painter.drawLabel(aRect, Text, rt, nbLines, isHover(aRect), style);
|
||||
end;
|
||||
|
||||
function UIContext.doButton(const r: Rect; const Text: string; var state: boolean; style: integer): boolean;
|
||||
@@ -609,14 +625,14 @@ var
|
||||
hover: boolean;
|
||||
isDown: boolean;
|
||||
begin
|
||||
aRect := placeRect(m_painter.getButtonRect(r, Text, rt));
|
||||
aRect := placeRect(Painter.getButtonRect(r, Text, rt));
|
||||
focus := hasFocus(aRect);
|
||||
hover := isHover(aRect);
|
||||
|
||||
isDown := state;
|
||||
//isDown := ((m_mouseButton[0].state and ButtonFlags_On)>0) and hover and focus;
|
||||
|
||||
m_painter.drawButton(aRect, Text, rt, isDown, hover, focus, style);
|
||||
Painter.drawButton(aRect, Text, rt, isDown, hover, focus, style);
|
||||
|
||||
if not focus then
|
||||
m_uiOnFocus := True;
|
||||
@@ -646,10 +662,10 @@ var
|
||||
focus: boolean;
|
||||
hover: boolean;
|
||||
begin
|
||||
aRect := placeRect(m_painter.getCheckRect(r, Text, rt, rc));
|
||||
aRect := placeRect(Painter.getCheckRect(r, Text, rt, rc));
|
||||
focus := hasFocus(aRect);
|
||||
hover := isHover(aRect);
|
||||
m_painter.drawCheckButton(aRect, Text, rt, rc, state, hover, focus, style);
|
||||
Painter.drawCheckButton(aRect, Text, rt, rc, state, hover, focus, style);
|
||||
|
||||
if hasFocus(aRect) then
|
||||
m_uiOnFocus := True;
|
||||
@@ -672,10 +688,10 @@ var
|
||||
focus: boolean;
|
||||
hover: boolean;
|
||||
begin
|
||||
aRect := placeRect(m_painter.getRadioRect(r, Text, rt, rr));
|
||||
aRect := placeRect(Painter.getRadioRect(r, Text, rt, rr));
|
||||
focus := hasFocus(aRect);
|
||||
hover := isHover(aRect);
|
||||
m_painter.drawRadioButton(aRect, Text, rt, rr, longbool(Value and EvalBool(reference = Value)), hover, focus, style);
|
||||
Painter.drawRadioButton(aRect, Text, rt, rr, longbool(Value and EvalBool(reference = Value)), hover, focus, style);
|
||||
|
||||
if focus then
|
||||
m_uiOnFocus := True;
|
||||
@@ -709,7 +725,7 @@ begin
|
||||
if f > 1 then
|
||||
f := 1;
|
||||
|
||||
rr := placeRect(m_painter.getHorizontalSliderRect(aRect, rs, f, rc));
|
||||
rr := placeRect(Painter.getHorizontalSliderRect(aRect, rs, f, rc));
|
||||
|
||||
if hasFocus(rr) then
|
||||
begin
|
||||
@@ -735,7 +751,7 @@ begin
|
||||
end;
|
||||
end;
|
||||
|
||||
m_painter.drawHorizontalSlider(rr, rs, f, rc, isHover(rr), style);
|
||||
Painter.drawHorizontalSlider(rr, rs, f, rc, isHover(rr), style);
|
||||
|
||||
Result := changed;
|
||||
end;
|
||||
@@ -745,8 +761,8 @@ var
|
||||
rt: Rect;
|
||||
r: Rect;
|
||||
begin
|
||||
r := placeRect(m_painter.getItemRect(aRect, Text, rt));
|
||||
m_painter.drawListItem(r, Text, rt, longbool(selected and EvalBool(index = selected)), isHover(r), style);
|
||||
r := placeRect(Painter.getItemRect(aRect, Text, rt));
|
||||
Painter.drawListItem(r, Text, rt, longbool(selected and EvalBool(index = selected)), isHover(r), style);
|
||||
|
||||
Result := isHover(r);
|
||||
end;
|
||||
@@ -761,7 +777,7 @@ var
|
||||
hovered: integer = -1;
|
||||
lSelected: integer = -1;
|
||||
begin
|
||||
rr := placeRect(m_painter.getListRect(aRect, numOptions, options, ri, rt));
|
||||
rr := placeRect(Painter.getListRect(aRect, numOptions, options, ri, rt));
|
||||
focus := hasFocus(rr);
|
||||
hover := isHover(rr);
|
||||
|
||||
@@ -771,7 +787,7 @@ begin
|
||||
if selected <> 0 then
|
||||
lSelected := selected;
|
||||
|
||||
m_painter.drawListBox(rr, numOptions, options, ri, rt, lSelected, hovered, style);
|
||||
Painter.drawListBox(rr, numOptions, options, ri, rt, lSelected, hovered, style);
|
||||
|
||||
if focus then
|
||||
m_uiOnFocus := True;
|
||||
@@ -800,7 +816,7 @@ var
|
||||
hoverOptions: boolean;
|
||||
begin
|
||||
// First get the rect of the combobox itself and do some test with it
|
||||
rr := placeRect(m_painter.getComboRect(aRect, numOptions, options, selected, rt, ra));
|
||||
rr := placeRect(Painter.getComboRect(aRect, numOptions, options, selected, rt, ra));
|
||||
focus := hasFocus(rr);
|
||||
hover := isHover(rr);
|
||||
|
||||
@@ -809,7 +825,7 @@ begin
|
||||
m_uiOnFocus := True;
|
||||
|
||||
// then if the combo box has focus, we can look for the geometry of the options frame
|
||||
ro := m_painter.getComboOptionsRect(rr, numOptions, options, ri, rit);
|
||||
ro := Painter.getComboOptionsRect(rr, numOptions, options, ri, rit);
|
||||
hovered := -1;
|
||||
hoverOptions := overlap(ro, m_currentCursor);
|
||||
|
||||
@@ -817,10 +833,10 @@ begin
|
||||
hovered := numOptions - 1 - (m_currentCursor.y - (ro.y + ri.y)) div (ri.h);
|
||||
|
||||
// draw combo anyway
|
||||
m_painter.drawComboBox(rr, numOptions, options, rt, ra, selected, hover, focus, style);
|
||||
Painter.drawComboBox(rr, numOptions, options, rt, ra, selected, hover, focus, style);
|
||||
|
||||
// draw options
|
||||
m_painter.drawComboOptions(ro, numOptions, options, ri, rit, selected, hovered, hover, focus, style);
|
||||
Painter.drawComboOptions(ro, numOptions, options, ri, rit, selected, hovered, hover, focus, style);
|
||||
|
||||
// When the widget get the focus, cache the focus point
|
||||
if not m_twoStepFocus then
|
||||
@@ -860,7 +876,7 @@ begin
|
||||
end;
|
||||
end
|
||||
else
|
||||
m_painter.drawComboBox(rr, numOptions, options, rt, ra, selected, hover, focus, style);
|
||||
Painter.drawComboBox(rr, numOptions, options, rt, ra, selected, hover, focus, style);
|
||||
|
||||
Result := False;
|
||||
end;
|
||||
@@ -877,7 +893,7 @@ var
|
||||
nbKeys: integer;
|
||||
keyNb: integer;
|
||||
begin
|
||||
rr := placeRect(m_painter.getLineEditRect(aRect, Text, rt));
|
||||
rr := placeRect(Painter.getLineEditRect(aRect, Text, rt));
|
||||
focus := hasFocus(rr);
|
||||
hover := isHover(rr);
|
||||
|
||||
@@ -910,7 +926,7 @@ begin
|
||||
|
||||
// Eval caret pos on every click hover
|
||||
if hover and ((m_mouseButton[0].state and ButtonFlags_Begin) > 0) then
|
||||
m_focusCaretPos := m_painter.getPickedCharNb(Text, SetPoint(m_currentCursor.x - rt.x - rr.x, m_currentCursor.y - rt.y - rr.y));
|
||||
m_focusCaretPos := Painter.getPickedCharNb(Text, SetPoint(m_currentCursor.x - rt.x - rr.x, m_currentCursor.y - rt.y - rr.y));
|
||||
|
||||
// If keys are buffered, apply input to the edited text
|
||||
if m_nbKeys <> 0 then
|
||||
@@ -993,7 +1009,7 @@ begin
|
||||
carretPos := m_focusCaretPos;
|
||||
end;
|
||||
|
||||
m_painter.drawLineEdit(rr, Text, rt, carretPos, focus, hover, style);
|
||||
Painter.drawLineEdit(rr, Text, rt, carretPos, focus, hover, style);
|
||||
|
||||
Result := _result;
|
||||
end;
|
||||
@@ -1036,8 +1052,8 @@ begin
|
||||
groupFlags := (groupFlags and GroupFlags_AlignXMask) or parentAlign;
|
||||
end;
|
||||
|
||||
newGroup^.margin := EvalBool((groupFlags and GroupFlags_LayoutNoMargin) = 0) * m_painter.getCanvasMargin;
|
||||
newGroup^.space := EvalBool((groupFlags and GroupFlags_LayoutNoSpace) = 0) * m_painter.getCanvasSpace;
|
||||
newGroup^.margin := EvalBool((groupFlags and GroupFlags_LayoutNoMargin) = 0) * Painter.getCanvasMargin;
|
||||
newGroup^.space := EvalBool((groupFlags and GroupFlags_LayoutNoSpace) = 0) * Painter.getCanvasSpace;
|
||||
newGroup^.flags := groupFlags;
|
||||
|
||||
//newLayout := groupFlags and GroupFlags_LayoutMask;
|
||||
@@ -1119,7 +1135,7 @@ begin
|
||||
parentGroup^.bounds.h := maxBoundY - minBoundY;
|
||||
end;
|
||||
|
||||
{$IFDEF DEBUG} m_painter.drawDebugRect(newGroup.bounds); {$ENDIF}
|
||||
{$IFDEF DEBUG} Painter.drawDebugRect(newGroup.bounds); {$ENDIF}
|
||||
end;
|
||||
|
||||
procedure UIContext.beginFrame(groupFlags: integer; const rect: Rect; style: integer);
|
||||
@@ -1130,7 +1146,7 @@ end;
|
||||
procedure UIContext.endFrame;
|
||||
begin
|
||||
endGroup;
|
||||
m_painter.drawFrame(m_groupStack[m_groupIndex + 1].bounds, m_groupStack[m_groupIndex + 1].margin, 0);
|
||||
Painter.drawFrame(m_groupStack[m_groupIndex + 1].bounds, m_groupStack[m_groupIndex + 1].margin, 0);
|
||||
end;
|
||||
|
||||
function UIContext.beginPanel(var r: Rect; const Text: string; var isUnfold: boolean; groupFlags: integer; style: integer): boolean;
|
||||
@@ -1143,7 +1159,7 @@ var
|
||||
hover: boolean;
|
||||
tmp: Rect;
|
||||
begin
|
||||
rpanel := m_painter.getPanelRect(SetRect(r.x, r.y), Text, rt, ra);
|
||||
rpanel := Painter.getPanelRect(SetRect(r.x, r.y), Text, rt, ra);
|
||||
|
||||
if (groupFlags and GroupFlags_LayoutDefault) > 0 then
|
||||
groupFlags := GroupFlags_LayoutDefaultFallback;
|
||||
@@ -1168,7 +1184,7 @@ begin
|
||||
if ((m_mouseButton[0].state and ButtonFlags_End) > 0) and focus and (overlap(SetRect(aRect.x + ra.x, aRect.y + ra.y, ra.w, ra.h), m_currentCursor)) then
|
||||
isUnfold := not isUnfold;
|
||||
|
||||
m_painter.drawPanel(aRect, Text, rt, ra, isUnfold, hover, focus, style);
|
||||
Painter.drawPanel(aRect, Text, rt, ra, isUnfold, hover, focus, style);
|
||||
|
||||
if isUnfold then
|
||||
begin
|
||||
@@ -1219,16 +1235,16 @@ var
|
||||
rt: Rect;
|
||||
rr: Rect;
|
||||
begin
|
||||
rr := placeRect(m_painter.getTextureViewRect(aRect, rt));
|
||||
rr := placeRect(Painter.getTextureViewRect(aRect, rt));
|
||||
if (zoomRect.w = 0) or (zoomRect.h = 0) then
|
||||
zoomRect.Rect(0, 0, rt.w, rt.h);
|
||||
|
||||
m_painter.drawTextureView(rr, texID, rt, zoomRect, mipLevel, texelScale, texelOffset, red, green, blue, alpha, style);
|
||||
Painter.drawTextureView(rr, texID, rt, zoomRect, mipLevel, texelScale, texelOffset, red, green, blue, alpha, style);
|
||||
end;
|
||||
|
||||
function UIContext.getPainter: UIPainter;
|
||||
begin
|
||||
Result := m_painter;
|
||||
Result := Painter;
|
||||
end;
|
||||
|
||||
function UIContext.window: Rect;
|
||||
@@ -1264,6 +1280,14 @@ begin
|
||||
Result := overlap(aRect, m_currentCursor);
|
||||
end;
|
||||
|
||||
procedure UIContext.SetPainter(AValue: UIPainter);
|
||||
begin
|
||||
if FPainter=AValue then
|
||||
exit;
|
||||
|
||||
FPainter:=AValue;
|
||||
end;
|
||||
|
||||
function UIContext.placeRect(const r: Rect): Rect;
|
||||
var
|
||||
aGroup: PGroup;
|
||||
@@ -1353,6 +1377,12 @@ end;
|
||||
|
||||
{ UIPainter }
|
||||
|
||||
procedure UIPainter.SetFont(AValue: TnvBaseFont);
|
||||
begin
|
||||
if FFont=AValue then Exit;
|
||||
FFont:=AValue;
|
||||
end;
|
||||
|
||||
constructor UIPainter.Create;
|
||||
begin
|
||||
inherited;
|
||||
|
||||
Reference in New Issue
Block a user