//--------------------------------------------------------------------------- #include #pragma hdrstop #include "Combo_F.h" #include "ComboForm.h" #include "FileManager_F.h" #include "Main.h" #include "MainImage.h" #include "Palette.h" #include "Undo.h" #ifndef ACADEMY #include "CommonPrint.h" #include "UserColor_F.h" #endif #include "FullView.h" //--------------------------------------------------------------------------- #pragma package(smart_init) #pragma link "Selector" #pragma link "TPSpin" #pragma resource "*.dfm" //--------------------------------------------------------------------------- #define IDS_COMBOMENU StringTable[0] #define IDS_CHANGECOLOR StringTable[1] #define IDS_HUELIGSAT StringTable[2] #define IDS_HUE StringTable[3] #define IDS_LIGHTNESS StringTable[4] #define IDS_SATURATION StringTable[5] //--------------------------------------------------------------------------- TComboMenu *ComboMenu; //--------------------------------------------------------------------------- __fastcall TComboMenu::TComboMenu(TComponent* Owner) : TForm(Owner) { hWnd = ((TWinControl *) Owner)->Handle; //====================================================== StringTable.Create(DirectoryItem, Language, "Combo"); SetSmallFont(Font); Caption = IDS_COMBOMENU; sbChange->Caption = IDS_CHANGECOLOR; sbFile->Caption = IDS_COMMON_FILE; sbHue->Caption = IDS_HUELIGSAT; sbPrint->Caption = IDS_COMMON_PRINT; // Label1->Caption = IDS_HUE; // Label2->Caption = IDS_LIGHTNESS; // Label3->Caption = IDS_SATURATION; sbComboRun->Caption = IDS_COMMON_RUN; sbComboExit->Caption = IDS_COMMON_EXIT; sbComboNew->Hint = IDS_COMMON_NEW; sbComboAll->Hint = IDS_COMMON_ALL; sbComboDelete->Hint = IDS_COMMON_INSERTCOLOR; sbComboBlock->Hint = IDS_COMMON_BLOCKCOLOR; //====================================================== } //--------------------------------------------------------------------------- void __fastcall TComboMenu::FormCreate(TObject *Sender) { #ifdef ACADEMY sbPrint->Enabled = false; runSw = false; mouseSw = false; PlaySW = false; #endif } //--------------------------------------------------------------------------- void __fastcall TComboMenu::sbComboNewClick(TObject *Sender) { TSpeedButton *s = (TSpeedButton *) Sender; if (s == sbComboNew) { Selector->Initial(); for (int m=0; m<=3; m++) { for (int k=0; k<36; k++) { if(SubForm->Selector[m]->ComboShape[k]->Selected) SubForm->Selector[m]->ShapeDown(k+1); } } } else if (s == sbComboAll) { TCursor cursor = Screen->Cursor; Screen->Cursor = crHourGlass; for (int i=0; iSelector[SubForm->page]->ChoiceColor->Count; i++) { Selector->ChoiceColor->Add(SubForm->Selector[SubForm->page]->Palette, SubForm->Selector[SubForm->page]->ChoiceColor->Code[i]); } Selector->Invalid(); FromSelector2comboSelector(); Screen->Cursor = cursor; } else if (s == sbComboBlock) { if (sbComboBlock->Down) sbComboBlock->Hint = IDS_COMMON_ONECOLOR; else sbComboBlock->Hint = IDS_COMMON_BLOCKCOLOR; } else if (s == sbComboDelete) { if (sbComboDelete->Down) sbComboDelete->Hint = IDS_COMMON_DELETECOLOR; else sbComboDelete->Hint = IDS_COMMON_INSERTCOLOR; } SubForm->SetData(); } //--------------------------------------------------------------------------- void __fastcall TComboMenu::FromSelector2comboSelector() { int cnt = Selector->Count; if (cnt>12) cnt = 13; for (int i=0; iChoiceColor->Code[i] == SubForm->ChoiceColor->Code[j]) { if (!SubForm->Selector[0]->ComboShape[j]->Selected) { for (int k=0; k<=3; k++) SubForm->Selector[k]->ShapeDown(j+1); break; } } } } } //--------------------------------------------------------------------------- void __fastcall TComboMenu::comboseHueChange(TObject *Sender) { if (comboseHue->Text.Length()>0) { if (bHS) CDrawHSBar(Hue, Sat); if (bL) CDrawLBar(Lig); CDrawL(); Hue = comboseHue->Value; CDrawHSBar(Hue, Sat); bHS = true; CDrawLBar(Lig); bL = true; CRunHLS(); } } //--------------------------------------------------------------------------- void __fastcall TComboMenu::comboseHueClick(TObject *Sender) { TPSpinEdit *sedit = (TPSpinEdit *)Sender; sedit->SetFocus(); sedit->SelectAll(); } //--------------------------------------------------------------------------- void __fastcall TComboMenu::comboseLigChange(TObject *Sender) { if (comboseLig->Text.Length()>0) { if (bL) CDrawLBar(Lig); Lig = comboseLig->Value; CDrawLBar(Lig); bL = true; CRunHLS(); } } //--------------------------------------------------------------------------- void __fastcall TComboMenu::comboseSatChange(TObject *Sender) { if (comboseSat->Text.Length()>0) { if (bHS) CDrawHSBar(Hue, Sat); Sat = comboseSat->Value; CDrawHSBar(Hue, Sat); bHS = true; CRunHLS(); } } //--------------------------------------------------------------------------- void __fastcall TComboMenu::ComboImageHSMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { mouseSw = true; if (Shift.Contains(ssLeft)) CMoveHS(X, Y); } //--------------------------------------------------------------------------- void __fastcall TComboMenu::ComboImageLMouseMove(TObject *Sender, TShiftState Shift, int X, int Y) { mouseSw = true; if (Shift.Contains(ssLeft)) CMoveL(Y); } //--------------------------------------------------------------------------- void __fastcall TComboMenu::sbBeforeClick(TObject *Sender) { ChangePanel->Visible = true; HuePanel->Visible = false; if(BasicPalette) { delete BasicPalette; BasicPalette = NULL;} ClientHeight = 153; Parent->Height = ParentHeight+ClientHeight; Selector->Invalid(); } //--------------------------------------------------------------------------- void __fastcall TComboMenu::sbHueClick(TObject *Sender) { int i, j, k; TCursor cursor = Screen->Cursor; Screen->Cursor = crHourGlass; if (SubForm->step > 0){ SubForm->DrawRectangle(Sender, SubForm->Temp); SubForm->step = 0; SubForm->Repaint(); } for (i=0; i<4; i++) SubForm->rotate.fix[i] = 0; SubForm->SpeedButton1->Font->Color = clBlack; SubForm->SpeedButton1->Caption = AnsiString(SubForm->SpeedButton1->Tag + 1); SubForm->SpeedButton1->Down = false; SubForm->SpeedButton2->Font->Color = clBlack; SubForm->SpeedButton2->Caption = AnsiString(SubForm->SpeedButton2->Tag + 1); SubForm->SpeedButton2->Down = false; SubForm->SpeedButton3->Font->Color = clBlack; SubForm->SpeedButton3->Caption = AnsiString(SubForm->SpeedButton3->Tag + 1); SubForm->SpeedButton3->Down = false; SubForm->SpeedButton4->Font->Color = clBlack; SubForm->SpeedButton4->Caption = AnsiString(SubForm->SpeedButton4->Tag + 1); SubForm->SpeedButton4->Down = false; SubForm->rotate.fix_cnt = 0; Selector->Initial(); SubForm->SetData(); SubForm->CanVisible(0); for (i=0; iSelector[SubForm->page]->ChoiceColor->Count; i++) { Selector->ChoiceColor->Add(SubForm->Selector[SubForm->page]->Palette, SubForm->Selector[SubForm->page]->ChoiceColor->Code[i]); } for (j=0; j<36; j++) { if (SubForm->Selector[0]->ComboShape[j]->Selected) for (k=0; k<=3; k++) SubForm->Selector[k]->ShapeDown(j+1); } Selector->Invalid(); if (!SubForm->Visible) SubForm->Visible = true; Screen->Cursor = cursor; } //--------------------------------------------------------------------------- void __fastcall TComboMenu::sbChangeClick(TObject *Sender) { if (SubForm->step > 0){ SubForm->DrawRectangle(Sender, SubForm->Temp); SubForm->step = 0; SubForm->Repaint(); } ChangePanel->Visible = true; HuePanel->Visible = false; if(BasicPalette) { delete BasicPalette; BasicPalette = NULL;} Selector->Initial(); for (int j=0; j<36; j++) { if (SubForm->Selector[0]->ComboShape[j]->Selected) for (int k=0; k<=3; k++) SubForm->Selector[k]->ShapeDown(j+1); } ClientHeight = 153; Parent->Height = ParentHeight+ClientHeight; if (!SubForm->Visible) SubForm->Visible = true; } //--------------------------------------------------------------------------- void __fastcall TComboMenu::sbFileClick(TObject *Sender) { //TFileManagerForm *Form = NULL; FileManagerForm = new TFileManagerForm(this); if (SubForm->step > 0){ SubForm->DrawRectangle(Sender, SubForm->Temp); SubForm->step = 0; SubForm->Repaint(); } if (FileManagerForm) { FileManagerForm->Extension = 0; //Combo¸¦ fileManager¿¡°Ô ¾Ë¸². FileManagerForm->FilterComboBox->Filter = "Texpro Combo File (*.cmb)|*.cmb"; FileManagerForm->OnRead = ComboRead; FileManagerForm->OnFileName = ComboFileName; FileManagerForm->OnSave = ComboSave; FileManagerForm->ShowModal(); delete FileManagerForm; } } //--------------------------------------------------------------------------- void __fastcall TComboMenu::sbPrintClick(TObject *Sender) { sbComboExitClick(this); if (SubForm->step > 0){ SubForm->DrawRectangle(Sender, SubForm->Temp); SubForm->step = 0; SubForm->Repaint(); } #ifndef ACADEMY TCommonPrintForm *Form = NULL; TTexpiaBitmap *Pattern = NULL; if ((Form = new TCommonPrintForm((TComponent *)NULL))==NULL) goto fail; if (Form->ShowModal() == mrOk) { if ((Pattern = new TTexpiaBitmap)==NULL) goto fail; if (!DrawPattern(Pattern)) goto fail; if (!SendToPrinterTP(Pattern, MainImageForm->CanvasInfor.DotsPerInch, "Combo - " + MainImageForm->FileName, Form->PageEdit->Value, Form->cbMethod->ItemIndex)) goto fail; // convert by celberus delete Pattern; sbChangeClick(sbChange); } delete Form; return; fail: if (Pattern) delete Pattern; if (Form) delete Form; EXCEPTION_MESSAGE_OK(EC_MEMORY_LACK); #endif } //--------------------------------------------------------------------------- void __fastcall TComboMenu::sbComboRunClick(TObject *Sender) { int j; double h, l, s, a; if (SubForm->step > 0){ SubForm->DrawRectangle(Sender, SubForm->Temp); SubForm->step = 0; SubForm->Repaint(); } if (sbChange->Down) { sbComboRun->Enabled = false; sbComboExit->Enabled = true; sbHue->Enabled = false; SelectorPanel->Visible = false; PlayPanel->Visible = true; SubForm->SetData(); SubForm->CanVisible(1); lPageTotal->Caption = Format("%d/%d", OPENARRAY (TVarRec, (SubForm->rotate.number, SubForm->rotate.total))); } else if (sbHue->Down) { if (Selector->Count == 0) { MessageDlg(IDS_MESSAGE_CHOOSECOLOR, mtInformation, TMsgDlgButtons()<Visible = true; HuePanel->Visible = false; ClientHeight = 153; Parent->Height = ParentHeight+ClientHeight; } else { ChangePanel->Visible = false; HuePanel->Visible = true; ClientHeight = 177; Parent->Height = ParentHeight + ClientHeight; Selector->SetPalette(SubForm->Selector[SubForm->page]->Palette); BasicPalette = new TPalette; bOK = true; BasicPalette->SetPalette(SubForm->Selector[SubForm->page]->Palette); Basic.Hue = 0; Basic.Lig = 0; Basic.Sat = 0; for (j=0; jCount; j++) { BasicPalette->RGB2HLS(Selector->Code[j], h, l, s); if (h != UNDEFINED) { if (j > 0) { a = Basic.Hue / j; if (a < 180) { if (h >= a + 180) h = h - 360; } else { if (h <= a - 180) h = h + 360; } } Basic.Hue = Basic.Hue + h; Basic.Lig = Basic.Lig + l; Basic.Sat = Basic.Sat + s; } } Basic.Hue = Basic.Hue / Selector->Count; if (Basic.Hue < 0) Basic.Hue = Basic.Hue + 360; else if (Basic.Hue >= 360) Basic.Hue = Basic.Hue - 360; Basic.Lig = Basic.Lig / Selector->Count; Basic.Sat = Basic.Sat / Selector->Count; Hue = Basic.Hue; Lig = 100*Basic.Lig; Sat = 100*Basic.Sat; ComboImageHS->Picture->Bitmap->PixelFormat = pf24bit; ComboImageHS->Picture->Bitmap->Width = 73; ComboImageHS->Picture->Bitmap->Height = 73; ComboImageHS->Canvas->Brush->Color = clBtnFace; ComboImageHS->Canvas->FillRect(Rect(0, 0, ComboImageHS->Width, ComboImageHS->Height)); CDrawHS(); ComboImageHS->Canvas->Pen->Mode = pmXor; ComboImageHS->Canvas->Pen->Color = clWhite; CDrawHSBar(Hue, Sat); bHS = true; ComboImageL->Picture->Bitmap->PixelFormat = pf24bit; ComboImageL->Picture->Bitmap->Width = 73; ComboImageL->Picture->Bitmap->Height = 73; ComboImageL->Canvas->Brush->Color = clBtnFace; ComboImageL->Canvas->FillRect(Rect(0, 0, ComboImageL->Width, ComboImageL->Height)); CDrawL(); ComboImageL->Canvas->Pen->Mode = pmXor; ComboImageL->Canvas->Pen->Color = clWhite; CDrawLBar(Lig); bL = true; comboseHue->Value = Hue; chHue = Hue; comboseLig->Value = Lig; chLig = Lig; comboseSat->Value = Sat; bOK = false; } } } //----------------------------------------------------------------------------- void __fastcall TComboMenu::SetSelectorPalette() { // HLS Áß 4°³ÀÇ À̹ÌÁö Áß Çϳª¸¦ ¼±ÅÃÇßÀ» ¶§ »ç¿ë... double h, l, s, a; BasicPalette->SetPalette(SubForm->Selector[SubForm->page]->Palette); Basic.Hue = 0; Basic.Lig = 0; Basic.Sat = 0; for (int j=0; jCount; j++) { BasicPalette->RGB2HLS(Selector->Code[j], h, l, s); if (h != UNDEFINED) { if (j > 0) { a = Basic.Hue / j; if (a < 180) { if (h >= a + 180) h = h - 360; } else { if (h <= a - 180) h = h + 360; } } Basic.Hue = Basic.Hue + h; Basic.Lig = Basic.Lig + l; Basic.Sat = Basic.Sat + s; } } Basic.Hue = Basic.Hue / Selector->Count; if (Basic.Hue < 0) Basic.Hue = Basic.Hue + 360; else if (Basic.Hue >= 360) Basic.Hue = Basic.Hue - 360; Basic.Lig = Basic.Lig / Selector->Count; Basic.Sat = Basic.Sat / Selector->Count; comboseHue->Value = Basic.Hue; comboseLig->Value = 100*Basic.Lig; comboseSat->Value = 100*Basic.Sat; } //----------------------------------------------------------------------------- void __fastcall TComboMenu::PlayBarPlay(TObject *Sender) { runSw = true; PlaySW = true; SubForm->ComChange(Sender); if (Selector->Count>8) Progress->Position = (SubForm->rotate.page * Progress->Frequency) /1000; else Progress->Position = SubForm->rotate.page * Progress->Frequency; lPageTotal->Caption = Format("%d/%d", OPENARRAY (TVarRec, (SubForm->rotate.number, SubForm->rotate.total))); for (int i = 0; i < 4; i++) SubForm->PaletteColorChange(i); PaletteForm->DIB256Palette->Invalidate(); PlaySW = false; } //--------------------------------------------------------------------------- void __fastcall TComboMenu::sbComboExitClick(TObject *Sender) { sbComboExit->Enabled = false; sbComboRun->Enabled = true; sbHue->Enabled = true; PlayBar->SetInit(); PlayPanel->Visible = false; SelectorPanel->Visible = true; } //--------------------------------------------------------------------------- void __fastcall TComboMenu::ProgressChange(TObject *Sender) { if(!PlaySW)PlayBar->SetInit(); //2001.7.12 lhskys C++Bilder 5->3 »ö»çÀü°³½Ã ÇѹøÇÏ°í ¸ØÃß´Â°Í ¼öÁ¤ runSw = true; if (Progress->Frequency) { if (Selector->Count>8) SubForm->rotate.page = (Progress->Position*1000 / Progress->Frequency); else SubForm->rotate.page = Progress->Position / Progress->Frequency; if(!PlaySW)SubForm->ComChange(Sender); //2001.7.12 lhskys C++Bilder 5->3 »ö»çÀü°³½Ã ÇѹøÇÏ°í ¸ØÃß´Â°Í ¼öÁ¤ lPageTotal->Caption = Format("%d/%d", OPENARRAY (TVarRec, (SubForm->rotate.number, SubForm->rotate.total))); for (int i = 0; i < 4; i++) SubForm->PaletteColorChange(i); PaletteForm->DIB256Palette->Invalidate(); } } //--------------------------------------------------------------------------- void __fastcall TComboMenu::InitForm() { PlayBar = new TPlayBar(PlayPanel); PlayBar->Parent = PlayPanel; PlayBar->Left = 4; PlayBar->Top = 4; PlayBar->OnPlay = PlayBarPlay; RECT r = (MainImageForm->WorkArea->Mask) ? MainImageForm->WorkArea->Range : Rect(0, 0, MainImageForm->iMainImage->uBitmap->Width, MainImageForm->iMainImage->uBitmap->Height) ; MainImageForm->UndoSave(UK_ALL, r); ParentHeight = Parent->Height+20; ClientHeight = 153; Parent->Height = ParentHeight+ClientHeight; SubForm = new TComboForms(MainForm); SubForm->Parent = MainForm; if (SubForm->InitForm() == false) { delete SubForm; error = true; } else error = false; sbChange->Down = true; ChangePanel->Visible = true; HuePanel->Visible = false; BasicPalette = NULL; Selector->SetPalette(MainImageForm->Palette); Selector->Initial(); if (error) PostMessage(hWnd, TPM_EXITFUNCTION, 0, 0); } //--------------------------------------------------------------------------- void __fastcall TComboMenu::ExitForm() { Byte *src, *dst, uc; int x, y, i, sx, sy, max; TPItemImage *Image = MainImageForm->iMainImage; if (!error) { sx = SubForm->window.s.x; sy = SubForm->window.s.y; max = 0; if (!Image->uBitmap->StartScanLine()) goto fail; for (y=0; yuBitmap->Height; y++){ src = (Byte *) Image->uBitmap->GetScanLine(y); for (x=0; xuBitmap->Width; x++) { if (maxuBitmap->StopScanLine(); uc = max; if (uc*2>=252) { EXCEPTION_MESSAGE_OK(EC_COLOR_OVERFLOW); } else { if(runSw == true){ for (i=uc+1; i<=uc*2; i++){ MainImageForm->Palette->ColorData[i] = SubForm->Selector[SubForm->page]->Palette->ColorData[i-uc]; if (!Image->uBitmap->StartScanLine()) goto fail; if (!SubForm->CImage[SubForm->page]->Bitmap->StartScanLine()) goto fail; for (y=0; ywindow.size.y; y++) { src = (Byte *) SubForm->CImage[SubForm->page]->Bitmap->GetScanLine(y); dst = (Byte *) Image->uBitmap->GetScanLine(y+sy); for (x=0; xwindow.size.x; x++) { dst[x+sx] = src[x]+uc; } Image->uBitmap->PutScanLine(y+sy); } SubForm->CImage[SubForm->page]->Bitmap->StopScanLine(); Image->uBitmap->StopScanLine(); } MainImageForm->Palette->UseColor = uc*2; PaletteForm->DIB256Palette->ChoiceIndex = 2; } } delete SubForm; SubForm = NULL; } if (BasicPalette) {delete BasicPalette; BasicPalette = NULL;} delete PlayBar; ::RepaintColor(); return; fail: Image->uBitmap->StopScanLine(); SubForm->CImage[SubForm->page]->Bitmap->StopScanLine(); if (SubForm) delete SubForm; if (BasicPalette) {delete BasicPalette; BasicPalette = NULL;} delete PlayBar; } //--------------------------------------------------------------------------- void __fastcall TComboMenu::CDrawHS() { int x, y, v, xx; double h, l, s; Byte r, g, b; Byte *sl, *sh; l = 0.5; for (y=0; y<=35; y++) { sl = (Byte *) ComboImageHS->Picture->Bitmap->ScanLine[36-y]; sh = (Byte *) ComboImageHS->Picture->Bitmap->ScanLine[36+y]; v = sqrt(1296-y*y); for (x=-v; x<=v; x++) { xx = 3*(36+x); s = sqrt(x*x + y*y)/36; if ((y==0) && (x==0)) h = 0; else h = atan2(y, x)*180/M_PI; HLS2RGB(h, l, s, r, g, b); *(sl+xx) = b; *(sl+xx+1) = g; *(sl+xx+2) = r; if ((y==0) && (x==0)) h = 180; else h = 180 + atan2(y, -x) * 180 / M_PI; HLS2RGB(h, l, s, r, g, b); *(sh+xx) = b; *(sh+xx+1) = g; *(sh+xx+2) = r; } } } //--------------------------------------------------------------------------- void __fastcall TComboMenu::CDrawL() { int x, y, v, xx; double h, l, s; Byte r, g, b; Byte *sl, *sh; h = comboseHue->Value; for (y=0; y<=36; y++) { sl = (Byte *) ComboImageL->Picture->Bitmap->ScanLine[36-y]; sh = (Byte *) ComboImageL->Picture->Bitmap->ScanLine[36+y]; v = 2*(36-y); for (x=0; x<=v; x++) { xx = 3*x; if (v==0) s = 0; else s = (double) x/v; l = 0.5+ y/72.0; HLS2RGB(h, l, s, r, g, b); *(sl+xx) = b; *(sl+xx+1) = g; *(sl+xx+2) = r; l = 0.5-y/72.0; HLS2RGB(h, l, s, r, g, b); *(sh+xx) = b; *(sh+xx+1) = g; *(sh+xx+2) = r; } } } //--------------------------------------------------------------------------- void __fastcall TComboMenu::CDrawHSBar(int h, int s) { double r, x, y; int cx, cy; r = h*M_PI/180; ComboImageHS->Canvas->MoveTo(36, 36); x = 36 * cos(r); y = 36 * sin(r); ComboImageHS->Canvas->LineTo(36+(int)x, 36-(int)y); cx = 36 + (x*s/100); cy = 36 - (y*s/100); ComboImageHS->Canvas->Rectangle(cx-2, cy-2, cx+2, cy+2); ComboImageHS->Update(); } //--------------------------------------------------------------------------- void __fastcall TComboMenu::CDrawLBar(int l) { int y; y = 71-l*71 / 100; ComboImageL->Canvas->MoveTo(0, y); ComboImageL->Canvas->LineTo(72, y); ComboImageHS->Update(); } //--------------------------------------------------------------------------- void __fastcall TComboMenu::CMoveHS(int X, int Y) { int h, s; X = X-36; Y = Y-36; if (Y<0) h = atan2(-Y, X)*180/M_PI; else { if ((Y==0) && (X==0)) h = 180; else h = 180+atan2(Y, -X)*180/M_PI; } comboseHue->Value = h; s = 100*sqrt(X*X+Y*Y)/36; if (s>100) s = 100; comboseSat->Value = s; } //--------------------------------------------------------------------------- void __fastcall TComboMenu::CMoveL(int Y) { int l; l = 100-100*Y / 71; if (l<0) l = 0; if (l>100) l =100; comboseLig->Value = l; } //--------------------------------------------------------------------------- void __fastcall TComboMenu::CRunHLS() { int i, n; double h, l, s, hc, lc, sc; RGBQUAD rgb[256]; hc = Hue-Basic.Hue; lc = Lig/100.0-Basic.Lig; sc = Sat/100.0-Basic.Sat; if (mouseSw == true) { if (chLig != Lig) runSw= true; if (chHue != Hue) runSw = true; } for (i=0; iCount; i++) { n = Selector->Code[i]; BasicPalette->RGB2HLS(n, h, l, s); h = h + hc; if (h<0) h = h+360; else if (h>=360) h = h-360; l = l+lc; if (l<0) l = 0; else if (l>1) l = 1; s = s+sc; if (s<0) s = 0; else if (s>1) s = 1; SubForm->Selector[SubForm->page]->Palette->HLS2RGB(n, h, l, s); } SubForm->Selector[SubForm->page]->Palette->ToRGBQUAD(rgb, 256); SubForm->CImage[SubForm->page]->Bitmap->PutColors(0, 256, rgb); SubForm->CImage[SubForm->page]->Repaint(); SubForm->Selector[SubForm->page]->Invalidate(); SubForm->PaletteColorChange(SubForm->page); PaletteForm->DIB256Palette->Invalidate(); } //--------------------------------------------------------------------------- bool __fastcall TComboMenu::DrawPattern(TTexpiaBitmap *Bmp) { int w, h, i, j, sw, k, l, m, tab, ww, hh, sx, sy, tw, size; double rx, ry; double dr = (double)MainImageForm->CanvasInfor.DotsPerInch/160.0; //dpi¿¡ µû¸¥ ºñÀ² 160dpi ±âÁØ TPoint sp, ep; TRect Src, Dst, BitRect, StrRect; RGBQUAD rgbcol[256]; AnsiString Name, c_page; TColorData *ColorMap; TCanvas *ca = NULL; HDC hDC = NULL; w = GetDeviceCaps(Printer()->Handle, HORZRES)*MainImageForm->CanvasInfor.DotsPerInch /GetDeviceCaps(Printer()->Handle, LOGPIXELSX); h = GetDeviceCaps(Printer()->Handle, VERTRES)*MainImageForm->CanvasInfor.DotsPerInch /GetDeviceCaps(Printer()->Handle, LOGPIXELSY); MainImageForm->Palette->ToRGBQUAD(rgbcol, 256); Bmp->Create(w, h, 8, rgbcol); Bmp->FillRect(Rect(0, 0, Bmp->Width, Bmp->Height), clWhite); w = Bmp->Width / 2; h = Bmp->Height / 2; if ((ca = Bmp->CreateCanvas()) == NULL) goto fail; ca->Pen->Color = clBlack; ca->Pen->Width = 3*dr ; size = ca->Font->Size; ca->Font->Size = size * dr + 0.5; ca->MoveTo(20*dr, 20*dr); ca->LineTo(20*dr, Bmp->Height-20*dr); ca->LineTo(Bmp->Width-20*dr, Bmp->Height-20*dr); ca->LineTo(Bmp->Width-20*dr, 20*dr); ca->LineTo(20*dr, 20*dr); ca->MoveTo(w, 20*dr); ca->LineTo(w, Bmp->Height-20*dr); ca->MoveTo(20*dr, h); ca->LineTo(Bmp->Width-20*dr, h); ca->Pen->Width = 1*dr; ca->MoveTo(20*dr, h-100*dr); ca->LineTo(Bmp->Width-20*dr, h-100*dr); ca->MoveTo(20*dr, Bmp->Height-120*dr); ca->LineTo(Bmp->Width-20*dr, Bmp->Height-120*dr); Src = Rect(0, 0, SubForm->CImage[0]->Bitmap->Width, SubForm->CImage[0]->Bitmap->Height); sx = w-40*dr; sy = h-130*dr; ww = SubForm->CImage[0]->Bitmap->Width; hh = SubForm->CImage[0]->Bitmap->Height; rx = (double) sx/ww; ry = (double) sy/hh; if (rx>ry) { sx = ww*ry; sy = hh*ry; } else { sx = ww*rx; sy = hh*rx; } for (m=0; m<=3; m++) { if ((hDC = SubForm->CImage[m]->Bitmap->CreateDC())==NULL) return false; switch (m) { case 0: Dst = Rect(30*dr, 30*dr, 30*dr+sx, 30*dr+sy); c_page = SubForm->Edit1->Text; StrRect = Rect(35*dr, 35*dr, 105*dr, 50*dr); break; case 1: Dst = Rect(w+10*dr, 30*dr, w+10*dr+sx, 30*dr+sy); c_page = SubForm->Edit2->Text; StrRect = Rect(w+15*dr, 35*dr, w+85*dr, 50*dr); break; case 2: Dst = Rect(30*dr, h+10*dr, 30*dr+sx, h+10*dr+sy); StrRect = Rect(35*dr, h+15*dr, 105*dr, h+30*dr); c_page = SubForm->Edit3->Text; break; case 3: Dst = Rect(w+10*dr, h+10*dr, w+10*dr+sx, h+10*dr+sy); StrRect = Rect(w+15*dr, h+15*dr, w+85*dr, h+30*dr); c_page = SubForm->Edit4->Text; break; } SetStretchBltMode(ca->Handle, COLORONCOLOR); StretchBlt(ca->Handle, Dst.Left, Dst.Top, (Dst.Right-Dst.Left), (Dst.Bottom-Dst.Top), hDC, Src.Left, Src.Top, (Src.Right-Src.Left), (Src.Bottom-Src.Top), SRCCOPY); SubForm->CImage[m]->Bitmap->DeleteDC(hDC); hDC = NULL; if (SubForm->Edit1->Visible) { ca->Pen->Width = 2*dr; ca->MoveTo(StrRect.Right, StrRect.Top); ca->LineTo(StrRect.Left, StrRect.Top); ca->LineTo(StrRect.Left, StrRect.Bottom); ca->LineTo(StrRect.Right, StrRect.Bottom); ca->LineTo(StrRect.Right, StrRect.Top); ca->Pen->Width = 1*dr; tw = 65*dr-ca->TextWidth(c_page); ca->TextRect(StrRect, StrRect.Left+tw, StrRect.Top, c_page); } } for (m=0; m<=3; m++) { i = SubForm->Selector[m]->ChoiceColor->Count; sw = (w-50*dr) / 6; //chip's width for (j = 0,l = 0, k = 0; j < i; j++, k++) { if (j > 11) break; //printingµÇ´Â color chip ¼ö¸¦ 12°³·Î Á¦ÇÑÇÑ´Ù.. if ((j % 6) == 0) { k = 0; l = j / 6; } switch (m) { case 0: // BitRect = Rect(40+sw*k, (h-90)+40*l, 40+(sw-5)+sw*k, (h-70)+40*l); StrRect = Rect(40*dr+sw*k, (h-70*dr)+40*dr*l, 40*dr+(sw-5*dr)+sw*k, (h-50*dr)+40*dr*l); break; case 1: // BitRect = Rect((w+20)+sw*k, (h-90)+40*l, (w+20)+(sw-5)+sw*k, (h-70)+40*l); StrRect = Rect((w+20*dr)+sw*k, (h-70*dr)+40*dr*l, (w+20*dr)+(sw-5*dr)+sw*k, (h-50*dr)+40*dr*l); break; case 2: // BitRect = Rect(40+sw*k, (Bmp->Height-110)+40*l, 40+(sw-5)+sw*k, (Bmp->Height-90)+40*l); StrRect = Rect(40*dr+sw*k, (Bmp->Height-90*dr)+40*dr*l, 40*dr+(sw-5*dr)+sw*k, (Bmp->Height-70*dr)+40*dr*l); break; case 3: // BitRect = Rect((w+20)+sw*k, (Bmp->Height-110)+40*l, (w+20)+(sw-5)+sw*k, (Bmp->Height-90)+40*l); StrRect = Rect((w+20*dr)+sw*k, (Bmp->Height-90*dr)+40*dr*l, (w+20*dr)+(sw-5*dr)+sw*k, (Bmp->Height-70*dr)+40*dr*l); break; } // ca->Brush->Color = SubForm->Selector[m]->Palette-> // ColorData[SubForm->Selector[m]->ChoiceColor->Code[j]]->Color; // ca->FillRect(BitRect); ca->Brush->Color = clWhite; ColorMap = SubForm->Selector[m]->Palette->ColorData[SubForm->Selector[m]-> ChoiceColor->Code[j]]; switch (ColorMap->Kind) { case 0: if (ColorMap->Page==0) Name = Format("%d-%d-%d", OPENARRAY (TVarRec, (255-ColorMap->RGB.rgbRed, 255-ColorMap->RGB.rgbGreen, 255-ColorMap->RGB.rgbBlue))); else Name = PrinterColor->PN2Code(ColorMap->Page, ColorMap->Number); break; case 3: Name = StandardColor->PN2Code(ColorMap->Page, ColorMap->Number); break; case 4: Name = TextileColor->PN2Code(ColorMap->Page, ColorMap->Number); break; case 0x10: case 0x13: case 0x14: Name = ColorMap->ColorName; break; } tab = (sw-5*dr-ca->TextWidth(Name)) / 2; if (tab<0) tab = 0; switch (m) { case 0: ca->TextRect(StrRect, 40*dr+tab+sw*k, (h-65*dr)+40*dr*l, Name); break; case 1: ca->TextRect(StrRect, (w+20*dr)+tab+sw*k, (h-65*dr)+40*dr*l, Name); break; case 2: ca->TextRect(StrRect, 40*dr+tab+sw*k, (Bmp->Height-85*dr)+40*dr*l, Name); break; case 3: ca->TextRect(StrRect, (w+20*dr)+tab+sw*k, (Bmp->Height-85*dr)+40*dr*l, Name); break; } } } Bmp->DeleteCanvas(ca); for (m=0; m<=3; m++) { i = SubForm->Selector[m]->ChoiceColor->Count; sw = (w-50*dr) / 6; //chip's width for (l = 0, k= 0, j = 0; j < i; j++, k++) { if (j > 11) break; //printingµÇ´Â color chip ¼ö¸¦ 12°³·Î Á¦ÇÑÇÑ´Ù.. if ((j % 6) == 0) { k = 0; l = j / 6; } switch (m) { case 0: sp = Point(40*dr+sw*k, (h-90*dr)+40*dr*l); ep = Point(40*dr+(sw-5*dr)+sw*k, (h-70*dr)+40*dr*l); break; case 1: sp = Point((w+20*dr)+sw*k, (h-90*dr)+40*dr*l); ep = Point((w+20*dr)+(sw-5*dr)+sw*k, (h-70*dr)+40*dr*l); break; case 2: sp = Point(40*dr+sw*k, (Bmp->Height-110*dr)+40*dr*l); ep = Point(40*dr+(sw-5*dr)+sw*k, (Bmp->Height-90*dr)+40*dr*l); break; case 3: sp = Point((w+20*dr)+sw*k, (Bmp->Height-110*dr)+40*dr*l); ep = Point((w+20*dr)+(sw-5*dr)+sw*k, (Bmp->Height-90*dr)+40*dr*l); break; } PrintColorChip8(Bmp, Rect(sp.x, sp.y, ep.x, ep.y), ((252 - (4 * i)) + m * i) + j); } } return true; fail: if (ca) Bmp->DeleteCanvas(ca); return false; } //--------------------------------------------------------------------------- bool __fastcall TComboMenu::Load_File(AnsiString FileName, int Index, TUnionBitmap *pBitmap, TPalette *pPalette, TPCanvasInfor &pi) { TEXPIAFILEHEADER tpfh; int i, k, x, y, ec; bool sw, nsw; Byte p, *sl; Byte c[225]; HANDLE hFile = INVALID_HANDLE_VALUE; DWORD dwRead; runSw = true; if (!FileExists(FileName)) { ec = EC_FILE_NOT_EXIST; goto fail; } if ((hFile = CreateFile(FileName.c_str(), GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { ec = EC_MEMORY_LACK; goto fail; } if ((ec = LoadFromTexpiaFile(hFile, pPalette, tpfh, pBitmap))!=EC_NONE) goto fail; #ifndef ACADEMY UserColorLibForm->ThisFileHasUserColor(pPalette); #endif pi = tpfh.CanvasInfor; if (tpfh.Version.Method == 'T') { if (tpfh.Version.Number < 200) sw = true; else { sw = false; if (tpfh.Version.Number >= 210) nsw = false; else nsw = true; } } else sw = true; if (!ReadFile(hFile, &(SubForm->page), 1, &dwRead, NULL)){ ec = EC_FILE_NOT_READ; goto fail; } if (!ReadFile(hFile, &(SubForm->color_count), 2, &dwRead, NULL)){ ec = EC_FILE_NOT_READ; goto fail; } if (sw) { SubForm->ChoiceColor->Initial(); SubForm->Selector[0]->Palette->SetPalette(pPalette); SubForm->Selector[1]->Palette->SetPalette(pPalette); SubForm->Selector[2]->Palette->SetPalette(pPalette); SubForm->Selector[3]->Palette->SetPalette(pPalette); if (!ReadFile(hFile, c, 225, &dwRead, NULL)) { ec = EC_FILE_NOT_READ; goto fail; } if (!pBitmap->StartScanLine()) { ec = EC_MEMORY_LACK; goto fail; } for (y=0; yHeight; y++) { sl = (Byte *)pBitmap->GetScanLine(y); for (x=0; xWidth; x++) { p = *(sl+x); if (c[p-1]<225) { SubForm->ChoiceColor->Add(pPalette, p); k = c[p-1]+1; SubForm->Selector[0]->Palette->ColorData[p] = pPalette->ColorData[k]; k = k+SubForm->color_count; SubForm->Selector[1]->Palette->ColorData[p] = pPalette->ColorData[k]; k = k+SubForm->color_count; SubForm->Selector[2]->Palette->ColorData[p] = pPalette->ColorData[k]; k = k+SubForm->color_count; SubForm->Selector[3]->Palette->ColorData[p] = pPalette->ColorData[k]; c[p] = 255; } } pBitmap->PutScanLine(y); } pBitmap->StopScanLine(); } else { if (nsw) { SubForm->ChoiceColor->LoadFromFile((int)hFile, 0); for (i=0; i<=3; i++) { SubForm->Selector[i]->Palette->LoadFromFileHandle((int)hFile, 0); } } else { SubForm->ChoiceColor->LoadFromFile((int)hFile, 1); for (i=0; i<=3; i++) { SubForm->Selector[i]->Palette->LoadFromFileHandle((int)hFile, 1); } } } CloseHandle(hFile); Selector->SetPalette(SubForm->Selector[SubForm->page]->Palette); SubForm->Visible = false; return true; fail: pBitmap->StopScanLine(); if (hFile!=INVALID_HANDLE_VALUE) CloseHandle(hFile); EXCEPTION_MESSAGE_OK(ec); return false; } //--------------------------------------------------------------------------- void __fastcall TComboMenu::ComboPaint(TObject *Sender) { SubForm->IsDraw = false; MainImageForm->iMainImage->OnPaintLocate = NULL;/////////////////by jeegeo } //--------------------------------------------------------------------------- void __fastcall TComboMenu::ComboSelectColor(int Value) { Selector->AddColor(Value); } //--------------------------------------------------------------------------- TPException __fastcall TComboMenu::ComboRead(TFMReadParameter rp) { TRect r; RECT rc; int pw, ph, sw, sh; int zi, zo; // speed-test TPCanvasInfor pi; RGBQUAD rgb[256]; TUnionBitmap *TempBitmap = NULL; TPItemImage *Image = MainImageForm->iMainImage; TPException ec = EC_NONE; MainImageForm->WorkAreaReset(true); r = Rect(0, 0, Image->uBitmap->Width, Image->uBitmap->Height); MainImageForm->UndoSave(UK_ALL, r); Image->uBitmap->FillRect(r, PALETTEINDEX(BackgroundColor)); if ((TempBitmap = new TUnionBitmap) == NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!Load_File(rp.FileName, rp.ExtIndex, TempBitmap, MainImageForm->Palette, pi)) goto fail; if ((TempBitmap->Width > Image->uBitmap->Width) || (TempBitmap->Height > Image->uBitmap->Height) || (MainImageForm->CanvasInfor.DotsPerInch != pi.DotsPerInch)) { MainImageForm->Undo->RemoveAll(); //may be bug don't ignore pi.SizeType = cstFree; pi.Width = TempBitmap->Width; pi.Height = TempBitmap->Height; MainImageForm->ResizePattern(pi, 8); FullViewForm->GetZoomRatio(MainImageForm->iMainImage, zi, zo); // speed-test MainImageForm->iMainImage->uBitmap->GetColors(0, 256, rgb); MainImageForm->iMainImage->InitbmFullView(zi, zo, PaletteForm->DIB256Palette->GetBGCOLORREF(8), rgb); // speed-test MainImageForm->iMainImage->uBitmap->SetAllToModified(); // convert by celberus fullview º¸¿©ÁÖ±â À§ÇØ } Image->uBitmap->FillRect(r, PaletteForm->DIB256Palette->GetBGCOLORREF(Image->uBitmap->BitsPerPixel)); /* #if !defined(CARPET) if (Image->LayerMask) Image->LayerMask->FillRect(r, 0); Image->uBitmap->GetColors(0, 256, rgb); Image->CreateBeforeBitmap(PaletteForm->DIB256Palette->GetBGCOLORREF(8), rgb); #endif */ ::RepaintColor(); rc = Rect(0, 0, TempBitmap->Width, TempBitmap->Height); Image->uBitmap->CopyToRect(rc.left, rc.top, TempBitmap, SRCCOPY); MainImageForm->WorkArea->SetRectangle(rc); MainImageForm->WorkAreaChange(); PaletteForm->DIB256Palette->ChoiceIndex = 2; sw = MainForm->ClientWidth-264; sh = MainForm->ClientHeight-MainForm->StatusBar->Height -GetSystemMetrics(SM_CYSMCAPTION)-GetSystemMetrics(SM_CYMENU)+3; pw = Image->uBitmap->Width + MainImageForm->PanelVert->Width; ph = Image->uBitmap->Height + MainImageForm->PanelHorz->Height; if (MainImageForm->sbRuler->Down) { pw += MainImageForm->Ruler->Thick; ph += MainImageForm->Ruler->Thick; } if (pwClientWidth = sw; MainImageForm->ClientHeight = sh; SubForm->SetComboImage(); sbChangeClick(sbChange); sbComboExitClick(sbComboExit); sbChange->Down = true; SubForm->Visible = true; ::RepaintColor(); delete TempBitmap; return EC_NONE; fail: if (TempBitmap) delete TempBitmap; if (ec == EC_NONE) ec = EC_FILE_NOT_READ; return ec; } //--------------------------------------------------------------------------- AnsiString __fastcall TComboMenu::ComboFileName(AnsiString FileName, TGraphicFileFormat ExtIndex) { PChar s; int FileNameLength, last1, last2, last3, last4; char FileIndex1, FileIndex2, FileIndex3, FileIndex4; //=============================================================== FileNameLength = FileName.Length(); if(FileNameLength > 4){ last1 = FileNameLength-3; last2 = FileNameLength-2; last3 = FileNameLength-1; last4 = FileNameLength; FileIndex1 = '.'; FileIndex2 = 'c'; FileIndex3 = 'm'; FileIndex4 = 'b'; if((FileIndex1 == FileName[last1])&&(FileIndex2 == FileName[last2]) && (FileIndex3 == FileName[last3])&&(FileIndex4 == FileName[last4])){ s = "PASS"; }else s=NULL; }else s=NULL; //=============================================================== // s = AnsiStrScan(FileName.c_str(), '.'); if (s==NULL) { AnsiString fn = FileName+".cmb"; return fn; } else { return FileName; } } //--------------------------------------------------------------------------- TPException __fastcall TComboMenu::ComboSave(AnsiString DirName, AnsiString FileName, TGraphicFileFormat ExtIndex, TCompressMethod cm) { int i, x, y, ww, hh, ec = EC_NONE; TEXPIAFILEHEADER tpfh; TRect src, dst; RGBQUAD rgb[256]; TTexpiaBitmap *tag = NULL; HDC dcSrc = NULL; TCanvas *cv = NULL; HANDLE hFile = INVALID_HANDLE_VALUE; DWORD dwWrite; if ((hFile = CreateFile(FullPathName(DirName, FileName).c_str(), GENERIC_WRITE, 0, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE) { ec = EC_FILE_NOT_CREATE; goto fail; } tpfh.Version = TexVersion('P', 'T', 300); tpfh.CanvasInfor = MainImageForm->CanvasInfor; tpfh.BitsPerPixel = 8; tpfh.Compress = cm; if (MainImageForm->WorkArea->Mask) { src = MainImageForm->WorkArea->Range; tpfh.CanvasInfor.SizeType = cstFree; tpfh.CanvasInfor.DotsPerInch = tpfh.CanvasInfor.DotsPerInch; tpfh.CanvasInfor.Width = src.Right-src.Left; tpfh.CanvasInfor.Height = src.Bottom-src.Top; } MainImageForm->Palette->ToRGBQUAD(rgb, 256); if ((tag = new TTexpiaBitmap) == NULL) { ec = EC_MEMORY_LACK; goto fail; } if (!tag->Create(80, 100, 8, rgb)) { ec = EC_MEMORY_LACK; goto fail; } if ((cv = tag->CreateCanvas()) == NULL) { ec = EC_RESOURCE_LACK; goto fail; } cv->Brush->Color = clWhite; cv->FillRect(Rect(0, 0, 80, 100)); ww = SubForm->CImage[0]->Bitmap->Width; hh = SubForm->CImage[0]->Bitmap->Height; for (i=0; i<4; i++) { x = i % 2; y = i / 2; if ((dcSrc = SubForm->CImage[i]->Bitmap->CreateDC()) == NULL) { ec = EC_RESOURCE_LACK; goto fail; } SetStretchBltMode(cv->Handle, COLORONCOLOR); StretchBlt(cv->Handle, x*42, y*52, 38, 48, dcSrc, 0, 0, ww, hh, SRCCOPY); SubForm->CImage[i]->Bitmap->DeleteDC(dcSrc); dcSrc = NULL; } tag->DeleteCanvas(cv); cv = NULL; if (MainImageForm->WorkArea && MainImageForm->WorkArea->Mask) { if (!SaveToTexpiaFile(hFile, MainImageForm->Palette, tpfh, tag, MainImageForm->iMainImage->uBitmap, &MainImageForm->WorkArea->Range)) goto fail; // ÀÛ¾÷±¸¿ª ÀúÀå need-conversion } else { if (!SaveToTexpiaFile(hFile, MainImageForm->Palette, tpfh, tag, MainImageForm->iMainImage->uBitmap)) goto fail; } delete tag; tag = NULL; if (!WriteFile(hFile, &(SubForm->page), 1, &dwWrite, NULL)) goto fail; if (!WriteFile(hFile, &(SubForm->color_count), 2, &dwWrite, NULL)) goto fail; SubForm->ChoiceColor->SaveToFile((int)hFile); for (i=0; i<=3; i++) { SubForm->Selector[i]->Palette->SaveToFileHandle((int)hFile); } CloseHandle(hFile); return EC_NONE; fail: if (tag) { if (cv) tag->DeleteCanvas(cv); delete tag; } if (hFile!=INVALID_HANDLE_VALUE) CloseHandle(hFile); if (ec == EC_NONE) ec = EC_FILE_NOT_WRITE; return ec; } //--------------------------------------------------------------------------- void __fastcall TComboMenu::FGChange(int Index) { if (sbChange->Down) { int k = 252 - 4*SubForm->ChoiceColor->Count; if (Index < k) { if (Selector->Count < 12) { Selector->ChoiceColor->Add(MainImageForm->Palette, Index); Selector->Invalid(); } else { EXCEPTION_MESSAGE_OK(EC_COLOR_OVERFLOW); } } else ShowMessage(IDS_MESSAGE_COLORNUMBER + Format("%d.", OPENARRAY(TVarRec, (k-2)))); } } //--------------------------------------------------------------------------- void __fastcall TComboMenu::iMainImageKeyDown(int Key) { if ( Key == 13 && (sbChange->Down == true || sbHue->Down == true )) sbComboRunClick(this); //lhskys ¿£ÅÍ·Î ½ÇÇàÇϱâ } //--------------------------------------------------------------------------- void __fastcall TComboMenu::SelectorMouseDown(TObject *Sender, TMouseButton Button, TShiftState Shift, int X, int Y) { int Square; Square = Selector->PointToSquare(X, Y); for (int m=0; m<=3; m++) { for (int k=0; kChoiceColor->Count/*36*/; k++) { if(SubForm->ChoiceColor->Code[k] == Selector->ChoiceColor->Code[Square]) SubForm->Selector[m]->ShapeDown(k+1); } } } //---------------------------------------------------------------------------