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
|
//mon code h:
#include "UndoRedoState.hpp" //créé par les composants
#include "_State.hpp" //créé par les composants
//---------------------------------------------------------------------------
class TForm2: public TForm, IState
{
typedef TForm inherited;
__published:
TImage *ImageVue;
TSpeedButton *Redo1;
TSpeedButton *Undo1;
void __fastcall FormCreate(TObject * Sender);
void __fastcall FormDestroy(TObject * Sender);
void __fastcall ImageVueMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall ImageVueMouseMove(TObject *Sender, TShiftState Shift, int X, int Y);
void __fastcall ImageVueMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y);
void __fastcall Undo1Click(TObject *Sender);
void __fastcall Redo1Click(TObject *Sender);
private:
TUndoRedoState *FUndoRedo;
bool FMouseDown;
public:
__fastcall TForm2(TComponent* Owner);
void __fastcall GetState(TStream *S);
void __fastcall SetState(TStream *S);
};
//---------------------------------------------------------------------------
extern PACKAGE TForm2 * Form2;
//---------------------------------------------------------------------------
#endif
//Code cpp
//#pragma link "_State" // n'apporte rien de plus
//#pragma link "UndoRedoState" // n'apporte rien de plus
//-------------------------------------------------
void __fastcall TForm2::GetState(TStream *S)
{ // mem écrit
ImageVue->Picture->Bitmap->SaveToStream(S);
}
//---------------------------------------------------------------------------
void __fastcall TForm2::SetState(TStream *S)
{ //mem lit
ImageVue->Picture->Bitmap->LoadFromStream(S);
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormCreate(TObject * Sender)
{ // Prépare l'image
ImageVue->Picture->Bitmap->Width = ImageVue->Width;
ImageVue->Picture->Bitmap->Height = ImageVue->Height;
TUndoRedoState *FUndoRedo;
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Redo1Click(TObject *Sender)
{ // Redo
FUndoRedo->Undo();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::Undo1Click(TObject *Sender)
{ // Undo
FUndoRedo->Redo();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::ImageVueMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
{ // Dessine à main nue (fait pour l'essai undo redo)
if(FMouseDown) return;
FMouseDown = true; FUndoRedo->BeginModify(); ImageVue->Canvas->MoveTo(X, Y);
}
//---------------------------------------------------------------------------
void __fastcall TForm2::ImageVueMouseMove(TObject *Sender, TShiftState Shift, int X, int Y)
{ // Dessine à main nue
if(FMouseDown) ImageVue->Canvas->LineTo(X, Y);
}
//---------------------------------------------------------------------------
void __fastcall TForm2::ImageVueMouseUp(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y)
{ // Finished Editing
if(FMouseDown) { FUndoRedo->EndModify(); FMouseDown = false; }
}
//---------------------------------------------------------------------------
void __fastcall TForm2::FormDestroy(TObject * Sender)
{ // Libère
FUndoRedo->Free();
} |
Partager