//--------------------------------------------------------------------------- #include #include #pragma hdrstop #include "PenManager.h" #include "MainImage.h" #include "Palette.h" #include "Undo.h" #include "Draw_F.h" //lhskys pointlist ÀÌ¿ë... #include "Window.h" // GreenFish Filtering PenÀ¸·Î ÀÌ¿ë //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "Selector" #pragma link "TPStretchImage" #pragma link "TPSpin" #pragma resource "*.dfm" //----------F----------------------------------------------------------------- #define IDS_PEN StringTable[0] #define IDS_TOSQUARE StringTable[1] #define IDS_AIRBRUSH StringTable[2] #define IDS_CRAYON StringTable[3] #define IDS_WATERPEN StringTable[4] #define IDS_SCRAPEPEN StringTable[5] #define IDS_MASKPEN StringTable[6] #define IDS_PRESSURE StringTable[7] #define IDS_ANTIALISE StringTable[8] #define IDS_SINGLE StringTable[9] #define IDS_MULTI StringTable[10] #define IDS_PATTERN StringTable[11] #define IDS_DENSITY StringTable[12] #define IDS_NOZZLE StringTable[13] #define IDS_SPREAD StringTable[14] #define IDS_COLOR StringTable[15] #define IDS_BRISTLES StringTable[16] #define IDS_SCALE StringTable[17] #define IDS_SPREADGRADE StringTable[18] #define IDS_SELECTCOLOR StringTable[19] #define IDS_SELECT StringTable[20] #define IDS_SIMPLE StringTable[21] #define IDS_SPATTER StringTable[22] #define IDS_PURE StringTable[23] #define IDS_DIFFUSE StringTable[24] #define IDS_EFFECT StringTable[25] #define IDS_SHAPE StringTable[26] #define IDS_DRAWINGPEN StringTable[27] #define IDS_INSIDEDENSITY StringTable[28] #define IDS_OUTSIDEDENSITY StringTable[29] #define IDS_CLEAR StringTable[30] #define IDS_DELETE StringTable[31] #define IDS_FILL StringTable[32] #define IDS_TOCIRCLE StringTable[33] #define IDS_REVERSAL StringTable[34] #define IDS_BLUR StringTable[35] #define MAX_PEN_HALF_WIDTH 25 // 7.42 ¹öÀü¿¡¼­ ÀÌ °ªÀº 14 (¹°·Ð 7.41ÀÌÀü¿¡ Á¤ÇØÁø °ªÀ̰ÚÁö¸¸..) #define MAX_PEN_LEFT_CENTER 25 // 7.42 ¹öÀü¿¡¼­ ÀÌ °ªÀº 13 (ÀÌ °ªÀÌ ¿¡·¯¸¦ À¯¹ßÇßÁö¸¸ ¾î¶² ¿ëµµ·Î »ç¿ëµÇ¾ú´ÂÁö ¸ô¶ó defineÀ» µû·Î Çß´Ù) by celberus //--------------------------------------------------------------------------- TPenManagerForm *PenManagerForm; //--------------------------------------------------------------------------- __fastcall TPenManagerForm::TPenManagerForm(TComponent* Owner) : TForm(Owner) { update=true; //=============================== 2001.5.3 lhskys FormCreate(TObject *Sender)³»¿ë ¿Å±è StringTable.Create(DirectoryCommon, Language, "PenManager"); SetFont(); Random = new TTexpiaRandom(360); Pen = new TPenObject(Tablet); if (!Tablet->IsDevice()) Tablet->MaxNPressure = 1; if (!Tablet->MaxNPressure) Tablet->MaxNPressure = 1; MenuSW = false; Type = PT_NORMAL; AirType = PAT_SINGLE; BtnClick = false; ClientHeight = ExitPanel->Top;// + ExitPanel->Height; FHeight = ClientHeight; EtcPanel->Left = 0; EtcPanel->Top = ClientHeight; ScrapePanel->Left = 0; ScrapePanel->Top = EtcSubPanel->Height; DensPanel->Left = 0; DensPanel->Top = EtcSubPanel->Height; ColorPanel->Left = DensPanel->Width; ColorPanel->Top = EtcSubPanel->Height; SpreadPanel->Left = 0; SpreadPanel->Top = EtcSubPanel->Height; WaterPanel->Left = 0; WaterPanel->Top = ClientHeight; AirPanel->Left = 0; AirPanel->Top = ClientHeight; SinglePanel->Left = 0; SinglePanel->Top = ButtonPanel->Height + 5; MultiPanel->Left = 0; MultiPanel->Top = ButtonPanel->Height + 5; PatternPanel->Left = 0; PatternPanel->Top = ButtonPanel->Height + 5; MaskPanel->Left = 0; MaskPanel->Top = ClientHeight; Pen->BasicThick = 12; sbNormal->Down = true; shNormal->Pen->Color = clRed; shNormal->Brush->Color = clRed; shAirBrush->Pen->Color = clBlack; shAirBrush->Brush->Color = clBlack; shCrayon->Pen->Color = clBlack; shCrayon->Brush->Color = clBlack; shWater->Pen->Color = clBlack; shWater->Brush->Color = clBlack; shScratch->Pen->Color = clBlack; shScratch->Brush->Color = clBlack; shMask->Pen->Color = clBlack; shMask->Brush->Color = clBlack; btnUp->Visible = false; btnDown->Visible = true; AirColorList = new TList; ColorPanel->Visible = false; SpreadPanel->Visible = false; ScrapePanel->Visible = false; DensPanel->Visible = false; EtcPanel->Height = EtcPanel->Height - SpreadPanel->Height; spread_pos = 0; spread_grade = 2; interval = 70; aspread = false; acolor = 0; Pen->Brush = 0; cr[PWT_SIMPLE] = 0.14; or[PWT_SIMPLE] = 0.90; cr[PWT_SPATTER] = 0.93; or[PWT_SPATTER] = 0.00; cr[PWT_PURE] = 0.66; or[PWT_PURE] = 0.93; cr[PWT_DIFFUSE] = 0.30; or[PWT_DIFFUSE] = 0.08; WaterType = PWT_SIMPLE; FPointPressurePen = point_pressure_pen; init_pressure_pen(); //======================================== Caption = IDS_PEN; PenWidthPanel->Hint = AnsiString(IDS_COMMON_CIRCLE)+ " : " + AnsiString(IDS_TOSQUARE); sbNormal->Hint = IDS_COMMON_NORMAL; sbAirBrush->Hint = IDS_AIRBRUSH; sbCrayon->Hint = IDS_CRAYON; sbWater->Hint = IDS_WATERPEN; sbScratch->Hint = IDS_SCRAPEPEN; sbMask->Hint = IDS_MASKPEN; cbPressure->Caption = IDS_PRESSURE; sbSingle->Caption = IDS_SINGLE; sbMulti->Caption = IDS_MULTI; sbPattern->Caption = IDS_PATTERN; Label44->Caption = IDS_DENSITY; Label45->Caption = IDS_NOZZLE; Label19->Caption = IDS_DENSITY; Label20->Caption = IDS_NOZZLE; Label17->Caption = IDS_DENSITY; Label43->Caption = IDS_NOZZLE; lSpread->Caption = AnsiString(IDS_SPREAD) + " : " + AnsiString(IDS_COMMON_OFF); lColor->Caption = AnsiString(IDS_COLOR) + " : " + AnsiString(IDS_COMMON_BUTTONNO); lBristles->Caption = IDS_BRISTLES; lScale->Caption = IDS_SCALE; sbNew->Hint = IDS_COMMON_NEW; sbAll->Hint = IDS_COMMON_ALL; sbBlock->Hint = IDS_COMMON_BLOCKCOLOR; sbDelete->Hint = IDS_COMMON_INSERTCOLOR; sbBefore->Hint = IDS_COMMON_BEFORECOLOR; spreadgrade->Caption = IDS_SPREADGRADE; // spreadgrade->Caption = AnsiString(IDS_SPREADGRADE) + "(2 - 70)"; sbWSimple->Hint = IDS_WATERPEN; sbWSpatter->Hint = IDS_SPATTER; sbClear->Caption = IDS_CLEAR; sbWPure->Hint = IDS_PURE; sbWDiffuse->Hint = IDS_DIFFUSE; BtnAvg->Hint = IDS_BLUR; Label5->Caption = IDS_DENSITY; Label1->Caption = IDS_COLOR; Label2->Caption = IDS_EFFECT; lSelectDraw->Caption = IDS_SELECTCOLOR; lDensity->Caption = IDS_DENSITY; chDelete->Caption = IDS_DELETE; chFill->Caption = IDS_FILL; chReversal->Caption = IDS_REVERSAL; //======================================== penspread = 0; //lhskys pentaper = 0; //lhskys #if defined(KNIT) sePenSize->Value = 1; #endif //=============================================== } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::PenShapeMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { MainImageForm->iMainImageChange(); if (Pen->Shape == 1) { PenShape->Shape = stCircle; sePenSize->Value = Pen->BasicThick; Pen->Shape = 0; PenWidthPanel->Hint = AnsiString(IDS_COMMON_CIRCLE) +" : " + AnsiString(IDS_TOSQUARE); } else if (Pen->Shape == 0) { PenShape->Shape = stRectangle; sePenSize->Value = Pen->BasicThick; Pen->Shape = 1; PenWidthPanel->Hint = AnsiString(IDS_COMMON_SQUARE) + " : " + AnsiString(IDS_TOCIRCLE); } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::PenWidthPanelClick(TObject *Sender) { MainImageForm->iMainImageChange(); if (Pen->Shape == 1) { PenShape->Shape = stCircle; sePenSize->Value = Pen->BasicThick; Pen->Shape = 0; PenWidthPanel->Hint = AnsiString(IDS_COMMON_CIRCLE) + " : " + AnsiString(IDS_TOSQUARE); } else if (Pen->Shape == 0) { PenShape->Shape = stRectangle; sePenSize->Value = Pen->BasicThick; Pen->Shape = 1; PenWidthPanel->Hint = AnsiString(IDS_COMMON_SQUARE) + " : " + AnsiString(IDS_TOCIRCLE); } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::sePenSizeChange(TObject *Sender) { if (sePenSize->Text.Length()>0) { if (MainImageForm) MainImageForm->iMainImageChange(); if (sePenSize->Value > 50) sePenSize->Value = 50; if (sePenSize->Value < 1) sePenSize->Value = 1; if(DrawForm)if(DrawForm->StartSize->Visible == true)DrawForm->StartSize->Value = sePenSize->Value; Pen->BasicThick = int(sePenSize->Value); PenShape->Height = Pen->BasicThick; PenShape->Width = Pen->BasicThick; PenShape->Top = (PenWidthPanel->Height - Pen->BasicThick + 1) / 2.0; PenShape->Left = (PenWidthPanel->Width - Pen->BasicThick + 1) / 2.0; } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::sePenSizeClick(TObject *Sender) { sePenSize->SetFocus(); sePenSize->SelectAll(); } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::PenSelectClick(TObject *Sender) { TSpeedButton *s; TPenType bftype; bftype = Type; /* ======================================================= Source // ExitMenu(); s = (TSpeedButton *)Sender; if (s == sbNormal) InitType(PT_NORMAL); else if (s == sbAirBrush) InitType(PT_AIR); else if (s == sbCrayon) InitType(PT_CRAYON); else if (s == sbWater) InitType(PT_WATER); else if (s == sbScratch) InitType(PT_SCRAPE); else if (s == sbMask) InitType(PT_MASK); */ s = (TSpeedButton *)Sender; if (s == sbNormal) Type = PT_NORMAL; else if (s == sbAirBrush) Type = PT_AIR; else if (s == sbCrayon) Type = PT_CRAYON; else if (s == sbWater) Type = PT_WATER; else if (s == sbScratch) Type = PT_SCRAPE; else if (s == sbMask) Type = PT_MASK; if (bftype != Type) MenuSW = true; InitType(); } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::sbNormalMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { /* #ifndef N_SCREENCAM AnsiString screencam, cam, camdir; TRegistry *Registry; SHELLEXECUTEINFO screeninfo; if (Button == mbRight && Shift.Contains(ssShift)) { Registry = new TRegistry; if (!Registry) return; Registry->RootKey = HKEY_LOCAL_MACHINE; Registry->OpenKey("SOFTWARE\\Youngwoo\\TexPro\\8.01\\Directory",TRUE); screencam = Registry->ReadString("screencam"); delete Registry; memset(&screeninfo,0,sizeof(screeninfo)); screeninfo.cbSize = sizeof(screeninfo); screeninfo.lpVerb = "open"; screeninfo.lpDirectory = screencam.c_str(); screeninfo.lpFile = "scplayer.exe"; switch(dynamic_cast(Sender)->Tag) { case 0 : cam = screencam + "\\textile\\pen2.scm"; break; case 1 : cam = screencam + "\\textile\\pen2.scm"; break; case 2 : cam = screencam + "\\textile\\pen3.scm"; break; case 3 : cam = screencam + "\\textile\\pen3.scm"; break; case 4 : cam = screencam + "\\textile\\pen4.scm"; break; case 5 : cam = screencam + "\\textile\\pen5.scm"; break; } camdir = "\"" + cam + "\""; screeninfo.lpParameters = camdir.c_str(); screeninfo.fMask = SEE_MASK_NOCLOSEPROCESS; screeninfo.nShow = SW_SHOWDEFAULT; if(!ShellExecuteEx(&screeninfo)) { ShowMessage("can't play screencam movie."); return; } } #endif */ } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::cbPressureClick(TObject *Sender) { Pen->Brush = cbPressure->Checked; } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::MenuClick(TObject *Sender) { int h; /* #ifdef KNIT if ((MenuSW == false) && (DesignMode == D_YARN)) { #else if (MenuSW == false) { #endif Show(); MenuSW = true; switch (Type) { case PT_NORMAL : if (spread_grade < 2) spread_grade = 2; if (252 - MainImageForm->Palette->UseColor - 1 > 70) interval = 70; else interval = 252 - MainImageForm->Palette->UseColor - 1; lGrade->Caption = Format("(2 - %d)", OPENARRAY(TVarRec, (interval))); EtcPanel->Visible = true; EtcPanel->BringToFront(); h = EtcSubPanel->Height; //=========================================== 2001.02.09 lhskys È®ÀÎ ¿ä¸Á if (SpreadPanel->Visible) { if (ColorPanel->Visible) { h += ColorPanel->Height; } SpreadPanel->Top = h; h += SpreadPanel->Height; aspread = true; } else { if (ColorPanel->Visible) { h += ColorPanel->Height; } } //=========================================== 2001.02.09 ¿ä±â±îÁö EtcPanel->Height = h; ClientHeight = EtcPanel->Top + h; break; case PT_AIR : AirSelectColor->Brush->Color = MainImageForm->Palette->Color[PaletteForm->DIB256Palette->ChoiceIndex]; if (MainImageForm->WorkArea->Mask) { sbPattern->Enabled = true; } else { sbSingle->Down = true; AirFunctionClick(sbSingle); sbPattern->Enabled = false; } AirPanel->Visible = true; AirPanel->BringToFront(); if (AirType == PAT_SINGLE) { MultiPanel->Visible = false; PatternPanel->Visible = false; SinglePanel->Visible = true; AirPanel->Height = SinglePanel->Top + SinglePanel->Height; } else if (AirType == PAT_MULTI) { SinglePanel->Visible = false; PatternPanel->Visible = false; MultiPanel->Visible = true; AirPanel->Height = MultiPanel->Top + MultiPanel->Height; } else if (AirType == PAT_PATTERN) { SinglePanel->Visible = false; MultiPanel->Visible = false; PatternPanel->Visible = true; AirPanel->Height = PatternPanel->Top + PatternPanel->Height; } ClientHeight = AirPanel->Top + AirPanel->Height; break; case PT_WATER : WaterPanel->Visible = true; WaterPanel->BringToFront(); InitWaterPanel(WaterType); ClientHeight = WaterPanel->Top + WaterPanel->Height; break; case PT_MASK : MaskPanel->Height = 50; MaskPanel->Visible = true; MaskPanel->BringToFront(); ClientHeight = MaskPanel->Top + MaskPanel->Height; break; default : if (spread_grade < 2) spread_grade = 2; if (252 - MainImageForm->Palette->UseColor - 1 > 70) interval = 70; else interval = 252 - MainImageForm->Palette->UseColor - 1; lGrade->Caption = Format("(2 - %d)", OPENARRAY(TVarRec, (interval))); EtcPanel->Visible = true; EtcPanel->BringToFront(); h = EtcSubPanel->Height; //============================================================== 2001.02.09 lhskys È®ÀÎ ¿ä¸Á if (SpreadPanel->Visible) { if (ScrapePanel->Visible || DensPanel->Visible || ColorPanel->Visible) { h += ColorPanel->Height; } SpreadPanel->Top = h; h += SpreadPanel->Height; aspread = true; } else { if (ScrapePanel->Visible || DensPanel->Visible || ColorPanel->Visible) { h += ColorPanel->Height; } } //=============================================================== 2001.02.09 lhskys ¿ä±â±îÁö EtcPanel->Height = h; ClientHeight = EtcPanel->Top + h; } btnUp->Visible = true; btnDown->Visible = false; } else if (MenuSW == true) { */ MenuSW = false; ClientHeight = FHeight; btnUp->Visible = false; btnDown->Visible = true; //==============================================================================lhskys if(SpreadPanel){ COLORREF c; //==================================================== 2001.02.09 lhskys È®ÀÎ ¿ä¸Á // aspread = false; // lSpread->Caption = AnsiString(IDS_SPREAD) + " : " + AnsiString(IDS_COMMON_OFF); // spread_sw[4] = 0; // lSelectDraw->Caption = IDS_SELECTCOLOR; //====================================================2001.02.09 lhskys ¿ä±â±îÁö if(DrawForm){ DrawForm->PointList = new TList; /*DrawForm->step = 0;*/ DrawForm->undos = 0; if (DrawForm->xkey){ DrawForm->step = 0; DrawForm->InitPointList(); }else DrawForm->AddPointList(DrawForm->Lsx, DrawForm->Lsy, c); } } //============================================================================== // } } void __fastcall TPenManagerForm::ResetClientHeight() { ClientHeight = FHeight; } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::LabelClick(TObject *Sender) { if(eGrade->Visible)EditKeyPress(eGrade, 13); else if(eScale->Visible)EditKeyPress(eScale, 13); TLabel *s; s = (TLabel *)Sender; // sePenSize->SetFocus(); if (s == lSpread) { if (aspread == false) { aspread = true; lSpread->Caption = AnsiString(IDS_SPREAD) + " : " + AnsiString(IDS_COMMON_ON); SpreadPanel->Visible = true; EtcPanel->Height = SpreadPanel->Top + SpreadPanel->Height; if (spread_grade < 2) spread_grade = 2; if (252 - MainImageForm->Palette->UseColor - 1 > 70) interval = 70; else interval = 252 - MainImageForm->Palette->UseColor - 1; lGrade->Caption = Format("(2 - %d)", OPENARRAY(TVarRec, (interval))); if (ScrapePanel->Visible || DensPanel->Visible || ColorPanel->Visible) { SpreadPanel->Top = DensPanel->Top + DensPanel->Height; } EtcPanel->Height = SpreadPanel->Top + SpreadPanel->Height; } else if (aspread == true) { lSelectDraw->Caption = IDS_SELECTCOLOR; spread_sw[4] = 0; //lhskys ¸ÕÀú aspread ¸¦ off... aspread = false; lSpread->Caption = AnsiString(IDS_SPREAD) + " : " + AnsiString(IDS_COMMON_OFF); SpreadPanel->Visible = false; if (ScrapePanel->Visible || DensPanel->Visible || ColorPanel->Visible) { EtcPanel->Height = DensPanel->Top + DensPanel->Height; } else { EtcPanel->Height = EtcSubPanel->Height; } } } else if (s == lColor) { if (acolor == 0) { Selector->Invalid(); acolor = 1; lColor->Caption = AnsiString(IDS_COLOR) + " : " + AnsiString(IDS_SELECT); ColorPanel->Visible = true; EtcPanel->Height = ColorPanel->Top + ColorPanel->Height; if (SpreadPanel->Visible) { SpreadPanel->Top = ColorPanel->Top + ColorPanel->Height; EtcPanel->Height += SpreadPanel->Height; } } else if (acolor == 1) { MainImageForm->iMainImage->InitBackGround(0x20); acolor = 2; lColor->Caption = AnsiString(IDS_COLOR) + " : " + AnsiString(IDS_COMMON_BUTTONYES); IsDraw = false; MainImageForm->iMainImage->OnPaintLocate = NULL;/////////////////by jeegeo step = 0; ::RepaintImage(); } else if (acolor == 2) { MainImageForm->iMainImage->ExitBackGround(0x20); acolor = 0; lColor->Caption = AnsiString(IDS_COLOR) + " : " + AnsiString(IDS_COMMON_BUTTONNO); ColorPanel->Visible = false; Selector->SaveToFile(DirectoryItem+"\\Pen.Ini", "Color"); if (SpreadPanel->Visible) { if (ScrapePanel->Visible || DensPanel->Visible) { SpreadPanel->Top = DensPanel->Top + DensPanel->Height; } else { SpreadPanel->Top = EtcSubPanel->Top + EtcSubPanel->Height; } EtcPanel->Height = SpreadPanel->Top + SpreadPanel->Height; } else { if (ScrapePanel->Visible || DensPanel->Visible) { EtcPanel->Height = DensPanel->Top + DensPanel->Height; } else { EtcPanel->Height = EtcSubPanel->Height; } } } MainImageForm->PenChange(); } else if (s == lSelectDraw) { if (spread_sw[4] == 0) { lSelectDraw->Caption = IDS_DRAWINGPEN; spread_sw[4] = 1; if (MainImageForm->iMainImage->uBitmap->BitsPerPixel==8) make_spread(); if (DrawForm && DrawForm->TaperLabel->Enabled == false)return; Selector->Invalid(); } else if (spread_sw[4] == 1) { lSelectDraw->Caption = IDS_SELECTCOLOR; spread_sw[4] = 0; } } ClientHeight = EtcPanel->Top + EtcPanel->Height; //=============================================================================lhskys if (DrawForm) { if (DrawForm->Lsx != NULL && DrawForm->Lsy != NULL) { int stx,sty; COLORREF c; if (penspread == 0){ if (spread_sw[4] == 1){ penspread = 1; stx = DrawForm->Lsx , sty = DrawForm->Lsy; DrawForm->iMainImageChange(); if (DrawForm->Line_type == 1 || DrawForm->Curve_type == 1) { DrawForm->PointList = new TList; /*DrawForm->step = 0;*/ DrawForm->undos = 0; pentaper = 0; DrawForm->Lsx = stx , DrawForm->Lsy = sty; if (DrawForm->xkey){ DrawForm->step = 0; DrawForm->InitPointList(); }else DrawForm->AddPointList(DrawForm->Lsx, DrawForm->Lsy, c); } } }else if(pentaper == 0){ if (spread_sw[4] == 0 && DrawForm->isTaper){ pentaper = 1; stx = DrawForm->Lsx , sty = DrawForm->Lsy; DrawForm->iMainImageChange(); if (DrawForm->Line_type == 1 || DrawForm->Curve_type == 1) { DrawForm-> PointList = new TList; /*DrawForm->step = 0;*/ DrawForm->undos = 0; penspread = 0; DrawForm->Lsx = stx , DrawForm->Lsy = sty; if (DrawForm->xkey){ DrawForm->step = 0; DrawForm->InitPointList(); }else DrawForm->AddPointList(DrawForm->Lsx, DrawForm->Lsy, c); } } } } } //============================================================================== } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::EditKeyPress(TObject *Sender, char &Key) { TEdit *s; s = (TEdit *)Sender; if (Key == 13) { if (s == eScale) { } else if (s == eGrade) { if ( StrToInt(s->Text) > 70 ) s->Text = "70"; spread_grade = StrToInt(s->Text); } else { if (AirColorList->Count >= s->Tag + 1) { InputPercent(Sender); } } PenManagerForm->SetFocus(); //lhskys zŰ ½ÇÇàÀ» À§ÇØ } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::EditMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { TEdit *s; s = (TEdit *)Sender; if (s == eGrade) { if (spread_sw[4] == 0) { s->SetFocus(); s->SelectAll(); } } else if (s == eScale) { s->SetFocus(); s->SelectAll(); } else { if (AirColorList->Count >= s->Tag + 1) { s->SetFocus(); s->SelectAll(); } } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::sbNewClick(TObject *Sender) { TSpeedButton *s; TCursor cursor; s = (TSpeedButton *)Sender; if (s == sbNew) { Selector->Initial(); } else if (s == sbAll) { cursor = Screen->Cursor; Screen->Cursor = crHourGlass; if (MainImageForm->WorkArea->Mask) MainImageForm->SearchWorkAreaColor(Selector->ChoiceColor); else MainImageForm->SearchWholeColor(Selector->ChoiceColor); Selector->Invalid(); Screen->Cursor = cursor; } else if (s == sbBlock) { if (sbBlock->Down) sbBlock->Hint = IDS_COMMON_ONECOLOR; else sbBlock->Hint = IDS_COMMON_BLOCKCOLOR; } else if (s == sbDelete) { if (sbDelete->Down) sbDelete->Hint = IDS_COMMON_DELETECOLOR; else sbDelete->Hint = IDS_COMMON_INSERTCOLOR; } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::sbBeforeClick(TObject *Sender) { Selector->LoadFromFile(DirectoryItem+"\\Pen.Ini", "Color"); } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::seDensityChange(TObject *Sender) { if (seDensity->Text.Length()>0) { density = seDensity->Value; } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::ShapeMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { TShape *s; s = (TShape *)Sender; if (s == shFirst) { shFirst->Pen->Color = clRed; shSecond->Pen->Color = clBlack; spread_pos = 0; } else if (s == shSecond) { shFirst->Pen->Color = clBlack; shSecond->Pen->Color = clRed; spread_pos = 1; } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::FormClick(TObject *Sender) { Show(); } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::FormClose(TObject *Sender, TCloseAction &Action) { Visible = false; if (FOnUpdateMenu) FOnUpdateMenu(Sender); } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::FormCreate(TObject *Sender) { //=============================== 2001.5.3 lhskys FormCreate(TObject *Sender)³»¿ë ¿Å±è hLibrary = LoadLibrary("ltdlg10n.dll"); } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::FormDestroy(TObject *Sender) { TColorList *pcolor; while (AirColorList->Count > 0) { pcolor = (TColorList *) AirColorList->Last(); AirColorList->Remove(pcolor); delete pcolor; } if (AirColorList) delete AirColorList; if (Pen) delete Pen; if (Random) delete Random; if(lineItr) delete lineItr; FreeLibrary(hLibrary); } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::WaterFuctionClick(TObject *Sender) { TSpeedButton *s = (TSpeedButton *) Sender; InitWaterPanel(s->Tag); } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::ScrollBarColorScroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { cr[WaterType] = ScrollPos/100.0; ColorLabel->Caption = ScrollPos; } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::ScrollBarEffectScroll(TObject *Sender, TScrollCode ScrollCode, int &ScrollPos) { if (WaterType == PWT_AVERAGE){ spEditDensity->Value = ScrollPos; EffectLabel->Caption = ScrollPos; return; } or[WaterType] = ScrollPos/100.0; EffectLabel->Caption = ScrollPos; } //--------------------------------------------------------------------------- // Private Function //--------------------------------------------------------------------------- /* void TPenManagerForm::WMEXITSIZEMOVE(TMessage &msg) { if ((Left <= MainForm->PenFormPos.x + 100) && (Left >= MainForm->PenFormPos.x - 100)) { if ((Top <= MainForm->PenFormPos.y + 100) && (Top >= MainForm->PenFormPos.y - 100)) { Top = MainForm->PenFormPos.y; Left = MainForm->PenFormPos.x; } } } */ //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::AirFunctionClick(TObject *Sender) { TSpeedButton *s; RGBQUAD rgb[256]; int Tx, Ty; TPItemImage *Image = MainImageForm->iMainImage; s = (TSpeedButton *)Sender; if (s == sbSingle) { AirSelectColor->Brush->Color = MainImageForm->Palette->Color[PaletteForm->DIB256Palette->ChoiceIndex]; AirType = PAT_SINGLE; MultiPanel->Visible = false; PatternPanel->Visible = false; SinglePanel->Visible = true; AirPanel->Height = SinglePanel->Top + SinglePanel->Height; ClientHeight = AirPanel->Top + AirPanel->Height; } else if (s == sbMulti) { AirType = PAT_MULTI; SinglePanel->Visible = false; PatternPanel->Visible = false; MultiPanel->Visible = true; AirPanel->Height = MultiPanel->Top + MultiPanel->Height; ClientHeight = AirPanel->Top + AirPanel->Height; // seMDotNum->SetFocus(); } else if (s == sbPattern) { AirType = PAT_PATTERN; SinglePanel->Visible = false; MultiPanel->Visible = false; PatternPanel->Visible = true; AirPanel->Height = PatternPanel->Top + PatternPanel->Height; ClientHeight = AirPanel->Top + AirPanel->Height; Tx = MainImageForm->WorkArea->Range.right - MainImageForm->WorkArea->Range.left; Ty = MainImageForm->WorkArea->Range.bottom - MainImageForm->WorkArea->Range.top; Screen->Cursor = crHourGlass; if (Image->uBitmap->BitsPerPixel==8) { MainImageForm->Palette->ToRGBQUAD(rgb, 256); if (!(Image1->Bitmap->Create(Tx, Ty, 8, rgb))) goto fail; } else { if (!(Image1->Bitmap->Create(Tx, Ty, 24))) goto fail; } /* Image1->Bitmap->CopyFromRect(Image->uBitmap, MainImageForm->WorkArea->Range.left, MainImageForm->WorkArea->Range.top, SRCCOPY);*/ Image->uBitmap->CopyToTexpia(Image1->Bitmap, 0, 0, Image1->Bitmap->Width, Image1->Bitmap->Height, MainImageForm->WorkArea->Range.left, MainImageForm->WorkArea->Range.top, SRCCOPY); // convert by celberus Screen->Cursor = crDefault; } return; fail: Screen->Cursor = crDefault; EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::sePDotNumChange(TObject *Sender) { if (sePDotNum->Text.Length() > 0) { if (sePDotNum->Value > sePDotNum->MaxValue) sePDotNum->Value = sePDotNum->MaxValue; else if (sePDotNum->Value < sePDotNum->MinValue) sePDotNum->Value = sePDotNum->MinValue; } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::sePNozzleChange(TObject *Sender) { if (sePNozzle->Text.Length() > 0) { if (sePNozzle->Value > sePNozzle->MaxValue) sePNozzle->Value = sePNozzle->MaxValue; else if (sePNozzle->Value < sePNozzle->MinValue) sePNozzle->Value = sePNozzle->MinValue; } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::shAirColorMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { TShape *sh = (TShape *)Sender; if (AirColorList->Count >= sh->Tag + 1) { DeleteAirColorPalette(sh->Tag); ChangeAirColorPalette(sh->Tag, true); } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::seMDotNumChange(TObject *Sender) { if (seMDotNum->Text.Length() > 0) { if (seMDotNum->Value > seMDotNum->MaxValue) seMDotNum->Value = seMDotNum->MaxValue; else if (seMDotNum->Value < seMDotNum->MinValue) seMDotNum->Value = seMDotNum->MinValue; } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::seMNozzleChange(TObject *Sender) { if (seMNozzle->Text.Length() > 0) { if (seMNozzle->Value > seMNozzle->MaxValue) seMNozzle->Value = seMNozzle->MaxValue; else if (seMNozzle->Value < seMNozzle->MinValue) seMNozzle->Value = seMNozzle->MinValue; } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::sbClearClick(TObject *Sender) { RECT r; SetRect(&r, 0, 0, MainImageForm->iMainImage->uBitmap->Width, MainImageForm->iMainImage->uBitmap->Height); // MainImageForm->UndoSave(UK_MASK, r, true); MainImageForm->UndoSave(UK_MASK,Rect(0,0,0,0)); //by linxujun for Undo_Method MainImageForm->iMainImage->Mask->FillRect(r, 0x00); ::RepaintImage(); } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::chDeleteClick(TObject *Sender) { if (MainImageForm->iMainImage->uBitmap->BitsPerPixel==8) { MainImageForm->OnSetHLine = MainImageForm->SetHLineMask8; if (chDelete->Checked) { MainImageForm->MaskPixel = 0x00; } else { MainImageForm->MaskPixel = 0x0F; } } else { if (chDelete->Checked) { MainImageForm->OnSetHLine = MainImageForm->SetHLineMaskDelete24; MainImageForm->MaskPixel = 0x00; } else { MainImageForm->OnSetHLine = MainImageForm->SetHLineMask24; MainImageForm->MaskPixel = 0x80; } } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::chReversalClick(TObject *Sender) { int x, y, w, h; Byte *bp = NULL, m; w = MainImageForm->iMainImage->Mask->Width; h = MainImageForm->iMainImage->Mask->Height; if ((MainImageForm->iMainImage->Mask->StartScanLine()) == false) goto fail; if (MainImageForm->iMainImage->uBitmap->BitsPerPixel == 8) { for (y=0; yiMainImage->Mask->GetScanLine(y); // for (x=0; xiMainImage->Mask->PutScanLine(y,0,w); // } } else { for (y=0; yiMainImage->Mask->GetScanLine(y); // /* m = 0x80; for (x = 0; x < w; x++) { if (*bp & m) *bp &= ~m; else *bp |= m; if (m == 1) { m = 0x80; bp++; } else m >>= 1; } */ for (x=0; x>3] ^= (0x80>>(x&7)); } MainImageForm->iMainImage->Mask->PutScanLine(y,0,w); // } } MainImageForm->iMainImage->Mask->StopScanLine(); MainImageForm->iMainImage->Repaint(); return; fail: EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::ChangeAirColorPalette(int index, bool del) { int i, count, cnt, modify, chcnt; TColorList *Temp, *Temp2; int TotalValue, DivValue; TShape *s; TEdit *e; TotalValue = 0; DivValue = 0; count = 0; modify = 0; for (i = 1; i <= AirColorList->Count; i++) { Temp = (TColorList *)(AirColorList->Items[i - 1]); if (Temp->modify) { TotalValue += Temp->percent; modify++; } else { count++; } } if (count) { DivValue = double(100 - TotalValue) / count; } else { if (modify > 1) { if (del) chcnt = modify; else chcnt = modify - 1; DivValue = (100 - TotalValue) / chcnt; } else DivValue = 100; } cnt = 0; for (i = 1; i <= 18; i++) { if (i <= AirColorList->Count) { Temp = (TColorList *)(AirColorList->Items[i - 1]); s = (TShape *)(FindComponent("shAirColor" + AnsiString(i))); s->Brush->Color = MainImageForm->Palette->Color[Temp->color]; if (AirColorList->Count == 1) { Temp->modify = false; Temp->percent = 100; } else { if (Temp->modify == false) { //°ªÀ» ¼öÁ¤ÇÏÁö ¾ÊÀº°Í cnt++; if (cnt == count) { Temp->percent = abs(100 - (DivValue * (count - 1) + TotalValue)); } else { Temp->percent = DivValue; } } else if ((count == 0) && (modify >1)) { //°ªÀ» ¼öÁ¤ÇÏÁö ¾ÊÀº °ÍÀÌ ¾ø°í cnt++; //°ªÀ» ¼öÁ¤ÇÑ °Í¸¸ ¿©·¯°³ ³²Àº °æ¿ì if (i-1 != index) { Temp->percent += DivValue; } if (cnt == modify) { if (cnt-1 == index) { Temp2 = (TColorList *)AirColorList->Items[index - 1]; Temp2->percent += abs(100 - (DivValue * chcnt + TotalValue)); e = (TEdit *)(FindComponent("Edit" + AnsiString(i-1))); e->Text = Temp2->percent; } else { Temp->percent += abs(100 - (DivValue * chcnt + TotalValue)); } } } } e = (TEdit *)(FindComponent("Edit" + AnsiString(i))); e->Text = Temp->percent; } else { s = (TShape *)(FindComponent("shAirColor" + AnsiString(i))); s->Brush->Color = clWhite; e = (TEdit *)(FindComponent("Edit" + AnsiString(i))); e->Text = "0"; } } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::DeleteAirColorPalette(int index) { //AirColorList->Delete(index); TColorList *pcolor = (TColorList *) AirColorList->Items[index]; AirColorList->Remove(pcolor); delete pcolor; } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::InputPercent(TObject *Sender) { int i, TotalValue, Percent, Not; TEdit *s; TColorList *Temp; s = (TEdit *)Sender; TotalValue = 0; Not = 0; for (i = 0; i < AirColorList->Count; i++) { if (i != s->Tag) { Temp = (TColorList *)(AirColorList->Items[i]); if (Temp->modify == false) Not++; else TotalValue += Temp->percent; } } Percent = StrToInt(s->Text); if (Percent > 100 - TotalValue - Not) Percent = 100 - TotalValue - Not; Temp = (TColorList *)(AirColorList->Items[s->Tag]); Temp->percent = Percent; Temp->modify = true; ChangeAirColorPalette(s->Tag); } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::drawFilledRectangle(TPItemImage *Image, int startX, int startY, int width, int height, COLORREF color) { lineItr->setBaseColor(color); for(int y = startY; y < startY + height; y++ ) { if(y >= 0 && y < Image->uBitmap->Height) { lineItr->getScanLine(y, startX, width); // for(int x = startX; x < startX + width; x++ ) { if (x >=0 && x < Image->uBitmap->Width) { lineItr->putPixel(x); } } lineItr->putScanLine(y, startX, width); // } } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::drawFilledRectangle_pattern(TPItemImage *Image, int startX, int startY, int width, int height) { Byte *pPatternLine; int patternX, patternY; RECT rect = MainImageForm->WorkArea->Range; for(int y = startY; y < startY + height; y++ ) { patternY = getMappingPosition(y, rect.top, rect.bottom); if(y >= 0 && y < Image->uBitmap->Height) { lineItr->getScanLine(y, startX, width); // pPatternLine = Image1->Bitmap->GetScanLine(patternY); // for(int x = startX; x < startX + width; x++ ) { patternX = getMappingPosition(x, rect.left, rect.right); lineItr->setBaseColor(lineItr->pickColor(pPatternLine, patternX)); if (x >=0 && x < Image->uBitmap->Width) { lineItr->putPixel(x); } } lineItr->putScanLine(y, startX, width); // } } } //--------------------------------------------------------------------------- int __fastcall TPenManagerForm::getMappingPosition(int value, int lowBound, int highBound) { if (value < lowBound) return highBound - (lowBound - value) % (highBound - lowBound) - lowBound -1; else return (value - lowBound) % (highBound - lowBound); } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::drawAirbrushImage(TPItemImage *Image, double drawDensity, int drawNozzle, COLORREF color) { int i, x, y, penWidth, randomNumber; double radius, angle; penWidth = Pen->Thick / 2 + 1; i = 0; while (i < drawDensity) { randomNumber = Random->Get(360); radius = randomNumber % penWidth; angle = DegToRad(randomNumber % 360); x = Lsx + radius * cos(angle); y = Lsy + radius * sin(angle); if (drawNozzle == 1) { drawFilledRectangle(Image, x, y, 1, 1, color); } else if (drawNozzle == 2) { if (x & 1) { // odd drawFilledRectangle(Image, x, y, 2, 1, color); } else { // even drawFilledRectangle(Image, x, y, 1, 2, color); } } else if (drawNozzle == 3) { drawFilledRectangle(Image, x, y, 2, 2, color); } else if (drawNozzle == 4) { if (x & 1) { // odd drawFilledRectangle(Image, x-1, y, 3, 2, color); } else { // even drawFilledRectangle(Image, x, y-1, 2, 3, color); } } else { // nozzle == 5 drawFilledRectangle(Image, x-1, y-1, 3, 3, color); } i++; } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::set_airbrush_pen_single(TPItemImage *Image) { COLORREF color; double drawDensity = seSDotNum->Value; int drawNozzle = seSNozzle->Value; color = getSelectedPaletteColor(Image->uBitmap->BitsPerPixel); drawAirbrushImage(Image, drawDensity, drawNozzle, color); } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::set_airbrush_pen_multi(TPItemImage *Image) { int j; TColorList *V; COLORREF color; double drawDensity; int denvalue = seMDotNum->Value; int drawNozzle = seMNozzle->Value; if (AirColorList->Count > 0) { for (j = 0; j < AirColorList->Count; j++) { V = (TColorList *) AirColorList->Items[j]; drawDensity = denvalue * V->percent / 100.0; color = getListColor(V, Image->uBitmap->BitsPerPixel); drawAirbrushImage(Image, drawDensity, drawNozzle, color); } } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::set_airbrush_pen_pattern(TPItemImage *Image) { int i, x, y, penWidth, randomNumber; double radius, angle, drawDensity; penWidth = Pen->Thick / 2 + 1; drawDensity = sePDotNum->Value; i = 0; while (i < drawDensity) { randomNumber = Random->Get(360); radius = randomNumber % penWidth; angle = DegToRad(randomNumber % 360); x = Lsx + radius * cos(angle); y = Lsy + radius * sin(angle); if (sePNozzle->Value == 1) { drawFilledRectangle_pattern(Image, x, y, 1, 1); } else if (sePNozzle->Value == 2) { if (x & 1) { // odd drawFilledRectangle_pattern(Image, x, y, 2, 1); } else { // even drawFilledRectangle_pattern(Image, x, y, 1, 2); } } else if (sePNozzle->Value == 3) { drawFilledRectangle_pattern(Image, x, y, 2, 2); } else if (sePNozzle->Value == 4) { if (x & 1) { // odd drawFilledRectangle_pattern(Image, x-1, y, 3, 2); } else { // even drawFilledRectangle_pattern(Image, x, y-1, 2, 3); } } else { // nozzle == 5 drawFilledRectangle_pattern(Image, x-1, y-1, 3, 3); } i++; } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::set_airbrush_pen(void) { TPItemImage *Image = MainImageForm->iMainImage; if (AirType == PAT_SINGLE) { set_airbrush_pen_single(Image); } else if (AirType == PAT_MULTI) { set_airbrush_pen_multi(Image); } else if (AirType == PAT_PATTERN) { set_airbrush_pen_pattern(Image); } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::line_airbrush_pen(void) { int sx, sy, ex, ey, i; double dx, dy; double slopex, slopey; TPItemImage *Image = MainImageForm->iMainImage; RECT rect; int ls, rs; ls = Pen->Thick >> 1; rs = Pen->Thick - ls; if(lineItr) { delete lineItr; lineItr = NULL; } if (Image->LayerMask) { if (MainImageForm->MaskArea) { lineItr = (LineItr *)new LineItr_Layer_Mask(Image); } else { lineItr = (LineItr *)new LineItr_Layer(Image); } } else { if (MainImageForm->MaskArea) { lineItr = (LineItr *)new LineItr_Mask(Image); } else { lineItr = (LineItr *)new LineItr(Image); } } lineItr->setColorProtected(MainImageForm->Protect); if (lineItr->startScanLine() == false) goto fail; if (AirType == PAT_PATTERN) { if (Image1->Bitmap->StartScanLine() == false) goto fail; } sx = Lsx; ex = Lex; sy = Lsy; ey = Ley; dx = ex - sx; dy = ey - sy; if (sx == ex) { if (sy == ey) { set_airbrush_pen(); } else { Lsx = sx; if (sy < ey) { for (i = sy; i <= ey; i += 3) { Lsy = i; set_airbrush_pen(); } } else { for (i = sy; i >= ey; i -= 3) { Lsy = i; set_airbrush_pen(); } } } } else { if (sy == ey) { Lsy = sy; if (sx < ex) { for (i = sx; i <= ex; i += 3) { Lsx = i; set_airbrush_pen(); } } else { for (i = sx; i >= ex; i -= 3) { Lsx = i; set_airbrush_pen(); } } } else { slopex = dy / dx; slopey = dx / dy; if (sx < ex) { if (sy < ey) { if (fabs(slopex) < 1.0) { for (i = sx; i <= ex; i += 3) { Lsx = i; Lsy = slopex * (Lsx - sx) + sy; set_airbrush_pen(); } } else { for (i = sy; i <= ey; i += 3) { Lsy = i; Lsx = slopey * (Lsy - sy) + sx; set_airbrush_pen(); } } } else { if (fabs(slopex) < 1.0) { for (i = sx; i <= ex; i += 3) { Lsx = i; Lsy = slopex * (Lsx - sx) + sy; set_airbrush_pen(); } } else { for (i = sy; i >= ey; i -= 3) { Lsy = i; Lsx = slopey * (Lsy - sy) + sx; set_airbrush_pen(); } } } } else { if (sy < ey) { if (fabs(slopex) < 1.0) { for (i = sx; i >= ex; i -= 3) { Lsx = i; Lsy = slopex * (Lsx - sx) + sy; set_airbrush_pen(); } } else { for (i = sy; i <= ey; i += 3) { Lsy = i; Lsx = slopey * (Lsy - sy) + sx; set_airbrush_pen(); } } } else { if (fabs(slopex) < 1.0) { for (i = sx; i >= ex; i -= 3) { Lsx = i; Lsy = slopex * (Lsx - sx) + sy; set_airbrush_pen(); } } else { for (i = sy; i >= ey; i -= 3) { Lsy = i; Lsx = slopey * (Lsy - sy) + sx; set_airbrush_pen(); } } } } } } if (AirType == PAT_PATTERN) { Image1->Bitmap->StopScanLine(); } lineItr->stopScanLine(); rect.left = min(sx, ex) - ls; rect.top = min(sy, ey) - ls; rect.right = max(sx, ex) + rs; rect.bottom = max(sy, ey) + rs; if(update)Image->RectPaint(rect); Lsx = sx; Lex = ex; Lsy = sy; Ley = ey; return; fail : if (AirType == PAT_PATTERN) { Image1->Bitmap->StopScanLine(); } EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::set_brush_spread_pen(int lsx, int lsy, int size, COLORREF color) { int sx, sy, x, y, s, e, pw; TPItemImage *Image = MainImageForm->iMainImage; pw = size; sx = lsx - MAX_PEN_HALF_WIDTH; sy = lsy - MAX_PEN_HALF_WIDTH; s = MAX_PEN_LEFT_CENTER - pw / 2.0; e = MAX_PEN_HALF_WIDTH + pw / 2.0; if(lineItr) { delete lineItr; lineItr = NULL; } if (Image->LayerMask) { if (MainImageForm->MaskArea) { lineItr = (LineItr *)new LineItr_Layer_Mask(Image); } else { lineItr = (LineItr *)new LineItr_Layer(Image); } } else { if (MainImageForm->MaskArea) { lineItr = (LineItr *)new LineItr_Mask(Image); } else { lineItr = (LineItr *)new LineItr(Image); } } lineItr->setColorProtected(MainImageForm->Protect); lineItr->setBaseColor(color); if (lineItr->startScanLine() == false) goto fail; if (Image->uBitmap->BitsPerPixel==8) { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Image->uBitmap->Height)) { lineItr->getScanLine(sy + y, sx + s, e - s + 1); // for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Image->uBitmap->Width)) { if ((pshape[Pen->Shape].size[pw - 1].dot[y][x]) && (acolor != 2 || Selector->Number[lineItr->pickColor(sx + x)] < 255)) { // ¼±ÅÃÇÑ color¿¡¸¸ ±×¸®±â ¿É¼Ç lineItr->putPixel(sx + x); } } } lineItr->putScanLine(sy + y, sx + s, e - s + 1); // } } } else { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Image->uBitmap->Height)) { lineItr->getScanLine(sy + y, sx + s, e - s + 1); // for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Image->uBitmap->Width)) { if (pshape[Pen->Shape].size[pw - 1].dot[y][x]) { lineItr->putPixel(sx + x); } } } lineItr->putScanLine(sy + y, sx + s, e - s + 1); // } } } lineItr->stopScanLine(); return; fail : EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::set_crayon_brush_spread_pen(int lsx, int lsy, int size, COLORREF color) { int s, e, sx, sy, x, y, pw, p; int ran; TPItemImage *Image = MainImageForm->iMainImage; if(lineItr) { delete lineItr; lineItr = NULL; } if (Image->LayerMask) { if (MainImageForm->MaskArea) { lineItr = (LineItr *)new LineItr_Layer_Mask(Image); } else { lineItr = (LineItr *)new LineItr_Layer(Image); } } else { if (MainImageForm->MaskArea) { lineItr = (LineItr *)new LineItr_Mask(Image); } else { lineItr = (LineItr *)new LineItr(Image); } } lineItr->setColorProtected(MainImageForm->Protect); lineItr->setBaseColor(color); pw = size; sx = lsx - MAX_PEN_HALF_WIDTH; sy = lsy - MAX_PEN_HALF_WIDTH; s = MAX_PEN_LEFT_CENTER - pw / 2.0; e = MAX_PEN_HALF_WIDTH + pw / 2.0; if (pw <= 0) p = 1; else p = pw; if (density == 1) { ran = 5000 / p; } else if (density == 2) { ran = 12000 / p; } else if (density == 3) { ran = 18000 / p; } else if (density == 4) { ran = 24000 / p; } else { ran = 30000 / p; } if(lineItr->startScanLine() == false) goto fail; if (Image->uBitmap->BitsPerPixel==8) { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Image->uBitmap->Height)) { lineItr->getScanLine(sy + y, sx + s, e - s + 1); // for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Image->uBitmap->Width)) { if ((pshape[Pen->Shape].size[pw - 1].dot[y][x]) && (rand() < ran) && (acolor != 2 || Selector->Number[lineItr->pickColor(sx + x)] < 255)) { lineItr->putPixel(sx + x); } } } lineItr->putScanLine(sy + y, sx + s, e - s + 1); // } } } else { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Image->uBitmap->Height)) { lineItr->getScanLine(sy + y, sx + s, e - s + 1); // for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Image->uBitmap->Width)) { if ((pshape[Pen->Shape].size[pw - 1].dot[y][x]) && (rand() < ran)) { lineItr->putPixel(sx + x); } } } lineItr->putScanLine(sy + y, sx + s, e - s + 1); // } } } lineItr->stopScanLine(); return; fail : EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::set_brush_mask_pen(int lsx, int lsy, int size) { int sx, sy, x, y, s, e, pw; Byte *P; TPItemImage *Image = MainImageForm->iMainImage; pw = size; sx = lsx - MAX_PEN_HALF_WIDTH; sy = lsy - MAX_PEN_HALF_WIDTH; s = MAX_PEN_LEFT_CENTER - pw / 2.0; e = MAX_PEN_HALF_WIDTH + pw / 2.0; if (Image->Mask->StartScanLine() == false) goto fail; if (Image->uBitmap->BitsPerPixel == 8) { if (chDelete->Checked) { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Image->uBitmap->Height)) { P = Image->Mask->GetScanLine(sy + y, sx + s, e - s + 1); // for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Image->uBitmap->Width)) { if (pshape[Pen->Shape].size[pw - 1].dot[y][x]) { P[sx + x] = 0x00; } } } Image->Mask->PutScanLine(sy + y, sx + s, e - s + 1); // } } } else { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Image->uBitmap->Height)) { P = Image->Mask->GetScanLine(sy + y, sx + s, e - s + 1); // for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Image->uBitmap->Width)) { if (pshape[Pen->Shape].size[pw - 1].dot[y][x]) { P[sx + x] = 0x0F; } } } Image->Mask->PutScanLine(sy + y, sx + s, e - s + 1); // } } } } else { if (chDelete->Checked) { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Image->uBitmap->Height)) { P = Image->Mask->GetScanLine(sy + y, sx + s, e - s + 1); // for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Image->uBitmap->Width)) { if (pshape[Pen->Shape].size[pw - 1].dot[y][x]) { P[(sx + x) >> 3] &= ~(0x80 >> ((sx + x) & 7)); } } } Image->Mask->PutScanLine(sy + y, sx + s, e - s + 1); // } } } else { for (y = s; y <= e; y++) { if ((sy + y >= 0) && (sy + y < Image->uBitmap->Height)) { P = Image->Mask->GetScanLine(sy + y, sx + s, e - s + 1); // for (x = s; x <= e; x++) { if ((sx + x >= 0) && (sx + x < Image->uBitmap->Width)) { if (pshape[Pen->Shape].size[pw - 1].dot[y][x]) { P[(sx + x) >> 3] |= (0x80 >> ((sx + x) & 7)); } } } Image->Mask->PutScanLine(sy + y, sx + s, e - s + 1); // } } } } Image->Mask->StopScanLine(); return; fail : Image->Mask->StopScanLine(); EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::init_pressure_pen() { int i, j, k, l, cx, cy, sx, sy, a, t; double r; for (i = 0; i <= 1; i++) { for (j = 0; j <= 49; j++) { for (k = 0; k <= 50; k++) { for (l = 0; l <= 50; l++) { pshape[i].size[j].dot[k][l] = 0; } } } } cx = MAX_PEN_HALF_WIDTH; cy = MAX_PEN_HALF_WIDTH; pshape[0].size[0].dot[cy][cx] = 1; for (j = 0; j <= 49; j++) { r = (j + 1.0) / 2.0; t = r; if (j & 1) { for (k = 0; k <= t - 1; k++) { l = sqrt(t * t - (k + 0.5) * (k + 0.5)) + 0.5; for (a = cx - l; a <= cx + l; a++) { pshape[0].size[j].dot[cy + k][a] = 1; pshape[0].size[j].dot[cy - k - 1][a] = 1; } } } else { for (k = 0; k <= t; k++) { l = sqrt(r * r - k * k); for (a = cx - l; a <= cx + l; a++) { pshape[0].size[j].dot[cy + k][a] = 1; pshape[0].size[j].dot[cy - k][a] = 1; } } } } pshape[1].size[0].dot[cy][cx] = 1; for (j = 1; j <= 49; j++) { sx = cx - (j + 1) / 2.0; sy = cy - (j + 1) / 2.0; for (k = sy; k <= sy + j; k++) { for (l = sx; l <= sx + j; l++) { pshape[1].size[j].dot[k][l] = 1; } } } } /*--------------------------------------------------------------------------- void __fastcall TPenManagerForm::point_pressure_pen(int lsx, int lsy, int size, COLORREF color) { TColor rgb; RGBQUAD m_rgb[3]; if (T_NONE == MainMenuForm->Item) { if (MainForm->MainImageForm->iMainImage->uBitmap->BitsPerPixel==8) { if (Type == PT_NORMAL) { set_brush_spread_pen(lsx, lsy, size, color); } else if (Type == PT_CRAYON) { set_crayon_brush_spread_pen(lsx, lsy, size, color); } } else { if (aspread) { m_rgb[0] = MainForm->MainImageForm->Palette->ColorData[spread_start]->RGB; m_rgb[1] = MainForm->MainImageForm->Palette->ColorData[spread_end]->RGB; m_rgb[2].rgbRed = m_rgb[0].rgbRed+color*(m_rgb[1].rgbRed-m_rgb[0].rgbRed)/255; m_rgb[2].rgbGreen = m_rgb[0].rgbGreen+color*(m_rgb[1].rgbGreen-m_rgb[0].rgbGreen)/255; m_rgb[2].rgbBlue = m_rgb[0].rgbBlue+color*(m_rgb[1].rgbBlue-m_rgb[0].rgbBlue)/255; rgb = RGBToTColor(m_rgb[2]); } else { rgb = MainForm->MainImageForm->Palette->Color[color]; } if (Type == PT_NORMAL) { set_brush_spread_pen(lsx, lsy, size, rgb); } else if (Type == PT_CRAYON) { set_crayon_brush_spread_pen(lsx, lsy, size, rgb); } } } else if (T_PATTERN == MainMenuForm->Item) { #ifndef ACADEMY if (Type == PT_NORMAL) { if (PatternRepeatForm->Item == T_REGULAR) set_brush_spread_regular_pattern_pen(lsx, lsy, size, color); else set_brush_spread_irregular_pattern_pen(lsx, lsy, size, color); } else if (Type == PT_CRAYON) { if (PatternRepeatForm->Item == T_REGULAR) set_crayon_brush_spread_regular_pattern_pen(lsx, lsy, size, color); else set_crayon_brush_spread_irregular_pattern_pen(lsx, lsy, size, color); } #endif } } */ //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::point_pressure_pen(int lsx, int lsy, int size, COLORREF color) { TColor rgb; RGBQUAD m_rgb[3]; if (MainImageForm->iMainImage->uBitmap->BitsPerPixel==8) { if (Type == PT_NORMAL) { set_brush_spread_pen(lsx, lsy, size, color); } else if (Type == PT_CRAYON) { set_crayon_brush_spread_pen(lsx, lsy, size, color); } else if (Type == PT_MASK) { set_brush_mask_pen(lsx, lsy, size); } } else { if (aspread) { m_rgb[0] = MainImageForm->Palette->ColorData[spread_start]->RGB; m_rgb[1] = MainImageForm->Palette->ColorData[spread_end]->RGB; m_rgb[2].rgbRed = m_rgb[0].rgbRed+color*(m_rgb[1].rgbRed-m_rgb[0].rgbRed)/Tablet->MaxNPressure; m_rgb[2].rgbGreen = m_rgb[0].rgbGreen+color*(m_rgb[1].rgbGreen-m_rgb[0].rgbGreen)/Tablet->MaxNPressure; m_rgb[2].rgbBlue = m_rgb[0].rgbBlue+color*(m_rgb[1].rgbBlue-m_rgb[0].rgbBlue)/Tablet->MaxNPressure; rgb = RGBToTColor(m_rgb[2]); } else { rgb = MainImageForm->Palette->Color[color];//color; } if (Type == PT_NORMAL) { set_brush_spread_pen(lsx, lsy, size, rgb); } else if (Type == PT_CRAYON) { set_crayon_brush_spread_pen(lsx, lsy, size, rgb); } else if (Type == PT_MASK) { set_brush_mask_pen(lsx, lsy, size); } } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::line_pressure_pen(int pw, COLORREF spc) { int size, sx, sy, ex, ey, pwl, pcl; COLORREF color; double pwx, pwy, pcx, pcy; double dx, dy; double slopex, slopey; TPItemImage *Image = MainImageForm->iMainImage; RECT rect; int ls, rs; ls = pw >> 1; rs = pw - ls; sx = Lsx; ex = Lex; sy = Lsy; ey = Ley; dx = ex - sx; dy = ey - sy; pwl = pw - o_size; if (dx == 0) pwx = pwl; else pwx = pwl / fabs(dx); if (dy == 0) pwy = pwl; else pwy = pwl / fabs(dy); pcl = spc - o_color; if (dx == 0) pcx = pcl; else pcx = pcl / fabs(dx); if (dy == 0) pcy = pcl; else pcy = pcl / fabs(dy); if (sx == ex) { if (sy == ey) { if (o_size < pw) { FPointPressurePen(Lsx, Lsy, pw, spc); } } else { Lsx = sx; if (sy < ey) { for (Lsy = sy; Lsy <= ey; Lsy++) { size = o_size + (Lsy - sy) * pwy + 0.5; color = o_color + (Lsy - sy) * pcy + 0.5; FPointPressurePen(Lsx, Lsy, size, color); } } else { for (Lsy = sy; Lsy >= ey; Lsy--) { size = o_size + (sy - Lsy) * pwy + 0.5; color = o_color + (sy - Lsy) * pcy + 0.5; FPointPressurePen(Lsx, Lsy, size, color); } } } } else { if (sy == ey) { Lsy = sy; if (sx < ex) { for (Lsx = sx; Lsx <= ex; Lsx++) { size = o_size + (Lsx - sx) * pwx + 0.5; color = o_color + (Lsx - sx) * pcx + 0.5; FPointPressurePen(Lsx, Lsy, size, color); } } else { for (Lsx = sx; Lsx >= ex; Lsx--) { size = o_size + (sx - Lsx) * pwx + 0.5; color = o_color + (sx - Lsx) * pcx + 0.5; FPointPressurePen(Lsx, Lsy, size, color); } } } else { slopex = dy / dx; slopey = dx / dy; if (sx < ex) { if (sy < ey) { if (fabs(slopex) < 1.0) { for (Lsx = sx; Lsx <= ex; Lsx++) { Lsy = slopex * (Lsx - sx) + sy; size = o_size + pwx * (Lsx - sx) + 0.5; color = o_color + pcx * (Lsx - sx) + 0.5; FPointPressurePen(Lsx, Lsy, size, color); } } else { for (Lsy = sy; Lsy <= ey; Lsy++) { Lsx = slopey * (Lsy - sy) + sx; size = o_size + pwy * (Lsy - sy) + 0.5; color = o_color + pcy * (Lsy - sy) + 0.5; FPointPressurePen(Lsx, Lsy, size, color); } } } else { if (fabs(slopex) < 1.0) { for (Lsx = sx; Lsx <= ex; Lsx++) { Lsy = slopex * (Lsx - sx) + sy; size = o_size + pwx * (Lsx - sx) + 0.5; color = o_color + pcx * (Lsx - sx) + 0.5; FPointPressurePen(Lsx, Lsy, size, color); } } else { for (Lsy = sy; Lsy >= ey; Lsy--) { Lsx = slopey * (Lsy - sy) + sx; size = o_size + pwy * (sy - Lsy) + 0.5; color = o_color + pcy * (sy - Lsy) + 0.5; FPointPressurePen(Lsx, Lsy, size, color); } } } } else { if (sy < ey) { if (fabs(slopex) < 1.0) { for (Lsx = sx; Lsx >= ex; Lsx--) { Lsy = slopex * (Lsx - sx) + sy; size = o_size + pwx * (sx - Lsx) + 0.5; color = o_color + pcx * (sx - Lsx) + 0.5; FPointPressurePen(Lsx, Lsy, size, color); } } else { for (Lsy = sy; Lsy <= ey; Lsy++) { Lsx = slopey * (Lsy - sy) + sx; size = o_size + pwy * (Lsy - sy) + 0.5; color = o_color + pcy * (Lsy - sy) + 0.5; FPointPressurePen(Lsx, Lsy, size, color); } } } else { if (fabs(slopex) < 1.0) { for (Lsx = sx; Lsx >= ex; Lsx--) { Lsy = slopex * (Lsx - sx) + sy; size = o_size + pwx * (sx - Lsx) + 0.5; color = o_color + pcx * (sx - Lsx) + 0.5; FPointPressurePen(Lsx, Lsy, size, color); } } else { for (Lsy = sy; Lsy >= ey; Lsy--) { Lsx = slopey * (Lsy - sy) + sx; size = o_size + pwy * (sy - Lsy) + 0.5; color = o_color + pcy * (sy - Lsy) + 0.5; FPointPressurePen(Lsx, Lsy, size, color); } } } } } } rect.left = min(sx, ex) - ls - 1; rect.top = min(sy, ey) - ls - 1; rect.right = max(sx, ex) + rs + 1; rect.bottom = max(sy, ey) + rs + 1; if(DrawForm){ if(DrawForm->btndelete != 1)if(update)Image->RectPaint(rect); Lsx = sx; Lex = ex; Lsy = sy; Ley = ey; }else { if(update)Image->RectPaint(rect); Lsx = sx; Lex = ex; Lsy = sy; Ley = ey; } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::set_pen(int x, int y, int size, COLORREF color) { int xx; double x1, yy, r, r2; Byte *P, *MP, *LP, *BP; TPItemImage *Image = MainImageForm->iMainImage; lineItr->setBaseColor(color); if (Image->uBitmap->BitsPerPixel==8) { if (Pen->Shape == 1) { r = size / 2.0 - 0.25; if ((y >= 0) && (y < Image->uBitmap->Height)) { lineItr->getScanLine(y, x - r, r + r + 1); // for (xx = -r; xx <= r; xx++) { if ((x + xx >= 0) && (x + xx < Image->uBitmap->Width) && (acolor != 2 || Selector->Number[lineItr->pickColor(x + xx)] < 255)) { lineItr->putPixel(x + xx); } } lineItr->putScanLine(y, x - r, r + r + 1); // } for (yy = 1; yy <= r; yy++) { if ((y - yy >= 0) && (y - yy < Image->uBitmap->Height)) { lineItr->getScanLine(y - yy, x - r, r + r + 1); // for (xx = -r; xx <= r; xx++) { if ((x + xx >= 0) && (x + xx < Image->uBitmap->Width) && (acolor != 2 || Selector->Number[lineItr->pickColor(x + xx)] < 255)) { lineItr->putPixel(x + xx); } } lineItr->putScanLine(y - yy, x - r, r + r + 1); // } if ((y + yy >= 0) && (y + yy < Image->uBitmap->Height)) { lineItr->getScanLine(y + yy, x - r, r + r + 1); // for (xx = -r; xx <= r; xx++) { if ((x + xx >= 0) && (x + xx < Image->uBitmap->Width) && (acolor != 2 || Selector->Number[lineItr->pickColor(x + xx)] < 255)) { lineItr->putPixel(x + xx); } } lineItr->putScanLine(y + yy, x - r, r + r + 1); // } } } else { // Pen->Shape != 1 r = size / 2.0 - 0.25; r2 = r * r; if ((y >= 0) && (y < Image->uBitmap->Height)) { lineItr->getScanLine(y, x - r, r + r + 1); // for (xx = -r; xx <= r; xx++) { if ((x + xx >= 0) && (x + xx < Image->uBitmap->Width) && (acolor != 2 || Selector->Number[lineItr->pickColor(x + xx)] < 255)) { lineItr->putPixel(x + xx); } } lineItr->putScanLine(y, x - r, r + r + 1); // } for (yy = 1; yy <= r; yy++) { x1 = sqrt(r2 - yy * yy); if ((y - yy >= 0) && (y - yy < Image->uBitmap->Height)) { lineItr->getScanLine(y - yy, x - x1, x1 + x1 + 1); // for (xx = -x1; xx <= x1; xx++) { if ((x + xx >= 0) && (x + xx < Image->uBitmap->Width) && (acolor != 2 || Selector->Number[lineItr->pickColor(x + xx)] < 255)) { lineItr->putPixel(x + xx); } } lineItr->putScanLine(y - yy, x - x1, x1 + x1 + 1); // } if ((y + yy >= 0) && (y + yy < Image->uBitmap->Height)) { lineItr->getScanLine(y + yy, x - x1, x1 + x1 + 1); // for (xx = -x1; xx <= x1; xx++) { if ((x + xx >= 0) && (x + xx < Image->uBitmap->Width) && (acolor != 2 || Selector->Number[lineItr->pickColor(x + xx)] < 255)) { lineItr->putPixel(x + xx); } } lineItr->putScanLine(y + yy, x - x1, x1 + x1 + 1); // } } } } else { if (Pen->Shape == 1) { r = size / 2.0 - 0.25; if ((y >= 0) && (y < Image->uBitmap->Height)) { lineItr->getScanLine(y, x - r, r + r + 1); // for (xx = -r; xx <= r; xx++) { if ((x + xx >= 0) && (x + xx < Image->uBitmap->Width)) { lineItr->putPixel(x + xx); } } lineItr->putScanLine(y, x - r, r + r + 1); // } for (yy = 1; yy <= r; yy++) { if ((y - yy >= 0) && (y - yy < Image->uBitmap->Height)) { lineItr->getScanLine(y - yy, x - r, r + r + 1); // for (xx = -r; xx <= r; xx++) { if ((x + xx >= 0) && (x + xx < Image->uBitmap->Width)) { lineItr->putPixel(x + xx); } } lineItr->putScanLine(y - yy, x - r, r + r + 1); // } if ((y + yy >= 0) && (y + yy < Image->uBitmap->Height)) { lineItr->getScanLine(y + yy, x - r, r + r + 1); // for (xx = -r; xx <= r; xx++) { if ((x + xx >= 0) && (x + xx < Image->uBitmap->Width)) { lineItr->putPixel(x + xx); } } lineItr->putScanLine(y + yy, x - r, r + r + 1); // } } } else { r = size / 2.0 - 0.25; r2 = r * r; if ((y >= 0) && (y < Image->uBitmap->Height)) { lineItr->getScanLine(y, x - r, r + r + 1); // for (xx = -r; xx <= r; xx++) { if ((x + xx >= 0) && (x + xx < Image->uBitmap->Width)) { lineItr->putPixel(x + xx); } } lineItr->putScanLine(y, x - r, r + r + 1); // } for (yy = 1; yy <= r; yy++) { x1 = sqrt(r2 - yy * yy); if ((y - yy >= 0) && (y - yy < Image->uBitmap->Height)) { lineItr->getScanLine(y - yy, x - x1, x1 + x1 + 1); // for (xx = -x1; xx <= x1; xx++) { if ((x + xx >= 0) && (x + xx < Image->uBitmap->Width)) { lineItr->putPixel(x + xx); } } lineItr->putScanLine(y - yy, x - x1, x1 + x1 + 1); // } if ((y + yy >= 0) && (y + yy < Image->uBitmap->Height)) { lineItr->getScanLine(y + yy, x - x1, x1 + x1 + 1); // for (xx = -x1; xx <= x1; xx++) { if ((x + xx >= 0) && (x + xx < Image->uBitmap->Width)) { lineItr->putPixel(x + xx); } } lineItr->putScanLine(y + yy, x - x1, x1 + x1 + 1); // } } } } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::calc_scrape_position(int size, int i, int &sx, int &sy, int &ex, int &ey) { int lx, ly; double theta, st, ct; lx = Lex - Lsx; ly = Ley - Lsy; theta = M_PI / 2.0 - atan2((double)ly, (double)lx); if (theta == M_PI / 2.0) { st = (StrToInt(eScale->Text) / 100.0) * size * i; sx = Lsx; sy = Lsy - st; ex = Lex; ey = Ley - st; } else if (theta == -M_PI / 2.0) { st = (StrToInt(eScale->Text) / 100.0) * size * i; sx = Lsx; sy = Lsy + st; ex = Lex; ey = Ley + st; } else { ct = cos(theta) * (StrToInt(eScale->Text) / 100.0) * size * i; st = sin(theta) * (StrToInt(eScale->Text) / 100.0) * size * i; sx = Lsx + ct; sy = Lsy - st; ex = Lex + ct; ey = Ley - st; } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::scrape_pen(int size, COLORREF color) { int px, py, i, radius, sx, sy, ex, ey, count, t; double s; TPItemImage *Image = MainImageForm->iMainImage; RECT rect; int ls, rs; ls = size >> 1; rs = size - ls; t = (size + 8) / 8.0; radius = seBristles->Value / 2.0; if (((int) seBristles->Value % 2)==1) count = radius + 1; else count = radius; sx = Lsx; sy = Lsy; ex = Lex; ey = Ley; if(lineItr) { delete lineItr; lineItr = NULL; } if (Image->LayerMask) { if (MainImageForm->MaskArea) { lineItr = (LineItr *)new LineItr_Layer_Mask(Image); } else { lineItr = (LineItr *)new LineItr_Layer(Image); } } else { if (MainImageForm->MaskArea) { lineItr = (LineItr *)new LineItr_Mask(Image); } else { lineItr = (LineItr *)new LineItr(Image); } } lineItr->setColorProtected(MainImageForm->Protect); if(lineItr->startScanLine() == false) goto fail; for (i = -radius; i <= count - 1; i++) { calc_scrape_position(size, i, sx, sy, ex, ey); if (sx == ex) { if (sy < ey) { py = sy; while (py <= ey) { set_pen(sx, py, size, color); py = py + t; } } else { py = sy; while (py >= ey) { set_pen(sx, py, size, color); py = py - t; } } } else if (sy == ey) { if (sx < ex) { px = sx; while (px <= ex) { set_pen(px, sy, size, color); px = px + t; } } else { px = sx; while (px >= ex) { set_pen(px, sy, size, color); px = px - t; } } } else { s = double(ey - sy) / (ex - sx); if (fabs(s) > 1.0) { if (sy < ey) { py = sy; while (py <= ey) { px = sx + (py - sy) / s + 0.5; set_pen(px, py, size, color); py = py + t; } } else { py = sy; while (py >= ey) { px = sx + (py - sy) / s + 0.5; set_pen(px, py, size, color); py = py - t; } } } else { if (sx < ex) { px = sx; while (px <= ex) { py = sy + (px - sx) * s + 0.5; set_pen(px, py, size, color); px = px + t; } } else { px = sx; while (px >= ex) { py = sy + (px - sx) * s + 0.5; set_pen(px, py, size, color); px = px - t; } } } } rect.left = min(sx, ex) - ls; rect.top = min(sy, ey) - ls; rect.right = max(sx, ex) + rs; rect.bottom = max(sy, ey) + rs; // Image->uBitmap->StopScanLine(); // by celberus lineItr->stopScanLine(); if(update)Image->RectPaint(rect); lineItr->startScanLine(); // Image->uBitmap->StartScanLine(); // by celberus StartScanLine ÈÄ RectPaintÇÏ´Â ÀÌÀ¯´Â? } lineItr->stopScanLine(); /* if (MainImageForm->MaskArea) Image->Mask->StopScanLine(); if (Image->LayerMask) { if (MainImageForm->Protect || acolor == 2) Image->BackGround->StopScanLine(); Image->LayerMask->StopScanLine(); } Image->uBitmap->StopScanLine();*/ return; fail : /* if (Image->LayerMask) { if (MainImageForm->Protect || acolor == 2) Image->BackGround->StopScanLine(); Image->LayerMask->StopScanLine(); } if (Image->Mask) Image->Mask->StopScanLine(); Image->uBitmap->StopScanLine();*/ EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::make_spread() { Byte s, e; char ColorIndex[2]; char ColorGap[1]; int i; if (MainImageForm->Palette->UseColor + spread_grade < 252) { ColorIndex[0] = spread_start; ColorIndex[1] = spread_end; spread_start = MainImageForm->Palette->UseColor + 1; ColorGap[0] = spread_grade - 1; MainImageForm->Palette->MakeSpread(1, ColorIndex, 2, ColorGap, 1); spread_end = MainImageForm->Palette->UseColor; s = spread_start; e = spread_end; ::RepaintColor(); } else if (MainImageForm->Palette->UseColor-1 != 250) { // lhskys i = 251 - MainImageForm->Palette->UseColor; //»ö¼±ÅÃÀÌ eGrade->Text = i; // 252¸¦ spread_grade = i; // ³Ñ´Â ColorIndex[0] = spread_start; ColorIndex[1] = spread_end; // °ÍÀ» spread_start = MainImageForm->Palette->UseColor + 1; // ¸·À½. ColorGap[0] = spread_grade - 1; // MainImageForm->Palette->MakeSpread(1, ColorIndex, 2, ColorGap, 1);// spread_end = MainImageForm->Palette->UseColor; // s = spread_start; e = spread_end; // EXCEPTION_MESSAGE_OK(EC_COLOR_OVERFLOW); // ::RepaintColor(); // /* eGrade->Text = "2"; spread_grade = 2; spread_start = s; spread_end = e; EXCEPTION_MESSAGE_OK(EC_COLOR_OVERFLOW); */ } else { EXCEPTION_MESSAGE_OK(EC_COLOR_OVERFLOW); //lhskys if (DrawForm){ //»ö¼±Åà if(DrawForm->isTaper)DrawForm->TaperLabelClick(this); // °ªÀÌ DrawForm->TaperLabel->Enabled = false; //°°À¸¸é } //return } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::InitWaterPanel(int i) { ScrollBarColor->Enabled = true; // Average pen ¿¡´Â ½ºÅ©·Ñ¹Ù ÇÊ¿ä ¾ø´Ù ScrollBarEffect->Max = 100; ScrollBarEffect->Min = 0; Label1->Visible = true; ColorLabel->Visible = true; switch (i) { case 0: WaterType = PWT_SIMPLE; Label1->Caption = IDS_COLOR; Label2->Caption = IDS_EFFECT; ScrollBarColor->Visible = true; ScrollBarColor->Position = 100*cr[PWT_SIMPLE]; ScrollBarEffect->Position = 100*or[PWT_SIMPLE]; Label5->Visible = false; spEditDensity->Visible = false; // Pen->PenDrawFunc = set_simple; SimpleShape->Brush->Color = clRed; SpatterShape->Brush->Color = clBlack; PureShape->Brush->Color = clBlack; DiffuseShape->Brush->Color = clBlack; AvgShape->Brush->Color = clBlack; break; case 1: WaterType = PWT_SPATTER; Label1->Caption = IDS_INSIDEDENSITY; Label2->Caption = IDS_OUTSIDEDENSITY; ScrollBarColor->Visible = true; ScrollBarColor->Position = 100*cr[PWT_SPATTER]; ScrollBarEffect->Position = 100*or[PWT_SPATTER]; Label5->Visible = true; spEditDensity->Visible = true; // Pen->PenDrawFunc = set_spatter; SimpleShape->Brush->Color = clBlack; SpatterShape->Brush->Color = clRed; PureShape->Brush->Color = clBlack; DiffuseShape->Brush->Color = clBlack; AvgShape->Brush->Color = clBlack; break; case 2: WaterType = PWT_PURE; Label1->Caption = IDS_COLOR; Label2->Caption = IDS_EFFECT; ScrollBarColor->Visible = true; ScrollBarColor->Position = 100*cr[PWT_PURE]; ScrollBarEffect->Position = 100*or[PWT_PURE]; Label5->Visible = false; spEditDensity->Visible = false; // Pen->PenDrawFunc = set_pure; SimpleShape->Brush->Color = clBlack; SpatterShape->Brush->Color = clBlack; PureShape->Brush->Color = clRed; DiffuseShape->Brush->Color = clBlack; AvgShape->Brush->Color = clBlack; break; case 3: WaterType = PWT_DIFFUSE; Label1->Caption = IDS_COLOR; Label2->Caption = IDS_SHAPE; ScrollBarColor->Visible = true; ScrollBarColor->Position = 100*cr[PWT_DIFFUSE]; ScrollBarEffect->Position = 100*or[PWT_DIFFUSE]; Label5->Visible = false; spEditDensity->Visible = false; // Pen->PenDrawFunc = set_diffuse; SimpleShape->Brush->Color = clBlack; SpatterShape->Brush->Color = clBlack; PureShape->Brush->Color = clBlack; DiffuseShape->Brush->Color = clRed; AvgShape->Brush->Color = clBlack; break; case 4: // By GreenFish AveragePen WaterType = PWT_AVERAGE; Label1->Caption = ""; Label2->Caption = IDS_DENSITY; // ScrollBarColor->Enabled = false; ScrollBarColor->Visible = false; ScrollBarEffect->Max = 5; ScrollBarEffect->Min = 1; ScrollBarEffect->Position = 3; Label1->Visible = false; ColorLabel->Visible = false; Label5->Visible = false; spEditDensity->Visible = false; spEditDensity->Value = 3; SimpleShape->Brush->Color = clBlack; SpatterShape->Brush->Color = clBlack; PureShape->Brush->Color = clBlack; DiffuseShape->Brush->Color = clBlack; AvgShape->Brush->Color = clRed; break; } ColorLabel->Caption = ScrollBarColor->Position; EffectLabel->Caption = ScrollBarEffect->Position; } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::set_water_func() { switch (WaterType) { case PWT_SIMPLE: if (MainImageForm->MaskArea) Pen->PenDrawFunc = set_simple_mask; else Pen->PenDrawFunc = set_simple_normal; break; case PWT_SPATTER: if (MainImageForm->MaskArea) Pen->PenDrawFunc = set_spatter_mask; else Pen->PenDrawFunc = set_spatter_normal; break; case PWT_PURE: if (MainImageForm->MaskArea) Pen->PenDrawFunc = set_pure_mask; else Pen->PenDrawFunc = set_pure_normal; break; case PWT_DIFFUSE: if (MainImageForm->MaskArea) Pen->PenDrawFunc = set_diffuse_mask; else Pen->PenDrawFunc = set_diffuse_normal; break; } } //--------------------------------------------------------------------------- /*#define GET_RGBCOLOR \ switch (draw.Image->IsBackGround()) { \ case 1: \ IP = draw.Image->LayerMask->GetScanLine(y, x, 1); \ if (IP[x >> 3] & (0x80 >> (x & 7))) { \ rgb = TColorToRGB((TColor)draw.Image->BackGround->GetPixelColor(x, y)); \ IP[x >> 3] &= ~(0x80 >> (x & 7)); \ draw.Image->LayerMask->PutScanLine(y, x, 1); \ } else { \ rgb = TColorToRGB((TColor)draw.Image->uBitmap->GetPixelColor(x, y)); \ } \ break; \ case 0: \ rgb = TColorToRGB((TColor)draw.Image->uBitmap->GetPixelColor(x, y)); \ break; \ }*/ #define GET_RGBCOLOR \ switch (draw.Image->IsBackGround()) { \ case 1: \ if (draw.Image->LayerMask->GetPixelColor(x, y)) { \ rgb = TColorToRGB((TColor)draw.Image->BackGround->GetPixelColor(x, y)); \ draw.Image->LayerMask->PutPixelColor(x, y, 0); \ } else { \ rgb = TColorToRGB((TColor)draw.Image->uBitmap->GetPixelColor(x, y)); \ } \ break; \ case 0: \ rgb = TColorToRGB((TColor)draw.Image->uBitmap->GetPixelColor(x, y)); \ break; \ } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::set_simple_normal(sPenDraw &draw) { int x, y; RGBQUAD rgb; double v, r = cr[PWT_SIMPLE]*0.2; Byte *IP; bool isNotInLMask; x = draw.cp.x+draw.mq.x; y = draw.cp.y+draw.mq.y; if (x>=0 && xuBitmap->Width && y>=0 && yuBitmap->Height) { GET_RGBCOLOR; rgb.rgbRed = rgb.rgbRed+(rgbWater.rgbRed-rgb.rgbRed)*r; rgb.rgbGreen = rgb.rgbGreen+(rgbWater.rgbGreen-rgb.rgbGreen)*r; rgb.rgbBlue = rgb.rgbBlue+(rgbWater.rgbBlue-rgb.rgbBlue)*r; draw.Image->uBitmap->PutPixelColor(x, y, RGBToTColor(rgb)); } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::set_simple_mask(sPenDraw &draw) { Byte *mp, *IP; int x, y; RGBQUAD rgb; double r = cr[PWT_SIMPLE]*0.2; x = draw.cp.x+draw.mq.x; y = draw.cp.y+draw.mq.y; if (x>=0 && xuBitmap->Width && y>=0 && yuBitmap->Height) { mp = draw.Image->Mask->GetScanLine(y, x, 1); // if (mp[x >> 3] & (0x80 >> (x & 7))) return; GET_RGBCOLOR; rgb.rgbRed = rgb.rgbRed+(rgbWater.rgbRed-rgb.rgbRed)*r; rgb.rgbGreen = rgb.rgbGreen+(rgbWater.rgbGreen-rgb.rgbGreen)*r; rgb.rgbBlue = rgb.rgbBlue+(rgbWater.rgbBlue-rgb.rgbBlue)*r; draw.Image->uBitmap->PutPixelColor(x, y, RGBToTColor(rgb)); } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::spatter(int X, int Y) { int size, width; double r, ran, temp; double interval[5] = { 1.0, 0.75, 0.5, 0.25, 0.1 }; Byte *IP; TPoint mp; width = Pen->BasicThick; size = Pen->Thick; r = (rand()%(size*3)); ran = (rand()%360)*(M_PI/180.0); mp = Point(X+r*cos(ran), Y+r*sin(ran)); temp = interval[(int)spEditDensity->Value-1]*size; if ((mp.x>X+temp || mp.xY+temp || mp.yThick = rand()%size+1; Pen->SetPixels(pd, mp.x, mp.y); Pen->BasicThick = width; } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::set_spatter_normal(sPenDraw &draw) { int x, y; RGBQUAD rgb; Byte *IP; double r; x = draw.cp.x+draw.mq.x; y = draw.cp.y+draw.mq.y; if (x>=0 && xuBitmap->Width && y>=0 && yuBitmap->Height) { GET_RGBCOLOR; r = sqrt(draw.mq.x*draw.mq.x+draw.mq.y*draw.mq.y)/Pen->Thick*2.0; if (r<0.0) r = 0.0; else if (r>1.0) r = 1.0; r = cr[PWT_SPATTER]-(cr[PWT_SPATTER]-or[PWT_SPATTER])*r; rgb.rgbRed = rgb.rgbRed+(rgbWater.rgbRed-rgb.rgbRed)*r; rgb.rgbGreen = rgb.rgbGreen+(rgbWater.rgbGreen-rgb.rgbGreen)*r; rgb.rgbBlue = rgb.rgbBlue+(rgbWater.rgbBlue-rgb.rgbBlue)*r; draw.Image->uBitmap->PutPixelColor(x, y, RGBToTColor(rgb)); } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::set_spatter_mask(sPenDraw &draw) { Byte *mp, *IP; int x, y; RGBQUAD rgb; double r; x = draw.cp.x+draw.mq.x; y = draw.cp.y+draw.mq.y; if (x>=0 && xuBitmap->Width && y>=0 && yuBitmap->Height) { mp = draw.Image->Mask->GetScanLine(y, x, 1); // if (mp[x >> 3] & (0x80 >> (x & 7))) return; GET_RGBCOLOR; r = sqrt(draw.mq.x*draw.mq.x+draw.mq.y*draw.mq.y)/Pen->Thick*2.0; if (r<0.0) r = 0.0; else if (r>1.0) r = 1.0; r = cr[PWT_SPATTER]-(cr[PWT_SPATTER]-or[PWT_SPATTER])*r; rgb.rgbRed = rgb.rgbRed+(rgbWater.rgbRed-rgb.rgbRed)*r; rgb.rgbGreen = rgb.rgbGreen+(rgbWater.rgbGreen-rgb.rgbGreen)*r; rgb.rgbBlue = rgb.rgbBlue+(rgbWater.rgbBlue-rgb.rgbBlue)*r; draw.Image->uBitmap->PutPixelColor(x, y, RGBToTColor(rgb)); } } //--------------------------------------------------------------------------- static int sigma(int n) { int i, t; for (i=1, t=0; i<=n; i++) t += i; return t; } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::set_pure_normal(sPenDraw &draw) { int x, y; COLORREF c1, c2; double rr, hls[2][3]; RGBQUAD rgb[3]; Byte *IP; x = draw.cp.x+draw.mq.x; y = draw.cp.y+draw.mq.y; if (x>=0 && xuBitmap->Width && y>=0 && yuBitmap->Height) { switch (draw.Image->IsBackGround()) { case 1: IP = draw.Image->LayerMask->GetScanLine(y, x, 1); // if (IP[x >> 3] & (0x80 >> (x & 7))) { c1 = draw.Image->BackGround->GetPixelColor(draw.fp.x, draw.fp.y); c2 = draw.Image->BackGround->GetPixelColor(x, y); IP[x >> 3] &= ~(0x80 >> (x & 7)); draw.Image->LayerMask->PutScanLine(y, x, 1); // } else { c1 = draw.Image->uBitmap->GetPixelColor(draw.fp.x, draw.fp.y); c2 = draw.Image->uBitmap->GetPixelColor(x, y); } break; case 0: c1 = draw.Image->uBitmap->GetPixelColor(draw.fp.x, draw.fp.y); c2 = draw.Image->uBitmap->GetPixelColor(x, y); break; } rgb[1] = TColorToRGB((TColor)c1); TColor2HLS((TColor)c1, hls[1][0], hls[1][1], hls[1][2]); rgb[0] = TColorToRGB((TColor)c2); TColor2HLS((TColor)c2, hls[0][0], hls[0][1], hls[0][2]); if (hls[0][2]==0.0 && hls[0][1]==1.0) { rr = cr[PWT_PURE]; } else { rr = (1.0-hls[0][1])*cr[PWT_PURE]; } rgb[2].rgbRed = rgb[0].rgbRed+(rgb[1].rgbRed-rgb[0].rgbRed)*rr; rgb[2].rgbGreen = rgb[0].rgbGreen+(rgb[1].rgbGreen-rgb[0].rgbGreen)*rr; rgb[2].rgbBlue = rgb[0].rgbBlue+(rgb[1].rgbBlue-rgb[0].rgbBlue)*rr; draw.Image->uBitmap->PutPixelColor(x, y, RGBToTColor(rgb[2])); } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::set_pure_mask(sPenDraw &draw) { Byte *mp, *IP; int x, y; COLORREF c1, c2; double rr, hls[2][3]; RGBQUAD rgb[3]; x = draw.cp.x+draw.mq.x; y = draw.cp.y+draw.mq.y; if (x>=0 && xuBitmap->Width && y>=0 && yuBitmap->Height) { mp = draw.Image->Mask->GetScanLine(y, x, 1); // if (mp[x >> 3] & (0x80 >> (x & 7))) return; switch (draw.Image->IsBackGround()) { case 1: IP = draw.Image->LayerMask->GetScanLine(y, x, 1); // if (IP[x >> 3] & (0x80 >> (x & 7))) { c1 = draw.Image->BackGround->GetPixelColor(draw.fp.x, draw.fp.y); c2 = draw.Image->BackGround->GetPixelColor(x, y); IP[x >> 3] &= ~(0x80 >> (x & 7)); draw.Image->LayerMask->PutScanLine(y, x, 1); // } else { c1 = draw.Image->uBitmap->GetPixelColor(draw.fp.x, draw.fp.y); c2 = draw.Image->uBitmap->GetPixelColor(x, y); } break; case 0: c1 = draw.Image->uBitmap->GetPixelColor(draw.fp.x, draw.fp.y); c2 = draw.Image->uBitmap->GetPixelColor(x, y); break; } rgb[1] = TColorToRGB((TColor)c1); TColor2HLS((TColor)c1, hls[1][0], hls[1][1], hls[1][2]); rgb[0] = TColorToRGB((TColor)c2); TColor2HLS((TColor)c2, hls[0][0], hls[0][1], hls[0][2]); if (hls[0][2]==0.0 && hls[0][1]==1.0) { rr = cr[PWT_PURE]; } else { rr = (1.0-hls[0][1])*cr[PWT_PURE]; } rgb[2].rgbRed = rgb[0].rgbRed+(rgb[1].rgbRed-rgb[0].rgbRed)*rr; rgb[2].rgbGreen = rgb[0].rgbGreen+(rgb[1].rgbGreen-rgb[0].rgbGreen)*rr; rgb[2].rgbBlue = rgb[0].rgbBlue+(rgb[1].rgbBlue-rgb[0].rgbBlue)*rr; draw.Image->uBitmap->PutPixelColor(x, y, RGBToTColor(rgb[2])); } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::set_diffuse_normal(sPenDraw &draw) { RGBQUAD rgb; int x, y, temp; bool sw = false; double r, ratio, radius; Byte *IP; x = draw.cp.x+draw.mq.x; y = draw.cp.y+draw.mq.y; if (x>=0 && xuBitmap->Width && y>=0 && yuBitmap->Height) { radius = Pen->Thick/4.0; ratio = sqrt(draw.mq.x*draw.mq.x+draw.mq.y*draw.mq.y)/radius; if (ratio<0.0) ratio = 0.0; else if (ratio>2.0) ratio = 2.0; if (ratio>1.75) { temp = rand()%9; if (temp<4) { sw = true; r = ratio*or[PWT_DIFFUSE]; } } else if (ratio>1.5 && ratio<=1.75) { temp = rand()%8; if (temp<3) { sw = true; r = ratio/1.1*or[PWT_DIFFUSE]; } else { sw = true; r = ratio*or[PWT_DIFFUSE]; } } else if (ratio>1.25 && ratio<=1.5) { temp = rand()%7; if (temp<3) { sw = true; r = ratio/1.2*or[PWT_DIFFUSE]; } else { sw = true; r = ratio*or[PWT_DIFFUSE]; } } else if (ratio>1.0 && ratio<=1.25) { temp = rand()%6; if (temp<3) { sw = true; r = ratio/1.3*or[PWT_DIFFUSE]; } else { sw = true; r = ratio*or[PWT_DIFFUSE]; } } else if (ratio>0.75 && ratio<=1.0) { temp = rand()%5; if (temp<3) { sw = true; r = ratio/1.4*or[PWT_DIFFUSE]; } else { sw = true; r = ratio*or[PWT_DIFFUSE]; } } else if (ratio>0.5 && ratio<=0.75) { temp = rand()%4; if (temp<2) { sw = true; r = ratio/1.5*or[PWT_DIFFUSE]; } else { sw = true; r = ratio*or[PWT_DIFFUSE]; } } else if (ratio>0.25 && ratio<=0.5) { temp = rand()%3; if (temp<2) { sw = true; r = ratio/1.6*or[PWT_DIFFUSE]; } else { sw = true; r = ratio*or[PWT_DIFFUSE]; } } else { sw = true; r = ratio*or[PWT_DIFFUSE]; } if (sw) { GET_RGBCOLOR; if (r<0.0) r = 0.0; else if (r>(1.5+or[PWT_DIFFUSE])*0.5) r = 1.0; r = 0.2*cr[PWT_DIFFUSE]*(2.0-r); rgb.rgbRed = rgb.rgbRed+(rgbWater.rgbRed-rgb.rgbRed)*r; rgb.rgbGreen = rgb.rgbGreen+(rgbWater.rgbGreen-rgb.rgbGreen)*r; rgb.rgbBlue = rgb.rgbBlue+(rgbWater.rgbBlue-rgb.rgbBlue)*r; draw.Image->uBitmap->PutPixelColor(x, y, RGBToTColor(rgb)); } } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::set_diffuse_mask(sPenDraw &draw) { Byte *mp, *IP; RGBQUAD rgb; int x, y, temp; bool sw = false; double r, ratio, radius; x = draw.cp.x+draw.mq.x; y = draw.cp.y+draw.mq.y; if (x>=0 && xuBitmap->Width && y>=0 && yuBitmap->Height) { mp = draw.Image->Mask->GetScanLine(y, x, 1); // if (mp[x >> 3] & (0x80 >> (x & 7))) return; radius = Pen->Thick/4.0; ratio = sqrt(draw.mq.x*draw.mq.x+draw.mq.y*draw.mq.y)/radius; if (ratio<0.0) ratio = 0.0; else if (ratio>2.0) ratio = 2.0; if (ratio>1.75) { temp = rand()%9; if (temp<4) { sw = true; r = ratio*or[PWT_DIFFUSE]; } } else if (ratio>1.5 && ratio<=1.75) { temp = rand()%8; if (temp<3) { sw = true; r = ratio/1.1*or[PWT_DIFFUSE]; } else { sw = true; r = ratio*or[PWT_DIFFUSE]; } } else if (ratio>1.25 && ratio<=1.5) { temp = rand()%7; if (temp<3) { sw = true; r = ratio/1.2*or[PWT_DIFFUSE]; } else { sw = true; r = ratio*or[PWT_DIFFUSE]; } } else if (ratio>1.0 && ratio<=1.25) { temp = rand()%6; if (temp<3) { sw = true; r = ratio/1.3*or[PWT_DIFFUSE]; } else { sw = true; r = ratio*or[PWT_DIFFUSE]; } } else if (ratio>0.75 && ratio<=1.0) { temp = rand()%5; if (temp<3) { sw = true; r = ratio/1.4*or[PWT_DIFFUSE]; } else { sw = true; r = ratio*or[PWT_DIFFUSE]; } } else if (ratio>0.5 && ratio<=0.75) { temp = rand()%4; if (temp<2) { sw = true; r = ratio/1.5*or[PWT_DIFFUSE]; } else { sw = true; r = ratio*or[PWT_DIFFUSE]; } } else if (ratio>0.25 && ratio<=0.5) { temp = rand()%3; if (temp<2) { sw = true; r = ratio/1.6*or[PWT_DIFFUSE]; } else { sw = true; r = ratio*or[PWT_DIFFUSE]; } } else { sw = true; r = ratio*or[PWT_DIFFUSE]; } if (sw) { GET_RGBCOLOR; if (r<0.0) r = 0.0; else if (r>(1.5+or[PWT_DIFFUSE])*0.5) r = 1.0; r = 0.2*cr[PWT_DIFFUSE]*(2.0-r); rgb.rgbRed = rgb.rgbRed+(rgbWater.rgbRed-rgb.rgbRed)*r; rgb.rgbGreen = rgb.rgbGreen+(rgbWater.rgbGreen-rgb.rgbGreen)*r; rgb.rgbBlue = rgb.rgbBlue+(rgbWater.rgbBlue-rgb.rgbBlue)*r; draw.Image->uBitmap->PutPixelColor(x, y, RGBToTColor(rgb)); } } } //--------------------------------------------------------------------------- // Public Function //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::SetFont() { SetSmallFont(Font); SetSmallFont(lSpread->Font); SetSmallFont(lColor->Font); SetSmallFont(lBristles->Font); SetSmallFont(lScale->Font); SetSmallFont(lDensity->Font); SetSmallFont(spreadgrade->Font); SetSmallFont(lGrade->Font); SetSmallFont(lSelectDraw->Font); SetSmallFont(Label1->Font); SetSmallFont(Label2->Font); SetSmallFont(Label5->Font); SetSmallFont(Label19->Font); SetSmallFont(Label20->Font); SetSmallFont(Label17->Font); SetSmallFont(Label43->Font); SetSmallFont(Label44->Font); SetSmallFont(Label45->Font); } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::InitType(bool init3d) { RGBQUAD rgb[256]; int Tx, Ty; TPItemImage *Image = MainImageForm->iMainImage; if (Type == PT_NORMAL) { sbNormal->Down = true; ScrapePanel->Visible = false; DensPanel->Visible = false; shNormal->Pen->Color = clRed; shNormal->Brush->Color = clRed; shAirBrush->Pen->Color = clBlack; shAirBrush->Brush->Color = clBlack; shCrayon->Pen->Color = clBlack; shCrayon->Brush->Color = clBlack; shWater->Pen->Color = clBlack; shWater->Brush->Color = clBlack; shScratch->Pen->Color = clBlack; shScratch->Brush->Color = clBlack; shMask->Pen->Color = clBlack; shMask->Brush->Color = clBlack; if (MainImageForm) MainImageForm->SetMaskShow(false); } else if (Type == PT_AIR) { if (!MainImageForm->WorkArea->Mask){ if(sbPattern->Down){ sbSingle->Down = true; AirFunctionClick(sbSingle); } } if (AirType == PAT_PATTERN) { if (MainImageForm->WorkArea->Mask) { sbPattern->Enabled = true; Tx = MainImageForm->WorkArea->Range.right - MainImageForm->WorkArea->Range.left; Ty = MainImageForm->WorkArea->Range.bottom - MainImageForm->WorkArea->Range.top; if (Image->uBitmap->BitsPerPixel==8) { MainImageForm->Palette->ToRGBQUAD(rgb, 256); if (!(Image1->Bitmap->Create(Tx, Ty, 8, rgb))) goto fail; } else { if (!(Image1->Bitmap->Create(Tx, Ty, 24))) goto fail; } /* Image1->Bitmap->CopyFromRect(Image->uBitmap, MainImageForm->WorkArea->Range.left, MainImageForm->WorkArea->Range.top, SRCCOPY); */ Image->uBitmap->CopyToTexpia(Image1->Bitmap, 0, 0, Image1->Bitmap->Width, Image1->Bitmap->Height, MainImageForm->WorkArea->Range.left, MainImageForm->WorkArea->Range.top, SRCCOPY); // convert by celberus Image1->Repaint(); } } sbAirBrush->Down = true; shNormal->Pen->Color = clBlack; shNormal->Brush->Color = clBlack; shAirBrush->Pen->Color = clRed; shAirBrush->Brush->Color = clRed; shCrayon->Pen->Color = clBlack; shCrayon->Brush->Color = clBlack; shWater->Pen->Color = clBlack; shWater->Brush->Color = clBlack; shScratch->Pen->Color = clBlack; shScratch->Brush->Color = clBlack; shMask->Pen->Color = clBlack; shMask->Brush->Color = clBlack; if (MainImageForm) MainImageForm->SetMaskShow(false); } else if (Type == PT_CRAYON) { sbCrayon->Down = true; ScrapePanel->Visible = false; DensPanel->Visible = true; shNormal->Pen->Color = clBlack; shNormal->Brush->Color = clBlack; shAirBrush->Pen->Color = clBlack; shAirBrush->Brush->Color = clBlack; shCrayon->Pen->Color = clRed; shCrayon->Brush->Color = clRed; shWater->Pen->Color = clBlack; shWater->Brush->Color = clBlack; shScratch->Pen->Color = clBlack; shScratch->Brush->Color = clBlack; shMask->Pen->Color = clBlack; shMask->Brush->Color = clBlack; if (MainImageForm) MainImageForm->SetMaskShow(false); } else if (Type == PT_WATER) { sbWater->Down = true; shNormal->Pen->Color = clBlack; shNormal->Brush->Color = clBlack; shAirBrush->Pen->Color = clBlack; shAirBrush->Brush->Color = clBlack; shCrayon->Pen->Color = clBlack; shCrayon->Brush->Color = clBlack; shWater->Pen->Color = clRed; shWater->Brush->Color = clRed; shScratch->Pen->Color = clBlack; shScratch->Brush->Color = clBlack; shMask->Pen->Color = clBlack; shMask->Brush->Color = clBlack; if (MainImageForm) MainImageForm->SetMaskShow(false); pd.Image = MainImageForm->iMainImage; } else if (Type == PT_SCRAPE) { sbScratch->Down = true; DensPanel->Visible = false; ScrapePanel->Visible = true; shNormal->Pen->Color = clBlack; shNormal->Brush->Color = clBlack; shAirBrush->Pen->Color = clBlack; shAirBrush->Brush->Color = clBlack; shCrayon->Pen->Color = clBlack; shCrayon->Brush->Color = clBlack; shWater->Pen->Color = clBlack; shWater->Brush->Color = clBlack; shScratch->Pen->Color = clRed; shScratch->Brush->Color = clRed; shMask->Pen->Color = clBlack; shMask->Brush->Color = clBlack; if (MainImageForm) MainImageForm->SetMaskShow(false); } else if (Type == PT_MASK) { sbMask->Down = true; shNormal->Pen->Color = clBlack; shNormal->Brush->Color = clBlack; shAirBrush->Pen->Color = clBlack; shAirBrush->Brush->Color = clBlack; shCrayon->Pen->Color = clBlack; shCrayon->Brush->Color = clBlack; shWater->Pen->Color = clBlack; shWater->Brush->Color = clBlack; shScratch->Pen->Color = clBlack; shScratch->Brush->Color = clBlack; shMask->Pen->Color = clRed; shMask->Brush->Color = clRed; TPItemImage *Image = MainImageForm->iMainImage; RECT r; if (Image->Mask==NULL) { if (Image->uBitmap->Width<=0 || Image->uBitmap->Height<=0) goto fail; Image->Mask = new TUnionBitmap; // convert by celberus if (Image->Mask==NULL) goto fail; if (Image->uBitmap->BitsPerPixel == 8) { if (Image->Mask->Create(Image->uBitmap->Width, Image->uBitmap->Height, 8)==false) goto fail; } else { if (Image->Mask->Create(Image->uBitmap->Width, Image->uBitmap->Height, 1)==false) goto fail; } SetRect(&r, 0, 0, Image->uBitmap->Width, Image->uBitmap->Height); Image->Mask->FillRect(r, 0); } MainImageForm->MaskArea = true; if (MainImageForm) MainImageForm->SetMaskShow(true); } if (init3d) MenuSW = true; //if 3d Menu click, prevent to show normal pen form MenuClick(NULL); MainImageForm->PenChange(); if (Type == PT_WATER) { MainImageForm->iMainImage->InitBackGround(0x04); } else { MainImageForm->iMainImage->ExitBackGround(0x04); } ::RepaintImage(); return; fail: EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::SelectColor(Byte Color) { switch (Type) { case PT_AIR : AddAirBrushColor(Color); break; default : if (spread_sw[4] == 0) { if (spread_grade < 2) spread_grade = 2; if (252 - MainImageForm->Palette->UseColor - 1 > 70) interval = 70; else interval = 252 - MainImageForm->Palette->UseColor - 1; lGrade->Caption = Format("(2 - %d)", OPENARRAY(TVarRec, (interval))); if (aspread) { if (spread_pos == 0) { spread_pos = 1; spread_start = Color; shFirst->Brush->Color = MainImageForm->Palette->Color[spread_start]; shFirst->Pen->Color = clBlack; shSecond->Pen->Color = clRed; } else if (spread_pos == 1) { spread_pos = 0; spread_end = Color; shSecond->Brush->Color = MainImageForm->Palette->Color[spread_end]; shFirst->Pen->Color = clRed; shSecond->Pen->Color = clBlack; } } } else { if (acolor == 1) { Selector->AddColor(Color); } } } PenShape->Pen->Color = MainImageForm->Palette->Color[Color]; PenShape->Brush->Color = MainImageForm->Palette->Color[Color]; PenWidthPanel->Color = MainImageForm->Palette->Color[BackgroundIndex]; } //--------------------------------------------------------------------------- bool __fastcall TPenManagerForm::mask_fill_read_8(Byte *p, int x) { return p[x] == 0x00; } //---------------------------------------------------------------------------- void __fastcall TPenManagerForm::mask_fill_save_8(Byte *p, int x) { p[x] = 0x0F; } //--------------------------------------------------------------------------- bool __fastcall TPenManagerForm::mask_fill_read_24(Byte *p, int x) { return (p[x >> 3] & (0x80 >> (x & 7))) == 0; } //---------------------------------------------------------------------------- void __fastcall TPenManagerForm::mask_fill_save_24(Byte *p, int x) { p[x >> 3] |= 0x80 >> (x & 7); } //--------------------------------------------------------------------------- bool __fastcall TPenManagerForm::mask_fill_delete_read_8(Byte *p, int x) { return p[x] == 0x0F; } //---------------------------------------------------------------------------- void __fastcall TPenManagerForm::mask_fill_delete_save_8(Byte *p, int x) { p[x] = 0x00; } //--------------------------------------------------------------------------- bool __fastcall TPenManagerForm::mask_fill_delete_read_24(Byte *p, int x) { return p[x >> 3] & (0x80 >> (x & 7)); } //---------------------------------------------------------------------------- void __fastcall TPenManagerForm::mask_fill_delete_save_24(Byte *p, int x) { p[x >> 3] &= ~(0x80 >> (x & 7)); } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::SpecialMouseDown(TMouseButton Button, TShiftState Shift, int X, int Y) { COLORREF spc, lc; int pw, ww, hh; RECT r, art; int ix, iy; TPItemImage *Image = MainImageForm->iMainImage; PenManagerForm->SetFocus(); if (Tablet->prsNew > Tablet->MaxNPressure) Tablet->prsNew = Tablet->MaxNPressure; if (Button==mbMiddle || (Shift.Contains(ssShift) && Button==mbLeft)) { if (acolor == 1) { if (sbBlock->Down) { if (Image->LayerMask) { lc = Image->LayerMask->GetPixelColor(X, Y); if (sbDelete->Down) { if (lc == 0) Selector->DeleteColor(Image->uBitmap->GetPixelColor(X, Y)); } else { if (lc == 0) Selector->AddColor(Image->uBitmap->GetPixelColor(X, Y)); } } else { if (sbDelete->Down) { Selector->DeleteColor(Image->uBitmap->GetPixelColor(X, Y)); } else { Selector->AddColor(Image->uBitmap->GetPixelColor(X, Y)); } } } else { if (step == 0) { Temp.left = X; Temp.top = Y; Temp.bottom = Temp.top; Temp.right = Temp.left; MainImageForm->DrawRectangleLocate(Temp); IsDraw = true; step = 1; } else if (step == 1) { Temp.right = X; Temp.bottom = Y; MainImageForm->DrawRectangleLocate(Temp); if (Temp.left > Temp.right) { r.left = Temp.right; r.right = Temp.left; } else { r.left = Temp.left; r.right = Temp.right; } if (Temp.top > Temp.bottom) { r.top = Temp.bottom; r.bottom = Temp.top; } else { r.top = Temp.top; r.bottom = Temp.bottom; } if (sbDelete->Down) { if (Image->LayerMask) { for (iy = r.top; iy < r.bottom; iy++) { for (ix = r.left; ix < r.right; ix++) { lc = Image->LayerMask->GetPixelColor(ix, iy); if (lc == 0) Selector->DeleteColor(Image->uBitmap->GetPixelColor(ix, iy)); } } } else { for (iy = r.top; iy < r.bottom; iy++) { for (ix = r.left; ix < r.right; ix++) { Selector->DeleteColor(Image->uBitmap->GetPixelColor(ix, iy)); } } } } else { if (Image->LayerMask) { for (iy = r.top; iy < r.bottom; iy++) { for (ix = r.left; ix < r.right; ix++) { lc = Image->LayerMask->GetPixelColor(ix, iy); if (lc == 0) Selector->AddColor(Image->uBitmap->GetPixelColor(ix, iy)); } } } else { for (iy = r.top; iy < r.bottom; iy++) { for (ix = r.left; ix < r.right; ix++) { Selector->AddColor(Image->uBitmap->GetPixelColor(ix, iy)); } } } } IsDraw = false; MainImageForm->iMainImage->OnPaintLocate = NULL;/////////////////by jeegeo step = 0; } } } } else if (Button == mbLeft) { if (acolor != 1) { #ifndef KNIT int ZoomIn = Image->ZoomIn; int ZoomOut = Image->ZoomOut; int PenSize = PenManagerForm->Pen->Thick; r.left = Image->PositionX - (PenSize + 30); // 30 is Caption Height if (r.left<0) r.left = 0; r.top = Image->PositionY - (PenSize + 30); if (r.top<0) r.top = 0; r.right = r.left+Image->Width*ZoomOut/ZoomIn + PenSize + 60; if (r.right>Image->uBitmap->Width) r.right = Image->uBitmap->Width; r.bottom = r.top+Image->Height*ZoomOut/ZoomIn + PenSize + 60; if (r.bottom>Image->uBitmap->Height) r.bottom = Image->uBitmap->Height; art = r; if (MainImageForm->AutoRepeat && (MainImageForm->LayerCNT == MainImageForm->ARLayerCnt)) art = MainImageForm->AutoRep_UndoRect(r); #else r = Rect(0, 0, Image->uBitmap->Width, Image->uBitmap->Height); art = r; #endif switch (Type) { case PT_NORMAL: #ifdef KNIT if ((DesignMode != D_YARN) && (Pen->Brush == 1 || aspread)) return; #endif // MainImageForm->UndoSave(UK_PATTERN, art, false); // RECT TempRect=RECT{0,0,0,0}; MainImageForm->UndoSave(UK_PATTERN, Rect(0,0,0,0)); //by linxujun Undo_Method BtnClick = true; Lsx = X; Lsy = Y; if (Pen->Brush == 0) { if (aspread) { if (spread_sw[4] == 1) { if (Image->uBitmap->BitsPerPixel==8) { spc = spread_start + double(spread_grade - 1) * Tablet->prsNew / Tablet->MaxNPressure + 0.5; } else { spc = Tablet->prsNew; } FPointPressurePen(Lsx, Lsy, Pen->Thick, spc); o_size = Pen->Thick; o_color = spc; if(update)MainImageForm->iMainImage->RectPaint(r); } } else { Lex = Lsx; Ley = Lsy; MainImageForm->line_pen(Lsx, Lsy, Lex, Ley, PaletteForm->DIB256Palette->GetFGCOLORREF(Image->uBitmap->BitsPerPixel), &r); if(update)MainImageForm->iMainImage->RectPaint(r); } } else if (Pen->Brush == 1) { if (aspread) { if (spread_sw[4] == 1) { if (Image->uBitmap->BitsPerPixel==8) { spc = spread_start + double(spread_grade - 1) * Tablet->prsNew / Tablet->MaxNPressure + 0.5; } else { spc = Tablet->prsNew; } pw = double(Pen->Thick - 1) * Tablet->prsNew / Tablet->MaxNPressure + 1.0; FPointPressurePen(Lsx, Lsy, pw, spc); o_size = pw; o_color = spc; } } else { spc = PaletteForm->DIB256Palette->ChoiceIndex; pw = double(Pen->Thick - 1) * Tablet->prsNew / Tablet->MaxNPressure + 1.0; FPointPressurePen(Lsx, Lsy, pw, spc); o_size = pw; o_color = spc; } } break; case PT_AIR: //MainImageForm->UndoSave(UK_PATTERN, art, false); //MainImageForm->UndoSave(UK_PATTERN, art); //by linuxjun For Undo_Method MainImageForm->UndoSave(UK_PATTERN, Rect(0,0,0,0)); //by linxujun Undo_Method BtnClick = true; Lsx = X; Lsy = Y; Lex = Lsx; Ley = Lsy; line_airbrush_pen(); break; case PT_CRAYON: //MainImageForm->UndoSave(UK_PATTERN, art, false); //MainImageForm->UndoSave(UK_PATTERN, art); //by linuxjun For Undo_Method MainImageForm->UndoSave(UK_PATTERN, Rect(0,0,0,0)); //by linxujun Undo_Method BtnClick = true; Lsx = X; Lsy = Y; if (Pen->Brush == 0) { if (aspread) { if (spread_sw[4] == 1) { if (Image->uBitmap->BitsPerPixel==8) { spc = spread_start + double(spread_grade - 1) * Tablet->prsNew / Tablet->MaxNPressure + 0.5; } else { spc = Tablet->prsNew; } FPointPressurePen(Lsx, Lsy, Pen->Thick, spc); o_size = Pen->Thick; o_color = spc; } } else { spc = PaletteForm->DIB256Palette->ChoiceIndex; FPointPressurePen(Lsx, Lsy, Pen->Thick, spc); o_size = Pen->Thick; o_color = spc; } } else if (Pen->Brush == 1) { if (aspread) { if (spread_sw[4] == 1) { if (Image->uBitmap->BitsPerPixel==8) { spc = spread_start + double(spread_grade - 1) * Tablet->prsNew / Tablet->MaxNPressure + 0.5; } else { spc = Tablet->prsNew; } pw = double(Pen->Thick - 1) * Tablet->prsNew / Tablet->MaxNPressure + 1.0; FPointPressurePen(Lsx, Lsy, pw, spc); o_size = pw; o_color = spc; } } else { spc = PaletteForm->DIB256Palette->ChoiceIndex; pw = double(Pen->Thick - 1) * Tablet->prsNew / Tablet->MaxNPressure + 1.0; FPointPressurePen(Lsx, Lsy, pw, spc); o_size = pw; o_color = spc; } } break; case PT_WATER: //MainImageForm->UndoSave(UK_PATTERN, art, false); //MainImageForm->UndoSave(UK_PATTERN, art); //by linuxjun For Undo_Method if(X>Lex){ r.left = Lex - (Pen->Thick)/2; r.right = X + (Pen->Thick+1)/2 +1; }else{ r.left = X - (Pen->Thick)/2; r.right = Lex + (Pen->Thick+1)/2 +1; } if(Y>Ley){ r.top = Ley - (Pen->Thick)/2; r.bottom = Y + (Pen->Thick+1)/2 +1; }else{ r.top = Y - (Pen->Thick)/2; r.bottom = Ley + (Pen->Thick+1)/2 +1; } // MainImageForm->UndoSave(UK_PATTERN, Rect(0,0,0,0)); //by linuxjun For Undo_Method MainImageForm->UndoSave(UK_PATTERN, r); //by linuxjun For Undo_Method set_water_func(); if (MainImageForm->iMainImage->LayerMask) MainImageForm->iMainImage->LayerMask->StartScanLine(); if (MainImageForm->MaskArea) MainImageForm->iMainImage->Mask->StartScanLine(); if (WaterType == PWT_AVERAGE) { // By GreenFish Average Pen±â´É /* pBITMAPHANDLE bh = MainImageForm->iMainImage->uBitmap->Handle; RGNXFORM XForm; RECT rc; HRGN rgnSrc, rgnDst; XForm.uViewPerspective = TOP_LEFT; XForm.nXScalarNum = 1; XForm.nXScalarDen = 1; XForm.nYScalarNum = 1; XForm.nYScalarDen = 1; XForm.nXOffset = 0; XForm.nYOffset = 0; */ // MainImageForm->iMainImage->uBitmap->PartialUndo->RectSaveUndo(r); Lex = AvgStartPt.x = X; Ley = AvgStartPt.y = Y; // ÇöÀç ÁÂÇ¥ ±â¾ï AvgPtCount = 1; /* rc.left = X - (Pen->Thick)/2; rc.right = X + (Pen->Thick+1)/2 +1; rc.top = Y - (Pen->Thick)/2; rc.bottom = Y + (Pen->Thick+1)/2 +1; L_SetBitmapRgnEllipse(bh, &XForm, &rc, L_RGN_SET); */ /* L_GetBitmapRgnHandle(bh, &XForm, &rgnDst); MainImageForm->WorkArea->SetMask(rgnDst); DeleteObject(rgnDst); */ /* L_INT nChange = 3; L_UINT32 uProcess; HINSTANCE hLibrary = LoadLibrary("ltdlg10n.dll"); if (hLibrary) { // TDlgGetChange DlgGetChange = (TDlgGetChange)GetProcAddress(hLibrary, "L_DlgGetChange"); if (nChange) { L_AverageFilterBitmap(bh, nChange); WindowForm->sbOffClick(this); // ÀÛ¾÷±¸¿ª ÇØÁ¦ } FreeLibrary(hLibrary); } */ } if (WaterType==PWT_SPATTER) { rgbWater = PaletteForm->DIB256Palette->ForegroundRgb; spatter(X, Y); } else { if (WaterType!=PWT_PURE) { rgbWater = PaletteForm->DIB256Palette->ForegroundRgb; } Pen->MoveRatio = WaterType==PWT_SIMPLE || WaterType==PWT_PURE ? 3+or[WaterType]*7 : 8; if (WaterType==PWT_DIFFUSE) Pen->ThickRatio = 1.0+or[PWT_DIFFUSE]; Pen->MoveTo(pd, X, Y); } BtnClick = true; break; case PT_SCRAPE: //MainImageForm->UndoSave(UK_PATTERN, art, false); //MainImageForm->UndoSave(UK_PATTERN, art); //by linuxjun For Undo_Method MainImageForm->UndoSave(UK_PATTERN, Rect(0,0,0,0)); //by linxujun Undo_Method BtnClick = true; Lsx = X; Lsy = Y; Lex = Lsx; Ley = Lsy; break; case PT_MASK: if (chFill->Checked) { POINT p = Point(X, Y); RECT rect; //MainImageForm->UndoSave(UK_MASK, false); //MainImageForm->UndoSave(UK_MASK); //by linxujun for Undo_Method MainImageForm->UndoSave(UK_MASK, Rect(0,0,0,0)); //by linxujun for Undo_Method if (MainImageForm->iMainImage->uBitmap->BitsPerPixel==8) { if (chDelete->Checked) { Image->Mask->FloodFill(p, mask_fill_delete_read_8, mask_fill_delete_save_8, rect); } else { Image->Mask->FloodFill(p, mask_fill_read_8, mask_fill_save_8, rect); } } else { if (chDelete->Checked) { Image->Mask->FloodFill(p, mask_fill_delete_read_24, mask_fill_delete_save_24, rect); } else { Image->Mask->FloodFill(p, mask_fill_read_24, mask_fill_save_24, rect); } } Image->Repaint(); } else { //MainImageForm->UndoSave(UK_MASK, art, false); //MainImageForm->UndoSave(UK_MASK, art); //by linuxjun for Undo_Method MainImageForm->UndoSave(UK_MASK, Rect(0,0,0,0)); //by linxujun for Undo_Method BtnClick = true; Lsx = X; Lsy = Y; if (Pen->Brush == 0) { Lex = Lsx; Ley = Lsy; MainImageForm->line_pen(Lsx, Lsy, Lex, Ley, PaletteForm->DIB256Palette->GetFGCOLORREF(Image->uBitmap->BitsPerPixel), &r); if(update)MainImageForm->iMainImage->RectPaint(r); } else if (Pen->Brush == 1) { spc = PaletteForm->DIB256Palette->ChoiceIndex; pw = double(Pen->Thick - 1) * Tablet->prsNew / Tablet->MaxNPressure + 1.0; FPointPressurePen(Lsx, Lsy, pw, spc); o_size = pw; o_color = spc; } } break; } } } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::SpecialMouseMove(TShiftState Shift, int X, int Y) { COLORREF spc; int pw; RGBQUAD m_rgb[3]; TPItemImage *Image = MainImageForm->iMainImage; RECT r; if (Tablet->prsNew > Tablet->MaxNPressure) Tablet->prsNew = Tablet->MaxNPressure; if (acolor != 1) { switch (Type) { case PT_NORMAL: if (BtnClick) { #ifdef KNIT if ((DesignMode != D_YARN) && (Pen->Brush == 1 || aspread)) return; #endif Lex = X; Ley = Y; if (Pen->Brush == 0) { if (aspread) { if (spread_sw[4] == 1) { if (Image->uBitmap->BitsPerPixel==8) { spc = spread_start + double(spread_grade - 1) * Tablet->prsNew / Tablet->MaxNPressure + 0.5; } else { spc = Tablet->prsNew; } line_pressure_pen(Pen->Thick, spc); o_size = Pen->Thick; o_color = spc; } } else { MainImageForm->line_pen(Lsx, Lsy, Lex, Ley, PaletteForm->DIB256Palette->GetFGCOLORREF(Image->uBitmap->BitsPerPixel), &r); if(update)MainImageForm->iMainImage->RectPaint(r); } } else if (Pen->Brush == 1) { if (aspread) { if (spread_sw[4] == 1) { if (Image->uBitmap->BitsPerPixel==8) { spc = spread_start + double(spread_grade - 1) * Tablet->prsNew / Tablet->MaxNPressure + 0.5; } else { spc = Tablet->prsNew; } pw = double(Pen->Thick - 1) * Tablet->prsNew / Tablet->MaxNPressure + 1.0; line_pressure_pen(pw, spc); o_size = pw; o_color = spc; } } else { spc = PaletteForm->DIB256Palette->ChoiceIndex; pw = double(Pen->Thick - 1) * Tablet->prsNew / Tablet->MaxNPressure + 1.0; line_pressure_pen(pw, spc); o_size = pw; o_color = spc; } } Lsx = Lex; Lsy = Ley; } break; case PT_AIR: if (BtnClick) { Lex = X; Ley = Y; line_airbrush_pen(); Lsx = Lex; Lsy = Ley; } break; case PT_CRAYON: if (BtnClick) { Lex = X; Ley = Y; if (Pen->Brush == 0) { if (aspread) { if (spread_sw[4] == 1) { if (Image->uBitmap->BitsPerPixel==8) { spc = spread_start + double(spread_grade - 1) * Tablet->prsNew / Tablet->MaxNPressure + 0.5; } else { spc = Tablet->prsNew; } line_pressure_pen(Pen->Thick, spc); o_size = Pen->Thick; o_color = spc; } } else { spc = PaletteForm->DIB256Palette->ChoiceIndex; line_pressure_pen(Pen->Thick, spc); o_size = Pen->Thick; o_color = spc; } } else if (Pen->Brush == 1) { if (aspread) { if (spread_sw[4] == 1) { if (Image->uBitmap->BitsPerPixel==8) { spc = spread_start + double(spread_grade - 1) * Tablet->prsNew / Tablet->MaxNPressure + 0.5; } else { spc = Tablet->prsNew; } pw = double(Pen->Thick - 1) * Tablet->prsNew / Tablet->MaxNPressure + 1.0; line_pressure_pen(pw, spc); o_size = pw; o_color = spc; } } else { spc = PaletteForm->DIB256Palette->ChoiceIndex; pw = double(Pen->Thick - 1) * Tablet->prsNew / Tablet->MaxNPressure + 1.0; line_pressure_pen(pw, spc); o_size = pw; o_color = spc; } } Lsx = Lex; Lsy = Ley; } break; case PT_WATER: if (BtnClick) { if (abs(X-pd.fp.x)>Pen->BasicThick || abs(Y-pd.fp.y)>Pen->BasicThick) { if (WaterType == PWT_AVERAGE) { // By GreenFish Average Pen±â´É /* pBITMAPHANDLE bh = MainImageForm->iMainImage->uBitmap->Handle; RGNXFORM XForm; RECT rc; HRGN rgnSrc, rgnDst; XForm.uViewPerspective = TOP_LEFT; XForm.nXScalarNum = 1; XForm.nXScalarDen = 1; XForm.nYScalarNum = 1; XForm.nYScalarDen = 1; XForm.nXOffset = 0; XForm.nYOffset = 0; */ if (AvgPtCount >= 200) return; POINT PolyPt[4]; POINT L_FAR *pPolyPt = PolyPt; int dx, dy, k; float sin, cos, dl; dx = X - Lex; dy = Y - Ley; dl = sqrt(dx*dx + dy*dy); k = (Pen->Thick+1)/2; if (dl == 0) break; sin = dy / dl * k ; cos = dx / dl * k; pPolyPt[0].x = Lex + sin; pPolyPt[0].y = Ley - cos; pPolyPt[1].x = X + sin; pPolyPt[1].y = Y - cos; pPolyPt[2].x = X - sin; pPolyPt[2].y = Y + cos; pPolyPt[3].x = Lex -sin; pPolyPt[3].y = Ley +cos; if (AvgPtCount == 1) { AvgUpperPt[0] = pPolyPt[3]; AvgLowerPt[0] = pPolyPt[0]; } AvgUpperPt[AvgPtCount] = pPolyPt[2]; AvgLowerPt[AvgPtCount] = pPolyPt[1]; AvgPtCount++; if (WaterType == PWT_AVERAGE) { // By GreenFish Average Pen±â´É if(X>Lex){ r.left = Lex - (Pen->Thick)/2; r.right = X + (Pen->Thick+1)/2 +1; }else{ r.left = X - (Pen->Thick)/2; r.right = Lex + (Pen->Thick+1)/2 +1; } if(Y>Ley){ r.top = Ley - (Pen->Thick)/2; r.bottom = Y + (Pen->Thick+1)/2 +1; }else{ r.top = Y - (Pen->Thick)/2; r.bottom = Ley + (Pen->Thick+1)/2 +1; } MainImageForm->iMainImage->uBitmap->PartialUndo->RectSaveUndo(r); } Lex = X; Ley = Y; break; /* L_SetBitmapRgnPolygon(bh, &XForm, pPolyPt, 4, L_POLY_WINDING, L_RGN_SET); L_INT nChange = 3; L_UINT32 uProcess; HINSTANCE hLibrary = LoadLibrary("ltdlg10n.dll"); if (hLibrary) { L_AverageFilterBitmap(bh, nChange); WindowForm->sbOffClick(this); // ÀÛ¾÷±¸¿ª ÇØÁ¦ } FreeLibrary(hLibrary); Lex = X; Ley = Y; break; */ } if (WaterType==PWT_SPATTER) { spatter(X, Y); } else { Pen->LineTo(pd, X, Y); } } } break; case PT_SCRAPE: if (BtnClick) { Lex = X; Ley = Y; if ((Lsx - 5 > Lex) || (Lsx + 5 < Lex) || (Lsy - 5 > Ley) || (Lsy + 5 < Ley)) { if (Pen->Brush == 1) { if (aspread) { if (spread_sw[4] == 1) { pw = double(Pen->Thick - 1) * Tablet->prsNew / Tablet->MaxNPressure + 1.0; if (Image->uBitmap->BitsPerPixel==8) { spc = spread_start + double(spread_grade - 1) * Tablet->prsNew / Tablet->MaxNPressure + 0.5; } else { m_rgb[0] = MainImageForm->Palette->ColorData[spread_start]->RGB; m_rgb[1] = MainImageForm->Palette->ColorData[spread_end]->RGB; m_rgb[2].rgbRed = m_rgb[0].rgbRed+Tablet->prsNew*(m_rgb[1].rgbRed-m_rgb[0].rgbRed)/Tablet->MaxNPressure; m_rgb[2].rgbGreen = m_rgb[0].rgbGreen+Tablet->prsNew*(m_rgb[1].rgbGreen-m_rgb[0].rgbGreen)/Tablet->MaxNPressure; m_rgb[2].rgbBlue = m_rgb[0].rgbBlue+Tablet->prsNew*(m_rgb[1].rgbBlue-m_rgb[0].rgbBlue)/Tablet->MaxNPressure; spc = RGBToTColor(m_rgb[2]); } scrape_pen(pw, spc); } } else { pw = double(Pen->Thick - 1) * Tablet->prsNew / Tablet->MaxNPressure + 1.0; scrape_pen(pw, PaletteForm->DIB256Palette->GetFGCOLORREF(Image->uBitmap->BitsPerPixel)); } } else if (Pen->Brush == 0) { if (aspread) { if (spread_sw[4] == 1) { if (Image->uBitmap->BitsPerPixel==8) { spc = spread_start + double(spread_grade - 1) * Tablet->prsNew / Tablet->MaxNPressure + 0.5; } else { m_rgb[0] = MainImageForm->Palette->ColorData[spread_start]->RGB; m_rgb[1] = MainImageForm->Palette->ColorData[spread_end]->RGB; m_rgb[2].rgbRed = m_rgb[0].rgbRed+Tablet->prsNew*(m_rgb[1].rgbRed-m_rgb[0].rgbRed)/Tablet->MaxNPressure; m_rgb[2].rgbGreen = m_rgb[0].rgbGreen+Tablet->prsNew*(m_rgb[1].rgbGreen-m_rgb[0].rgbGreen)/Tablet->MaxNPressure; m_rgb[2].rgbBlue = m_rgb[0].rgbBlue+Tablet->prsNew*(m_rgb[1].rgbBlue-m_rgb[0].rgbBlue)/Tablet->MaxNPressure; spc = RGBToTColor(m_rgb[2]); } scrape_pen(Pen->Thick, spc); } } else { scrape_pen(Pen->Thick, PaletteForm->DIB256Palette->GetFGCOLORREF(Image->uBitmap->BitsPerPixel)); } } Lsx = Lex; Lsy = Ley; } } break; case PT_MASK: if (BtnClick) { Lex = X; Ley = Y; if (Pen->Brush == 0) { MainImageForm->line_pen(Lsx, Lsy, Lex, Ley, PaletteForm->DIB256Palette->GetFGCOLORREF(Image->uBitmap->BitsPerPixel), &r); if(update)MainImageForm->iMainImage->RectPaint(r); } else if (Pen->Brush == 1) { spc = PaletteForm->DIB256Palette->ChoiceIndex; pw = double(Pen->Thick - 1) * Tablet->prsNew / Tablet->MaxNPressure + 1.0; line_pressure_pen(pw, spc); o_size = pw; o_color = spc; } Lsx = Lex; Lsy = Ley; } break; } } else if (acolor == 1) { if (step == 1) { if (IsDraw) MainImageForm->DrawRectangleLocate(Temp); Temp.right = X; Temp.bottom = Y; MainImageForm->DrawRectangleLocate(Temp); IsDraw = true; } } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::SpecialMouseUp(TMouseButton Button, TShiftState Shift, int X, int Y) { switch (Type) { case PT_NORMAL: case PT_AIR: case PT_CRAYON: case PT_SCRAPE: case PT_WATER: case PT_MASK: BtnClick = false; } if (Type == PT_WATER) { if (WaterType == PWT_AVERAGE) { // By GreenFish Average Pen±â´É AvgDestPt.x = X; AvgDestPt.y = Y; pBITMAPHANDLE bh = MainImageForm->iMainImage->uBitmap->Handle; TCursor OldCursor = Screen->Cursor; Screen->Cursor = crHourGlass; RGNXFORM XForm; RECT rc; HRGN rgnSrc, rgnDst; XForm.uViewPerspective = TOP_LEFT; XForm.nXScalarNum = 1; XForm.nXScalarDen = 1; XForm.nYScalarNum = 1; XForm.nYScalarDen = 1; XForm.nXOffset = 0; XForm.nYOffset = 0; L_INT nChange = spEditDensity->Value+1; rc.left = AvgStartPt.x - (Pen->Thick)/2; rc.right = AvgStartPt.x + (Pen->Thick+1)/2 +1; rc.top = AvgStartPt.y - (Pen->Thick)/2; rc.bottom = AvgStartPt.y + (Pen->Thick+1)/2 +1; //==============================¼öÁ¤Áß(¼Óµµ°³¼±) GreenFish TTexpiaBitmap *BtTemp; // ºñÆ®¸Ê Àӽà ÀúÀå RGBQUAD Btrgb[256]; TPException ec = EC_NONE; int TempWidth = rc.right - rc.left, TempHeight = rc.bottom - rc.top; RECT Temprc; if ((BtTemp = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } MainImageForm->iMainImage->uBitmap->GetColors(0, 256, Btrgb); if (!BtTemp->Create(TempWidth, TempHeight, MainImageForm->iMainImage->uBitmap->BitsPerPixel, Btrgb)) { ec = EC_MEMORY_LACK; goto fail; } /* BtTemp->Copy(0, 0, TempWidth, TempHeight, MainImageForm->iMainImage->uBitmap, rc.left, rc.top, SRCCOPY); // BtTemp Á¶°¢(¿µ¿ª¸¸) º¸°ü */ MainImageForm->iMainImage->uBitmap->CopyToTexpia(BtTemp, 0, 0, TempWidth, TempHeight, rc.left, rc.top, SRCCOPY); // convert by celberus Temprc.left = 0; Temprc.right = TempWidth; Temprc.top = 0; Temprc.bottom = TempHeight; L_SetBitmapRgnEllipse(BtTemp->Handle, &XForm, &Temprc, L_RGN_SET); if (hLibrary) { // Á¶°¢ ¿µ¿ª¸¸ ÇÊÅ͸µ if (nChange) { L_AverageFilterBitmap(BtTemp->Handle, nChange); // ½ÃÀÛÁ¡ ºÎºÐ (¿ø) WindowForm->sbOffClick(this); } } MainImageForm->iMainImage->uBitmap->Copy(rc.left, rc.top, TempWidth, TempHeight, BtTemp, 0, 0, SRCCOPY); // BtTemp Á¶°¢(¿µ¿ª¸¸) º¸°ü delete BtTemp; //======================================= /* ¿ø·¡ ÇÔ¼ö (¼öÁ¤Áß À§) L_SetBitmapRgnEllipse(bh, &XForm, &rc, L_RGN_SET); if (hLibrary) { if (nChange) { L_AverageFilterBitmap(bh, nChange); // ½ÃÀÛÁ¡ ºÎºÐ (¿ø) WindowForm->sbOffClick(this); // ÀÛ¾÷±¸¿ª ÇØÁ¦ } } */ if (AvgPtCount > 1) { /* rc.left = AvgDestPt.x - (Pen->Thick)/2; rc.right = AvgDestPt.x + (Pen->Thick+1)/2 +1; rc.top = AvgDestPt.y - (Pen->Thick)/2; rc.bottom = AvgDestPt.y + (Pen->Thick+1)/2 +1; L_SetBitmapRgnEllipse(bh, &XForm, &rc, L_RGN_SET); if (hLibrary) { if (nChange) { L_AverageFilterBitmap(bh, nChange); // Á¾ÂøÁ¡ ºÎºÐ (¿ø) WindowForm->sbOffClick(this); // ÀÛ¾÷±¸¿ª ÇØÁ¦ } } */ POINT AvgPt[400]; POINT L_FAR *pAvgPt = AvgPt; //=============================================== ÀÛ¾÷Áß ¾Æ·¡(GreenFish) for (int i = 0; i < AvgPtCount; i++) { pAvgPt[i] = AvgLowerPt[i]; pAvgPt[AvgPtCount*2 - i - 1] = AvgUpperPt[i]; rc.right = rc.right < AvgLowerPt[i].x +(Pen->Thick)/2 ? AvgLowerPt[i].x +(Pen->Thick)/2 : rc.right; rc.left = rc.left > AvgLowerPt[i].x -(Pen->Thick)/2 ? AvgLowerPt[i].x -(Pen->Thick)/2 : rc.left; rc.top = rc.top > AvgLowerPt[i].y -(Pen->Thick)/2 ? AvgLowerPt[i].y -(Pen->Thick)/2 : rc.top; rc.bottom = rc.bottom < AvgLowerPt[i].y +(Pen->Thick)/2 ? AvgLowerPt[i].y +(Pen->Thick)/2 : rc.bottom; rc.right = rc.right < AvgUpperPt[i].x +(Pen->Thick)/2 ? AvgUpperPt[i].x +(Pen->Thick)/2 : rc.right; rc.left = rc.left > AvgUpperPt[i].x -(Pen->Thick)/2 ? AvgUpperPt[i].x -(Pen->Thick)/2 : rc.left; rc.top = rc.top > AvgUpperPt[i].y -(Pen->Thick)/2 ? AvgUpperPt[i].y -(Pen->Thick)/2 : rc.top; rc.bottom = rc.bottom < AvgUpperPt[i].y +(Pen->Thick)/2 ? AvgUpperPt[i].y +(Pen->Thick)/2 : rc.bottom; } TempWidth = rc.right - rc.left; TempHeight = rc.bottom - rc.top; if ((BtTemp = new TTexpiaBitmap)==NULL) { ec = EC_MEMORY_LACK; goto fail; } MainImageForm->iMainImage->uBitmap->GetColors(0, 256, Btrgb); if (!BtTemp->Create(TempWidth, TempHeight, MainImageForm->iMainImage->uBitmap->BitsPerPixel, Btrgb)) { ec = EC_MEMORY_LACK; goto fail; } /* BtTemp->Copy(0, 0, TempWidth, TempHeight, MainImageForm->iMainImage->uBitmap, rc.left, rc.top, SRCCOPY); // BtTemp Á¶°¢(¿µ¿ª¸¸) º¸°ü */ MainImageForm->iMainImage->uBitmap->CopyToTexpia(BtTemp, 0, 0, TempWidth, TempHeight, rc.left, rc.top, SRCCOPY); // convert by celberus for (int i = 0; i < AvgPtCount*2; i++) { pAvgPt[i].x -= rc.left; pAvgPt[i].y -= rc.top; } L_SetBitmapRgnPolygon(BtTemp->Handle, &XForm, pAvgPt, AvgPtCount*2, L_POLY_WINDING, L_RGN_SET); if (hLibrary) { L_AverageFilterBitmap(BtTemp->Handle, nChange); // ´Ù°¢Çü ºÎºÐ WindowForm->sbOffClick(this); } MainImageForm->iMainImage->uBitmap->Copy(rc.left, rc.top, TempWidth, TempHeight, BtTemp, 0, 0, SRCCOPY); // BtTemp Á¶°¢(¿µ¿ª¸¸) º¸°ü delete BtTemp; //===========================================ÀÛ¾÷Áß À§ /* L_SetBitmapRgnPolygon(bh, &XForm, pAvgPt, AvgPtCount*2, L_POLY_WINDING, L_RGN_SET); if (hLibrary) { L_AverageFilterBitmap(bh, nChange); // ´Ù°¢Çü ºÎºÐ WindowForm->sbOffClick(this); // ÀÛ¾÷±¸¿ª ÇØÁ¦ } */ } Screen->Cursor = OldCursor; MainImageForm->iMainImage->Repaint(); fail: } if (MainImageForm->MaskArea) MainImageForm->iMainImage->Mask->StopScanLine(); if (MainImageForm->iMainImage->LayerMask) MainImageForm->iMainImage->LayerMask->StopScanLine(); } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::SpecialPaint() { IsDraw = false; MainImageForm->iMainImage->OnPaintLocate = NULL;/////////////////by jeegeo } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::AddAirBrushColor(Byte SetColor) { TColorList *pcolor, *p; if (AirType == PAT_SINGLE) { AirSelectColor->Brush->Color = MainImageForm->Palette->Color[SetColor]; } else if (AirType == PAT_MULTI) { if (AirColorList->Count < 18) { pcolor = new TColorList; pcolor->color = SetColor; pcolor->modify = false; for (int i = 0; i < AirColorList->Count; i++) { p = (TColorList *) AirColorList->Items[i]; if (p->color == pcolor->color) { delete pcolor; return; } } AirColorList->Add(pcolor); ChangeAirColorPalette(AirColorList->Count - 1); } } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::WorkAreaChange() { RGBQUAD rgb[256]; int Tx, Ty; TPItemImage *Image = MainImageForm->iMainImage; if (Type == PT_AIR) { if (AirType == PAT_PATTERN) { if (MainImageForm->WorkArea->Mask) { sbPattern->Enabled = true; Tx = MainImageForm->WorkArea->Range.right - MainImageForm->WorkArea->Range.left; Ty = MainImageForm->WorkArea->Range.bottom - MainImageForm->WorkArea->Range.top; if (Image->uBitmap->BitsPerPixel==8) { MainImageForm->Palette->ToRGBQUAD(rgb, 256); if (!(Image1->Bitmap->Create(Tx, Ty, 8, rgb))) goto fail; } else { if (!(Image1->Bitmap->Create(Tx, Ty, 24))) goto fail; } /* Image1->Bitmap->CopyFromRect(Image->uBitmap, MainImageForm->WorkArea->Range.left, MainImageForm->WorkArea->Range.top, SRCCOPY); */ Image->uBitmap->CopyToTexpia(Image1->Bitmap, 0, 0, Image1->Bitmap->Width, Image1->Bitmap->Height, MainImageForm->WorkArea->Range.left, MainImageForm->WorkArea->Range.top, SRCCOPY); // convert by celberus Image1->Repaint(); } else { sbSingle->Down = true; AirType = PAT_SINGLE; MultiPanel->Visible = false; PatternPanel->Visible = false; SinglePanel->Visible = true; sbPattern->Enabled = false; } } else { if (AirPanel->Visible) { if (MainImageForm->WorkArea->Mask) sbPattern->Enabled = true; else { sbSingle->Down = true; AirFunctionClick(sbSingle); sbPattern->Enabled = false; } } } } return; fail: EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::iMainImageChange() { if (IsDraw) {IsDraw = false; MainImageForm->iMainImage->OnPaintLocate = NULL;/////////////////by jeegeo } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::SetColor(TPalette *Palette) { Selector->SetPalette(Palette); Selector->Invalid(); shFirst->Update(); shSecond->Update(); PenShape->Pen->Color = Palette->Color[PaletteForm->DIB256Palette->ChoiceIndex]; PenShape->Brush->Color = Palette->Color[PaletteForm->DIB256Palette->ChoiceIndex]; PenWidthPanel->Color = Palette->Color[BackgroundIndex]; } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::SpreadChange(TPalette *Palette) { Byte ChoiceIndex = PaletteForm->DIB256Palette->ChoiceIndex; TColor ChoiceColor = Palette->Color[ChoiceIndex]; Selector->Initial(); Selector->SetPalette(Palette); spread_grade = 2; eGrade->Text = "2"; if (252 - Palette->UseColor - 1 > 70) interval = 70; else interval = 252 - Palette->UseColor - 1; lGrade->Caption = Format("(2 - %d)", OPENARRAY(TVarRec, (interval))); spread_start = ChoiceIndex; shFirst->Brush->Color = ChoiceColor; spread_end = ChoiceIndex; shSecond->Brush->Color = ChoiceColor; lSelectDraw->Caption = IDS_SELECTCOLOR; spread_sw[4] = 0; spread_pos = 0; shFirst->Pen->Color = clRed; shSecond->Pen->Color = clBlack; PenShape->Pen->Color = ChoiceColor; PenShape->Brush->Color = ChoiceColor; PenWidthPanel->Color = Palette->Color[BackgroundIndex]; AirSelectColor->Brush->Color = ChoiceColor; TShape *s = 0; TColorList *Temp = 0; for (int i = 1; i <= AirColorList->Count; i++) { Temp = (TColorList *)(AirColorList->Items[i - 1]); s = (TShape *)(FindComponent("shAirColor" + AnsiString(i))); s->Brush->Color = Palette->Color[Temp->color]; } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::PenShapeChange(int value) { PenShape->Pen->Color = PaletteForm->DIB256Palette->Palette->Color[value]; PenShape->Brush->Color = PaletteForm->DIB256Palette->Palette->Color[value]; } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::FormChange(TPalette *Palette) { MainImageForm->PenChange(); if (Type == PT_AIR) { if (MainImageForm->WorkArea->Mask) { sbPattern->Enabled = true; } else { sbSingle->Down = true; AirFunctionClick(sbSingle); sbPattern->Enabled = false; } EtcPanel->Visible = false; AirPanel->Visible = true; if (AirType == PAT_SINGLE) { MultiPanel->Visible = false; PatternPanel->Visible = false; SinglePanel->Visible = true; AirPanel->Height = SinglePanel->Top + SinglePanel->Height - 1; } else if (AirType == PAT_MULTI) { SinglePanel->Visible = false; PatternPanel->Visible = false; MultiPanel->Visible = true; AirPanel->Height = MultiPanel->Top + MultiPanel->Height - 1; } else if (AirType == PAT_PATTERN) { SinglePanel->Visible = false; MultiPanel->Visible = false; PatternPanel->Visible = true; AirPanel->Height = PatternPanel->Top + PatternPanel->Height - 1; } ClientHeight = AirPanel->Top + AirPanel->Height - 1; MenuSW = true; btnUp->Visible = true; btnDown->Visible = false; } else if (Type == PT_MASK) { TPItemImage *Image = MainImageForm->iMainImage; // ti -> Image ·Î À̸§º¯°æ by celberus RECT r; if (Image->Mask==NULL) { if (Image->uBitmap->Width<=0 || Image->uBitmap->Height<=0) goto fail; Image->Mask = new TUnionBitmap; // convert by celberus if (Image->Mask==NULL) goto fail; if (Image->uBitmap->BitsPerPixel == 8) { if (Image->Mask->Create(Image->uBitmap->Width, Image->uBitmap->Height, 8) == false) goto fail; } else { if (Image->Mask->Create(Image->uBitmap->Width, Image->uBitmap->Height, 1) == false) goto fail; } SetRect(&r, 0, 0, Image->uBitmap->Width, Image->uBitmap->Height); Image->Mask->FillRect(r, 0); } } WorkAreaChange(); return; fail: EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::InitPenForm() { Type = PT_NORMAL; InitType(); sbNormal->Down = true; ClientHeight = FHeight; btnUp->Visible = false; btnDown->Visible = true; MenuSW = false; SpreadChange(MainImageForm->Palette); if (acolor != 0) InitColorPen(); } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::InitColorPen() { acolor = 0; lColor->Caption = AnsiString(IDS_COLOR) + " : " + AnsiString(IDS_COMMON_BUTTONNO); ColorPanel->Visible = false; Selector->SaveToFile(DirectoryItem+"\\Pen.Ini", "Color"); if (SpreadPanel->Visible) { if (ScrapePanel->Visible || DensPanel->Visible) { SpreadPanel->Top = DensPanel->Top + DensPanel->Height; } else { SpreadPanel->Top = EtcSubPanel->Top + EtcSubPanel->Height; } EtcPanel->Height = SpreadPanel->Top + SpreadPanel->Height; } else { if (ScrapePanel->Visible || DensPanel->Visible) { EtcPanel->Height = DensPanel->Top + DensPanel->Height; } else { EtcPanel->Height = EtcSubPanel->Height; } } MainImageForm->PenChange(); } //--------------------------------------------------------------------------- #ifdef KNIT void __fastcall TPenManagerForm::ChangeMode() { if (DesignMode == D_YARN){ sbNormal->Enabled = true; sbAirBrush->Enabled = true; sbCrayon->Enabled = true; sbWater->Enabled = false; sbScratch->Enabled = true; sbMask->Enabled = true; btnUp->Visible = true; cbPressure->Enabled = true; } else { sbNormal->Enabled = true; sbAirBrush->Enabled = false; sbCrayon->Enabled = false; sbWater->Enabled = false; sbScratch->Enabled = false; sbMask->Enabled = false; btnUp->Visible = false; cbPressure->Enabled = false; } } #endif //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::DrawTaperLine(int lsx, int lsy, int lex, int ley, int s_size, int e_size, double s_rate, double e_rate, COLORREF color) { int pw; COLORREF spc; if (aspread) { Lsx = lsx; Lsy = lsy; Lex = lex; Ley = ley; o_size = s_size + (e_size - s_size) * s_rate; pw = s_size + (e_size - s_size) * e_rate; if (MainImageForm->iMainImage->uBitmap->BitsPerPixel == 8) { o_color = spread_start + (spread_end - spread_start) * s_rate + 0.5; spc = spread_start + (spread_end - spread_start) * e_rate + 0.5; } else { o_color = Tablet->MaxNPressure * s_rate; spc = Tablet->MaxNPressure * e_rate; } line_pressure_pen(pw, spc); } else { Lsx = lsx; Lsy = lsy; Lex = lex; Ley = ley; o_size = s_size + (e_size - s_size) * s_rate; pw = s_size + (e_size - s_size) * e_rate; o_color = color; spc = color; line_pressure_pen(pw, spc); } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::BtnAvgClick(TObject *Sender) { TSpeedButton *s = (TSpeedButton *) Sender; InitWaterPanel(s->Tag); } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::spEditDensityChange(TObject *Sender) { if (WaterType == PWT_AVERAGE){ ScrollBarEffect->Position = spEditDensity->Value; EffectLabel->Caption = spEditDensity->Value; return; } } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::eGradeChange(TObject *Sender) { TEdit *s; s = (TEdit *)Sender; if ( StrToInt(s->Text) > 70 ) s->Text = "70"; spread_grade = StrToInt(s->Text); } //--------------------------------------------------------------------------- void __fastcall TPenManagerForm::EditKeyUp(TObject *Sender, WORD &Key, TShiftState Shift) { TEdit *s; s = (TEdit *)Sender; if (AirColorList->Count >= s->Tag + 1) { InputPercent(Sender); } } //--------------------------------------------------------------------------- COLORREF __fastcall TPenManagerForm::getListColor(TColorList *colorList, int bitsPerPixel) // by celberus { if(bitsPerPixel == 8) return colorList->color; else return MainImageForm->Palette->Color[colorList->color]; } //--------------------------------------------------------------------------- COLORREF __fastcall TPenManagerForm::getSelectedPaletteColor(int bitsPerPixel) { return PaletteForm->DIB256Palette->GetFGCOLORREF(bitsPerPixel); } //--------------------------------------------------------------------------- void __fastcall DrawingPen::setDrawingLine(Byte *pLine) { drawingLine = pLine; } //--------------------------------------------------------------------------- void __fastcall DrawingPen::setColor(COLORREF color) { _color = color; } //--------------------------------------------------------------------------- void __fastcall DrawingPen_8::setColorProtected(bool value) { _colorProtected = value; } //--------------------------------------------------------------------------- void __fastcall DrawingPen_8::setProtectCheckLine(Byte *pLine) { protectCheckLine = pLine; } //--------------------------------------------------------------------------- void __fastcall DrawingPen_8::putPixel(int x) { if (!_colorProtected||MainImageForm->Palette->ColorData[protectCheckLine[x]]->Protect == 0) { drawingLine[x] = _color; } } //--------------------------------------------------------------------------- void __fastcall DrawingPen_8::copyPixel(int x, Byte *pixel) { if (!_colorProtected||MainImageForm->Palette->ColorData[protectCheckLine[x]]->Protect == 0) { drawingLine[x] = *pixel; } } //--------------------------------------------------------------------------- void __fastcall DrawingPen_8::putPixel(int x, Byte *pMaskLine) { if(pMaskLine[x] == 0) putPixel(x); } //--------------------------------------------------------------------------- void __fastcall DrawingPen_8::copyPixel(int x, Byte *pMaskLine, Byte *pixel) { if(pMaskLine[x] == 0) copyPixel(x, pixel); } //--------------------------------------------------------------------------- COLORREF __fastcall DrawingPen_8::pickColor(Byte *pSourceLine, int x) { return pSourceLine[x]; } //--------------------------------------------------------------------------- bool __fastcall DrawingPen_8::isProtected(int x) { return _colorProtected && MainImageForm->Palette->ColorData[protectCheckLine[x]]->Protect != 0; } //--------------------------------------------------------------------------- bool __fastcall DrawingPen_8::isProtected(int x, Byte *pMaskLine) { return (_colorProtected && MainImageForm->Palette->ColorData[protectCheckLine[x]]->Protect != 0) || pMaskLine[x] != 0; } //--------------------------------------------------------------------------- void __fastcall DrawingPen_24::putPixel(int x) { setPixel(drawingLine + 3 * x, _color); } //--------------------------------------------------------------------------- void __fastcall DrawingPen_24::copyPixel(int x, Byte *pixel) { copyPixel(drawingLine + 3 * x, pixel); } //--------------------------------------------------------------------------- void __fastcall DrawingPen_24::putPixel(int x, Byte *pMaskLine) { if ((pMaskLine[x >> 3] & (0x80 >> (x & 7))) == 0) putPixel(x); } //--------------------------------------------------------------------------- void __fastcall DrawingPen_24::copyPixel(int x, Byte *pMaskLine, Byte *pixel) { if ((pMaskLine[x >> 3] & (0x80 >> (x & 7))) == 0) copyPixel(x, pixel); } //--------------------------------------------------------------------------- void __fastcall DrawingPen_24::setPixel(Byte *pLine, COLORREF color) { SetPixel24(pLine, color); } //--------------------------------------------------------------------------- void __fastcall DrawingPen_24::copyPixel(Byte *pLine, Byte *pixel) { CopyPixel24(pLine, pixel); } //--------------------------------------------------------------------------- COLORREF __fastcall DrawingPen_24::pickColor(Byte *pSourceLine, int x) { COLORREF result; // GetPixel24(pSourceLine, result); result = (pSourceLine[3*x] << 16) + (pSourceLine[3*x+1] << 8) + pSourceLine[3*x+2]; return result; } //--------------------------------------------------------------------------- bool __fastcall DrawingPen_24::isProtected(int x) { return false; } //--------------------------------------------------------------------------- bool __fastcall DrawingPen_24::isProtected(int x, Byte *pMaskLine) { return (pMaskLine[x >> 3] & (0x80 >> (x & 7)))!= 0; } //--------------------------------------------------------------------------- void __fastcall DrawingPen_1::putPixel(int x) { drawingLine[x >> 3] &= ~(0x80 >> (x & 7)); } //--------------------------------------------------------------------------- void __fastcall DrawingPen_1::putPixel(int x, Byte *pMaskLine) { if ((pMaskLine[x >> 3] & (0x80 >> (x & 7))) == 0) putPixel(x); } //--------------------------------------------------------------------------- __fastcall LineItr::LineItr(TPItemImage *theImage) { Image = theImage; if(Image->uBitmap->BitsPerPixel == 8) { basePen = (DrawingPen *)new DrawingPen_8; maskPen = (DrawingPen *)new DrawingPen_8; maskPen->setColor(0); } else if(Image->uBitmap->BitsPerPixel == 24) { basePen = (DrawingPen *)new DrawingPen_24; maskPen = (DrawingPen *)new DrawingPen_1; maskPen->setColor(0); } } //--------------------------------------------------------------------------- __fastcall LineItr::~LineItr() { delete basePen; delete maskPen; } //--------------------------------------------------------------------------- void __fastcall LineItr::setBaseColor(COLORREF color) { basePen->setColor(color); } //--------------------------------------------------------------------------- COLORREF __fastcall LineItr::pickColor(int x) { return basePen->pickColor(protectCheckLine, x); } //--------------------------------------------------------------------------- COLORREF __fastcall LineItr::pickColor(Byte *pSourceLine, int x) { return basePen->pickColor(pSourceLine, x); } //--------------------------------------------------------------------------- void __fastcall LineItr::setColorProtected(bool value) { _colorProtected = value; basePen->setColorProtected(value); } //--------------------------------------------------------------------------- bool __fastcall LineItr::startScanLine() { if (Image->uBitmap->StartScanLine() == false) goto fail; return true; fail: stopScanLine(); return false; } //--------------------------------------------------------------------------- void __fastcall LineItr::stopScanLine() { Image->uBitmap->StopScanLine(); } //--------------------------------------------------------------------------- void __fastcall LineItr::getScanLine(int y, int startX, int length) { baseLine = Image->uBitmap->GetScanLine(y, startX, length); // basePen->setDrawingLine(baseLine); protectCheckLine = baseLine; basePen->setProtectCheckLine(baseLine); } //--------------------------------------------------------------------------- void __fastcall LineItr::putScanLine(int y, int startX, int length) { Image->uBitmap->PutScanLine(y, startX, length); // } //--------------------------------------------------------------------------- void __fastcall LineItr::putPixel(int x) { basePen->putPixel(x); } //--------------------------------------------------------------------------- void __fastcall LineItr::copyPixel(int x, Byte *pixel) { basePen->copyPixel(x, pixel); } //--------------------------------------------------------------------------- bool __fastcall LineItr::isProtected(int x) { return basePen->isProtected(x); } //--------------------------------------------------------------------------- void __fastcall LineItr_Layer::setColorProtected(bool value) { _colorProtected = value; basePen->setColorProtected(value); maskPen->setColorProtected(value); } //--------------------------------------------------------------------------- bool __fastcall LineItr_Layer::startScanLine() { if (Image->uBitmap->StartScanLine() == false) goto fail; if (Image->LayerMask->StartScanLine() == false) goto fail; if (_colorProtected) { if (Image->BackGround->StartScanLine() == false) goto fail; } return true; fail: stopScanLine(); return false; } //--------------------------------------------------------------------------- void __fastcall LineItr_Layer::stopScanLine() { Image->uBitmap->StopScanLine(); Image->LayerMask->StopScanLine(); } //--------------------------------------------------------------------------- void __fastcall LineItr_Layer::getScanLine(int y, int startX, int length) { baseLine = Image->uBitmap->GetScanLine(y, startX, length); // basePen->setDrawingLine(baseLine); layerMaskLine = Image->LayerMask->GetScanLine(y, startX, length); maskPen->setDrawingLine(layerMaskLine); if (_colorProtected) { backgroundLine = Image->BackGround->GetScanLine(y, startX, length); protectCheckLine = backgroundLine; basePen->setProtectCheckLine(backgroundLine); maskPen->setProtectCheckLine(backgroundLine); } else { protectCheckLine = baseLine; basePen->setProtectCheckLine(baseLine); maskPen->setProtectCheckLine(baseLine); } } //--------------------------------------------------------------------------- void __fastcall LineItr_Layer::putScanLine(int y, int startX, int length) { Image->uBitmap->PutScanLine(y, startX, length); // Image->LayerMask->PutScanLine(y, startX, length); // } //--------------------------------------------------------------------------- void __fastcall LineItr_Layer::putPixel(int x) { basePen->putPixel(x); maskPen->putPixel(x); } //--------------------------------------------------------------------------- void __fastcall LineItr_Layer::copyPixel(int x, Byte *pixel) { basePen->copyPixel(x, pixel); maskPen->putPixel(x); } //--------------------------------------------------------------------------- bool __fastcall LineItr_Layer::isProtected(int x) { return basePen->isProtected(x); } //--------------------------------------------------------------------------- bool __fastcall LineItr_Mask::startScanLine() { if (Image->uBitmap->StartScanLine() == false) goto fail; if (Image->Mask->StartScanLine() == false) goto fail; return true; fail: stopScanLine(); return false; } //--------------------------------------------------------------------------- void __fastcall LineItr_Mask::stopScanLine() { Image->Mask->StopScanLine(); Image->uBitmap->StopScanLine(); } //--------------------------------------------------------------------------- void __fastcall LineItr_Mask::getScanLine(int y, int startX, int length) { baseLine = Image->uBitmap->GetScanLine(y, startX, length); // basePen->setDrawingLine(baseLine); maskLine = Image->Mask->GetScanLine(y, startX, length); protectCheckLine = baseLine; basePen->setProtectCheckLine(baseLine); } //--------------------------------------------------------------------------- void __fastcall LineItr_Mask::putScanLine(int y, int startX, int length) { Image->uBitmap->PutScanLine(y, startX, length); // } //--------------------------------------------------------------------------- void __fastcall LineItr_Mask::putPixel(int x) { basePen->putPixel(x, maskLine); } //--------------------------------------------------------------------------- void __fastcall LineItr_Mask::copyPixel(int x, Byte *pixel) { basePen->copyPixel(x, pixel); } //--------------------------------------------------------------------------- bool __fastcall LineItr_Mask::isProtected(int x) { return basePen->isProtected(x, maskLine); } //--------------------------------------------------------------------------- void __fastcall LineItr_Layer_Mask::setColorProtected(bool value) { _colorProtected = value; basePen->setColorProtected(value); maskPen->setColorProtected(value); } //--------------------------------------------------------------------------- bool __fastcall LineItr_Layer_Mask::startScanLine() { if (Image->uBitmap->StartScanLine() == false) goto fail; if (Image->LayerMask->StartScanLine() == false) goto fail; if (_colorProtected) { if (Image->BackGround->StartScanLine() == false) goto fail; } if (Image->Mask->StartScanLine() == false) goto fail; return true; fail: stopScanLine(); return false; } //--------------------------------------------------------------------------- void __fastcall LineItr_Layer_Mask::stopScanLine() { Image->Mask->StopScanLine(); if (_colorProtected) Image->BackGround->StopScanLine(); Image->LayerMask->StopScanLine(); Image->uBitmap->StopScanLine(); } //--------------------------------------------------------------------------- void __fastcall LineItr_Layer_Mask::getScanLine(int y, int startX, int length) { baseLine = Image->uBitmap->GetScanLine(y, startX, length); // basePen->setDrawingLine(baseLine); layerMaskLine = Image->LayerMask->GetScanLine(y, startX, length); maskPen->setDrawingLine(layerMaskLine); if (_colorProtected) { backgroundLine = Image->BackGround->GetScanLine(y); protectCheckLine = backgroundLine; basePen->setProtectCheckLine(backgroundLine); maskPen->setProtectCheckLine(backgroundLine); } else { protectCheckLine = baseLine; basePen->setProtectCheckLine(baseLine); maskPen->setProtectCheckLine(baseLine); } maskLine = Image->Mask->GetScanLine(y, startX, length); } //--------------------------------------------------------------------------- void __fastcall LineItr_Layer_Mask::putScanLine(int y, int startX, int length) { Image->uBitmap->PutScanLine(y, startX, length); // Image->LayerMask->PutScanLine(y, startX, length); // } //--------------------------------------------------------------------------- void __fastcall LineItr_Layer_Mask::putPixel(int x) { basePen->putPixel(x, maskLine); maskPen->putPixel(x, maskLine); } //--------------------------------------------------------------------------- void __fastcall LineItr_Layer_Mask::copyPixel(int x, Byte *pixel) { basePen->copyPixel(x, pixel); maskPen->putPixel(x); } //--------------------------------------------------------------------------- bool __fastcall LineItr_Layer_Mask::isProtected(int x) { return basePen->isProtected(x, maskLine); } //---------------------------------------------------------------------------