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:
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;
|
||||
|
Reference in New Issue
Block a user