📄 c13_5f.h
字号:
//---------------------------------------------------------------------------
#ifndef C13_5fH
#define C13_5fH
//---------------------------------------------------------------------------
#include <stdlib.h>
#include <math.h>
#include <vcl\Classes.hpp>
#include <vcl\Controls.hpp>
#include <vcl\StdCtrls.hpp>
#include <vcl\Forms.hpp>
#include <vcl\Menus.hpp>
#include <vcl\ExtCtrls.hpp>
#include <vcl\Buttons.hpp>
//---------------------------------------------------------------------------
// 自定义数据
#define IC_ARROW 1
#define IC_LINE 2
#define IC_RECTANGLE 3
#define DISTENCE 5
#define BACKCOLOR clWhite // 背景色
#define FORECOLOR clBlack // 前景色
//---------------------------------------------------------------------------
// 自定义类
class Unit //: public TObject
{ // 公用类
public:
long type;
protected:
long X1, Y1;
long X2, Y2;
public:
virtual bool IsMe(long x, long y) // 判断输入点是否接近本对象
{return(false);} // 虚拟(virtual)函数,用于重载。
// 虚拟函数的重载是C++语言的重要特性之一 ,
// 重载为继承类的功能扩展与代码重用提供了良好的机制。
virtual void Draw(TCanvas *Canvas) // 画对象自身
{}
virtual void UpDate(long dx, long dy)
{ X1 += dx; Y1 += dy; X2 += dx; Y2 += dy;}
virtual void UpDate1(long x, long y)
{X1 = x; Y1 = y;}
virtual void UpDate2(long x, long y)
{X2 = x; Y2 = y;}
};
class UnitLine : public Unit
{ // 直线类
public:
virtual bool IsMe(long x, long y);
virtual void Draw(TCanvas *Canvas);
__fastcall UnitLine(){};
};
class UnitRect : public Unit
{ // 矩形类
public:
virtual bool IsMe(long x, long y);
virtual void Draw(TCanvas *Canvas);
};
//---------------------------------------------------------------------------
class sUnit
{ // 链表项类
public:
Unit* p;
sUnit *prev;
sUnit *next;
__fastcall sUnit() //构造函数,在创建该对象的实例时由系统调用
{prev = NULL; next = NULL; p = NULL;}
__fastcall ~sUnit() // 析构函数
{if(p) delete p;} // 删除 Unit 对象 p 。
};
class UnitLink //: TObject
{ // 链表类
private:
sUnit* pHead;
public:
void AddItem(Unit *p);
Unit* GetAt(int i);
int GetNum();
void DelItem(Unit* p);
Unit* IsThis(long x, long y);
void Draw(TCanvas* Canvas);
__fastcall UnitLink()
{pHead = NULL;}
__fastcall ~UnitLink();
};
//---------------------------------------------------------------------------
class TForm1 : public TForm
{
__published: // IDE-managed Components
TMainMenu *MainMenu1;
TMenuItem *N1;
TMenuItem *Exit;
TPanel *Panel1;
TSpeedButton *Arrow;
TSpeedButton *Line;
TSpeedButton *Rect;
TSpeedButton *Delete;
TPaintBox *PaintBox1;
void __fastcall ExitClick(TObject *Sender);
void __fastcall FormCreate(TObject *Sender);
void __fastcall ArrowClick(TObject *Sender);
void __fastcall LineClick(TObject *Sender);
void __fastcall RectClick(TObject *Sender);
void __fastcall PaintBox1MouseDown(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y);
void __fastcall PaintBox1MouseUp(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y);
void __fastcall PaintBox1MouseMove(TObject *Sender, TShiftState Shift, int X,
int Y);
void __fastcall FormDestroy(TObject *Sender);
void __fastcall DeleteClick(TObject *Sender);
void __fastcall PaintBox1Paint(TObject *Sender);
private: // User declarations
public: // User declarations
int UserAction;
bool Drawing;
Unit* CurrentUnit;
UnitLink* Linker;
long CurrentX, CurrentY;
void __fastcall ClearDraw();
__fastcall TForm1(TComponent* Owner);
};
//---------------------------------------------------------------------------
extern TForm1 *Form1;
//---------------------------------------------------------------------------
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -