diff options
author | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-07-23 09:40:43 +0000 |
---|---|---|
committer | graemeg <graemeg@ae50a9b5-8222-0410-bf8d-8a13f76226bf> | 2007-07-23 09:40:43 +0000 |
commit | 652ba160012b1eda3a1f6dafb9311b0dcade476c (patch) | |
tree | 8abf8d7cc6246484c646b8160b8ab0179ac5b069 /examples/corelib/canvastest | |
parent | 6bda2054c8dda9b98f9958c54fce9f27927642c5 (diff) | |
download | fpGUI-652ba160012b1eda3a1f6dafb9311b0dcade476c.tar.xz |
Restructure Part 3.
* Moved all the examples over from the prototype directory.
* Removed obsolete GFX examples.
Diffstat (limited to 'examples/corelib/canvastest')
-rw-r--r-- | examples/corelib/canvastest/button.bmp | bin | 0 -> 4438 bytes | |||
-rw-r--r-- | examples/corelib/canvastest/fpgcanvas.lpi | 54 | ||||
-rw-r--r-- | examples/corelib/canvastest/fpgcanvas.lpr | 205 | ||||
-rwxr-xr-x | examples/corelib/canvastest/gears2.bmp | bin | 0 -> 822 bytes | |||
-rw-r--r-- | examples/corelib/canvastest/linux_screenshot.png | bin | 0 -> 29173 bytes |
5 files changed, 259 insertions, 0 deletions
diff --git a/examples/corelib/canvastest/button.bmp b/examples/corelib/canvastest/button.bmp Binary files differnew file mode 100644 index 00000000..8ae427cf --- /dev/null +++ b/examples/corelib/canvastest/button.bmp diff --git a/examples/corelib/canvastest/fpgcanvas.lpi b/examples/corelib/canvastest/fpgcanvas.lpi new file mode 100644 index 00000000..9c070422 --- /dev/null +++ b/examples/corelib/canvastest/fpgcanvas.lpi @@ -0,0 +1,54 @@ +<?xml version="1.0"?> +<CONFIG> + <ProjectOptions> + <PathDelim Value="/"/> + <Version Value="5"/> + <General> + <Flags> + <SaveOnlyProjectUnits Value="True"/> + </Flags> + <SessionStorage Value="InProjectDir"/> + <MainUnit Value="0"/> + <IconPath Value="./"/> + <TargetFileExt Value=""/> + <Title Value="fpcanvas"/> + </General> + <VersionInfo> + <ProjectVersion Value=""/> + </VersionInfo> + <PublishOptions> + <Version Value="2"/> + <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="1"> + <Unit0> + <Filename Value="fpgcanvas.lpr"/> + <IsPartOfProject Value="True"/> + <UnitName Value="fpgcanvas"/> + </Unit0> + </Units> + </ProjectOptions> + <CompilerOptions> + <Version Value="5"/> + <CodeGeneration> + <Generate Value="Faster"/> + </CodeGeneration> + <Other> + <CustomOptions Value="-FUunits +"/> + <CompilerPath Value="$(CompPath)"/> + </Other> + </CompilerOptions> +</CONFIG> diff --git a/examples/corelib/canvastest/fpgcanvas.lpr b/examples/corelib/canvastest/fpgcanvas.lpr new file mode 100644 index 00000000..4e3b0944 --- /dev/null +++ b/examples/corelib/canvastest/fpgcanvas.lpr @@ -0,0 +1,205 @@ +program fpgcanvas; + +{$mode objfpc}{$H+} + +uses + {$IFDEF UNIX}{$IFDEF UseCThreads} + cthreads, + {$ENDIF}{$ENDIF} + Classes, SysUtils, + fpgfx, + gfxbase, + gui_form, + gfx_imgfmt_bmp; + + +type + + { TMainForm } + + TMainForm = class(TfpgForm) + private + bmp: TfpgImage; + dst: TfpgImage; + protected + procedure HandlePaint; override; + public + procedure AfterCreate; override; + procedure BeforeDestruction; override; + end; + +{ TMainForm } + +procedure TMainForm.HandlePaint; +var + r: TfpgRect; + fnt: TfpgFont; + y: integer; + c: TfpgColor; +begin + // Enable double buffering. Must be before 'inherited' to prevent form + // clearing itself. + Canvas.BeginDraw; + inherited HandlePaint; + + // Testing Rectangles + Canvas.SetColor(clBlack); + r.Top := 5; + r.Left := 60; + r.Width := 50; + r.Height := 50; + Canvas.DrawRectangle(r); + + r.Left := 120; + Canvas.SetLineStyle(2, lsDash); + Canvas.DrawRectangle(r); + + r.Left := 180; + Canvas.SetColor(clGreen); + Canvas.SetLineStyle(1, lsDot); + Canvas.DrawRectangle(r); + + r.Left := 240; + Canvas.SetColor(clBlue); + Canvas.SetLineStyle(1, lsSolid); + Canvas.FillRectangle(r); + + + // Testing line drawing + Canvas.DrawLine(5, 5, 50, 50); + Canvas.SetColor(clBlue); + Canvas.DrawLine(50, 5, 5, 50); + Canvas.SetColor(clRed); + { Diagonal line } + Canvas.DrawLine(60, 5, 110, 55); + { Horizontal line } + Canvas.DrawLine(60, 3, 110, 3); + { Vertical line } + Canvas.DrawLine(58, 5, 58, 55); + + + // Testing Text and Fonts + y := 60; + Canvas.SetTextColor(clBlack); + Canvas.DrawString(5, y, 'This text must be black and default font (' + fpgApplication.DefaultFont.FontDesc + ')'); + Canvas.SetTextColor(clRed); + y := y + Canvas.Font.Height; // fonts are different sizes on differet OS's + Canvas.DrawString(5, y, 'This text must be red.'); + Canvas.SetTextColor(clBlack); + y := y + Canvas.Font.Height; + Canvas.DrawString(5, y, 'Russian (UTF-8) text -> Òåñò'); + y := y + Canvas.Font.Height; + fnt := fpgApplication.GetFont('Times-14:bold'); + Canvas.Font := fnt; + Canvas.DrawString(5, y, 'Font used is ' + Canvas.Font.FontDesc); + y := y + Canvas.Font.Height; + + + // Testing basic style drawings + Canvas.Font := fpgApplication.DefaultFont; + Canvas.DrawString(320, 3, 'DrawButtonFace():'); + Canvas.DrawButtonFace(300, 20, 75, 25, []); + Canvas.DrawString(385, 20, '= []'); + Canvas.DrawButtonFace(300, 50, 75, 25, [btnIsDefault]); + Canvas.DrawString(385, 50, '= [btnIsDefault]'); + Canvas.DrawButtonFace(300, 80, 75, 25, [btnIsPressed]); + Canvas.DrawString(385, 80, '= [btnIsPressed]'); + Canvas.DrawButtonFace(300, 110, 75, 25, [btnIsEmbedded, btnIsPressed]); + Canvas.DrawString(385, 110, '= [embed & press]'); + Canvas.DrawButtonFace(300, 140, 75, 25, [btnIsEmbedded]); + Canvas.DrawString(385, 140, '= [btnIsEmbedded]'); + + Canvas.DrawString(45, y, 'DrawControlFrame():'); + y := y + Canvas.Font.Height; + Canvas.DrawControlFrame(5, y, 200, 23); + + + // Testing Bitmap painting + Canvas.DrawString(5, 180, 'Single BMP file:'); + Canvas.DrawString(300, 210, '(mask enabled for all images)'); + Canvas.DrawImage(150, 180, bmp); + Canvas.DrawString(5, 210, 'Parts of BMP file:'); + Canvas.DrawImagePart(150, 210, bmp, 0, 0, 32, 21); + Canvas.DrawImagePart(190, 210, bmp, 32, 0, 32, 21); + Canvas.DrawImagePart(230, 210, bmp, 64, 0, 32, 21); + +// Canvas.StretchDraw(150, 240, 160, 21, bmp); + Canvas.StretchDraw(150, 240, 300, 50, bmp); + + Canvas.DrawImage(150, 300, dst); + Canvas.StretchDraw(180, 300, 70, 70, dst); + Canvas.StretchDraw(265, 300, 230, 25, bmp); + + + // testing accuracy of line/rectangle drawing + Canvas.SetColor(clBlack); + Canvas.SetLineStyle(1, lsSolid); + r.Top := 302; + r.Left := 182; + r.Width := 66; + r.Height := 66; + Canvas.DrawRectangle(r); + + Canvas.SetColor(clBlue); + Canvas.DrawLine(183, 303, 247, 303); + + +// Stretch(bmp, dst, ResampleFilters[6].Filter, ResampleFilters[6].Width); +//// Canvas.DrawImage(150, 240, bmp); +// Canvas.DrawImage(160, 250, dst); + + + + // Testing Canvas.Pixels[] + // two pixels should have changed color in the top left of the form + Canvas.Pixels[7,5] := clBlue; // This tests consistant bit order handling (RGB) + Canvas.Pixels[8,5] := clRed; + c := Canvas.Pixels[192, 227]; // should be orange like color + Canvas.Pixels[9,5] := c; + c := Canvas.Pixels[150 + (32*4) + 3, 199]; // should be lightblue like color + Canvas.Pixels[10,5] := c; + + Canvas.EndDraw; +end; + +procedure TMainForm.AfterCreate; +begin + inherited AfterCreate; + SetPosition(100, 100, 500, 400); + WindowTitle := 'fpGFX Canvas Test'; + + bmp := LoadImage_BMP('button.bmp'); + if not Assigned(bmp) then + raise Exception.Create('Failed to load button.bmp'); + bmp.CreateMaskFromSample(0,0); + bmp.UpdateImage; + +// dst := TfpgImage.Create; +// dst.AllocateImage(bmp.ColorDepth, 200, 50); + dst := LoadImage_BMP('gears2.bmp'); + dst.CreateMaskFromSample(0,0); + dst.UpdateImage; +end; + +procedure TMainForm.BeforeDestruction; +begin + dst.Free; + bmp.Free; + inherited BeforeDestruction; +end; + +procedure MainProc; +var + frm: TMainForm; +begin + fpgApplication.Initialize; + frm := TMainForm.Create(nil); + frm.Show; + fpgApplication.Run; +end; + + +begin + MainProc; +end. + diff --git a/examples/corelib/canvastest/gears2.bmp b/examples/corelib/canvastest/gears2.bmp Binary files differnew file mode 100755 index 00000000..52ac3254 --- /dev/null +++ b/examples/corelib/canvastest/gears2.bmp diff --git a/examples/corelib/canvastest/linux_screenshot.png b/examples/corelib/canvastest/linux_screenshot.png Binary files differnew file mode 100644 index 00000000..e7268d23 --- /dev/null +++ b/examples/corelib/canvastest/linux_screenshot.png |