Лабораторные работы: пятнашки и редактор фигур
This commit is contained in:
commit
a5dbf9d3a2
1 changed files with 2579 additions and 0 deletions
92
BaseFigure.cpp
Normal file
92
BaseFigure.cpp
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
#include <vcl.h>
|
||||
#pragma hdrstop
|
||||
|
||||
#include "BaseFigure.h"
|
||||
|
||||
#pragma package(smart_init)
|
||||
|
||||
int InRange(int v, int a, int b)
|
||||
{
|
||||
if (v < a) return a;
|
||||
if (v > b) return b;
|
||||
return v;
|
||||
}
|
||||
|
||||
TFigure::TFigure(int aNum)
|
||||
{
|
||||
num = aNum;
|
||||
x = 0;
|
||||
y = 0;
|
||||
w = 110;
|
||||
h = 90;
|
||||
fillColor = clWhite;
|
||||
lineColor = clBlack;
|
||||
}
|
||||
|
||||
TFigure::~TFigure()
|
||||
{
|
||||
}
|
||||
|
||||
int TFigure::GetNum() { return num; }
|
||||
int TFigure::GetX() { return x; }
|
||||
int TFigure::GetY() { return y; }
|
||||
int TFigure::GetW() { return w; }
|
||||
int TFigure::GetH() { return h; }
|
||||
TColor TFigure::GetFill() { return fillColor; }
|
||||
TColor TFigure::GetLine() { return lineColor; }
|
||||
|
||||
// здесь проверяются все границы, снаружи поля напрямую не меняются
|
||||
void TFigure::SetBounds(int ax, int ay, int aw, int ah)
|
||||
{
|
||||
x = InRange(ax, POS_MIN, POS_MAX);
|
||||
y = InRange(ay, POS_MIN, POS_MAX);
|
||||
w = InRange(aw, SIDE_MIN, SIDE_MAX);
|
||||
h = InRange(ah, SIDE_MIN, SIDE_MAX);
|
||||
}
|
||||
|
||||
void TFigure::MoveTo(int ax, int ay)
|
||||
{
|
||||
SetBounds(ax, ay, w, h);
|
||||
}
|
||||
|
||||
void TFigure::SetFill(TColor c)
|
||||
{
|
||||
fillColor = c;
|
||||
}
|
||||
|
||||
void TFigure::SetLine(TColor c)
|
||||
{
|
||||
lineColor = c;
|
||||
}
|
||||
|
||||
void TFigure::SetupCanvas(TCanvas *c)
|
||||
{
|
||||
c->Pen->Style = psSolid;
|
||||
c->Pen->Width = 2;
|
||||
c->Pen->Color = lineColor;
|
||||
c->Brush->Style = bsSolid;
|
||||
c->Brush->Color = fillColor;
|
||||
}
|
||||
|
||||
// номер в центре: на тёмной заливке белый, на светлой чёрный
|
||||
void TFigure::PaintNumber(TCanvas *c)
|
||||
{
|
||||
int rgb = ColorToRGB(fillColor);
|
||||
int r = GetRValue(rgb);
|
||||
int g = GetGValue(rgb);
|
||||
int b = GetBValue(rgb);
|
||||
int bright = (r * 3 + g * 6 + b) / 10;
|
||||
if (bright < 130)
|
||||
c->Font->Color = clWhite;
|
||||
else
|
||||
c->Font->Color = clBlack;
|
||||
c->Font->Name = "Verdana";
|
||||
c->Font->Size = 11;
|
||||
c->Font->Style = TFontStyles() << fsBold;
|
||||
String s = IntToStr(num);
|
||||
int tx = x + (w - c->TextWidth(s)) / 2;
|
||||
int ty = y + (h - c->TextHeight(s)) / 2;
|
||||
c->Brush->Style = bsClear;
|
||||
c->TextOut(tx, ty, s);
|
||||
c->Brush->Style = bsSolid;
|
||||
}
|
||||
Loading…
Reference in a new issue