paintu.cpp
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:4k
源码类别:

Delphi控件源码

开发平台:

Delphi

  1. //---------------------------------------------------------------------------
  2. #include <vcl.h>
  3. #pragma hdrstop
  4. #include "paintu.h"
  5. #include "infounit.h"
  6. //---------------------------------------------------------------------------
  7. #pragma package(smart_init)
  8. #pragma link "fcButton"
  9. #pragma link "fcButtonGroup"
  10. #pragma link "fcClearPanel"
  11. #pragma link "fcColorCombo"
  12. #pragma link "fcCombo"
  13. #pragma link "fcImgBtn"
  14. #pragma link "fcLabel"
  15. #pragma link "fcOutlookBar"
  16. #pragma link "fcOutlookList"
  17. #pragma link "fcShapeBtn"
  18. #pragma resource "*.dfm"
  19. TPaintForm *PaintForm;
  20. //---------------------------------------------------------------------------
  21. __fastcall TPaintForm::TPaintForm(TComponent* Owner)
  22.         : TForm(Owner)
  23. {
  24. }
  25. //---------------------------------------------------------------------------
  26. void __fastcall TPaintForm::FormCreate(TObject *Sender)
  27. {
  28.  InfoForm = new TInfoForm(this);
  29. }
  30. //---------------------------------------------------------------------------
  31. void __fastcall TPaintForm::FormActivate(TObject *Sender)
  32. {
  33.   if (!InfoShown) {
  34.     InfoForm->Show();
  35.     InfoShown = True;
  36.   }
  37. }
  38. //---------------------------------------------------------------------------
  39. void __fastcall TPaintForm::FormShow(TObject *Sender)
  40. {
  41.   PaintBox->Canvas->Brush->Color = clWhite;
  42.   PaintBox->Canvas->FillRect(PaintBox->ClientRect);
  43. }
  44. //---------------------------------------------------------------------------
  45. void __fastcall TPaintForm::DrawShape(TPoint *TopLeft,TPoint *BottomRight, TPenMode AMode)
  46. {
  47.  PaintBox->Canvas->Brush->Color = BrushColorCombo->SelectedColor;
  48.  PaintBox->Canvas->Pen->Color = PenColorCombo->SelectedColor;
  49.  PaintBox->Canvas->Pen->Mode = AMode;
  50.  if (BrushesOutlookList->Selected != NULL)
  51.     PaintBox->Canvas->Brush->Style = (TBrushStyle)(BrushesOutlookList->Selected->Index);
  52.  if (PensOutlookList->Selected != NULL)
  53.     PaintBox->Canvas->Pen->Style = (TPenStyle)(PensOutlookList->Selected->Index);
  54.  if (ToolsOutlookList->Selected != NULL)
  55.     switch ((TDrawingTool)(ToolsOutlookList->Selected->Index)) {
  56.     case dtLine: PaintBox->Canvas->MoveTo(TopLeft->x, TopLeft->y);
  57.                  PaintBox->Canvas->LineTo(BottomRight->x, BottomRight->y);
  58.                  break;
  59.     case dtRectangle: PaintBox->Canvas->Rectangle(TopLeft->x, TopLeft->y, BottomRight->x,
  60.          BottomRight->y);
  61.          break;
  62.     case dtEllipse: PaintBox->Canvas->Ellipse(TopLeft->x, TopLeft->y, BottomRight->x,
  63.          BottomRight->y);
  64.          break;
  65.     case dtRoundRect: PaintBox->Canvas->RoundRect(TopLeft->x, TopLeft->y, BottomRight->x,
  66.          BottomRight->y, (TopLeft->x - BottomRight->x) / 2,
  67.         (TopLeft->y - BottomRight->y) / 2);
  68.     }
  69. }
  70. //---------------------------------------------------------------------------
  71. void __fastcall TPaintForm::PaintBoxMouseDown(TObject *Sender,
  72.       TMouseButton Button, TShiftState Shift, int X, int Y)
  73. {
  74.   Drawing = true;
  75.   PaintBox->Canvas->MoveTo(X, Y);
  76.   Origin = Point(X, Y);
  77.   MovePt = Origin;
  78. }
  79. //---------------------------------------------------------------------------
  80. void __fastcall TPaintForm::PaintBoxMouseMove(TObject *Sender,
  81.       TShiftState Shift, int X, int Y)
  82. {
  83.   if (Drawing) {
  84.     DrawShape(&Origin, &MovePt, pmNotXor);
  85.     MovePt = Point(X, Y);
  86.     DrawShape(&Origin, &MovePt, pmNotXor);
  87.   }
  88. }
  89. //---------------------------------------------------------------------------
  90. void __fastcall TPaintForm::PaintBoxMouseUp(TObject *Sender,
  91.       TMouseButton Button, TShiftState Shift, int X, int Y)
  92. {
  93.   TPoint temppt;
  94.   temppt = Point(X,Y);
  95.   if (Drawing) {
  96.     DrawShape(&Origin, &temppt, pmCopy);
  97.     Drawing = false;
  98.   }
  99. }
  100. //---------------------------------------------------------------------------