summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGraeme Geldenhuys <graeme@mastermaths.co.za>2012-11-13 09:29:39 +0000
committerGraeme Geldenhuys <graeme@mastermaths.co.za>2012-11-13 15:11:09 +0000
commiteb69e35c4c633128d1f65709cae7c284ad44f1b7 (patch)
treecf6c55c0151f487bd6a0a620ab1aabc4282cd143
parentc1172f1ca324d0df54050a9b023acf35750467ee (diff)
downloadfpGUI-eb69e35c4c633128d1f65709cae7c284ad44f1b7.tar.xz
Implements a very basic ImagePanel component.
This makes it very easy to display an image on a form.
-rw-r--r--src/gui/fpg_panel.pas72
1 files changed, 72 insertions, 0 deletions
diff --git a/src/gui/fpg_panel.pas b/src/gui/fpg_panel.pas
index 2bc5f93b..0a0c6e57 100644
--- a/src/gui/fpg_panel.pas
+++ b/src/gui/fpg_panel.pas
@@ -294,6 +294,25 @@ type
TfpgFrameClass = class of TfpgFrame;
+ TfpgImagePanel = class(TfpgWidget)
+ private
+ FImage: TfpgImage;
+ FOwnsImage: Boolean;
+ FScaleImage: Boolean;
+ procedure SetImage(const AValue: TfpgImage);
+ procedure SetScaleImage(const AValue: Boolean);
+ protected
+ procedure HandlePaint; override;
+ public
+ constructor Create(AOwner: TComponent); override;
+ destructor Destroy; override;
+ property Image: TfpgImage read FImage write SetImage;
+ property OwnsImage: Boolean read FOwnsImage write FOwnsImage;
+ property ScaleImage: Boolean read FScaleImage write SetScaleImage;
+ end;
+
+
+
function CreateBevel(AOwner: TComponent; ALeft, ATop, AWidth, AHeight: TfpgCoord; AShape: TPanelShape;
AStyle: TPanelStyle): TfpgBevel;
@@ -1048,5 +1067,58 @@ begin
inherited Destroy;
end;
+{ TfpgImagePanel }
+
+procedure TfpgImagePanel.SetImage(const AValue: TfpgImage);
+begin
+ if FOwnsImage and Assigned(FImage) then
+ FImage.Free;
+ FImage := AValue;
+ Repaint;
+end;
+
+procedure TfpgImagePanel.SetScaleImage(const AValue: Boolean);
+begin
+ if FScaleImage = AValue then
+ Exit;
+ FScaleImage := AValue;
+ if Assigned(FImage) then
+ Repaint;
+end;
+
+procedure TfpgImagePanel.HandlePaint;
+var
+ x: integer;
+ y: integer;
+begin
+ inherited HandlePaint;
+ Canvas.Clear(BackgroundColor);
+ if Assigned(FImage) then
+ begin
+ x := (Width - FImage.Width) div 2;
+ y := (Height - FImage.Height) div 2;
+ if ScaleImage then
+ Canvas.StretchDraw(0, 0, Width, Height, FImage)
+ else
+ Canvas.DrawImage(x, y, FImage);
+ end;
+end;
+
+constructor TfpgImagePanel.Create(AOwner: TComponent);
+begin
+ inherited Create(AOwner);
+ FImage := nil;
+ FOwnsImage := False;
+end;
+
+destructor TfpgImagePanel.Destroy;
+begin
+ if FOwnsImage then
+ FImage.Free;
+ inherited Destroy;
+end;
+
+
+
end.