summaryrefslogtreecommitdiff
path: root/prototypes
diff options
context:
space:
mode:
authorgraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2007-07-19 12:58:07 +0000
committergraemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf>2007-07-19 12:58:07 +0000
commit305c7919280c57516e55a8df96bcad0e0d60dfb0 (patch)
tree30b6177e7600375fba9c3ac9f1403e234f897ade /prototypes
parent8cc3714242ec4ece8675dd587ce4ccb820443bb8 (diff)
downloadfpGUI-305c7919280c57516e55a8df96bcad0e0d60dfb0.tar.xz
GFX: Implemented Font Underline support.
* The start of a theme test project. Proof of concept only.
Diffstat (limited to 'prototypes')
-rw-r--r--prototypes/fpgui2/source/core/gfxbase.pas19
-rw-r--r--prototypes/fpgui2/tests/themetest.lpi264
-rw-r--r--prototypes/fpgui2/tests/themetest.lpr265
3 files changed, 548 insertions, 0 deletions
diff --git a/prototypes/fpgui2/source/core/gfxbase.pas b/prototypes/fpgui2/source/core/gfxbase.pas
index a00730ac..5f76ee14 100644
--- a/prototypes/fpgui2/source/core/gfxbase.pas
+++ b/prototypes/fpgui2/source/core/gfxbase.pas
@@ -712,8 +712,27 @@ begin
end;
procedure TfpgCanvasBase.DrawString(x, y: TfpgCoord; const txt: string);
+var
+ underline: integer;
begin
DoDrawString(x, y, txt);
+
+ { What was not handled: underline }
+ if Pos('UNDERLINE', UpperCase(Font.FontDesc)) > 0 then
+ begin
+ underline := (Font.Descent div 2) + 1;
+ if underline = 0 then
+ underline := 1;
+ if underline >= Font.Descent then
+ underline := Font.Descent - 1;
+
+// if Pos('BOLD', UpperCase(Font.FontDesc)) = 0 then
+ DoSetLineStyle(1, lsSolid);
+// else
+// DoSetLineStyle(2, lsSolid);
+ DoSetColor(TextColor);
+ DoDrawLine(x, Font.Height-underline, x+Font.TextWidth(txt), Font.Height-underline);
+ end;
end;
procedure TfpgCanvasBase.FillRectangle(x, y, w, h: TfpgCoord);
diff --git a/prototypes/fpgui2/tests/themetest.lpi b/prototypes/fpgui2/tests/themetest.lpi
new file mode 100644
index 00000000..77427571
--- /dev/null
+++ b/prototypes/fpgui2/tests/themetest.lpi
@@ -0,0 +1,264 @@
+<?xml version="1.0"?>
+<CONFIG>
+ <ProjectOptions>
+ <PathDelim Value="/"/>
+ <Version Value="5"/>
+ <General>
+ <MainUnit Value="0"/>
+ <TargetFileExt Value=""/>
+ <ActiveEditorIndexAtStart Value="6"/>
+ </General>
+ <VersionInfo>
+ <ProjectVersion Value=""/>
+ <Language Value=""/>
+ <CharSet Value=""/>
+ </VersionInfo>
+ <PublishOptions>
+ <Version Value="2"/>
+ <IgnoreBinaries Value="False"/>
+ <IncludeFileFilter Value="*.(pas|pp|inc|lfm|lpr|lrs|lpi|lpk|sh|xml)"/>
+ <ExcludeFileFilter Value="*.(bak|ppu|ppw|o|so);*~;backup"/>
+ </PublishOptions>
+ <RunParams>
+ <local>
+ <FormatVersion Value="1"/>
+ <LaunchingApplication PathPlusParams="/usr/X11R6/bin/xterm -T 'Lazarus Run Output' -e $(LazarusDir)/tools/runwait.sh $(TargetCmdLine)"/>
+ </local>
+ </RunParams>
+ <RequiredPackages Count="1">
+ <Item1>
+ <PackageName Value="fpGFX2"/>
+ </Item1>
+ </RequiredPackages>
+ <Units Count="13">
+ <Unit0>
+ <Filename Value="themetest.lpr"/>
+ <IsPartOfProject Value="True"/>
+ <UnitName Value="themetest"/>
+ <CursorPos X="41" Y="239"/>
+ <TopLine Value="233"/>
+ <EditorIndex Value="0"/>
+ <UsageCount Value="20"/>
+ <Loaded Value="True"/>
+ </Unit0>
+ <Unit1>
+ <Filename Value="edittest.dpr"/>
+ <UnitName Value="edittest"/>
+ <CursorPos X="1" Y="11"/>
+ <TopLine Value="1"/>
+ <EditorIndex Value="3"/>
+ <UsageCount Value="10"/>
+ <Loaded Value="True"/>
+ </Unit1>
+ <Unit2>
+ <Filename Value="../source/gui/gui_label.pas"/>
+ <UnitName Value="gui_label"/>
+ <CursorPos X="3" Y="118"/>
+ <TopLine Value="78"/>
+ <EditorIndex Value="2"/>
+ <UsageCount Value="10"/>
+ <Loaded Value="True"/>
+ </Unit2>
+ <Unit3>
+ <Filename Value="../../../../lptk/src/gfxbase.pas"/>
+ <UnitName Value="gfxbase"/>
+ <CursorPos X="21" Y="1915"/>
+ <TopLine Value="1940"/>
+ <UsageCount Value="10"/>
+ </Unit3>
+ <Unit4>
+ <Filename Value="../../../../fpgui/prototypes/fpgui2/source/core/gdi/gfx_gdi.pas"/>
+ <UnitName Value="gfx_gdi"/>
+ <CursorPos X="32" Y="1371"/>
+ <TopLine Value="1357"/>
+ <UsageCount Value="10"/>
+ </Unit4>
+ <Unit5>
+ <Filename Value="../../../../../../opt_backup/mseide/msegui/lib/common/kernel/msegraphics.pas"/>
+ <UnitName Value="msegraphics"/>
+ <CursorPos X="14" Y="2585"/>
+ <TopLine Value="2570"/>
+ <UsageCount Value="10"/>
+ </Unit5>
+ <Unit6>
+ <Filename Value="../../../../../../opt_backup/mseide/msegui/lib/common/kernel/msepostscriptprinter.pas"/>
+ <UnitName Value="msepostscriptprinter"/>
+ <CursorPos X="8" Y="1120"/>
+ <TopLine Value="1105"/>
+ <UsageCount Value="10"/>
+ </Unit6>
+ <Unit7>
+ <Filename Value="../../../../../../opt_backup/mseide/msegui/lib/common/kernel/i386-linux/mseguiintf.pas"/>
+ <UnitName Value="mseguiintf"/>
+ <CursorPos X="14" Y="3297"/>
+ <TopLine Value="3282"/>
+ <UsageCount Value="10"/>
+ </Unit7>
+ <Unit8>
+ <Filename Value="../../../../../../opt_backup/mseide/msegui/lib/common/kernel/msedrawtext.pas"/>
+ <UnitName Value="msedrawtext"/>
+ <CursorPos X="1" Y="842"/>
+ <TopLine Value="827"/>
+ <EditorIndex Value="7"/>
+ <UsageCount Value="10"/>
+ <Loaded Value="True"/>
+ </Unit8>
+ <Unit9>
+ <Filename Value="../source/core/x11/gfx_x11.pas"/>
+ <UnitName Value="gfx_x11"/>
+ <CursorPos X="1" Y="1337"/>
+ <TopLine Value="1330"/>
+ <EditorIndex Value="4"/>
+ <UsageCount Value="10"/>
+ <Loaded Value="True"/>
+ </Unit9>
+ <Unit10>
+ <Filename Value="../source/core/gfxbase.pas"/>
+ <UnitName Value="gfxbase"/>
+ <CursorPos X="1" Y="720"/>
+ <TopLine Value="714"/>
+ <EditorIndex Value="6"/>
+ <UsageCount Value="10"/>
+ <Loaded Value="True"/>
+ </Unit10>
+ <Unit11>
+ <Filename Value="../source/core/fpgfx.pas"/>
+ <UnitName Value="fpgfx"/>
+ <CursorPos X="17" Y="156"/>
+ <TopLine Value="136"/>
+ <EditorIndex Value="1"/>
+ <UsageCount Value="10"/>
+ <Loaded Value="True"/>
+ </Unit11>
+ <Unit12>
+ <Filename Value="../source/core/gdi/gfx_gdi.pas"/>
+ <UnitName Value="gfx_gdi"/>
+ <CursorPos X="1" Y="1100"/>
+ <TopLine Value="1073"/>
+ <EditorIndex Value="5"/>
+ <UsageCount Value="10"/>
+ <Loaded Value="True"/>
+ </Unit12>
+ </Units>
+ <JumpHistory Count="27" HistoryIndex="26">
+ <Position1>
+ <Filename Value="themetest.lpr"/>
+ <Caret Line="18" Column="9" TopLine="9"/>
+ </Position1>
+ <Position2>
+ <Filename Value="themetest.lpr"/>
+ <Caret Line="50" Column="11" TopLine="34"/>
+ </Position2>
+ <Position3>
+ <Filename Value="themetest.lpr"/>
+ <Caret Line="49" Column="23" TopLine="36"/>
+ </Position3>
+ <Position4>
+ <Filename Value="themetest.lpr"/>
+ <Caret Line="233" Column="3" TopLine="231"/>
+ </Position4>
+ <Position5>
+ <Filename Value="edittest.dpr"/>
+ <Caret Line="300" Column="1" TopLine="288"/>
+ </Position5>
+ <Position6>
+ <Filename Value="themetest.lpr"/>
+ <Caret Line="215" Column="25" TopLine="201"/>
+ </Position6>
+ <Position7>
+ <Filename Value="themetest.lpr"/>
+ <Caret Line="15" Column="13" TopLine="1"/>
+ </Position7>
+ <Position8>
+ <Filename Value="themetest.lpr"/>
+ <Caret Line="216" Column="39" TopLine="202"/>
+ </Position8>
+ <Position9>
+ <Filename Value="themetest.lpr"/>
+ <Caret Line="240" Column="17" TopLine="233"/>
+ </Position9>
+ <Position10>
+ <Filename Value="../source/gui/gui_label.pas"/>
+ <Caret Line="35" Column="63" TopLine="21"/>
+ </Position10>
+ <Position11>
+ <Filename Value="themetest.lpr"/>
+ <Caret Line="240" Column="16" TopLine="233"/>
+ </Position11>
+ <Position12>
+ <Filename Value="../source/gui/gui_label.pas"/>
+ <Caret Line="34" Column="52" TopLine="21"/>
+ </Position12>
+ <Position13>
+ <Filename Value="../source/core/x11/gfx_x11.pas"/>
+ <Caret Line="14" Column="26" TopLine="1"/>
+ </Position13>
+ <Position14>
+ <Filename Value="../../../../../../opt_backup/mseide/msegui/lib/common/kernel/msedrawtext.pas"/>
+ <Caret Line="840" Column="14" TopLine="822"/>
+ </Position14>
+ <Position15>
+ <Filename Value="../../../../../../opt_backup/mseide/msegui/lib/common/kernel/msedrawtext.pas"/>
+ <Caret Line="841" Column="4" TopLine="844"/>
+ </Position15>
+ <Position16>
+ <Filename Value="../../../../../../opt_backup/mseide/msegui/lib/common/kernel/msedrawtext.pas"/>
+ <Caret Line="737" Column="12" TopLine="723"/>
+ </Position16>
+ <Position17>
+ <Filename Value="../source/core/x11/gfx_x11.pas"/>
+ <Caret Line="1349" Column="76" TopLine="1324"/>
+ </Position17>
+ <Position18>
+ <Filename Value="../source/core/x11/gfx_x11.pas"/>
+ <Caret Line="1347" Column="28" TopLine="1324"/>
+ </Position18>
+ <Position19>
+ <Filename Value="../source/core/x11/gfx_x11.pas"/>
+ <Caret Line="1349" Column="17" TopLine="1324"/>
+ </Position19>
+ <Position20>
+ <Filename Value="../source/core/x11/gfx_x11.pas"/>
+ <Caret Line="1351" Column="92" TopLine="1330"/>
+ </Position20>
+ <Position21>
+ <Filename Value="../source/core/x11/gfx_x11.pas"/>
+ <Caret Line="1352" Column="1" TopLine="1330"/>
+ </Position21>
+ <Position22>
+ <Filename Value="../source/core/x11/gfx_x11.pas"/>
+ <Caret Line="1343" Column="34" TopLine="1329"/>
+ </Position22>
+ <Position23>
+ <Filename Value="../source/core/x11/gfx_x11.pas"/>
+ <Caret Line="1352" Column="73" TopLine="1334"/>
+ </Position23>
+ <Position24>
+ <Filename Value="../source/core/x11/gfx_x11.pas"/>
+ <Caret Line="1347" Column="1" TopLine="1329"/>
+ </Position24>
+ <Position25>
+ <Filename Value="../source/core/x11/gfx_x11.pas"/>
+ <Caret Line="129" Column="19" TopLine="118"/>
+ </Position25>
+ <Position26>
+ <Filename Value="../source/core/x11/gfx_x11.pas"/>
+ <Caret Line="78" Column="36" TopLine="77"/>
+ </Position26>
+ <Position27>
+ <Filename Value="../source/core/gdi/gfx_gdi.pas"/>
+ <Caret Line="1" Column="1" TopLine="1"/>
+ </Position27>
+ </JumpHistory>
+ </ProjectOptions>
+ <CompilerOptions>
+ <Version Value="5"/>
+ <CodeGeneration>
+ <Generate Value="Faster"/>
+ </CodeGeneration>
+ <Other>
+ <CustomOptions Value="-FUunits"/>
+ <CompilerPath Value="$(CompPath)"/>
+ </Other>
+ </CompilerOptions>
+</CONFIG>
diff --git a/prototypes/fpgui2/tests/themetest.lpr b/prototypes/fpgui2/tests/themetest.lpr
new file mode 100644
index 00000000..adb26616
--- /dev/null
+++ b/prototypes/fpgui2/tests/themetest.lpr
@@ -0,0 +1,265 @@
+program themetest;
+
+{$mode objfpc}{$H+}
+
+uses
+ {$IFDEF UNIX}{$IFDEF UseCThreads}
+ cthreads,
+ {$ENDIF}{$ENDIF}
+ Classes,
+ SysUtils,
+ fpgfx,
+ gfxbase,
+ gui_form,
+ gui_scrollbar,
+ gui_button,
+ gui_label,
+ gfx_imgfmt_bmp;
+
+type
+ { Concept theme button }
+ TThemeButton = class(TfpgButton)
+ private
+ State: integer;
+ // 0 - normal
+ // 1 - hover
+ // 2 - mouse down
+ // 3 - disabled
+ // 4 - got focus or default
+ image: TfpgImage;
+ procedure SetThemeImage(const AValue: TfpgImage);
+ protected
+ procedure HandlePaint; override;
+ procedure HandleLMouseDown(X, Y: integer; ShiftState: TShiftState); override;
+ procedure HandleLMouseUp(x, y: integer; shiftstate: TShiftState); override;
+ procedure HandleMouseExit; override;
+ procedure HandleMouseEnter; override;
+ public
+ constructor Create(AOwner: TComponent); override;
+ destructor Destroy; override;
+ { this property is only for demo purposes! }
+ property ThemeImage: TfpgImage read image write SetThemeImage;
+ end;
+
+
+ TThemeScrollbar = class(TfpgScrollBar)
+ end;
+
+
+ TMainForm = class(TfpgForm)
+ private
+ lblLuna: TfpgLabel;
+ lblSilver: TfpgLabel;
+ public
+ constructor Create(AOwner: TComponent); override;
+ end;
+
+
+
+{ TXPButton }
+
+procedure TThemeButton.SetThemeImage(const AValue: TfpgImage);
+begin
+ if Assigned(image) then
+ image.Free;
+ image := AValue;
+ Repaint;
+end;
+
+procedure TThemeButton.HandlePaint;
+var
+ x, i: integer;
+ r: TfpgRect;
+ iy, y: integer;
+ w: integer;
+ pofs: integer;
+begin
+ Canvas.BeginDraw;
+// inherited HandlePaint;
+ Canvas.ClearClipRect;
+ Canvas.Clear(clButtonFace);
+
+ if State <> 1 then
+ begin
+ if Down then
+ State := 2
+ else if Focused then
+ State := 4
+ else if not Enabled then
+ State := 3
+ else
+ State := 0;
+ end;
+
+ x := 0;
+ { left }
+ Canvas.DrawImagePart(x, 0, image, state*32, 0, 3, 21);
+ { body }
+ for i := (x+3) to (x+3+69) do
+ Canvas.DrawImagePart(i, 0, image, (state*32)+3, 0, 1, 21);
+ { right }
+ Canvas.DrawImagePart(i, 0, image, (state*32)+29, 0, 3, 21);
+
+ if Focused and (not Embedded) then
+ begin
+ Canvas.SetColor(clText1);
+ Canvas.SetLineStyle(1, lsDot);
+ Canvas.DrawRectangle(3, 3, Width - 6, Height - 6);
+ end
+ else
+ begin
+ Canvas.SetTextColor(clText1);
+ Canvas.SetColor(clText1);
+ end;
+
+ if not Enabled then
+ Canvas.SetTextColor(clShadow1);
+
+ r.left := 2;
+ r.top := 2;
+ r.Width := Width - 4;
+ r.Height := Height - 4;
+ Canvas.SetClipRect(r);
+
+ Canvas.SetFont(Font);
+ y := Height div 2 - FFont.Height div 2;
+ if y < 3 then
+ y := 3;
+
+ // offset text and image
+ if Down then
+ pofs := 1
+ else
+ pofs := 0;
+
+ if (ShowImage) and (FImage <> nil) then
+ begin
+ iy := Height div 2 - FImage.Height div 2;
+ if ImageMargin = -1 then // centered
+ begin
+ w := FFont.TextWidth(FText) + FImage.Width;
+ if FImageSpacing > 0 then
+ Inc(w, FImageSpacing);
+ x := (Width div 2) - (w div 2);
+ if x < 3 then
+ x := 3;
+ end
+ else
+ begin
+ x := FImageMargin + 3;
+ end;
+
+ Canvas.DrawImage(x + pofs, iy + pofs, FImage);
+ Inc(x, FImage.Width);
+ if FImageSpacing > 0 then
+ Inc(x, FImageSpacing);
+
+ if (FImageSpacing = -1) and (FImageMargin >= 0) then
+ begin
+ w := (Width - 3 - x) div 2 - FFont.TextWidth(FText) div 2;
+ if w < 1 then
+ w := 1; // minimal spacing
+ x := x + w;
+ end;
+ end
+ else
+ x := (Width div 2) - (FFont.TextWidth(FText) div 2);
+
+ if x < 3 then
+ x := 3;
+
+ Canvas.DrawString(x + pofs, y + pofs, FText);
+
+ Canvas.EndDraw;
+end;
+
+procedure TThemeButton.HandleLMouseDown(X, Y: integer; ShiftState: TShiftState);
+begin
+ State := 2;
+ Repaint;
+ inherited HandleLMouseDown(X, Y, ShiftState);
+end;
+
+procedure TThemeButton.HandleLMouseUp(x, y: integer; shiftstate: TShiftState);
+begin
+ State := 1;
+ Repaint;
+ inherited HandleLMouseUp(x, y, shiftstate);
+end;
+
+procedure TThemeButton.HandleMouseExit;
+begin
+ inherited HandleMouseExit;
+ if Enabled then
+ begin
+ State := 0;
+ Repaint;
+ end;
+end;
+
+procedure TThemeButton.HandleMouseEnter;
+begin
+ inherited HandleMouseEnter;
+ if Enabled then
+ begin
+ State := 1;
+ Repaint;
+ end;
+end;
+
+constructor TThemeButton.Create(AOwner: TComponent);
+begin
+ inherited Create(AOwner);
+ Width := 75;
+ Height := 21;
+ State := 0;
+
+ image := LoadImage_BMP(SetDirSeparators('../images/themes/luna/button.bmp'));
+ image.CreateMaskFromSample(0, 0);
+ image.UpdateImage;
+ if not Assigned(image) then
+ writeln('Image is nil');
+end;
+
+destructor TThemeButton.Destroy;
+begin
+ image.Free;
+ inherited Destroy;
+end;
+
+
+{ TMainForm }
+
+constructor TMainForm.Create(AOwner: TComponent);
+begin
+ inherited Create(AOwner);
+ WindowTitle := 'Theme test';
+ SetPosition(100, 100, 400, 300);
+
+ lblLuna := CreateLabel(self, 100, 5, 'Luna');
+ lblLuna.FontDesc := 'Sans-12:bold:underline';
+ lblLuna.Height := lblLuna.Font.Height;
+ lblLuna.Width := lblLuna.Font.TextWidth(lblLuna.Text);
+
+ lblSilver := CreateLabel(self, 250, 5, 'Silver');
+ lblSilver.FontDesc := 'Sans-12:bold:underline';
+ lblSilver.Height := lblSilver.Font.Height;
+ lblSilver.Width := lblSilver.Font.TextWidth(lblSilver.Text);
+end;
+
+
+
+procedure MainProc;
+var
+ frm: TMainForm;
+begin
+ fpgApplication.Initialize;
+ frm := TMainForm.Create(nil);
+ frm.Show;
+ fpgApplication.Run;
+end;
+
+begin
+ MainProc;
+end.
+