1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
__fastcall jPaintBox::jPaintBox(TComponent *AOwner)
: TCustomControl(AOwner)
{
if(AOwner->InheritsFrom(__classid(TWinControl))) Parent = (TWinControl*)AOwner;
Actions = new TList;
OnMouseDown = OnMouseDownAdd;
}
__fastcall jPaintBox::~jPaintBox()
{
Actions->Clear();
delete Actions;
Actions = NULL;
}
void __fastcall jPaintBox::SetStep(int Value)
{
FStep = Value;
Repaint(); //pour rendre la modification visible immédiatement
}
void __fastcall jPaintBox::SetImage(Graphics::TBitmap *Value)
{
FImage = Value;
Repaint(); //pour rendre la modification visible immédiatement
}
void __fastcall jPaintBox::Paint()
{
if(Image != NULL)
{
Canvas->Draw(0,0,Image);
}
else
{
Canvas->Brush->Style = bsSolid;
Canvas->Brush->Color = Brush->Color;
Canvas->FillRect(Rect(0,0,Width,Height));
}
if(Actions != NULL) // par sécurité
{
for(int j = 0; (j < Step) && (j < Actions->Count); j++)
{
((jAction*)Actions->Items[j])->Do();
}
}
}
void __fastcall jPaintBox::Add(Graphics::TBitmap *I, TPoint P)
{
jAction *Action = new jAction(this, I, Canvas, P);
Actions->Add(Action);
Step = Actions->Count; //Step = Count à chaque ajout
}
void __fastcall jPaintBox::OnMouseDownAdd(TObject *Sender, TMouseButton Button,
TShiftState Shift, int X, int Y)
{
// pour faire la distinction entre sélectionner/supprimer et ajouter
if(Button == mbRight)
{
jAction *Action = HasFocus(Rect(X,Y,X,Y));
if(Action != NULL)
{
if (MessageDlg("Supprimer l'action ?", mtConfirmation,
TMsgDlgButtons() << mbYes << mbNo, 0) == mrYes)
{
Actions->Delete(Actions->IndexOf(Action));
delete Action; // suppression manuelle ici
Step = Step - 1; // pour une suppression réaliste
}
}
}
else
{
Add(Target->Picture->Bitmap, Point(X,Y));
}
}
/*
Ici, on va travailler en mode rétro simplement par ce que chaque action est
dessinée sous la suivante.
*/
jAction* __fastcall jPaintBox::HasFocus(TRect R)
{
jAction *Action;
int max = Actions->Count - 1;
if(Step < max) max = Step;
for(int j = max; j >=0; j--)
{
Action = (jAction*)Actions->Items[j];
if(Action->HasFocus(R)) return Action;
}
return NULL;
} |
Partager