Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Main;
- interface
- uses
- Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
- Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.Buttons, Vcl.ComCtrls, Vcl.ExtCtrls,
- Vcl.StdCtrls, Vcl.Samples.Spin, Vcl.Menus, JPEG;
- type
- TFurniture = class(TObject)
- protected
- FX,FY,FHeight,FLength,FWidth: integer;
- FColor: TColor;
- FCanvas: TCanvas;
- procedure Draw(x,y,length,width,height: integer; color: TColor; Canvas: TCanvas); virtual; abstract;
- procedure SetX(value: integer);
- procedure SetY(value: integer);
- procedure SetHeight(value: integer);
- procedure SetLength(value: integer);
- procedure SetWidth(value: integer);
- procedure SetColor(value: TColor);
- public
- constructor Create(x,y,length,width,height: integer; color: TColor; canvas: TCanvas);
- published
- property x: integer read FX write SetX;
- property y: integer read FY write SetY;
- property height: integer read FHeight write SetHeight;
- property length: integer read FLength write SetLength;
- property width: integer read FWidth write SetWidth;
- property color: TColor read FColor write SetColor;
- property canvas: TCanvas read FCanvas;
- end;
- TPic = class(TFurniture)
- protected
- FPic: TImage;
- procedure Draw(x,y,length,width,height: integer; color: TColor; Canvas: TCanvas); override;
- procedure SetPic(value: TImage);
- published
- property pic: TImage read FPic write SetPic;
- end;
- TStand = class(TFurniture)
- protected
- procedure Draw(x,y,length,width,height: integer; color: TColor; Canvas: TCanvas); override;
- end;
- TTable = class(TFurniture)
- protected
- procedure Draw(x,y,length,width,height: integer; color: TColor; Canvas: TCanvas); override;
- end;
- TForm1 = class(TForm)
- MainMenu1: TMainMenu;
- N1: TMenuItem;
- N2: TMenuItem;
- N3: TMenuItem;
- N4: TMenuItem;
- SpinEditX: TSpinEdit;
- SpinEditY: TSpinEdit;
- Label1: TLabel;
- Label2: TLabel;
- ColorBox1: TColorBox;
- Label4: TLabel;
- StatusBar1: TStatusBar;
- PaintBox1: TPaintBox;
- ComboBox1: TComboBox;
- Label5: TLabel;
- Label7: TLabel;
- Label8: TLabel;
- SpinEditLength: TSpinEdit;
- SpinEditWidth: TSpinEdit;
- SpinEditHeight: TSpinEdit;
- Button2: TButton;
- GroupBox1: TGroupBox;
- GroupBox2: TGroupBox;
- Label3: TLabel;
- Button1: TButton;
- OpenDialog1: TOpenDialog;
- procedure PaintBox1Paint(Sender: TObject);
- procedure N2Click(Sender: TObject);
- procedure Button2Click(Sender: TObject);
- procedure SpinEditXChange(Sender: TObject);
- procedure SpinEditYChange(Sender: TObject);
- procedure SpinEditLengthChange(Sender: TObject);
- procedure SpinEditWidthChange(Sender: TObject);
- procedure SpinEditHeightChange(Sender: TObject);
- procedure ColorBox1Change(Sender: TObject);
- procedure ComboBox1Change(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- Form1: TForm1;
- Obj: Array[0..2] of TFurniture;
- const x0=192;
- y0=250;
- implementation
- {$R *.dfm}
- constructor TFurniture.Create(x,y,length,width,height: integer; color: TColor; canvas: TCanvas);
- begin
- FX:=x;
- FY:=y;
- FLength:=length;
- FWidth:=width;
- FHeight:=height;
- FColor:=color;
- FCanvas:=canvas;
- Draw(x,y,length,width,height,color,canvas);
- end;
- procedure TFurniture.SetX(value: Integer);
- begin
- self.Draw(FX,FY,FLength,FWidth,FHeight,clBlack,FCanvas);
- FX:=value;
- self.Draw(FX,FY,FLength,FWidth,FHeight,FColor,FCanvas);
- end;
- procedure TFurniture.SetY(value: Integer);
- begin
- self.Draw(FX,FY,FLength,FWidth,FHeight,clBlack,FCanvas);
- FY:=value;
- self.Draw(FX,FY,FLength,FWidth,FHeight,FColor,FCanvas);
- end;
- procedure TFurniture.SetHeight(value: integer);
- begin
- self.Draw(FX,FY,FLength,FWidth,FHeight,clBlack,FCanvas);
- FHeight:=value;
- self.Draw(FX,FY,FLength,FWidth,FHeight,FColor,FCanvas);
- end;
- procedure TFurniture.SetLength(value: Integer);
- begin
- self.Draw(FX,FY,FLength,FWidth,FHeight,clBlack,FCanvas);
- FLength:=value;
- self.Draw(FX,FY,FLength,FWidth,FHeight,FColor,FCanvas);
- end;
- procedure TFurniture.SetWidth(value: Integer);
- begin
- self.Draw(FX,FY,FLength,FWidth,FHeight,clBlack,FCanvas);
- FWidth:=value;
- self.Draw(FX,FY,FLength,FWidth,FHeight,FColor,FCanvas);
- end;
- procedure TFurniture.SetColor(value: TColor);
- begin
- FColor:=value;
- self.Draw(FX,FY,FLength,FWidth,FHeight,FColor,FCanvas);
- end;
- procedure TPic.SetPic(value: TImage);
- begin
- FPic:=value;
- end;
- procedure TPic.Draw(x: Integer; y: Integer; length: Integer; width: Integer; height: Integer; color: TColor; Canvas: TCanvas);
- begin
- with Canvas do
- begin
- Pen.Color:=color;
- Pen.Width:=1;
- MoveTo(x,y);
- LineTo(x+length,y);
- LineTo(x+length,y+height);
- LineTo(x,y+height);
- LineTo(x,y);
- LineTo(x-width,y-width);
- LineTo(x+width+length,y-width);
- LineTo(x+length,y);
- MoveTo(x+width+length,y-width);
- LineTo(x+width+length,y+width+height);
- LineTo(x+length,y+height);
- MoveTo(x+width+length,y+width+height);
- LineTo(x-width,y+width+height);
- LineTo(x,y+height);
- MoveTo(x-width,y+width+height);
- LineTo(x-width,y-width);
- end;
- end;
- procedure TStand.Draw(x: Integer; y: Integer; length: Integer; width: Integer; height: Integer; color: TColor; Canvas: TCanvas);
- var AngWidth,BoxLength,BoxHeight,PadX,PadY: integer;
- begin
- AngWidth:=round(width/1.4); //Переходная величина от квадрата к параллелограмму на sqrt(2)~1.4 меньше ширины(по т.Пифагора)
- PadX:=round(length/10); //Отступы для ящиков тумбы составляют 0.1 от длины/высоты
- PadY:=round(height/10);
- BoxLength:=length-PadX*2; //Существует 2 отсупа по горизонтали
- BoxHeight:=round((height-PadY*3)/2); //И 3 отсупа по вертикали, т.к. мы рисуем 2 ящика
- with Canvas do
- begin
- Pen.Color:=color;
- Pen.Width:=1;
- //Плоскость
- MoveTo(x,y);
- LineTo(x-AngWidth,y+AngWidth);
- LineTo(x+length-AngWidth,y+AngWidth);
- LineTo(x+length,y);
- LineTo(x,y);
- //Основание
- MoveTo(x-AngWidth,y+AngWidth);
- LineTo(x-AngWidth,y+AngWidth+height);
- MoveTo(x+length-AngWidth,y+AngWidth);
- LineTo(x+Length-AngWidth,y+AngWidth+height);
- MoveTo(x+length,y);
- LineTo(x+length,y+height);
- LineTo(x+length-AngWidth,y+AngWidth+height);
- LineTo(x-AngWidth,y+AngWidth+height);
- //Первый ящик
- MoveTo(x-AngWidth+PadX,y+AngWidth+PadY);
- LineTo(x-AngWidth+PadX,y+AngWidth+PadY+BoxHeight);
- LineTo(x-AngWidth+PadX+BoxLength,y+AngWidth+PadY+BoxHeight);
- LineTo(x-AngWidth+PadX+BoxLength,y+AngWidth+PadY);
- LineTo(x-AngWidth+PadX,y+AngWidth+PadY);
- MoveTo(x-AngWidth+round(length/2)-PadX,y+AngWidth+PadY*2);
- LineTo(x-AngWidth+round(length/2)+PadX,y+AngWidth+PadY*2);
- //Второй ящик
- MoveTo(x-AngWidth+PadX,y+AngWidth+PadY*2+BoxHeight);
- LineTo(x-AngWidth+PadX,y+AngWidth+PadY*2+BoxHeight*2);
- LineTo(x-AngWidth+PadX+BoxLength,y+AngWidth+PadY*2+BoxHeight*2);
- LineTo(x-AngWidth+PadX+BoxLength,y+AngWidth+PadY*2+BoxHeight);
- LineTo(x-AngWidth+PadX,y+AngWidth+PadY*2+BoxHeight);
- MoveTo(x-AngWidth+round(length/2)-PadX,y+AngWidth+PadY*3+BoxHeight);
- LineTo(x-AngWidth+round(length/2)+PadX,y+AngWidth+PadY*3+BoxHeight);
- end;
- end;
- procedure TTable.Draw(x: Integer; y: Integer; length: Integer; width: Integer; height: Integer; color: TColor; Canvas: TCanvas);
- var AngWidth: integer;
- begin
- AngWidth:=round(width/1.4); //Переходная величина от квадрата к параллелограмму на sqrt(2)~1.4 меньше ширины(по т.Пифагора)
- with Canvas do
- begin
- Pen.Color:=color;
- Pen.Width:=1;
- //Плоскость
- MoveTo(x, y);
- LineTo(x-AngWidth,y+AngWidth);
- LineTo(x+length-AngWidth,y+AngWidth);
- LineTo(x+length,y);
- LineTo(x,y);
- //Ножки
- MoveTo(x-AngWidth,y+AngWidth);
- LineTo(x-AngWidth,y+AngWidth+height);
- MoveTo(x+length-AngWidth,y+AngWidth);
- LineTo(x+Length-AngWidth,y+AngWidth+height);
- MoveTo(x+length,y);
- LineTo(x+length,y+height);
- end;
- end;
- procedure TForm1.PaintBox1Paint(Sender: TObject);
- begin
- with PaintBox1.Canvas do
- begin
- Brush.Color:=clBlack; //Черный цвет кисти
- FillRect(ClientRect); //Заливка фона
- Pen.Color:=clWhite; //Цвет пера
- Pen.Width:=2; //Толщина пера
- MoveTo(x0,y0); //Перемещаемся в начало координат
- LineTo(PaintBox1.Width,y0); //Ось X
- MoveTo(x0,y0);
- LineTo(x0,0); //Ось Y
- MoveTo(x0,y0);
- LineTo(0,PaintBox1.Height); //Ось Z
- end;
- end;
- procedure TForm1.Button2Click(Sender: TObject);
- begin
- if Obj[ComboBox1.ItemIndex]=nil then
- case ComboBox1.ItemIndex of
- 0: Obj[0]:=TPic.Create(SpinEditX.Value,SpinEditY.Value,SpinEditLength.Value,SpinEditWidth.Value,SpinEditHeight.Value,ColorBox1.Selected,PaintBox1.Canvas);
- 1: Obj[1]:=TTable.Create(SpinEditX.Value,SpinEditY.Value,SpinEditLength.Value,SpinEditWidth.Value,SpinEditHeight.Value,ColorBox1.Selected,PaintBox1.Canvas);
- 2: Obj[2]:=TStand.Create(SpinEditX.Value,SpinEditY.Value,SpinEditLength.Value,SpinEditWidth.Value,SpinEditHeight.Value,ColorBox1.Selected,PaintBox1.Canvas);
- end
- else ShowMessage('Создание запрещено, т.к. данный объект уже был создан. Вы можете изменить его параметры.');
- end;
- procedure TForm1.N2Click(Sender: TObject);
- begin
- Close;
- end;
- procedure TForm1.SpinEditXChange(Sender: TObject);
- begin
- if Obj[ComboBox1.ItemIndex]<>nil then //Данная проверка предназначена для исключения краша программы из-за неправильного распределения памяти
- Obj[ComboBox1.ItemIndex].x:=SpinEditX.Value;
- end;
- procedure TForm1.SpinEditYChange(Sender: TObject);
- begin
- if Obj[ComboBox1.ItemIndex]<>nil then
- Obj[ComboBox1.ItemIndex].y:=SpinEditY.Value;
- end;
- procedure TForm1.SpinEditLengthChange(Sender: TObject);
- begin
- if Obj[ComboBox1.ItemIndex]<>nil then
- Obj[ComboBox1.ItemIndex].length:=SpinEditLength.Value;
- end;
- procedure TForm1.SpinEditWidthChange(Sender: TObject);
- begin
- if Obj[ComboBox1.ItemIndex]<>nil then
- Obj[ComboBox1.ItemIndex].width:=SpinEditWidth.Value;
- end;
- procedure TForm1.SpinEditHeightChange(Sender: TObject);
- begin
- if Obj[ComboBox1.ItemIndex]<>nil then
- Obj[ComboBox1.ItemIndex].height:=SpinEditHeight.Value;
- end;
- procedure TForm1.ColorBox1Change(Sender: TObject);
- begin
- if Obj[ComboBox1.ItemIndex]<>nil then
- Obj[ComboBox1.ItemIndex].color:=ColorBox1.Selected;
- end;
- procedure TForm1.ComboBox1Change(Sender: TObject);
- begin
- if Obj[ComboBox1.ItemIndex]<>nil then
- begin
- SpinEditX.Value:=Obj[ComboBox1.ItemIndex].x;
- SpinEditY.Value:=Obj[ComboBox1.ItemIndex].y;
- SpinEditLength.Value:=Obj[ComboBox1.ItemIndex].length;
- SpinEditWidth.Value:=Obj[ComboBox1.ItemIndex].width;
- SpinEditHeight.Value:=Obj[ComboBox1.ItemIndex].height;
- ColorBox1.Selected:=Obj[ComboBox1.ItemIndex].color;
- end;
- if ComboBox1.ItemIndex=0 then
- begin
- GroupBox2.Show;
- Label3.Show;
- Button1.Show;
- end
- else
- begin
- GroupBox2.Hide;
- Label3.Hide;
- Button1.Hide;
- end;
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement