home *** CD-ROM | disk | FTP | other *** search
/ Mastering Visual Basic 5 / MasteringVisualBasic5.iso / olympus / ik32_15t / delphi2.shr / UASSIGN.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-08-01  |  11.8 KB  |  312 lines

  1. {  Project Assign.DPR Delphi 2.0 Demos
  2.  
  3.    Description:- Assign.Dpr Project:-
  4.  
  5.    Demonstrates the use of:
  6.  
  7.    1) 'AssignMode'
  8.    2) 'ResizeMode'
  9.    3) 'Assign' Method
  10.  
  11.    Date of Origin: 15/04/96
  12.    Original Author: Andrew Hutchison
  13.    Modification History:
  14.  
  15.    Date        Person                            Change
  16.    ----------------------------------------------------
  17.    15/04/96    A Hutchison                       Created
  18.  
  19.    (c) Copyright Media Architects Inc. 1996.
  20.    All rights reserved.   No part of this program may be
  21.    photocopied, reproduced, translated to another programming
  22.    language or transported to any computer system without the
  23.    prior written consent of Media Architects Inc.}
  24.    
  25. unit UAssign;
  26.  
  27. interface
  28.  
  29. uses
  30.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  31.   Menus, ExtCtrls, Buttons, OleCtrls, ImageKnife32, StdCtrls;
  32.  
  33. type
  34.   TMasterform = class(TForm)
  35.     MainMenu: TMainMenu;
  36.     File_Menu: TMenuItem;
  37.     File_Menu_LoadAssignImage: TMenuItem;
  38.     File_Menu_LoadResizeImage: TMenuItem;
  39.     N1: TMenuItem;
  40.     File_Menu_ClearallImages: TMenuItem;
  41.     N2: TMenuItem;
  42.     File_Menu_Exit: TMenuItem;
  43.     Bevel1: TBevel;
  44.     Label1: TLabel;
  45.     Label2: TLabel;
  46.     AssignMode: TComboBox;
  47.     ResizeMode: TComboBox;
  48.     PicbufSrc: TPicbuf;
  49.     PicbufDest: TPicbuf;
  50.     SrcToDestAssign: TSpeedButton;
  51.     DestToSrcAssign: TSpeedButton;
  52.     Bevel2: TBevel;
  53.     Bevel3: TBevel;
  54.     GroupBox1: TGroupBox;
  55.     GroupBox2: TGroupBox;
  56.     SrcFull: TRadioButton;
  57.     SrcSel: TRadioButton;
  58.     DestFull: TRadioButton;
  59.     DestSel: TRadioButton;
  60.     Reset: TSpeedButton;
  61.     FileOpenDialog: TOpenDialog;
  62.     DitherSrctoDest: TSpeedButton;
  63.     DitherDesttoSrc: TSpeedButton;
  64.     procedure File_Menu_LoadAssignImageClick(Sender: TObject);
  65.     procedure File_Menu_LoadResizeImageClick(Sender: TObject);
  66.     procedure ResetClick(Sender: TObject);
  67.     procedure File_Menu_ClearallImagesClick(Sender: TObject);
  68.     procedure File_Menu_ExitClick(Sender: TObject);
  69.     procedure SrcToDestAssignClick(Sender: TObject);
  70.     procedure DestToSrcAssignClick(Sender: TObject);
  71.     procedure FormCreate(Sender: TObject);
  72.     procedure AssignModeClick(Sender: TObject);
  73.     procedure ResizeModeClick(Sender: TObject);
  74.     procedure DitherSrctoDestClick(Sender: TObject);
  75.     procedure DitherDesttoSrcClick(Sender: TObject);
  76.   private
  77.     { Private declarations }
  78.   public
  79.   { Public declarations }
  80.   end;
  81.  
  82. var
  83. Masterform: TMasterform;
  84.  
  85. {Additional function added for Demo Only - See Below for function}
  86. function GetImageLocation:String;
  87.  
  88. implementation
  89.  
  90. {$R *.DFM}
  91.  
  92. {-------------------------------------------------------------------------------)
  93. {File Menu Item  - Click Event}
  94. {'Source Picbuf' - Load a File using a Common Dialogue Component}
  95. procedure TMasterform.File_Menu_LoadAssignImageClick(Sender: TObject);
  96. begin
  97. {Display Dialogue - Has the User Selected OK and a Valid File extension}
  98. if FileOpenDialog.Execute then
  99.   begin
  100.   {Reference Common Dialogue - We can then refer just to its properties}
  101.    with FileOpenDialog do
  102.    PicbufSrc.Filename:= Filename;         {Set the Name to the Dialogue Filename}
  103.    PicbufSrc.Load;                                               {Load The Image}
  104.   end;
  105. end;
  106.  
  107. {-------------------------------------------------------------------------------)
  108. {File Menu Item - Click Event}
  109. {'Destination Picbuf' - Load a File using a Common Dialogue Component}
  110. procedure TMasterform.File_Menu_LoadResizeImageClick(Sender: TObject);
  111. begin
  112. {Has the User Selected OK and a Valid File extension}
  113. if FileOpenDialog.Execute then
  114.  begin
  115.  {Reference Common Dialogue - We can then refer just to its properties}
  116.   with FileOpenDialog do
  117.   PicbufDest.Filename:= Filename;
  118.   PicbufDest.Load;                                               {Load The Image}
  119.  end;
  120. end;
  121.  
  122. {-------------------------------------------------------------------------------)
  123. {Reset Button - Click Event}
  124. {Reload the Source and Destination Images}
  125. procedure TMasterform.ResetClick(Sender: TObject);
  126. begin
  127. PicbufSrc.Clear;                                                  {Standard Call}
  128. PicbufDest.Clear;                                                 {Standard Call}
  129. PicbufSrc.Load;                            {Force a Load using last set filename}
  130. PicbufDest.Load;                           {Force a Load using last set filename}
  131. end;
  132.  
  133. {-------------------------------------------------------------------------------)
  134. {File Menu Item - Click Event}
  135. {Clear the Images}
  136. procedure TMasterform.File_Menu_ClearallImagesClick(Sender: TObject);
  137. begin
  138. PicbufSrc.Clear;                                                  {Standard Call}
  139. PicbufDest.Clear;                                                 {Standard Call}
  140. end;
  141.  
  142. {-------------------------------------------------------------------------------)
  143. {File Menu Item - Click Event}
  144. {Exit the Program}
  145. procedure TMasterform.File_Menu_ExitClick(Sender: TObject);
  146. begin
  147. Halt;                                    {Terminates all objects unconditionally}
  148. end;
  149.  
  150. {-------------------------------------------------------------------------------)
  151. {Transfer Button:-
  152. Transfer the 'Source' buffer to the 'Destination' buffer.
  153. Use the 'Assign' Method, and use the 'Option' buttons as the True/False Flags
  154. for the two selection 'Parameters' of the 'Assign' Method. For 8 Bit Images
  155. dither the Images to the Same Palette}
  156. procedure TMasterform.SrcToDestAssignClick(Sender: TObject);
  157. begin
  158. PicbufDest.Assign(DestSel.Checked, PicbufSrc.OLEOBJECT, SrcSel.Checked);
  159. end;
  160.  
  161. {-------------------------------------------------------------------------------)
  162. {Transfer Button:-
  163. Transfer 'Destination' buffer to the 'Source' Buffer.
  164. Use the 'Assign' Method, and use the 'Option' buttons as the True/False Flags
  165. for the two selection 'Parameters' of the 'Assign' Method. For 8 Bit Images
  166. dither the Images to the Same Palette}
  167. procedure TMasterform.DestToSrcAssignClick(Sender: TObject);
  168. begin
  169. PicbufSrc.Assign(SrcSel.Checked, PicbufDest.OLEOBJECT,DestSel.Checked);
  170. end;
  171.  
  172. {-------------------------------------------------------------------------------)
  173. {Form Creation - Set Defaults:-
  174. Set up all defaults required using the 'Masterform' 'FormCreate' Event.
  175.  
  176. Note:-  All string Items ie Captions are added at design time using Delphi to any
  177. controls requiring them. The 'Combo Boxes' giving the user the ability to set the
  178. required 'Resize' and 'Assign' modes are filled in using the controls built in text
  179. string editor. All we do at load time is to tell the control which item to set
  180. as a starting value - default value.}
  181. procedure TMasterform.FormCreate(Sender: TObject);
  182. begin
  183. {Set Project Properties - not part of MAI demo}
  184. Application.HintPause := 10;                                         {Hint Pause}
  185. Application.HintColor := clAqua;                                    {Hint Colour}
  186.  
  187. {Set Combo Boxes to Item Index 0}
  188. AssignMode.ItemIndex:=0;                                      {Total Replacement}
  189. ResizeMode.ItemIndex:=0;                                         {Pixel Deletion}
  190.  
  191. {Demo Default Images are loaded if they exist)
  192. {Set Image Defaults - Uses GetImageLocation function - this function is provided
  193. so the demo program finds default test Images}
  194. PicbufSrc.Filename:=GetImageLocation + 'images\leaves8.pcx';
  195. PicbufDest.Filename:=GetImageLocation + 'images\marybeth.tif';
  196.  
  197. {Load Default Source Image if they exist}
  198. if FileExists(GetImageLocation + 'images\leaves8.pcx') then
  199. PicbufSrc.Load
  200.  else
  201.  MessageDlg('Cannot find Sample file [\Images\Leaves8.PCX].' +
  202.  ' Users should manually load this Image into the Source Picture.', mtInformation,
  203.  [mbOk], 0);
  204.  
  205. {Load Default Destination Image if they exist}
  206. if FileExists(GetImageLocation + 'images\marybeth.tif') then
  207. PicbufDest.Load
  208.  else
  209.  MessageDlg('Cannot find Sample file [\Images\Marybeth.TIF].' +
  210.  ' Users should manually load this Image into the Source Picture.', mtInformation,
  211.  [mbOk], 0);
  212.  
  213. {Set default selection areas for both source and destination picbuf's}
  214. PicbufSrc.SelectWidth:=100;
  215. PicbufSrc.SelectHeight:=100;
  216. PicbufDest.SelectWidth:=100;
  217. PicbufDest.SelectHeight:=100;
  218. end;
  219.  
  220. {-------------------------------------------------------------------------------)
  221. {Set 'AssignMode' of both picture buffers using 'ComboBox' click events:-
  222.  
  223. DELPHI USERS NOTE:-  Without Pre-Defining 'AssignModes' as 'Constants' we must refer
  224. to each mode/property as an 'Integer'.  If the user wishes he can Ccreate constants
  225. for each function so AssignMode 'AMTotal' is the same as 'AssignMode' Value of 0.  So
  226. if you wish to set a property by using 'Constants' you must predefine a constant eg:-
  227.  
  228. Const
  229. AMMode = 0; You can then use 'AMMode' instead of '0'
  230.  
  231. From then on you can use 'AMMode' to set a property.  Use Object Inspector to see the
  232. Integer values assigned to each property.  Users note that this method does allow you
  233. to use 'String' expressions to set properties, however, if you stick to using integer
  234. values it means you can greatly simplify the setting of properties. See the following
  235. routine.  Since the AssignMode is expecting a value of 0 to 3, this matches the index
  236. values returned by a combobox so you can use the 'itemindex' to directly set the
  237. value - It simplifies the sub down to a couple of lines. Note:- When you are adding
  238. the Items [Strings] to the ComboBox make sure you put them in the correct order so
  239. the correct index value is  returned for the correct function - use this order:-
  240.  
  241. 0 - Total Replacement      [Item Index 0]
  242. 1 - Union Composite        [Item Index 1]
  243. 2 - Intersection Composite [Item Index 2]
  244. 3 - Resize Composite       [Item Index 3] }
  245.  
  246. procedure TMasterform.AssignModeClick(Sender: TObject);
  247. begin
  248. {Refer to Sending Combobox - ie 'AssignMode'}
  249. with AssignMode do
  250.   begin
  251.   {Use 'ItemIndex' that is part of the 'AssignMode' Combo Box}
  252.   PicbufSrc.AssignMode:=ItemIndex;                    {Set Mode of Source Picbuf}
  253.   PicbufDest.AssignMode:=ItemIndex;              {Set Mode of Destination Picbuf}
  254.   end;
  255. end;
  256.  
  257. {-------------------------------------------------------------------------------)
  258. {Set 'ResizeMode' of both Picture buffers:-
  259.  
  260. Index Values and Item String List for ComboBox:-
  261.  
  262. 0 - Pixel Deletion/Replication, Fixed Aspect
  263. 1 - Pixel Deletion/Replication, Variable Aspect
  264. 2 - Resampling, Fixed Aspect
  265. 3 - Resampling, Variable Aspect
  266.  
  267. Please refer to notes above.}
  268. procedure TMasterform.ResizeModeClick(Sender: TObject);
  269. begin
  270. {Refer to Sending Combobox - 'ResizeMode'}
  271. with ResizeMode do
  272.  begin
  273.  PicbufSrc.ResizeMode:=ItemIndex;                               {Set Source Mode}
  274.  PicbufDest.ResizeMode:=ItemIndex;                         {Set Destination Mode}
  275.  end;
  276. end;
  277.  
  278. {-------------------------------------------------------------------------------}
  279. {Map Source Image to Destination}
  280. procedure TMasterform.DitherSrctoDestClick(Sender: TObject);
  281. begin
  282. Picbufsrc.DitherPal(Picbufdest.OLEOBJECT);
  283. end;
  284.  
  285. {-------------------------------------------------------------------------------}
  286. {Map Destination to Source}
  287. procedure TMasterform.DitherDesttoSrcClick(Sender: TObject);
  288. begin
  289. PicbufDest.DitherPal(PicbufSrc.OLEOBJECT);
  290. end;
  291.  
  292.  
  293. {-------------------------------------------------------------------------------}
  294. {Get path of default files:-
  295. Basically the function gets the path name of the EXE location, strips of the last
  296. directory, ready for use - only applicable to this Demo}
  297. function GetImageLocation:String;
  298. Var
  299. Temp:String;
  300. DelphiLocation:Integer;
  301. begin
  302. Temp := ExtractFileDir(Application.exename);               {Get full path of EXE}
  303. Temp := UpperCase(Temp);                             {Make Sure it is upper Case}
  304. DelphiLocation := Pos('\DELPHI2',Temp);
  305. Delete(Temp,DelphiLocation,length('\DELPHI2'));         {Strip of last Directory}
  306. Result:=Temp + '\';                                         {Add the Missing '\'}
  307. end;
  308.  
  309.  
  310.  
  311. end.
  312.