1 // edit_pixelmap_dlg.cpp : implementation file
2 //
3 
4 #include "stdafx.h"
5 #include "studiox.h"
6 #include "edit_pixelmap_dlg.h"
7 
8 static int _32bpp_allowed_formats[] = {
9     GX_COLOR_FORMAT_8BIT_ALPHAMAP,
10     GX_COLOR_FORMAT_8BIT_PALETTE,
11     GX_COLOR_FORMAT_565RGB,
12     GX_COLOR_FORMAT_4444ARGB,
13     GX_COLOR_FORMAT_24XRGB,
14     GX_COLOR_FORMAT_32ARGB,
15     0,
16 };
17 
18 static int _332rgb_allowed_formats[] = {
19     GX_COLOR_FORMAT_8BIT_ALPHAMAP,
20     GX_COLOR_FORMAT_8BIT_PACKED_PIXEL,
21     0,
22 };
23 
24 static int _4444argb_allowed_formats[] = {
25     GX_COLOR_FORMAT_8BIT_ALPHAMAP,
26     GX_COLOR_FORMAT_4444ARGB,
27     0,
28 };
29 
30 static int _565rgb_allowed_formats[] = {
31     GX_COLOR_FORMAT_8BIT_ALPHAMAP,
32     GX_COLOR_FORMAT_8BIT_PALETTE,
33     GX_COLOR_FORMAT_565RGB,
34     GX_COLOR_FORMAT_4444ARGB,
35     0,
36 };
37 
38 static int _565rgb_synergy_allowed_formats[] = {
39     GX_COLOR_FORMAT_8BIT_ALPHAMAP,
40     GX_COLOR_FORMAT_8BIT_PALETTE,
41     GX_COLOR_FORMAT_565RGB,
42     GX_COLOR_FORMAT_4444ARGB,
43     GX_COLOR_FORMAT_32ARGB,
44     0
45 };
46 
47 static int _565rgb_st_chromeart_allowed_formats[] = {
48     GX_COLOR_FORMAT_8BIT_ALPHAMAP,
49     GX_COLOR_FORMAT_8BIT_PALETTE,
50     GX_COLOR_FORMAT_565RGB,
51     GX_COLOR_FORMAT_4444ARGB,
52     GX_COLOR_FORMAT_32ARGB,
53     0
54 };
55 
56 static int _1555xrgb_allowed_formats[] = {
57     GX_COLOR_FORMAT_8BIT_ALPHAMAP,
58     GX_COLOR_FORMAT_1555XRGB,
59     0
60 };
61 
62 STRING_VAL_PAIR PaletteTypes[] = {
63     { _T("None"), PALETTE_TYPE_NONE },
64     { _T("Local/Private Palette"), PALETTE_TYPE_PRIVATE },
65     { _T("Global/Shared Palette"), PALETTE_TYPE_SHARED },
66     { _T(""), 0 }
67 };
68 
69 enum edit_pixelmap_dlg_test_commands{
70     TEST_SET_IMAGE_PATH = 1,
71     TEST_SET_IMAGE_NAME,
72     TEST_CHECK_CUSTOM_OUTPUT,
73     TEST_SET_CUSTOM_OUTPUT_FILE,
74     TEST_CHECK_RAW_FORMAT,
75     TEST_CHECK_COMPRESS,
76     TEST_CHECK_ALPHA,
77     TEST_CHECK_DITHER,
78     TEST_SET_OUTPUT_FORMAT,
79     TEST_SET_PALETTE_TYPE,
80     TEST_SAVE_PIXELMAP_EDIT,
81     TEST_CANCEL_PIXELMAP_EDIT
82 };
83 
84 // edit_pixelmap_dlg dialog
85 
IMPLEMENT_DYNAMIC(edit_pixelmap_dlg,express_dialog)86 IMPLEMENT_DYNAMIC(edit_pixelmap_dlg, express_dialog)
87 BEGIN_MESSAGE_MAP(edit_pixelmap_dlg, express_dialog)
88     ON_BN_CLICKED(IDC_BROWSE, &edit_pixelmap_dlg::OnBnClickedBrowse)
89     ON_BN_CLICKED(IDC_CUSTOM_OUTPUT, &edit_pixelmap_dlg::OnBnClickedCustomOutput)
90     ON_BN_CLICKED(IDB_PATH_TYPE, &edit_pixelmap_dlg::OnBnClickedPathType)
91     ON_BN_CLICKED(IDCANCEL, &edit_pixelmap_dlg::OnCancel)
92     ON_BN_CLICKED(IDOK,&edit_pixelmap_dlg::OnBnClickedOk)
93     ON_COMMAND(ID_PATHTYPE_PROJECTRELATIVE, SetPathProjectRelative)
94     ON_COMMAND(ID_PATHTYPE_STUDIORELATIVE, SetPathStudioRelative)
95     ON_COMMAND(ID_PATHTYPE_ABSOLUTE, SetPathAbsolute)
96     ON_BN_CLICKED(IDC_RAW_FORMAT, &edit_pixelmap_dlg::OnBnClickedRawFormat)
97     ON_BN_CLICKED(IDC_ALPHA, &edit_pixelmap_dlg::OnBnClickedAlpha)
98     ON_CBN_SELCHANGE(IDC_OUTPUT_FORMAT, &edit_pixelmap_dlg::OnCbnSelchangeOutputFormat)
99     ON_CBN_SELCHANGE(IDC_PALETTE_DEF_LIST, &edit_pixelmap_dlg::OnCbangePaletteDef)
100     //ON_EN_CHANGE(IDC_ID_NAME, &edit_pixelmap_dlg::OnEnChangeIdName)
101     ON_MESSAGE(STUDIO_TEST, &edit_pixelmap_dlg::OnTestMessage)
102     ON_EN_KILLFOCUS(IDC_IMAGE_PATH, &edit_pixelmap_dlg::OnEditImagePath)
103     ON_WM_PAINT()
104 END_MESSAGE_MAP()
105 
106 #define PIXINFO_NOT_EQUAL -1
107 #define PIXINFO_NOT_SET   -2
108 
109 /*****************************************************************************/
110 edit_pixelmap_dlg::edit_pixelmap_dlg(res_info *info, CWnd* pParent /*=NULL*/)
111     : express_dialog(edit_pixelmap_dlg::IDD, pParent)
112 {
113     IconId = IDB_PIXELMAPS;
114     SetTitleText("Edit Pixelmap(s)");
115     studiox_project *project = GetOpenProject();
116 
117     if (project)
118     {
119         mDisplay = project->GetDisplayIndex(info);
120         mDisplayColorFormat = project->mDisplays[mDisplay].colorformat;
121     }
122     mpInfo = info;
123     m_pathinfo = info->pathinfo;
124 }
125 
126 
127 /*****************************************************************************/
~edit_pixelmap_dlg()128 edit_pixelmap_dlg::~edit_pixelmap_dlg()
129 {
130 }
131 
132 /*****************************************************************************/
OnInitDialog()133 BOOL edit_pixelmap_dlg::OnInitDialog()
134 {
135     express_dialog::OnInitDialog();
136 
137     // TODO:  Add extra initialization here
138     AddCancelButton();
139     AddSaveButton();
140 
141     return TRUE;  // return TRUE unless you set the focus to a control
142                   // EXCEPTION: OCX Property Pages should return FALSE
143 }
144 
145 /*****************************************************************************/
OnPaint()146 void edit_pixelmap_dlg::OnPaint()
147 {
148     CPaintDC dc(this); // device context for painting
149                        // TODO: Add your message handler code here
150                        // Do not call express_dialog::OnPaint() for painting messages
151 
152     if (!mpInfo->is_default && !IsPixelmapFolder())
153     {
154         PaintRequiredAsterisk(IDC_ID_NAME);
155         PaintRequiredAsterisk(IDC_REQUIRED_FIELD_LEGEND);
156     }
157 
158     int xpos, ypos;
159     CRect rect;
160     GetDlgItem(IDC_COMPRESS_OPTION_NOTE)->GetWindowRect(&rect);
161     ScreenToClient(&rect);
162 
163     int width = GetSystemMetrics(SM_CXSMICON);
164     int height = GetSystemMetrics(SM_CYSMICON);
165 
166     xpos = rect.left - (width * 4 / 3);
167     ypos = (rect.top + rect.bottom - height) / 2;
168 
169     HMODULE hMod = GetModuleHandle(L"user32.dll");
170     HICON hIconExclamation = (HICON)LoadImage(hMod, MAKEINTRESOURCE(104), IMAGE_ICON, width, height, LR_DEFAULTCOLOR);
171 
172     DrawIconEx(dc, xpos, ypos, hIconExclamation, width, height, 0, NULL, DI_NORMAL);
173 }
174 
175 /*****************************************************************************/
DoDataExchange(CDataExchange * pDX)176 void edit_pixelmap_dlg::DoDataExchange(CDataExchange* pDX)
177 {
178     CDialog::DoDataExchange(pDX);
179 
180     DDX_Control(pDX, IDC_OUTPUT_FILE, mCustomFile);
181     DDX_Control(pDX, IDC_BINARY_MODE, mBinaryMode);
182     DDX_Control(pDX, IDC_PALETTE_LABEL, mPaletteLabel);
183     DDX_Control(pDX, IDC_PALETTE_DEF_LIST, mPaletteDefList);
184     DDX_Control(pDX, IDC_OUTPUT_FORMAT, mOutputFormatCombo);
185     DDX_Control(pDX, IDB_PATH_TYPE, mPathTypeButton);
186 
187     CEdit* edit = (CEdit*)GetDlgItem(IDC_ID_NAME);
188     if (mpInfo->is_default)
189     {
190         // they cannot change the name of system pixelmaps
191 
192         edit->SetReadOnly(TRUE);
193         GetDlgItem(IDC_REQUIRED_FIELD_LEGEND)->ShowWindow(FALSE);
194     }
195     else if (IsPixelmapFolder())
196     {
197         GetDlgItem(IDB_PATH_TYPE)->EnableWindow(FALSE);
198         GetDlgItem(IDC_IMAGE_PATH)->EnableWindow(FALSE);
199         GetDlgItem(IDC_BROWSE)->EnableWindow(FALSE);
200         edit->EnableWindow(FALSE);
201         GetDlgItem(IDC_REQUIRED_FIELD_LEGEND)->ShowWindow(FALSE);
202     }
203     else
204     {
205         SetAccessibleFullDescription(edit->GetSafeHwnd(), L"Required");
206         SetAccessibleDescription(edit->GetSafeHwnd(), L"Required");
207     }
208 
209     if (pDX->m_bSaveAndValidate)
210     {
211         SavePixelmapDlgConfig();
212     }
213     else
214     {
215         InitPixelmapDlgConfig();
216     }
217 }
218 
219 /*****************************************************************************/
SetCheck(int control_id,int check)220 void edit_pixelmap_dlg::SetCheck(int control_id, int check)
221 {
222     CButton* button = (CButton*)GetDlgItem(control_id);
223 
224     if (!button)
225     {
226         return;
227     }
228 
229     if (check == PIXINFO_NOT_EQUAL)
230     {
231         button->SetButtonStyle(BS_AUTO3STATE);
232         button->SetCheck(BST_INDETERMINATE);
233     }
234     else
235     {
236         button->SetCheck(check);
237     }
238 }
239 
240 /*****************************************************************************/
GetCheck(int control_id,int & check)241 void edit_pixelmap_dlg::GetCheck(int control_id, int &check)
242 {
243     CButton* button = (CButton*)GetDlgItem(control_id);
244 
245     if (!button)
246     {
247         return;
248     }
249 
250     switch (button->GetCheck())
251     {
252     case BST_CHECKED:
253         check = 1;
254         break;
255 
256     case BST_UNCHECKED:
257         check = 0;
258         break;
259 
260     case BST_INDETERMINATE:
261         check = PIXINFO_NOT_EQUAL;
262         break;
263     }
264 }
265 
266 /*****************************************************************************/
InitPixelmapDlgConfig()267 void edit_pixelmap_dlg::InitPixelmapDlgConfig()
268 {
269     CDataExchange nx(this, FALSE);
270 
271     SetControlAccessibleName(GetDlgItem(IDC_OUTPUT_FILE)->GetSafeHwnd(), L"Custom Output File");
272 
273     mPixelmapInfo.compress = PIXINFO_NOT_SET;
274     mPixelmapInfo.dither = PIXINFO_NOT_SET;
275     mPixelmapInfo.keep_alpha = PIXINFO_NOT_SET;
276     mPixelmapInfo.raw = PIXINFO_NOT_SET;
277     mPixelmapInfo.output_color_format = PIXINFO_NOT_SET;
278     mPixelmapInfo.palette_type = PIXINFO_NOT_SET;
279     mPixelmapInfo.output_file_enabled = PIXINFO_NOT_SET;
280     mPixelmapInfo.output_file = "";
281     mPixelmapInfo.binary_mode = PIXINFO_NOT_SET;
282 
283     GetPixelmapInfo(mpInfo);
284 
285     SetCheck(IDC_COMPRESS, mPixelmapInfo.compress);
286 
287     if (mPixelmapInfo.keep_alpha != PIXINFO_NOT_SET)
288     {
289         SetCheck(IDC_ALPHA, mPixelmapInfo.keep_alpha);
290     }
291 
292     SetCheck(IDC_DITHER, mPixelmapInfo.dither);
293     SetCheck(IDC_RAW_FORMAT, mPixelmapInfo.raw);
294     SetCheck(IDC_CUSTOM_OUTPUT, mPixelmapInfo.output_file_enabled);
295     SetCheck(IDC_BINARY_MODE, mPixelmapInfo.binary_mode);
296 
297     if (!IsPixelmapFolder())
298     {
299         DDX_Text(&nx, IDC_IMAGE_PATH, m_pathinfo.pathname);
300         DDX_Text(&nx, IDC_ID_NAME, mpInfo->name);
301     }
302 
303     mPathBitmap.LoadBitmap(IDB_DOWN_ARROW);
304     mPathTypeButton.SetBitmap(mPathBitmap);
305     SetPathPrefix();
306 
307     studiox_project* project = GetOpenProject();
308     CRect size;
309     int table_index;
310     int combo_index;
311     int selected_index;
312 
313     // Set the drop-down list size.
314     // There doesn't seem to be any way to do it in resource editor.
315 
316     if (mPixelmapInfo.output_file_enabled > 0)
317     {
318         mCustomFile.ShowWindow(TRUE);
319         mCustomFile.SetWindowText(mPixelmapInfo.output_file);
320 
321         mBinaryMode.ShowWindow(TRUE);
322     }
323 
324     mOutputFormatCombo.GetWindowRect(&size);
325     size.bottom = size.top + 200;
326     ScreenToClient(&size);
327     mOutputFormatCombo.MoveWindow(&size);
328 
329     mOutputFormatCombo.AddString(_T("Use display default"));
330     mOutputFormatCombo.SetItemData(0, 0);
331 
332     SetControlAccessibleName(mOutputFormatCombo.GetSafeHwnd(), _T("Output Format"));
333 
334     table_index = 0;
335     selected_index = 0;
336     int* allowed_color_formats = GetAllowedFormats(project->mDisplays[mDisplay].colorformat);
337 
338     if (allowed_color_formats != NULL)
339     {
340         while (allowed_color_formats[table_index])
341         {
342             if (allowed_color_formats[table_index] != project->mDisplays[mDisplay].colorformat)
343             {
344                 CString name = resource_gen::GetColorFormatName(allowed_color_formats[table_index]);
345                 combo_index = mOutputFormatCombo.AddString(name);
346                 mOutputFormatCombo.SetItemData(combo_index, allowed_color_formats[table_index]);
347             }
348 
349             table_index++;
350         }
351 
352         if (mPixelmapInfo.output_color_format == PIXINFO_NOT_EQUAL)
353         {
354             combo_index = mOutputFormatCombo.AddString(L"<different color formats>");
355             mOutputFormatCombo.SetItemData(combo_index, mPixelmapInfo.output_color_format);
356         }
357         else if (mPixelmapInfo.output_color_format == mDisplayColorFormat)
358         {
359             // The pixelmap color format is the same as display color format,
360             // set the pixelmap color format to default.
361             mPixelmapInfo.output_color_format = 0;
362         }
363         SelectDropListItem(&mOutputFormatCombo, mPixelmapInfo.output_color_format);
364     }
365 
366     table_index = 0;
367     selected_index = 0;
368 
369     while (!PaletteTypes[table_index].name.IsEmpty())
370     {
371         combo_index = mPaletteDefList.AddString(PaletteTypes[table_index].name);
372         mPaletteDefList.SetItemData(combo_index, PaletteTypes[table_index].val);
373         table_index++;
374     }
375 
376     if (mPixelmapInfo.palette_type == PIXINFO_NOT_EQUAL)
377     {
378         combo_index = mPaletteDefList.AddString(L"<different palette types>");
379         mPaletteDefList.SetItemData(combo_index, mPixelmapInfo.palette_type);
380     }
381     SelectDropListItem(&mPaletteDefList, mPixelmapInfo.palette_type);
382     if (mDisplayColorFormat <= GX_COLOR_FORMAT_8BIT_PALETTE)
383     {
384         mOutputFormatCombo.ShowWindow(FALSE);
385     }
386     EnableDisableRawFields();
387     ShowHidePaletteType(mpInfo->output_color_format);
388 }
389 
390 /*****************************************************************************/
SavePixelmapDlgConfig()391 void edit_pixelmap_dlg::SavePixelmapDlgConfig()
392 {
393     CDataExchange nx(this, TRUE);
394 
395     GetCheck(IDC_COMPRESS, mPixelmapInfo.compress);
396     GetCheck(IDC_ALPHA, mPixelmapInfo.keep_alpha);
397     GetCheck(IDC_DITHER, mPixelmapInfo.dither);
398     GetCheck(IDC_RAW_FORMAT, mPixelmapInfo.raw);
399     GetCheck(IDC_CUSTOM_OUTPUT, mPixelmapInfo.output_file_enabled);
400 
401     if (!IsPixelmapFolder())
402     {
403         DDX_Text(&nx, IDC_ID_NAME, mpInfo->name);
404 
405         mpInfo->pathinfo = m_pathinfo;
406     }
407 
408     int combo_index;
409     studiox_project* project = GetOpenProject();
410 
411     if (mOutputFormatCombo.IsWindowVisible())
412     {
413         combo_index = mOutputFormatCombo.GetCurSel();
414         mPixelmapInfo.output_color_format = mOutputFormatCombo.GetItemData(combo_index);
415 
416         if (mPixelmapInfo.output_color_format != 0)
417         {
418             project->mDisplays[mDisplay].default_map_format = FALSE;
419         }
420     }
421     else
422     {
423         project->mDisplays[mDisplay].default_map_format = TRUE;
424     }
425 
426     if (mPaletteDefList.IsWindowVisible())
427     {
428         combo_index = mPaletteDefList.GetCurSel();
429         mPixelmapInfo.palette_type = mPaletteDefList.GetItemData(combo_index);
430     }
431 
432     mCustomFile.GetWindowText(mPixelmapInfo.output_file);
433 
434     if (mPixelmapInfo.output_file.IsEmpty())
435     {
436         mPixelmapInfo.output_file_enabled = FALSE;
437     }
438 
439     GetCheck(IDC_BINARY_MODE, mPixelmapInfo.binary_mode);
440 
441     SavePixelmapInfo(mpInfo);
442 }
443 
444 /*****************************************************************************/
IsPixelmapFolder()445 BOOL edit_pixelmap_dlg::IsPixelmapFolder()
446 {
447 
448     if ((mpInfo->type == RES_TYPE_FOLDER) ||
449         (mpInfo->type == RES_TYPE_GROUP))
450     {
451         return TRUE;
452     }
453 
454     return FALSE;
455 }
456 
457 /*****************************************************************************/
GetPixelmapInfo(int & current_val,int input_val)458 void edit_pixelmap_dlg::GetPixelmapInfo(int &current_val, int input_val)
459 {
460     if (current_val == PIXINFO_NOT_SET)
461     {
462         current_val = input_val;
463     }
464     else if (current_val != input_val)
465     {
466         current_val = PIXINFO_NOT_EQUAL;
467     }
468 }
469 
470 /*****************************************************************************/
SavePixelmapInfo(int & val,int input_val)471 BOOL edit_pixelmap_dlg::SavePixelmapInfo(int& val, int input_val)
472 {
473     if ((input_val != PIXINFO_NOT_EQUAL) && (val != input_val))
474     {
475         val = input_val;
476         return TRUE;
477     }
478 
479     return FALSE;
480 }
481 
482 /*****************************************************************************/
SavePixelmapInfo(res_info * info)483 void edit_pixelmap_dlg::SavePixelmapInfo(res_info* info)
484 {
485     res_info* child;
486     int update_pixelmap = 0;
487 
488     switch (info->type)
489     {
490 
491     case RES_TYPE_GROUP:
492     case RES_TYPE_FOLDER:
493         child = info->child;
494         while (child)
495         {
496             SavePixelmapInfo(child);
497             child = child->next;
498         }
499         break;
500 
501     case RES_TYPE_PIXELMAP:
502         update_pixelmap = SavePixelmapInfo(info->compress, mPixelmapInfo.compress);
503 
504         if (HasAlpha(info))
505         {
506             update_pixelmap += SavePixelmapInfo(info->keep_alpha, mPixelmapInfo.keep_alpha);
507         }
508         update_pixelmap += SavePixelmapInfo(info->dither, mPixelmapInfo.dither);
509         update_pixelmap += SavePixelmapInfo(info->raw, mPixelmapInfo.raw);
510         update_pixelmap += SavePixelmapInfo(info->output_color_format, mPixelmapInfo.output_color_format);
511         update_pixelmap += SavePixelmapInfo(info->palette_type, mPixelmapInfo.palette_type);
512         update_pixelmap += SavePixelmapInfo(info->output_file_enabled, mPixelmapInfo.output_file_enabled);
513         update_pixelmap += SavePixelmapInfo(info->binary_mode, mPixelmapInfo.binary_mode);
514 
515         if (mPixelmapInfo.output_file != "<different output file>")
516         {
517             info->output_file = mPixelmapInfo.output_file;
518         }
519 
520         if (!IsPixelmapFolder() || update_pixelmap)
521         {
522             info->is_modified = TRUE;
523         }
524         break;
525     }
526 }
527 
528 /*****************************************************************************/
GetPixelmapInfo(res_info * info)529 void edit_pixelmap_dlg::GetPixelmapInfo(res_info *info)
530 {
531     res_info* child;
532     switch (info->type)
533     {
534 
535     case RES_TYPE_GROUP:
536     case RES_TYPE_FOLDER:
537         child = info->child;
538         while (child)
539         {
540             GetPixelmapInfo(child);
541             child = child->next;
542         }
543         break;
544 
545     case RES_TYPE_PIXELMAP:
546         GetPixelmapInfo(mPixelmapInfo.compress, info->compress);
547         if (HasAlpha(info))
548         {
549             GetPixelmapInfo(mPixelmapInfo.keep_alpha, info->keep_alpha);
550         }
551         GetPixelmapInfo(mPixelmapInfo.dither, info->dither);
552         GetPixelmapInfo(mPixelmapInfo.raw, info->raw);
553         GetPixelmapInfo(mPixelmapInfo.output_color_format, info->output_color_format);
554         GetPixelmapInfo(mPixelmapInfo.palette_type, info->palette_type);
555 
556         if (mPixelmapInfo.output_file_enabled == PIXINFO_NOT_SET)
557         {
558             mPixelmapInfo.output_file = info->output_file;
559         }
560         else
561         {
562             if (mPixelmapInfo.output_file != info->output_file)
563             {
564                 mPixelmapInfo.output_file = "<different output file>";
565             }
566         }
567 
568         GetPixelmapInfo(mPixelmapInfo.output_file_enabled, info->output_file_enabled);
569         GetPixelmapInfo(mPixelmapInfo.binary_mode, info->binary_mode);
570         break;
571     }
572 }
573 
574 /*****************************************************************************/
SetPathPrefix()575 void edit_pixelmap_dlg::SetPathPrefix()
576 {
577     CWnd *pathtype = GetDlgItem(IDC_PATH_PREFIX);
578     HWND hWndPathType= 0;
579 
580     if (pathtype)
581     {
582         hWndPathType = pathtype->GetSafeHwnd();
583     }
584 
585     switch (m_pathinfo.pathtype)
586     {
587 
588     case PATH_TYPE_PROJECT_RELATIVE:
589         SetDlgItemText(IDC_PATH_PREFIX, _T("<Project Relative Path>"));
590         SetControlAccessibleName(hWndPathType, _T("Project Relative Path"));
591         break;
592 
593     case PATH_TYPE_INSTALL_RELATIVE:
594         SetDlgItemText(IDC_PATH_PREFIX, _T("<GUIX Repo Relative Path>"));
595         SetControlAccessibleName(hWndPathType, _T("GUIX Repo Relative Path"));
596         break;
597 
598     case PATH_TYPE_ABSOLUTE:
599     default:
600         SetDlgItemText(IDC_PATH_PREFIX, _T("<Absolute Path>"));
601         SetControlAccessibleName(hWndPathType, _T("Absolute Path"));
602         break;
603     }
604 }
605 
606 /*****************************************************************************/
CheckPathname(CString pathname)607 BOOL edit_pixelmap_dlg::CheckPathname(CString pathname)
608 {
609     CString oldpath, newpath;
610 
611     oldpath = MakeAbsolutePathname(m_pathinfo);
612     ConvertToProjectRelativePath(oldpath);
613     FormatPath(oldpath);
614 
615     newpath = pathname;
616     ConvertToProjectRelativePath(newpath);
617     FormatPath(newpath);
618 
619     if (_tcscmp(newpath, oldpath))
620     {
621         if (FileExists(mDisplay, RES_TYPE_PIXELMAP, pathname))
622         {
623             ErrorMsg("Pixelmap Already Exists.", this);
624         }
625 
626         studiox_project* project = GetOpenProject();
627 
628         if (project)
629         {
630             if ((project->mDisplays[mDisplay].num_themes > 1) &&
631                 (image_reader::GetFrameCount(newpath) != mpInfo->GetPixelmapFrameCount()))
632             {
633                 return AskUser("The selected pixelmap has different frame count, the change will apply to all other theme(s), continue?", this);
634             }
635         }
636     }
637 
638     return TRUE;
639 }
640 
641 /*****************************************************************************/
OnBnClickedBrowse()642 void edit_pixelmap_dlg::OnBnClickedBrowse()
643 {
644     CString pathname;
645     TCHAR *filter;
646 
647     if (mpInfo->is_default)
648     {
649         filter = _T("Image Files\0*.png;*.jpg\0");
650     }
651     else
652     {
653         filter = _T("Image Files\0*.png;*.jpg;*.gif\0");
654     }
655 
656     if (BrowseForSingleFile(_T("Select pixelmap source file"),
657         filter, NULL, pathname, this))
658     {
659         if (CheckPathname(pathname))
660         {
661             SaveToPathInfo(m_pathinfo, pathname);
662             SetPathPrefix();
663             CheckAlphaStatus(TRUE);
664             SetDlgItemText(IDC_IMAGE_PATH, m_pathinfo.pathname);
665         }
666     }
667 }
668 
669 /*****************************************************************************/
OnEditImagePath()670 void edit_pixelmap_dlg::OnEditImagePath()
671 {
672     // TODO: Add your control notification handler code here
673     GetDlgItemText(IDC_IMAGE_PATH, m_pathinfo.pathname);
674 
675     CheckPathname(m_pathinfo.pathname);
676 }
677 
678 
679 /*****************************************************************************/
OnBnClickedCustomOutput()680 void edit_pixelmap_dlg::OnBnClickedCustomOutput()
681 {
682     // TODO: Add your control notification handler code here
683     CButton *pb = (CButton *) GetDlgItem(IDC_CUSTOM_OUTPUT);
684 
685     if (pb->GetCheck() == BST_CHECKED)
686     {
687         mCustomFile.ShowWindow(SW_SHOW);
688         mBinaryMode.ShowWindow(SW_SHOW);
689     }
690     else
691     {
692         mCustomFile.ShowWindow(SW_HIDE);
693         mBinaryMode.ShowWindow(SW_HIDE);
694     }
695 }
696 
697 /*****************************************************************************/
OnBnClickedPathType()698 void edit_pixelmap_dlg::OnBnClickedPathType()
699 {
700     // TODO: Add your control notification handler code here
701     CMenu menu;
702     CMenu *pPopup;
703     CPoint pos;
704     CRect  buttonsize;
705     mPathTypeButton.GetWindowRect(&buttonsize);
706 
707     pos.x = buttonsize.left;
708     pos.y = buttonsize.bottom + 2;
709 
710     menu.LoadMenu(IDR_PATHTYPE);
711       pPopup = menu.GetSubMenu(0);
712     //ClientToScreen(&pos);
713     pPopup->TrackPopupMenu( TPM_LEFTALIGN, pos.x, pos.y, this);
714 }
715 
716 /*****************************************************************************/
SetPathProjectRelative()717 void  edit_pixelmap_dlg::SetPathProjectRelative()
718 {
719     if (!m_pathinfo.pathname.IsEmpty())
720     {
721         CString abspath = MakeAbsolutePathname(m_pathinfo);
722         m_pathinfo.pathtype = PATH_TYPE_PROJECT_RELATIVE;
723         SaveToPathInfo(m_pathinfo, abspath);
724         SetDlgItemText(IDC_IMAGE_PATH, m_pathinfo.pathname);
725         SetPathPrefix();
726     }
727 }
728 
729 /*****************************************************************************/
SetPathStudioRelative()730 void  edit_pixelmap_dlg::SetPathStudioRelative()
731 {
732     if (!m_pathinfo.pathname.IsEmpty())
733     {
734         CString abspath = MakeAbsolutePathname(m_pathinfo);
735         m_pathinfo.pathtype = PATH_TYPE_INSTALL_RELATIVE;
736         SaveToPathInfo(m_pathinfo, abspath);
737         SetDlgItemText(IDC_IMAGE_PATH, m_pathinfo.pathname);
738         SetPathPrefix();
739     }
740 }
741 
742 /*****************************************************************************/
SetPathAbsolute()743 void  edit_pixelmap_dlg::SetPathAbsolute()
744 {
745     if (!m_pathinfo.pathname.IsEmpty())
746     {
747         CString abspath = MakeAbsolutePathname(m_pathinfo);
748         m_pathinfo.pathtype = PATH_TYPE_ABSOLUTE;
749         SaveToPathInfo(m_pathinfo, abspath);
750         SetDlgItemText(IDC_IMAGE_PATH, m_pathinfo.pathname);
751         SetPathPrefix();
752     }
753 }
754 
755 /*****************************************************************************/
ShowHidePaletteType(int selected_format)756 void edit_pixelmap_dlg::ShowHidePaletteType(int selected_format)
757 {
758     BOOL show = FALSE;
759 
760     if (mDisplayColorFormat > GX_COLOR_FORMAT_8BIT_PACKED_PIXEL)
761     {
762         if (selected_format == GX_COLOR_FORMAT_8BIT_PALETTE)
763         {
764             show = TRUE;
765         }
766     }
767     mPaletteLabel.ShowWindow(show);
768     mPaletteDefList.ShowWindow(show);
769 }
770 
771 /*****************************************************************************/
HasAlpha(res_info * info)772 BOOL edit_pixelmap_dlg::HasAlpha(res_info* info)
773 {
774     BOOL result = FALSE;
775 
776     if (mDisplayColorFormat > GX_COLOR_FORMAT_8BIT_PALETTE)
777     {
778         CString abspath = MakeAbsolutePathname(info->pathinfo);
779         image_reader* pReader = image_reader::CreateProperReader(abspath);
780 
781         if (pReader)
782         {
783             if (pReader->CheckImageHasAlphaChannel(abspath))
784             {
785                 result = TRUE;
786             }
787             delete pReader;
788         }
789     }
790 
791     return result;
792 }
793 
794 /*****************************************************************************/
CheckAlphaStatus(BOOL Initialize)795 void edit_pixelmap_dlg::CheckAlphaStatus(BOOL Initialize)
796 {
797     if (IsPixelmapFolder())
798     {
799         if (mPixelmapInfo.keep_alpha == PIXINFO_NOT_SET)
800         {
801             GetDlgItem(IDC_ALPHA)->EnableWindow(FALSE);
802         }
803         else
804         {
805             GetDlgItem(IDC_ALPHA)->EnableWindow(TRUE);
806         }
807     }
808     else
809     {
810         // if the source has an alpha channel, default to keeping it
811         if (mDisplayColorFormat <= GX_COLOR_FORMAT_8BIT_PALETTE)
812         {
813             CButton* pb = (CButton*)GetDlgItem(IDC_ALPHA);
814             GetDlgItem(IDC_ALPHA)->EnableWindow(FALSE);
815             pb->SetCheck(FALSE);
816         }
817         else
818         {
819             CString abspath = MakeAbsolutePathname(m_pathinfo);
820             image_reader* pReader = image_reader::CreateProperReader(abspath);
821 
822             if (pReader)
823             {
824                 if (pReader->CheckImageHasAlphaChannel(abspath))
825                 {
826                     CButton* pb = (CButton*)GetDlgItem(IDC_ALPHA);
827                     pb->EnableWindow(TRUE);
828 
829                     if (Initialize)
830                     {
831                         pb->SetCheck(TRUE);
832                         mPixelmapInfo.keep_alpha = TRUE;
833                     }
834                 }
835                 else
836                 {
837                     mPixelmapInfo.keep_alpha = FALSE;
838                     GetDlgItem(IDC_ALPHA)->EnableWindow(FALSE);
839                 }
840                 delete pReader;
841             }
842         }
843     }
844 }
845 
846 
847 /*****************************************************************************/
EnableDisableRawFields()848 void edit_pixelmap_dlg::EnableDisableRawFields()
849 {
850     CButton *pb = (CButton *)GetDlgItem(IDC_RAW_FORMAT);
851 
852 
853     if (pb->GetCheck())
854     {
855         mOutputFormatCombo.EnableWindow(FALSE);
856         GetDlgItem(IDC_ALPHA)->EnableWindow(FALSE);
857         GetDlgItem(IDC_COMPRESS)->EnableWindow(FALSE);
858         GetDlgItem(IDC_DITHER)->EnableWindow(FALSE);
859 
860         if (mPaletteDefList.IsWindowVisible())
861         {
862             mPaletteDefList.EnableWindow(FALSE);
863             mPaletteLabel.EnableWindow(FALSE);
864         }
865     }
866     else
867     {
868         mOutputFormatCombo.EnableWindow(TRUE);
869         CheckAlphaStatus();
870         GetDlgItem(IDC_COMPRESS)->EnableWindow(TRUE);
871         GetDlgItem(IDC_DITHER)->EnableWindow(TRUE);
872 
873         if (mPaletteDefList.IsWindowVisible())
874         {
875             mPaletteDefList.EnableWindow(TRUE);
876             mPaletteLabel.EnableWindow(TRUE);
877         }
878     }
879 }
880 
881 /*****************************************************************************/
OnBnClickedRawFormat()882 void edit_pixelmap_dlg::OnBnClickedRawFormat()
883 {
884     // TODO: Add your control notification handler code here
885     CButton *pb = (CButton *) GetDlgItem(IDC_RAW_FORMAT);
886     studiox_project *project = GetOpenProject();
887 
888     if (pb->GetCheck())
889     {
890         if (IsRenesasHwJpeg(project) ||
891             project->mHeader.target_cpu == CPU_RZ)
892         {
893             CString abspath = MakeAbsolutePathname(m_pathinfo);
894             int image_type = image_reader::GetImageType(abspath);
895 
896             if (image_type != IMAGE_TYPE_JPG)
897             {
898                 ErrorMsg("This image type is not compatible with the target hardware decoder.", this);
899                 pb->SetCheck(FALSE);
900             }
901             else
902             {
903                 image_reader* pReader = image_reader::CreateProperReader(abspath);
904 
905                 if (pReader)
906                 {
907                     pReader->SetOutputColorFormat(GX_COLOR_FORMAT_24XRGB, GX_COLOR_FORMAT_24XRGB);
908                     pReader->SetSaveAlphaVal(FALSE);
909 
910                     if (pReader->ReadImage(abspath))
911                     {
912                         GX_PIXELMAP* pmap = pReader->GetPixelmap();
913                         if ((pmap->gx_pixelmap_height & 0x07) != 0 ||
914                             (pmap->gx_pixelmap_width & 0x07) != 0)
915                         {
916                             ErrorMsg("Image size is not compatible with target hardware decoder.", this);
917                             pb->SetCheck(FALSE);
918                             pReader->DestroyImage();
919                         }
920                     }
921                     delete pReader;
922                 }
923             }
924         }
925     }
926     EnableDisableRawFields();
927 }
928 
929 /*****************************************************************************/
OnBnClickedAlpha()930 void edit_pixelmap_dlg::OnBnClickedAlpha()
931 {
932     int SelectedFormat;
933 
934     CButton *alpha_button = (CButton *) GetDlgItem(IDC_ALPHA);
935     studiox_project *project = GetOpenProject();
936 
937     // If the target CPU is Synergy in 565 mode, force the output format to compatible format
938     // if they turn on using alpha
939     if (IsRenesasDave2D(project) &&
940         alpha_button->GetCheck())
941     {
942         SelectedFormat = mOutputFormatCombo.GetItemData(mOutputFormatCombo.GetCurSel());
943         if (SelectedFormat == 0)
944         {
945             SelectedFormat = mDisplayColorFormat;
946         }
947         if (!IsAlphaFormat(SelectedFormat))
948         {
949             ErrorMsg("Selected output format does not support alpha channel. Forcing output format to 32 bpp argb", this);
950             SelectDropListItem(&mOutputFormatCombo, GX_COLOR_FORMAT_32ARGB);
951         }
952     }
953 }
954 
955 
956 /*****************************************************************************/
OnCbnSelchangeOutputFormat()957 void edit_pixelmap_dlg::OnCbnSelchangeOutputFormat()
958 {
959     int SelectedFormat;
960     CButton *alpha_button;
961 
962     SelectedFormat = mOutputFormatCombo.GetItemData(mOutputFormatCombo.GetCurSel());
963     studiox_project *project = GetOpenProject();
964 
965     // if target CPU is Synergy using D2D in 565 mode and the selected output format does
966     // not support alpha channel, disable alpha channel
967     if (IsRenesasDave2D(project))
968     {
969         if (!IsAlphaFormat(SelectedFormat))
970         {
971             alpha_button = (CButton *) GetDlgItem(IDC_ALPHA);
972             if (alpha_button->GetCheck())
973             {
974                 ErrorMsg("Alpha channel data is not supported using the selected output format. Alpha channel will be disabled", this);
975                 alpha_button->SetCheck(FALSE);
976             }
977         }
978     }
979 
980     ShowHidePaletteType(SelectedFormat);
981 }
982 
983 
984 /*****************************************************************************/
OnCbangePaletteDef()985 void edit_pixelmap_dlg::OnCbangePaletteDef()
986 {
987     // TODO: Add your control notification handler code here
988 }
989 
990 /*
991 void edit_pixelmap_dlg::OnEnChangeIdName()
992 {
993     // TODO:  If this is a RICHEDIT control, the control will not
994     // send this notification unless you override the express_dialog::OnInitDialog()
995     // function and call CRichEditCtrl().SetEventMask()
996     // with the ENM_CHANGE flag ORed into the mask.
997 
998     // TODO:  Add your control notification handler code here
999 }
1000 */
1001 
OnBnClickedOk()1002 void edit_pixelmap_dlg::OnBnClickedOk()
1003 {
1004     if (!IsPixelmapFolder())
1005     {
1006         CString pixelmap_name = mpInfo->name;
1007         CEdit* edit = (CEdit*)GetDlgItem(IDC_ID_NAME);
1008 
1009         GetDlgItemText(IDC_ID_NAME, pixelmap_name);
1010         if (_tcscmp(pixelmap_name, mpInfo->name))
1011         {
1012             /*Check ID name in whole pixelmap folder.*/
1013             if (NameExists(mDisplay, RES_TYPE_PIXELMAP, pixelmap_name))
1014             {
1015                 ErrorMsg("Pixelmap Name ID already Exists.", this);
1016                 SetDlgItemText(IDC_ID_NAME, mpInfo->name);
1017                 return;
1018             }
1019         }
1020 
1021         if (TestInputName(edit, "Pixelmap ID", mpInfo->name, this))
1022         {
1023             express_dialog::OnOK();
1024         }
1025     }
1026     else
1027     {
1028         express_dialog::OnOK();
1029     }
1030 }
1031 
OnTestMessage(WPARAM wParam,LPARAM lParam)1032 LRESULT edit_pixelmap_dlg::OnTestMessage(WPARAM wParam, LPARAM lParam)
1033 {
1034     CWnd *pWnd;
1035 
1036     switch (wParam)
1037     {
1038     case TEST_SET_IMAGE_PATH:
1039         pWnd = GetDlgItem(IDC_IMAGE_PATH);
1040         ((CEdit *)pWnd)->SetWindowText(GetTestingParam(0));
1041         SendMessage(WM_COMMAND, MAKEWPARAM(IDC_IMAGE_PATH, EN_KILLFOCUS), (LPARAM)((CEdit *)pWnd)->m_hWnd);
1042         break;
1043 
1044     case TEST_SET_IMAGE_NAME:
1045         pWnd = GetDlgItem(IDC_ID_NAME);
1046         ((CEdit *)pWnd)->SetWindowText(GetTestingParam(0));
1047         SendMessage(WM_COMMAND, MAKEWPARAM(IDC_ID_NAME, EN_KILLFOCUS), (LPARAM)((CEdit *)pWnd)->m_hWnd);
1048         break;
1049 
1050     case TEST_CHECK_CUSTOM_OUTPUT:
1051         pWnd = GetDlgItem(IDC_CUSTOM_OUTPUT);
1052         ((CButton *)pWnd)->SetCheck(lParam);
1053         SendMessage(WM_COMMAND, MAKEWPARAM(IDC_CUSTOM_OUTPUT, BN_CLICKED), (LPARAM)pWnd->m_hWnd);
1054         break;
1055 
1056     case TEST_SET_CUSTOM_OUTPUT_FILE:
1057         pWnd = GetDlgItem(IDC_OUTPUT_FILE);
1058         ((CEdit *)pWnd)->SetWindowText(GetTestingParam(0));
1059         SendMessage(WM_COMMAND, MAKEWPARAM(IDC_OUTPUT_FILE, EN_KILLFOCUS), (LPARAM)((CEdit *)pWnd)->m_hWnd);
1060         break;
1061 
1062     case TEST_CHECK_RAW_FORMAT:
1063         pWnd = GetDlgItem(IDC_RAW_FORMAT);
1064         ((CButton *)pWnd)->SetCheck(lParam);
1065         SendMessage(WM_COMMAND, MAKEWPARAM(IDC_RAW_FORMAT, BN_CLICKED), (LPARAM)pWnd->m_hWnd);
1066         break;
1067 
1068     case TEST_CHECK_COMPRESS:
1069         pWnd = GetDlgItem(IDC_COMPRESS);
1070         ((CButton *)pWnd)->SetCheck(lParam);
1071         SendMessage(WM_COMMAND, MAKEWPARAM(IDC_COMPRESS, BN_CLICKED), (LPARAM)pWnd->m_hWnd);
1072         break;
1073 
1074     case TEST_CHECK_ALPHA:
1075         pWnd = GetDlgItem(IDC_ALPHA);
1076         ((CButton *)pWnd)->SetCheck(lParam);
1077         SendMessage(WM_COMMAND, MAKEWPARAM(IDC_ALPHA, BN_CLICKED), (LPARAM)pWnd->m_hWnd);
1078         break;
1079 
1080     case TEST_CHECK_DITHER:
1081         pWnd = GetDlgItem(IDC_DITHER);
1082         ((CButton *)pWnd)->SetCheck(lParam);
1083         SendMessage(WM_COMMAND, MAKEWPARAM(IDC_DITHER, BN_CLICKED), (LPARAM)pWnd->m_hWnd);
1084         break;
1085 
1086     case TEST_SET_OUTPUT_FORMAT:
1087         for (int index = 0; index < mOutputFormatCombo.GetCount(); index++)
1088         {
1089             if (mOutputFormatCombo.GetItemData(index) == lParam)
1090             {
1091                 mOutputFormatCombo.SetCurSel(index);
1092                 pWnd = GetDlgItem(IDC_OUTPUT_FORMAT);
1093                 SendMessage(WM_COMMAND, MAKEWPARAM(IDC_OUTPUT_FORMAT, CBN_SELCHANGE), (LPARAM)pWnd->m_hWnd);
1094             }
1095         }
1096         break;
1097 
1098     case TEST_SET_PALETTE_TYPE:
1099         for (int index = 0; index < mPaletteDefList.GetCount(); index++)
1100         {
1101             if (mPaletteDefList.GetItemData(index) == lParam)
1102             {
1103                 mPaletteDefList.SetCurSel(index);
1104                 pWnd = GetDlgItem(IDC_PALETTE_DEF_LIST);
1105                 SendMessage(WM_COMMAND, MAKEWPARAM(IDC_PALETTE_DEF_LIST, CBN_SELCHANGE), (LPARAM)pWnd->m_hWnd);
1106             }
1107         }
1108         break;
1109 
1110     case TEST_SAVE_PIXELMAP_EDIT:
1111         OnBnClickedOk();
1112         break;
1113 
1114     case TEST_CANCEL_PIXELMAP_EDIT:
1115         OnCancel();
1116         break;
1117     }
1118 
1119     return 0;
1120 }
1121 
GetAllowedFormats(int display_format)1122 INT* edit_pixelmap_dlg::GetAllowedFormats(int display_format)
1123 {
1124     INT *allowed_color_formats = NULL;
1125     studiox_project *project = GetOpenProject();
1126 
1127     switch (display_format)
1128     {
1129     case GX_COLOR_FORMAT_8BIT_PACKED_PIXEL:
1130         allowed_color_formats = _332rgb_allowed_formats;
1131         break;
1132 
1133     case GX_COLOR_FORMAT_4444ARGB:
1134         allowed_color_formats = _4444argb_allowed_formats;
1135         break;
1136 
1137     case GX_COLOR_FORMAT_565RGB:
1138     case GX_COLOR_FORMAT_565BGR:
1139         if (IsRenesasDave2D(project))
1140         {
1141             /* Synergy CPU supports 32argb in 565 driver. */
1142             allowed_color_formats = _565rgb_synergy_allowed_formats;
1143         }
1144         else if (IsSTChromeArt(project))
1145         {
1146             allowed_color_formats = _565rgb_st_chromeart_allowed_formats;
1147         }
1148         else
1149         {
1150             allowed_color_formats = _565rgb_allowed_formats;
1151         }
1152         break;
1153 
1154     case GX_COLOR_FORMAT_1555XRGB:
1155         allowed_color_formats = _1555xrgb_allowed_formats;
1156         break;
1157 
1158     case GX_COLOR_FORMAT_24XRGB:
1159     case GX_COLOR_FORMAT_32ABGR:
1160     case GX_COLOR_FORMAT_32ARGB:
1161         allowed_color_formats = _32bpp_allowed_formats;
1162         break;
1163 
1164     default:
1165         break;
1166     }
1167 
1168     return allowed_color_formats;
1169 }
1170 
1171 //Check if the ouput pixelmap format is supported
IsOutputFormatSupported(int display_format,int output_format)1172 BOOL edit_pixelmap_dlg::IsOutputFormatSupported(int display_format, int output_format)
1173 {
1174     INT *allowed_formats = GetAllowedFormats(display_format);
1175     INT index = 0;
1176 
1177     if (!allowed_formats)
1178     {
1179         return FALSE;
1180     }
1181 
1182     while (allowed_formats[index])
1183     {
1184         if (allowed_formats[index] == output_format)
1185         {
1186             return TRUE;
1187         }
1188 
1189         index++;
1190     }
1191 
1192     return FALSE;
1193 }
1194