//--------------------------------------------------------------------------- #include #pragma hdrstop #include "Undo_F.h" #include "MainImage.h" #include "Undo.h" #include "MainMenu.h" //lhskys shifta¸¦ ¾²±â À§ÇØ shifta ´Â »ö¹Ù²Ù±â Ææ¿¡¼­ shift¿Í ¸¶¿ì½º¿ÞÂÊÀ» Ŭ¸¯ÇßÀ»¶§¸¦ ³ªÅ¸³¿ //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "TPSpin" #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_PEN StringTable[0] #define IDS_MAXIMUMCOUNT StringTable[1] #define IDS_NUMBER StringTable[2] #define IDS_LAST StringTable[3] #define IDS_STACK StringTable[4] #define IDS_SWAP StringTable[5] //--------------------------------------------------------------------------- TUndoForm *UndoForm; //--------------------------------------------------------------------------- __fastcall TUndoForm::TUndoForm(TComponent* Owner) : TForm(Owner) { StringTable.Create(DirectoryBin, Language, "Undo"); SetSmallFont(Font); SetSmallFont(Label1->Font); SetSmallFont(Label2->Font); SetSmallFont(Label3->Font); SetSmallFont(Label5->Font); SetSmallFont(LUndoState->Font); SetSmallFont(LDelLabel->Font); UndoAll->Caption = IDS_COMMON_WHOLE; UndoPen->Caption = IDS_PEN; Label5->Caption = IDS_COMMON_METHOD; LUndoState->Caption = IDS_STACK; BitBtn1->Caption = IDS_COMMON_RUN; Label1->Caption = IDS_MAXIMUMCOUNT; Label2->Caption = IDS_NUMBER; Label3->Caption = IDS_COMMON_DELETE; LDelLabel->Caption = IDS_LAST; BitBtn2->Caption = IDS_COMMON_RUN; } //--------------------------------------------------------------------------- void __fastcall TUndoForm::FormCreate(TObject *Sender) { LUndoState->Enabled = true; UndoCount = Undo->Maximum; //lhskys UndoCount = ÃʱâÈ­ } //--------------------------------------------------------------------------- void __fastcall TUndoForm::LUndoStateClick(TObject *Sender) { switch (Undo->Method) { case UM_SWAP: Undo->Method = UM_STACK; LUndoState->Caption = IDS_STACK; break; case UM_STACK: Undo->Method = UM_SWAP; LUndoState->Caption = IDS_SWAP; break; } Review(); } //--------------------------------------------------------------------------- void __fastcall TUndoForm::LDelLabelMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { if (DelItem==Delete1) { LDelLabel->Caption = IDS_COMMON_WHOLE; DelItem = Delete2; } else if (DelItem==Delete2) { LDelLabel->Caption = IDS_LAST; DelItem = Delete1; } } //--------------------------------------------------------------------------- void __fastcall TUndoForm::BitBtn2Click(TObject *Sender) { if (DelItem==Delete1) { Undo->RemoveLast(); } else if (DelItem==Delete2) { Undo->RemoveAll(); } StatusPen(); Review(); } //--------------------------------------------------------------------------- void __fastcall TUndoForm::EUndoMaxChange(TObject *Sender) { if (EUndoMax->Text.Length() > 0) { if (EUndoMax->Value < 1) EUndoMax->Value = 1; if (EUndoMax->Value > 10) EUndoMax->Value = 10; Undo->Maximum = EUndoMax->Value; } } //--------------------------------------------------------------------------- void __fastcall TUndoForm::BitBtn1Click(TObject *Sender) { Undo->Read(); #ifdef KNIT MainImageForm->iMainImage->SetMark(); #endif ::RepaintColor(); StatusPen(); Review(); MainImageForm->WorkAreaChange(); } //--------------------------------------------------------------------------- void __fastcall TUndoForm::UndoAllClick(TObject *Sender) { Review(); } //--------------------------------------------------------------------------- void __fastcall TUndoForm::UndoPenClick(TObject *Sender) { Review(); } //--------------------------------------------------------------------------- void __fastcall TUndoForm::Review() { BitBtn1->Enabled = UndoAll->Checked && Undo->Count>0; BitBtn2->Enabled = Undo->Count>0; switch (Undo->Method) { case UM_STACK: ClientHeight = UndoPanel->Top+UndoPanel->Height; Parent->Height = ParentHeight+ClientHeight; UndoPanel->Enabled = true; UndoPanel->Visible = true; LUndoState->Caption = IDS_STACK; EUndoMax->Value = Undo->Maximum; Edit2->Text = Undo->Count; break; case UM_SWAP: ClientHeight = UndoPanel->Top; Parent->Height = ParentHeight+ClientHeight; UndoPanel->Enabled = false; UndoPanel->Visible = false; LUndoState->Caption = IDS_SWAP; break; } } //--------------------------------------------------------------------------- void __fastcall TUndoForm::StatusPen() { TUndoData *ud; int i, j; try { if (Undo->Count > 0) { memset(piChange, 0, 256); ud = Undo->Last; if (ud==NULL) throw EC_NONE; if (ud->Palette) { for (i=1, j=0; i<=ud->Palette->UseColor; i++) { if (ud->Palette->ColorData[i]->Compare(MainImageForm->Palette->ColorData[i])==false) { j++; piChange[i] = ud->Palette->UseColor+j; } } UndoPen->Enabled = ud->Palette->UseColor+j<252; } } else { UndoAll->Checked = true; UndoPen->Enabled = false; } bFirst = true; } catch (int ec) { EXCEPTION_MESSAGE_OK(ec); } } //--------------------------------------------------------------------------- void __fastcall TUndoForm::InitForm() { ParentHeight = Parent->Height+20; if (MainImageForm->iMainImage->Bitmap->BitsPerPixel==8) { MainImageForm->OnSetHLine = SetHLine8; } else { MainImageForm->OnSetHLine = SetHLine24; } UndoAll->Checked = true; DelItem = Delete1; StatusPen(); Review(); } //--------------------------------------------------------------------------- void __fastcall TUndoForm::SetHLine8(int x, int y, int len, COLORREF c) { TUndoData *ud; int xx, yy, i, j; Byte *IP, *UP; try { ud = Undo->Last; if (ud==NULL) throw EC_NONE; if (ud->Kind&UK_PATTERN) { if (bFirst) { for (i=1, j=0; i<252; i++) { if (piChange[i]) { MainImageForm->Palette->Copy(piChange[i], ud->Palette->ColorData[i]); j++; } else { piChange[i] = i; } } MainImageForm->Palette->UseColor = ud->Palette->UseColor+j; ::RepaintColor(); bFirst = false; } if ((y >= ud->Range.top) && (y < ud->Range.bottom)) { yy = y - ud->Range.top; if (!ud->Bitmap->StartScanLine()) throw EC_MEMORY_LACK; IP = MainImageForm->iMainImage->Bitmap->GetScanLine(y)+x; UP = ud->Bitmap->GetScanLine(yy)+x-ud->Range.left; for (xx = x; xx < x + len; xx++, IP++, UP++) { if ((xx >= ud->Range.left) && (xx < ud->Range.right)) { *IP = piChange[*UP]; } } MainImageForm->iMainImage->Bitmap->PutScanLine(y); ud->Bitmap->StopScanLine(); } } if (ud->Kind&UK_MASK) { if (MainImageForm->iMainImage->Mask) { if ((y >= ud->Range.top) && (y < ud->Range.bottom)) { yy = y - ud->Range.top; if (!ud->Mask->StartScanLine()) throw EC_MEMORY_LACK; IP = MainImageForm->iMainImage->Mask->GetScanLine(y)+x; UP = ud->Mask->GetScanLine(yy)+x-ud->Range.left; for (xx = x; xx < x + len; xx++, IP++, UP++) { if ((xx >= ud->Range.left) && (xx < ud->Range.right)) { *IP = *UP; } } MainImageForm->iMainImage->Mask->PutScanLine(y); ud->Mask->StopScanLine(); } } } } catch (int ec) { EXCEPTION_MESSAGE_OK(ec); } } //--------------------------------------------------------------------------- void __fastcall TUndoForm::SetHLine24(int x, int y, int len, COLORREF c) { TUndoData *ud; int xx, yy; BYTE *IP, *UP, im, um; try { ud = Undo->Last; if (ud==NULL) throw EC_NONE; if ((y >= ud->Range.top) && (y < ud->Range.bottom)) { yy = y - ud->Range.top; if (ud->Kind&UK_PATTERN) { if (!ud->Bitmap->StartScanLine()) throw EC_MEMORY_LACK; IP = MainImageForm->iMainImage->Bitmap->GetScanLine(y)+3*x; UP = ud->Bitmap->GetScanLine(yy)+3*(x-ud->Range.left); for (xx = x; xx < x + len; xx++, IP+=3, UP+=3) { if ((xx >= ud->Range.left) && (xx < ud->Range.right)) { CopyPixel24(IP, UP); } } MainImageForm->iMainImage->Bitmap->PutScanLine(y); ud->Bitmap->StopScanLine(); } if (ud->Kind&UK_MASK) { if (MainImageForm->iMainImage->Mask) { if (!ud->Mask->StartScanLine()) throw EC_MEMORY_LACK; IP = MainImageForm->iMainImage->Mask->GetScanLine(y)+(x>>3); im = 0x80>>(x&7); UP = ud->Mask->GetScanLine(yy)+((x-ud->Range.left)>>3); um = 0x80>>((x-ud->Range.left)&7); for (xx = x; xx < x + len; xx++) { if ((xx >= ud->Range.left) && (xx < ud->Range.right)) { if (*UP&um) { *IP |= im; } else { *IP &= ~im; } } if (im==1) { IP++; im = 0x80; } else im >>= 1; if (um==1) { UP++; um = 0x80; } else um >>= 1; } MainImageForm->iMainImage->Mask->PutScanLine(y); ud->Mask->StopScanLine(); } } } } catch (int ec) { EXCEPTION_MESSAGE_OK(ec); } } //--------------------------------------------------------------------------- void __fastcall TUndoForm::iMainImageKeyDown(int Key) { if ( Key == 13 && UndoAll->Checked == true)BitBtn1Click(this); //lhskys Àüü¸¦ ¿¡¼­ ¿£ÅÍŰ ½ÇÇà if ( Key == 13 && UndoPen->Checked == true)BitBtn2Click(this); //lhskys ÆæÀ¸·Î ¿¡¼­ ¿£ÅÍŰ ½ÇÇà } //----------------------------------------------------------------------------