1 
2 #ifndef _STUDIOX_UTIL_
3 #define _STUDIOX_UTIL_
4 
5 #include "project_view.h"
6 #include "target_view.h"
7 #include "resource_view.h"
8 #include "undo_manager.h"
9 #include "CommandInfo.h"
10 #include "studiox_screen_driver.h"
11 
12 #define INI_FILE_NAME   _T("GUIX_Studio.ini")
13 
14 /* handy utility functions that are used at various places within studiox */
15 
16 BOOL BrowseForFolder(HWND hwnd, LPCTSTR caption, LPCTSTR szCurrent, LPTSTR szPath);
17 BOOL BrowseForSingleFile(LPCTSTR caption, LPCTSTR filter,
18     LPCTSTR def_extension, CString &szPath, CWnd *parent);
19 int BrowseForMultipleFiles(TCHAR *caption, TCHAR *filter,
20                            TCHAR *def_extension, TCHAR **pathptr, TCHAR **nameptr, CWnd *parent);
21 
22 BOOL GetOutputFileName(TCHAR *SavePathname, TCHAR *SaveFilename,
23                        TCHAR *title, TCHAR *filter, TCHAR *initial_dir,
24                        TCHAR *def_extension, CWnd *parent = NULL);
25 
26 BOOL ConvertToProjectRelativePath(CString &path);
27 void SaveToPathInfo(PATHINFO &info, CString &dirname);
28 CString ConcatPathNames(CString &root, CString &extra);
29 CString MakeAbsolutePathname(PATHINFO &info);
30 
31 void GotoProjectDirectory();
32 void SetProjectDirectory(CString &path);
33 CString RemoveFileExtension(CString &filename);
34 BOOL CheckOutputFileSecurity(CString &pathname, BOOL binary_mode = 0);
35 
36 
37 wchar_t *CStringToWideChar(CString &string);
38 void pixelmap_destroy(GX_PIXELMAP *pixelmap);
39 void pixelmap_list_destroy(CArray<GX_PIXELMAP *> &pixelmap_list);
40 void SelectDropListItem(CComboBox *box, long item_val);
41 
42 void MakePath(CString path);
43 void WriteToDosFile(CFile &outfile, CString &out);
44 FILE *OpenWorkingDirFile(CString filename, const char *mode);
45 CString GetSamplesDir();
46 CString GetStudioInstallFolder();
47 CString GetMallocName();
48 CString GetTestingParam(int index);
49 CString GetAppDataPath();
50 
51 void ErrorMsg(const char *msg, CWnd *parent = NULL);
52 void ErrorMsg(const CString &msg, CWnd *parent = NULL);
53 void Notify(const char *msg, CWnd *parent = NULL);
54 BOOL StartWorkThread(LPTHREAD_START_ROUTINE routine, LPVOID param, const char *msg, BOOL block_canvas_refresh = FALSE);
55 void BusyMsg(const char *msg, HANDLE thread);
56 void EndBusyMsg(void);
57 BOOL IsWaitDialogRunning();
58 BOOL IsGuixCanvasRefreshBlocked();
59 
60 BOOL AskUser(const char *msg, CWnd *parent = NULL);
61 BOOL ReadIniInfo(void);
62 void WriteIniInfo(void);
63 void AddRecentProject(CString &pathname);
64 
65 studiox_project *GetOpenProject();
66 void SetOpenProject(studiox_project *open_project);
67 
68 project_view  *GetProjectView();
69 target_view   *GetTargetView();
70 target_screen *GetTargetScreen();
71 resource_view *GetResourceView();
72 properties_win *GetPropsWin();
73 CCommandInfo   *GetCmdInfo();
74 string_table *GetActiveStringTable();
75 FontCharMap *GetActiveCharacterMap(BOOL reset);
76 undo_manager *UndoManager();
77 
78 GX_COLOR ColorRefToGxColor(COLORREF cr);
79 COLORREF GxColorToColorRef(GX_COLOR gx);
80 BOOL IsAlphaFormat(int color_format);
81 
82 BOOL IsCpuWithDave2D(int cpu_type);                             // does the CPU support Dave2D?
83 BOOL IsCpuWithDave2D(studiox_project *);                        // does the CPU support Dave2D?
84 BOOL IsRenesasDave2D(studiox_project *);                        // Is the project configured with Dave2D enabled?
85 BOOL IsDave2dFontFormat(studiox_project* project, int display); // Are we using custom Dave2D font format?
86 BOOL IsSTChromeArt(studiox_project*);                           // Is the project configured with ST ChromeArt enabled?
87 BOOL IsRenesasHwJpeg(studiox_project *);
88 BOOL IsInNameList(CArray<CString> *name_list, CString &name);
89 int  project_lib_version();
90 
91 void RleEncodeGlyphData(GX_COMPRESSED_GLYPH* glyph, int bits_per_pix);
92 GX_UBYTE* RleDecodeGlyphData(GX_COMPRESSED_GLYPH* glyph, int bits_per_pix);
93 GX_FONT *MakeFont(res_info *info, int display, BOOL warn_on_error);
94 GX_FONT *MakeOptimizedFont(res_info *info, int display, BOOL warn_on_error = FALSE);
95 BOOL InsertStringTableGlyphs(FontCharMap *map, res_info *info, int display);
96 INT  GetRowPitch(INT width, INT bits_per_pix);
97 INT  GetFontBits(INT font_format);
98 BOOL IsFontBitsSupported(INT font_bits);
99 INT  GetFontStorage(res_info *info, studiox_project *project, int display);
100 INT  GetPixelmapStorage(res_info *info);
101 VOID FormatPath(CString &path);
102 BOOL FileExists(INT pathtype, CString pathname);
103 BOOL FileExists(INT display_index, INT resource_type, CString pathname);
104 BOOL NameExists(INT display_index, INT resource_type, CString name);
105 BOOL SetImportIdName(INT display_index, CString &input_name);
106 BOOL TestInputName(CEdit *input_field, char *field_name, CString &original_value, CWnd *parent = NULL);
107 BOOL TestInputName(CString &name, char *field_name, CWnd *parent = NULL, BOOL show_error_message = TRUE);
108 BOOL IsFileNameFormat(CString name);
109 CString MakePixelmapName(res_info *info, int frame_id);
110 ULONG GetTextScaler();
111 int GetScaledValue(int value, int dpi = DEFAULT_DPI_96, int text_scaler = DEFAULT_TEXT_SCALER);
112 INT GetSubMenuIndex(CMenu *pMenu, CString string);
113 INT GetSubMenuIndex(CMenu *pMenu, INT id);
114 
115 int CalculateStudioVersion();
116 int GuixVersionFieldsToVersionNumber(int major, int minor, int service_pack);
117 void GuixVersionNumberToVersionFields(int version_number, int &major, int &minor, int &service_pack);
118 
119 void SetUtf8Text(CRichEditCtrl *edit, CString &text);
120 CString GetUtf8Text(CRichEditCtrl *edit);
121 
122 void DestroyFont(GX_FONT *font);
123 
124 void PaintBmp(CDC *dc, int x, int y, int icon_id);
125 CString NumberFormatWithCommas(long value);
126 void SplitString(CString str, CHAR splitter, CStringArray *list);
127 int GetSystemDPI();
128 GX_UBYTE ToUByte(INT value);
129 int FindPairVal(STRING_VAL_PAIR* entry, CString name);
130 CString FindPairString(STRING_VAL_PAIR* entry, int val);
131 
132 template <class T>
IsItemInArray(const CArray<T> & target,const T & item)133 bool IsItemInArray(const CArray<T> &target, const T &item)
134 {
135     for (int index = 0; index < target.GetSize(); index++)
136     {
137         if (target.GetAt(index) == item) return true;
138     }
139 
140     return false;
141 };
142 
143 #define WIN_BACKGROUND_COLOR  RGB(255, 255, 255)
144 #define HIGH_TEXT_COLOR       RGB(0, 0, 255)
145 #define NORMAL_TEXT_COLOR     RGB(0, 0, 0)
146 #define LINE_COLOR            RGB(180, 180, 180)
147 
148 #define MAX_RECENT_PROJECTS 5
149 #define MAX_OPEN_FILES      128
150 
151 #define STUDIO_INI_VERSION  2
152 
153 typedef struct {
154     int ini_version;
155     int studio_version;
156 
157     int first_run;
158     int xpos;
159     int ypos;
160     int width;
161     int height;
162     int proj_view_width;
163     int resource_view_width;
164     int proj_view_height;
165     CString samples_dir;        // guix repo clone dir, or dir to which we installed GUIX system resources.
166     CString recent_project_paths[MAX_RECENT_PROJECTS];
167 } INI_INFO;
168 
169 typedef struct{
170     int ini_version;
171     int xpos;
172     int ypos;
173     int width;
174     int height;
175     int proj_view_width;
176     int resource_view_width;
177     BOOL color_open;
178     BOOL font_open;
179     BOOL pixelmap_open;
180     BOOL string_open;
181     int  res_view_scrollpos;
182     int  proj_view_scrollpos;
183     int  props_win_scrollpos;
184     int  proj_tree_item_count;
185 } MACRO_HEAD_INFO;
186 
187 #endif