summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graeme@mastermaths.co.za>2010-07-01 16:03:28 +0200
committerGraeme Geldenhuys <graeme@mastermaths.co.za>2010-07-01 16:03:28 +0200
commit7b85a6d7e2243640c2389c26f586720da0596d3e (patch)
treea793f3e0e85a84ee656375c5ed3174bf82d845a1
parent203ed9270d67f3e2e99817e33a2ae8454ff54b30 (diff)
downloadfpGUI-7b85a6d7e2243640c2389c26f586720da0596d3e.tar.xz
fpg_panel: Refactored the HandlePaint method.
* It was extremely hard to maintain that method as all Shape types drawing code are mixed together. * Not all shape types (eg line top,bottom,right,left) was painted 100% because of shared code. * Each shape type now has its own DrawXXX method, with the result both issues mentioned above are resolved.
-rw-r--r--src/gui/fpg_panel.pas146
1 files changed, 125 insertions, 21 deletions
diff --git a/src/gui/fpg_panel.pas b/src/gui/fpg_panel.pas
index 8d04b360..b11ccd68 100644
--- a/src/gui/fpg_panel.pas
+++ b/src/gui/fpg_panel.pas
@@ -62,6 +62,14 @@ type
private
FPanelShape: TPanelShape;
procedure SetPanelShape(const AValue: TPanelShape);
+ procedure DrawBox; // bsBox
+ procedure DrawFrame; // bsFrame
+ procedure DrawTopLine; // bsTopLine
+ procedure DrawBottomLine; // bsBottomLine
+ procedure DrawLeftLine; // bsLeftLine
+ procedure DrawRightLine; // bsRightLine
+ procedure DrawSpacer; // bsSpacer
+ procedure DrawVerDivider; // bsVerDivider
protected
procedure HandlePaint; override;
published
@@ -318,23 +326,106 @@ begin
end;
end;
-procedure TfpgBevel.HandlePaint;
+procedure TfpgBevel.DrawBox;
begin
- inherited HandlePaint;
+ if FPanelBorder = bsSingle then
+ Canvas.DrawLine(0, 0, Width - 1, 0)
+ else
+ Canvas.DrawLine(0, 1, Width - 1, 1);
- // Canvas.SetLineStyle(2, lsSolid);
- // Canvas.SetColor(clWindowBackground);
- // Canvas.DrawRectangle(1, 1, Width - 1, Height - 1);
if FPanelBorder = bsSingle then
- Canvas.SetLineStyle(1, lsSolid)
+ Canvas.DrawLine(0, 1, 0, Height - 1)
else
- Canvas.SetLineStyle(2, lsSolid);
+ Canvas.DrawLine(1, 1, 1, Height - 1);
if Style = bsRaised then
- Canvas.SetColor(clHilite2)
+ Canvas.SetColor(clShadow2)
else
- Canvas.SetColor(clShadow2);
+ Canvas.SetColor(clHilite2);
+
+ Canvas.DrawLine(Width - 1, 0, Width - 1, Height - 1);
+ Canvas.DrawLine(0, Height - 1, Width, Height - 1);
+end;
+
+procedure TfpgBevel.DrawFrame;
+begin
+ Canvas.DrawLine(0, 0, Width - 1, 0);
+ Canvas.DrawLine(0, 1, 0, Height - 1);
+ Canvas.DrawLine(Width - 2, 1, Width - 2, Height - 1);
+ Canvas.DrawLine(1, Height - 2, Width - 1, Height - 2);
+
+ if Style = bsRaised then
+ Canvas.SetColor(clShadow2)
+ else
+ Canvas.SetColor(clHilite2);
+
+ Canvas.DrawLine(1, 1, Width - 2, 1);
+ Canvas.DrawLine(1, 2, 1, Height - 2);
+ Canvas.DrawLine(Width - 1, 0, Width - 1, Height - 1);
+ Canvas.DrawLine(0, Height - 1, Width, Height - 1);
+end;
+
+procedure TfpgBevel.DrawTopLine;
+begin
+ Canvas.DrawLine(0, 0, Width, 0);
+
+ if Style = bsRaised then
+ Canvas.SetColor(clShadow2)
+ else
+ Canvas.SetColor(clHilite2);
+
+ Canvas.DrawLine(0, 1, Width, 1);
+end;
+
+procedure TfpgBevel.DrawBottomLine;
+begin
+ Canvas.DrawLine(0, Height - 2, Width, Height - 2);
+
+ if Style = bsRaised then
+ Canvas.SetColor(clShadow2)
+ else
+ Canvas.SetColor(clHilite2);
+
+ Canvas.DrawLine(0, Height - 1, Width, Height - 1);
+end;
+procedure TfpgBevel.DrawLeftLine;
+begin
+ Canvas.DrawLine(0, 1, 0, Height - 1);
+
+ if Style = bsRaised then
+ Canvas.SetColor(clShadow2)
+ else
+ Canvas.SetColor(clHilite2);
+
+ Canvas.DrawLine(1, 1, 1, Height - 1);
+end;
+
+procedure TfpgBevel.DrawRightLine;
+begin
+ Canvas.DrawLine(Width - 2, 0, Width - 2, Height - 1);
+
+ if Style = bsRaised then
+ Canvas.SetColor(clShadow2)
+ else
+ Canvas.SetColor(clHilite2);
+
+ Canvas.DrawLine(Width - 1, 0, Width - 1, Height - 1);
+end;
+
+procedure TfpgBevel.DrawSpacer;
+begin
+ // To make it more visible in the UI Designer
+ if csDesigning in ComponentState then
+ begin
+ Canvas.SetColor(clInactiveWgFrame);
+ Canvas.SetLineStyle(1, lsDash);
+ Canvas.DrawRectangle(0, 0, Width, Height);
+ end;
+end;
+
+procedure TfpgBevel.DrawVerDivider;
+begin
if Shape in [bsBox] then
if FPanelBorder = bsSingle then
Canvas.DrawLine(0, 0, Width - 1, 0)
@@ -367,18 +458,31 @@ begin
Canvas.DrawLine(Width - 1, 0, Width - 1, Height - 1);
if Shape in [bsBox, bsFrame, bsBottomLine] then
Canvas.DrawLine(0, Height - 1, Width, Height - 1);
-
- // To make it more visible in the UI Designer
- if csDesigning in ComponentState then
- begin
- if Shape in [bsSpacer] then
- begin
- Canvas.SetColor(clInactiveWgFrame);
- Canvas.SetLineStyle(1, lsDash);
- Canvas.DrawRectangle(0, 0, Width, Height);
-// Canvas.SetTextColor(clText1);
-// Canvas.DrawString(2, 2, Name + ': ' + Classname);
- end;
+
+end;
+
+procedure TfpgBevel.HandlePaint;
+begin
+ inherited HandlePaint;
+
+ if FPanelBorder = bsSingle then
+ Canvas.SetLineStyle(1, lsSolid)
+ else
+ Canvas.SetLineStyle(2, lsSolid);
+
+ if Style = bsRaised then
+ Canvas.SetColor(clHilite2)
+ else
+ Canvas.SetColor(clShadow2);
+
+ case Shape of
+ bsBox: DrawBox;
+ bsFrame: DrawFrame;
+ bsTopLine: DrawTopLine;
+ bsBottomLine: DrawBottomLine;
+ bsLeftLine: DrawLeftLine;
+ bsRightLine: DrawRightLine;
+ bsSpacer: DrawSpacer;
end;
end;