{"id":1341,"date":"2014-04-22T22:19:39","date_gmt":"2014-04-22T21:19:39","guid":{"rendered":"http:\/\/tulip-ui.azurewebsites.net\/?page_id=1341"},"modified":"2014-04-22T23:16:44","modified_gmt":"2014-04-22T22:16:44","slug":"tulip-ui-paintboxes-pas","status":"publish","type":"page","link":"http:\/\/tulip-ui.azurewebsites.net\/?page_id=1341","title":{"rendered":"Tulip.UI.PaintBoxes.pas"},"content":{"rendered":"<div style=\"background-color: #FFFFFF; width: 680px\">\n<p style=\"text-align: right;\"><a title=\"Source Files\" href=\"http:\/\/tulip-ui.azurewebsites.net\/?page_id=1091\">Source Files<\/a><\/p>\n<p><code><\/p>\n<pre>\r\n{******************************************************************************}\r\n{                                                                              }\r\n{                        Tulip - User Interface Library                        }\r\n{                                                                              }\r\n{             Copyright(c) 2012 Marcos Gomes. All rights Reserved.             }\r\n{                                                                              }\r\n{  --------------------------------------------------------------------------  }\r\n{                                                                              }\r\n{  This product is based on Asphyre Sphinx (c) 2000 - 2012  Yuriy Kotsarenko.  }\r\n{       All rights reserved. Official web site: http:\/\/www.afterwarp.net       }\r\n{                                                                              }\r\n{******************************************************************************}\r\n{                                                                              }\r\n{  Important Notice:                                                           }\r\n{                                                                              }\r\n{  If you modify\/use this code or one of its parts either in original or       }\r\n{  modified form, you must comply with Mozilla Public License Version 2.0,     }\r\n{  including section 3, \"Responsibilities\". Failure to do so will result in    }\r\n{  the license breach, which will be resolved in the court. Remember that      }\r\n{  violating author's rights either accidentally or intentionally is           }\r\n{  considered a serious crime in many countries. Thank you!                    }\r\n{                                                                              }\r\n{  !! Please *read* Mozilla Public License 2.0 document located at:            }\r\n{  http:\/\/www.mozilla.org\/MPL\/                                                 }\r\n{                                                                              }\r\n{  --------------------------------------------------------------------------  }\r\n{                                                                              }\r\n{  The contents of this file are subject to the Mozilla Public License         }\r\n{  Version 2.0 (the \"License\"); you may not use this file except in            }\r\n{  compliance with the License. You may obtain a copy of the License at        }\r\n{  http:\/\/www.mozilla.org\/MPL\/                                                 }\r\n{                                                                              }\r\n{  Software distributed under the License is distributed on an \"AS IS\"         }\r\n{  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the     }\r\n{  License for the specific language governing rights and limitations          }\r\n{  under the License.                                                          }\r\n{                                                                              }\r\n{  The Original Code is Tulip.UI.PaintBoxes.pas.                               }\r\n{                                                                              }\r\n{  The Initial Developer of the Original Code is Marcos Gomes.                 }\r\n{  Portions created by Marcos Gomes are Copyright (C) 2012, Marcos Gomes.      }\r\n{  All Rights Reserved.                                                        }\r\n{                                                                              }\r\n{******************************************************************************}\r\n{                                                                              }\r\n{  Tulip.UI.PaintBoxes.pas                              Modified: 05-Out-2012  }\r\n{  --------------------------------------------------------------------------  }\r\n{                                                                              }\r\n{                  Base Implementations for PaintBox Controls                  }\r\n{                                                                              }\r\n{                                Version 1.02                                  }\r\n{                                                                              }\r\n{******************************************************************************}\r\n\r\nunit Tulip.UI.PaintBoxes;\r\n\r\ninterface\r\n\r\nuses\r\n  System.SysUtils, System.Classes,\r\n  \/\/ Tulip UI Units\r\n  Tulip.UI.Types, Tulip.UI.Controls, Tulip.UI.Forms;\r\n\r\ntype\r\n{$REGION 'TCustomAPaintBox'}\r\n  TCustomAPaintBox = class(TAControl)\r\n  private\r\n    FAntialiased: Boolean;\r\n    FCanMoveHandle: Boolean;\r\n    FOnPaint: TNotifyEvent;\r\n    procedure SetAntialiased(Value: Boolean);\r\n    procedure SetCanMoveHandle(Value: Boolean);\r\n  protected\r\n    procedure AssignTo(Dest: TPersistent); override;\r\n    procedure Paint; override;\r\n  public\r\n    constructor Create(AOwner: TComponent); override;\r\n    destructor Destroy; override;\r\n\r\n    procedure MouseDown(Button: TMouseButton; Shift: TShiftState;\r\n      X, Y: Integer); override;\r\n    procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;\r\n    procedure MouseUp(Button: TMouseButton; Shift: TShiftState;\r\n      X, Y: Integer); override;\r\n\r\n    property Antialiased: Boolean read FAntialiased write SetAntialiased;\r\n    property CanMoveHandle: Boolean read FCanMoveHandle write SetCanMoveHandle;\r\n    property OnPaint: TNotifyEvent read FOnPaint write FOnPaint;\r\n  end;\r\n{$ENDREGION}\r\n\r\nimplementation\r\n\r\nvar\r\n  XOffSet, YOffSet: Integer;\r\n\r\n{$REGION 'TCustomAPaintBox'}\r\n  { TCustomAPaintBox }\r\n\r\nprocedure TCustomAPaintBox.AssignTo(Dest: TPersistent);\r\nbegin\r\n  ControlState := ControlState + [csReadingState];\r\n\r\n  inherited AssignTo(Dest);\r\n\r\n  if Dest is TCustomAPaintBox then\r\n    with TCustomAPaintBox(Dest) do\r\n    begin\r\n      Antialiased := Self.Antialiased;\r\n      CanMoveHandle := Self.CanMoveHandle;\r\n    end;\r\n\r\n  ControlState := ControlState - [csReadingState];\r\nend;\r\n\r\nconstructor TCustomAPaintBox.Create(AOwner: TComponent);\r\nvar\r\n  Num: Integer;\r\nbegin\r\n  ControlState := ControlState + [csCreating];\r\n\r\n  inherited Create(AOwner);\r\n\r\n  if (AOwner <> nil) and (AOwner <> Self) and (AOwner is TWControl) then\r\n  begin\r\n    \/\/ Auto generate name\r\n    Num := 1;\r\n    begin\r\n      while (TWControl(AOwner).Handle.FindChildControl('PaintBox' +\r\n        IntToStr(Num), True) <> nil) do\r\n        Inc(Num);\r\n      Name := 'PaintBox' + IntToStr(Num);\r\n    end;\r\n  end;\r\n\r\n  \/\/ Fields\r\n  FAntialiased := True;\r\n  FCanMoveHandle := False;\r\n\r\n  \/\/ Properties\r\n  Left := 0;\r\n  Top := 0;\r\n  Width := 120;\r\n  Height := 80;\r\n  Visible := True;\r\n\r\n  ControlState := ControlState - [csCreating];\r\nend;\r\n\r\ndestructor TCustomAPaintBox.Destroy;\r\nbegin\r\n\r\n  inherited;\r\nend;\r\n\r\nprocedure TCustomAPaintBox.MouseDown(Button: TMouseButton; Shift: TShiftState;\r\n  X, Y: Integer);\r\nbegin\r\n  \/\/ Start move the form Handle\r\n  if (FCanMoveHandle) and (Handle is TCustomAForm) then\r\n  begin\r\n    if (Button = mbLeft) and (TCustomAForm(Handle).CanMove) then\r\n    begin\r\n      XOffSet := X - TCustomAForm(Handle).Left;\r\n      YOffSet := Y - TCustomAForm(Handle).Top;\r\n      TCustomAForm(Handle).IsMoving := True;\r\n    end;\r\n  end;\r\n\r\n  inherited MouseDown(Button, Shift, X, Y);\r\nend;\r\n\r\nprocedure TCustomAPaintBox.MouseMove(Shift: TShiftState; X, Y: Integer);\r\nbegin\r\n  \/\/ Move the form Handle\r\n  if (FCanMoveHandle) and (Handle is TCustomAForm) then\r\n  begin\r\n    if TCustomAForm(Handle).IsMoving = True then\r\n    begin\r\n      TCustomAForm(Handle).Left := X - XOffSet;\r\n      TCustomAForm(Handle).Top := Y - YOffSet;\r\n    end;\r\n  end;\r\n\r\n  inherited MouseMove(Shift, X, Y);\r\nend;\r\n\r\nprocedure TCustomAPaintBox.MouseUp(Button: TMouseButton; Shift: TShiftState;\r\n  X, Y: Integer);\r\nbegin\r\n  \/\/ Stop move the form Handle\r\n  if (FCanMoveHandle) and (Handle is TCustomAForm) then\r\n  begin\r\n    if (Button = mbLeft) and (TCustomAForm(Handle).IsMoving) then\r\n      TCustomAForm(Handle).IsMoving := False;\r\n  end;\r\n\r\n  inherited MouseUp(Button, Shift, X, Y);\r\nend;\r\n\r\nprocedure TCustomAPaintBox.Paint;\r\nbegin\r\n  if Assigned(FOnPaint) then\r\n  begin\r\n    ControlManager.Canvas.Antialias := FAntialiased;\r\n    FOnPaint(Self);\r\n  end;\r\nend;\r\n\r\nprocedure TCustomAPaintBox.SetAntialiased(Value: Boolean);\r\nbegin\r\n  FAntialiased := Value;\r\nend;\r\n\r\nprocedure TCustomAPaintBox.SetCanMoveHandle(Value: Boolean);\r\nbegin\r\n  FCanMoveHandle := Value;\r\nend;\r\n{$ENDREGION}\r\n\r\nend.\r\n<\/pre>\n<p><\/code>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Source Files {******************************************************************************} { } { Tulip &#8211; User Interface Library } { } { Copyright(c) 2012 Marcos Gomes. All rights Reserved. } { } { &#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211; } { } <a class=\"more-link\" href=\"http:\/\/tulip-ui.azurewebsites.net\/?page_id=1341\">Continue Reading &rarr;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1091,"menu_order":0,"comment_status":"closed","ping_status":"open","template":"","meta":[],"_links":{"self":[{"href":"http:\/\/tulip-ui.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/pages\/1341"}],"collection":[{"href":"http:\/\/tulip-ui.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"http:\/\/tulip-ui.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"http:\/\/tulip-ui.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/tulip-ui.azurewebsites.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1341"}],"version-history":[{"count":2,"href":"http:\/\/tulip-ui.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/pages\/1341\/revisions"}],"predecessor-version":[{"id":1771,"href":"http:\/\/tulip-ui.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/pages\/1341\/revisions\/1771"}],"up":[{"embeddable":true,"href":"http:\/\/tulip-ui.azurewebsites.net\/index.php?rest_route=\/wp\/v2\/pages\/1091"}],"wp:attachment":[{"href":"http:\/\/tulip-ui.azurewebsites.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1341"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}