diff options
author | David Walter Seikel | 2013-01-13 18:54:10 +1000 |
---|---|---|
committer | David Walter Seikel | 2013-01-13 18:54:10 +1000 |
commit | 959831f4ef5a3e797f576c3de08cd65032c997ad (patch) | |
tree | e7351908be5995f0b325b2ebeaa02d5a34b82583 /libraries/irrlicht-1.8/tools/IrrFontTool/newFontTool/main.cpp | |
parent | Add info about changes to Irrlicht. (diff) | |
download | SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.zip SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.gz SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.bz2 SledjHamr-959831f4ef5a3e797f576c3de08cd65032c997ad.tar.xz |
Remove damned ancient DOS line endings from Irrlicht. Hopefully I did not go overboard.
Diffstat (limited to '')
-rw-r--r-- | libraries/irrlicht-1.8/tools/IrrFontTool/newFontTool/main.cpp | 986 |
1 files changed, 493 insertions, 493 deletions
diff --git a/libraries/irrlicht-1.8/tools/IrrFontTool/newFontTool/main.cpp b/libraries/irrlicht-1.8/tools/IrrFontTool/newFontTool/main.cpp index 9e9e87f..1170bcc 100644 --- a/libraries/irrlicht-1.8/tools/IrrFontTool/newFontTool/main.cpp +++ b/libraries/irrlicht-1.8/tools/IrrFontTool/newFontTool/main.cpp | |||
@@ -1,493 +1,493 @@ | |||
1 | /* | 1 | /* |
2 | Tool for creating Irrlicht bitmap+vector fonts, | 2 | Tool for creating Irrlicht bitmap+vector fonts, |
3 | started by Gaz Davidson in December 2006 | 3 | started by Gaz Davidson in December 2006 |
4 | 4 | ||
5 | Due to my laziness and Microsoft's unituitive API, surragate pairs and | 5 | Due to my laziness and Microsoft's unituitive API, surragate pairs and |
6 | nonspacing diacritical marks are not supported! | 6 | nonspacing diacritical marks are not supported! |
7 | 7 | ||
8 | Linux bitmap font support added by Neil Burlock Oct 2008 | 8 | Linux bitmap font support added by Neil Burlock Oct 2008 |
9 | Note: Xft/Freetype2 is used to render the fonts under X11. Anti-aliasing | 9 | Note: Xft/Freetype2 is used to render the fonts under X11. Anti-aliasing |
10 | is controlled by the system and cannot be overriden by an application, | 10 | is controlled by the system and cannot be overriden by an application, |
11 | so fonts that are rendered will be aliased or anti-aliased depending | 11 | so fonts that are rendered will be aliased or anti-aliased depending |
12 | on the system that they are created on. | 12 | on the system that they are created on. |
13 | 13 | ||
14 | */ | 14 | */ |
15 | 15 | ||
16 | 16 | ||
17 | #include <irrlicht.h> | 17 | #include <irrlicht.h> |
18 | #include <iostream> | 18 | #include <iostream> |
19 | 19 | ||
20 | #include "CFontTool.h" | 20 | #include "CFontTool.h" |
21 | #include "CVectorFontTool.h" | 21 | #include "CVectorFontTool.h" |
22 | #include "ITexture.h" | 22 | #include "ITexture.h" |
23 | 23 | ||
24 | using namespace irr; | 24 | using namespace irr; |
25 | using namespace gui; | 25 | using namespace gui; |
26 | 26 | ||
27 | #pragma comment(lib, "Irrlicht.lib") | 27 | #pragma comment(lib, "Irrlicht.lib") |
28 | 28 | ||
29 | const s32 texturesizes[] = {128, 256, 512, 1024, 2048, 4096, 0}; | 29 | const s32 texturesizes[] = {128, 256, 512, 1024, 2048, 4096, 0}; |
30 | 30 | ||
31 | const wchar_t *fileformats[] = { L"bmp", L"ppm", 0 }; // bitmap font formats | 31 | const wchar_t *fileformats[] = { L"bmp", L"ppm", 0 }; // bitmap font formats |
32 | const wchar_t *alphafileformats[] = { L"png", L"tga", 0 }; // bitmap font formats which support alpha channels | 32 | const wchar_t *alphafileformats[] = { L"png", L"tga", 0 }; // bitmap font formats which support alpha channels |
33 | const wchar_t *vectorfileformats[] = { L"xml", L"bin", 0 }; // file formats for vector fonts | 33 | const wchar_t *vectorfileformats[] = { L"xml", L"bin", 0 }; // file formats for vector fonts |
34 | 34 | ||
35 | const wchar_t *warntext = L"Legal Notice\n" | 35 | const wchar_t *warntext = L"Legal Notice\n" |
36 | L"------------\n\n" | 36 | L"------------\n\n" |
37 | L"When making bitmap and vector fonts, you should consider the potential legal " | 37 | L"When making bitmap and vector fonts, you should consider the potential legal " |
38 | L"issues with redistributing the fonts with your software; this tool basically " | 38 | L"issues with redistributing the fonts with your software; this tool basically " |
39 | L"copies font data and some authors might not like this!\n" | 39 | L"copies font data and some authors might not like this!\n" |
40 | L"If you purchased fonts or they came with an application or your OS, you'll have" | 40 | L"If you purchased fonts or they came with an application or your OS, you'll have" |
41 | L"to check the license to see what restrictions are placed on making derivative works.\n\n" | 41 | L"to check the license to see what restrictions are placed on making derivative works.\n\n" |
42 | L"PD and the OFL\n" | 42 | L"PD and the OFL\n" |
43 | L"--------------\n\n" | 43 | L"--------------\n\n" |
44 | L"You'll find lots of fonts on the web listed as Public Domain, you can do what you like " | 44 | L"You'll find lots of fonts on the web listed as Public Domain, you can do what you like " |
45 | L"with these.\n" | 45 | L"with these.\n" |
46 | L"Many fonts are released under the Open Font License, which is a 'viral' open source " | 46 | L"Many fonts are released under the Open Font License, which is a 'viral' open source " |
47 | L"license like the GPL. It's worth reading the license here: http://scripts.sil.org/OFL\n" | 47 | L"license like the GPL. It's worth reading the license here: http://scripts.sil.org/OFL\n" |
48 | L"The most important restrictions are- you must include the original font's license, you " | 48 | L"The most important restrictions are- you must include the original font's license, you " |
49 | L"can't stop your users from using or distributing the font, the font must have a " | 49 | L"can't stop your users from using or distributing the font, the font must have a " |
50 | L"different name the original.\n\n" | 50 | L"different name the original.\n\n" |
51 | L"Some free fonts can be found here- www.openfontlibrary.org\n" | 51 | L"Some free fonts can be found here- www.openfontlibrary.org\n" |
52 | L"http://savannah.nongnu.org/projects/freefont/"; | 52 | L"http://savannah.nongnu.org/projects/freefont/"; |
53 | 53 | ||
54 | const wchar_t *helptext = L"This tool creates bitmap fonts for the Irrlicht Engine\n\n" | 54 | const wchar_t *helptext = L"This tool creates bitmap fonts for the Irrlicht Engine\n\n" |
55 | 55 | ||
56 | L"First select a character encoding from the list, then choose the font, " | 56 | L"First select a character encoding from the list, then choose the font, " |
57 | L"size, and whether you'd like bold, italic, antialiasing and an alpha channel. " | 57 | L"size, and whether you'd like bold, italic, antialiasing and an alpha channel. " |
58 | L"In Windows, antialiasing will be ignored for small fonts\n\n" | 58 | L"In Windows, antialiasing will be ignored for small fonts\n\n" |
59 | 59 | ||
60 | L"Then select a texture width and height. If the output exceeds this then more than " | 60 | L"Then select a texture width and height. If the output exceeds this then more than " |
61 | L"one image will be created. You can use the scrollbar at the top of the screen to " | 61 | L"one image will be created. You can use the scrollbar at the top of the screen to " |
62 | L"preview them. Most modern graphics cards will support up to 2048x2048, " | 62 | L"preview them. Most modern graphics cards will support up to 2048x2048, " |
63 | L"keep in mind that more images means worse performance when drawing text!\n\n" | 63 | L"keep in mind that more images means worse performance when drawing text!\n\n" |
64 | 64 | ||
65 | L"If you want a vector font rather than a bitmap font, check the vector box. " | 65 | L"If you want a vector font rather than a bitmap font, check the vector box. " |
66 | L"Vector fonts are stored in system memory while bitmap fonts are in video ram\n\n" | 66 | L"Vector fonts are stored in system memory while bitmap fonts are in video ram\n\n" |
67 | 67 | ||
68 | L"Click create to preview your font, this may take lots of time and memory " | 68 | L"Click create to preview your font, this may take lots of time and memory " |
69 | L"when making a font with a lot of characters, please be patient!\n\n" | 69 | L"when making a font with a lot of characters, please be patient!\n\n" |
70 | 70 | ||
71 | L"Now you're ready to give your font a name, select a format and click save.\n\n" | 71 | L"Now you're ready to give your font a name, select a format and click save.\n\n" |
72 | L"To load your font in Irrlicht, simply use env->getFont(\"Myfont.xml\");\n\n" | 72 | L"To load your font in Irrlicht, simply use env->getFont(\"Myfont.xml\");\n\n" |
73 | 73 | ||
74 | L"That's all, have fun :-)"; | 74 | L"That's all, have fun :-)"; |
75 | 75 | ||
76 | #ifdef _IRR_WINDOWS_ | 76 | #ifdef _IRR_WINDOWS_ |
77 | const wchar_t *completeText = L"Font created"; | 77 | const wchar_t *completeText = L"Font created"; |
78 | #else | 78 | #else |
79 | const wchar_t *completeText = L"Font created\n\n" | 79 | const wchar_t *completeText = L"Font created\n\n" |
80 | L"Please note that anti-aliasing under X11 is controlled by the system " | 80 | L"Please note that anti-aliasing under X11 is controlled by the system " |
81 | L"configuration, so if your system is set to use anti-aliasing, then so " | 81 | L"configuration, so if your system is set to use anti-aliasing, then so " |
82 | L"will any fonts you create with FontTool"; | 82 | L"will any fonts you create with FontTool"; |
83 | #endif | 83 | #endif |
84 | 84 | ||
85 | enum MYGUI | 85 | enum MYGUI |
86 | { | 86 | { |
87 | MYGUI_CHARSET = 100, | 87 | MYGUI_CHARSET = 100, |
88 | MYGUI_FONTNAME, | 88 | MYGUI_FONTNAME, |
89 | MYGUI_SIZE, | 89 | MYGUI_SIZE, |
90 | MYGUI_TEXWIDTH, | 90 | MYGUI_TEXWIDTH, |
91 | MYGUI_TEXHEIGHT, | 91 | MYGUI_TEXHEIGHT, |
92 | MYGUI_BOLD, | 92 | MYGUI_BOLD, |
93 | MYGUI_ITALIC, | 93 | MYGUI_ITALIC, |
94 | MYGUI_ANTIALIAS, | 94 | MYGUI_ANTIALIAS, |
95 | MYGUI_ALPHA, | 95 | MYGUI_ALPHA, |
96 | MYGUI_VECTOR, | 96 | MYGUI_VECTOR, |
97 | MYGUI_FILENAME, | 97 | MYGUI_FILENAME, |
98 | MYGUI_FORMAT, | 98 | MYGUI_FORMAT, |
99 | MYGUI_CREATE, | 99 | MYGUI_CREATE, |
100 | MYGUI_SAVE, | 100 | MYGUI_SAVE, |
101 | MYGUI_IMAGE, | 101 | MYGUI_IMAGE, |
102 | MYGUI_CURRENTIMAGE, | 102 | MYGUI_CURRENTIMAGE, |
103 | MYGUI_HELPBUTTON | 103 | MYGUI_HELPBUTTON |
104 | }; | 104 | }; |
105 | 105 | ||
106 | 106 | ||
107 | // event reciever | 107 | // event reciever |
108 | class MyEventReceiver : public IEventReceiver | 108 | class MyEventReceiver : public IEventReceiver |
109 | { | 109 | { |
110 | public: | 110 | public: |
111 | 111 | ||
112 | MyEventReceiver(IrrlichtDevice* device, CFontTool*& fonttool, CVectorFontTool* &vectool) : | 112 | MyEventReceiver(IrrlichtDevice* device, CFontTool*& fonttool, CVectorFontTool* &vectool) : |
113 | Device(device), FontTool(fonttool), VecTool(vectool) | 113 | Device(device), FontTool(fonttool), VecTool(vectool) |
114 | { | 114 | { |
115 | device->setEventReceiver(this); | 115 | device->setEventReceiver(this); |
116 | } | 116 | } |
117 | 117 | ||
118 | virtual bool OnEvent(const SEvent &event) | 118 | virtual bool OnEvent(const SEvent &event) |
119 | { | 119 | { |
120 | if (event.EventType == EET_GUI_EVENT) | 120 | if (event.EventType == EET_GUI_EVENT) |
121 | { | 121 | { |
122 | s32 id = event.GUIEvent.Caller->getID(); | 122 | s32 id = event.GUIEvent.Caller->getID(); |
123 | IGUIEnvironment* env = Device->getGUIEnvironment(); | 123 | IGUIEnvironment* env = Device->getGUIEnvironment(); |
124 | 124 | ||
125 | switch(event.GUIEvent.EventType) | 125 | switch(event.GUIEvent.EventType) |
126 | { | 126 | { |
127 | case EGET_SCROLL_BAR_CHANGED: | 127 | case EGET_SCROLL_BAR_CHANGED: |
128 | if (id == MYGUI_CURRENTIMAGE) | 128 | if (id == MYGUI_CURRENTIMAGE) |
129 | { | 129 | { |
130 | IGUIImage* img = (IGUIImage*)env->getRootGUIElement()->getElementFromId(MYGUI_IMAGE,true); | 130 | IGUIImage* img = (IGUIImage*)env->getRootGUIElement()->getElementFromId(MYGUI_IMAGE,true); |
131 | s32 i = ((IGUIScrollBar*)event.GUIEvent.Caller)->getPos(); | 131 | s32 i = ((IGUIScrollBar*)event.GUIEvent.Caller)->getPos(); |
132 | img->setImage(FontTool->currentTextures[i]); | 132 | img->setImage(FontTool->currentTextures[i]); |
133 | 133 | ||
134 | return true; | 134 | return true; |
135 | } | 135 | } |
136 | break; | 136 | break; |
137 | case EGET_COMBO_BOX_CHANGED: | 137 | case EGET_COMBO_BOX_CHANGED: |
138 | if (id == MYGUI_CHARSET) | 138 | if (id == MYGUI_CHARSET) |
139 | { | 139 | { |
140 | IGUIComboBox* cbo = (IGUIComboBox*)event.GUIEvent.Caller; | 140 | IGUIComboBox* cbo = (IGUIComboBox*)event.GUIEvent.Caller; |
141 | FontTool->selectCharSet(cbo->getSelected()); | 141 | FontTool->selectCharSet(cbo->getSelected()); |
142 | // rebuild font list | 142 | // rebuild font list |
143 | cbo = (IGUIComboBox*)env->getRootGUIElement()->getElementFromId(MYGUI_FONTNAME,true); | 143 | cbo = (IGUIComboBox*)env->getRootGUIElement()->getElementFromId(MYGUI_FONTNAME,true); |
144 | cbo->clear(); | 144 | cbo->clear(); |
145 | for (u32 i=0; i < FontTool->FontNames.size(); ++i) | 145 | for (u32 i=0; i < FontTool->FontNames.size(); ++i) |
146 | cbo->addItem(FontTool->FontNames[i].c_str()); | 146 | cbo->addItem(FontTool->FontNames[i].c_str()); |
147 | return true; | 147 | return true; |
148 | } | 148 | } |
149 | break; | 149 | break; |
150 | case EGET_CHECKBOX_CHANGED: | 150 | case EGET_CHECKBOX_CHANGED: |
151 | if (id == MYGUI_VECTOR) | 151 | if (id == MYGUI_VECTOR) |
152 | { | 152 | { |
153 | IGUICheckBox* chk = (IGUICheckBox*)event.GUIEvent.Caller; | 153 | IGUICheckBox* chk = (IGUICheckBox*)event.GUIEvent.Caller; |
154 | 154 | ||
155 | IGUIComboBox *cbo = (IGUIComboBox*)env->getRootGUIElement()->getElementFromId(MYGUI_FORMAT,true); | 155 | IGUIComboBox *cbo = (IGUIComboBox*)env->getRootGUIElement()->getElementFromId(MYGUI_FORMAT,true); |
156 | cbo->clear(); | 156 | cbo->clear(); |
157 | 157 | ||
158 | if (chk->isChecked() && VecTool) | 158 | if (chk->isChecked() && VecTool) |
159 | { | 159 | { |
160 | // vector formats | 160 | // vector formats |
161 | for (s32 i=0; fileformats[i] != 0; ++i) | 161 | for (s32 i=0; fileformats[i] != 0; ++i) |
162 | cbo->addItem( core::stringw(vectorfileformats[i]).c_str()); | 162 | cbo->addItem( core::stringw(vectorfileformats[i]).c_str()); |
163 | 163 | ||
164 | } | 164 | } |
165 | else | 165 | else |
166 | { | 166 | { |
167 | 167 | ||
168 | // bitmap formats | 168 | // bitmap formats |
169 | if (!FontTool->UseAlphaChannel) | 169 | if (!FontTool->UseAlphaChannel) |
170 | { | 170 | { |
171 | // add non-alpha formats | 171 | // add non-alpha formats |
172 | for (s32 i=0; fileformats[i] != 0; ++i) | 172 | for (s32 i=0; fileformats[i] != 0; ++i) |
173 | cbo->addItem( core::stringw(fileformats[i]).c_str()); | 173 | cbo->addItem( core::stringw(fileformats[i]).c_str()); |
174 | } | 174 | } |
175 | // add formats which support alpha | 175 | // add formats which support alpha |
176 | for (s32 i=0; alphafileformats[i] != 0; ++i) | 176 | for (s32 i=0; alphafileformats[i] != 0; ++i) |
177 | cbo->addItem( core::stringw(alphafileformats[i]).c_str()); | 177 | cbo->addItem( core::stringw(alphafileformats[i]).c_str()); |
178 | } | 178 | } |
179 | 179 | ||
180 | } | 180 | } |
181 | break; | 181 | break; |
182 | 182 | ||
183 | case EGET_BUTTON_CLICKED: | 183 | case EGET_BUTTON_CLICKED: |
184 | 184 | ||
185 | if (id == MYGUI_CREATE) | 185 | if (id == MYGUI_CREATE) |
186 | { | 186 | { |
187 | // create the font with the params | 187 | // create the font with the params |
188 | IGUIComboBox* cbo = (IGUIComboBox*)env->getRootGUIElement()->getElementFromId(MYGUI_CHARSET, true); | 188 | IGUIComboBox* cbo = (IGUIComboBox*)env->getRootGUIElement()->getElementFromId(MYGUI_CHARSET, true); |
189 | int charset = cbo->getSelected(); | 189 | int charset = cbo->getSelected(); |
190 | 190 | ||
191 | cbo = (IGUIComboBox*)env->getRootGUIElement()->getElementFromId(MYGUI_FONTNAME,true); | 191 | cbo = (IGUIComboBox*)env->getRootGUIElement()->getElementFromId(MYGUI_FONTNAME,true); |
192 | int fontname = cbo->getSelected(); | 192 | int fontname = cbo->getSelected(); |
193 | 193 | ||
194 | cbo = (IGUIComboBox*)env->getRootGUIElement()->getElementFromId(MYGUI_SIZE,true); | 194 | cbo = (IGUIComboBox*)env->getRootGUIElement()->getElementFromId(MYGUI_SIZE,true); |
195 | int fontsize = cbo->getSelected(); | 195 | int fontsize = cbo->getSelected(); |
196 | 196 | ||
197 | cbo = (IGUIComboBox*)env->getRootGUIElement()->getElementFromId(MYGUI_TEXWIDTH,true); | 197 | cbo = (IGUIComboBox*)env->getRootGUIElement()->getElementFromId(MYGUI_TEXWIDTH,true); |
198 | int texwidth = cbo->getSelected(); | 198 | int texwidth = cbo->getSelected(); |
199 | 199 | ||
200 | cbo = (IGUIComboBox*)env->getRootGUIElement()->getElementFromId(MYGUI_TEXHEIGHT,true); | 200 | cbo = (IGUIComboBox*)env->getRootGUIElement()->getElementFromId(MYGUI_TEXHEIGHT,true); |
201 | int texheight = cbo->getSelected(); | 201 | int texheight = cbo->getSelected(); |
202 | 202 | ||
203 | IGUICheckBox* chk = (IGUICheckBox*)env->getRootGUIElement()->getElementFromId(MYGUI_BOLD,true); | 203 | IGUICheckBox* chk = (IGUICheckBox*)env->getRootGUIElement()->getElementFromId(MYGUI_BOLD,true); |
204 | bool bold = chk->isChecked(); | 204 | bool bold = chk->isChecked(); |
205 | chk = (IGUICheckBox*)env->getRootGUIElement()->getElementFromId(MYGUI_ITALIC,true); | 205 | chk = (IGUICheckBox*)env->getRootGUIElement()->getElementFromId(MYGUI_ITALIC,true); |
206 | bool italic = chk->isChecked(); | 206 | bool italic = chk->isChecked(); |
207 | 207 | ||
208 | chk = (IGUICheckBox*)env->getRootGUIElement()->getElementFromId(MYGUI_ALPHA,true); | 208 | chk = (IGUICheckBox*)env->getRootGUIElement()->getElementFromId(MYGUI_ALPHA,true); |
209 | bool alpha = chk->isChecked(); | 209 | bool alpha = chk->isChecked(); |
210 | 210 | ||
211 | chk = (IGUICheckBox*)env->getRootGUIElement()->getElementFromId(MYGUI_ANTIALIAS,true); | 211 | chk = (IGUICheckBox*)env->getRootGUIElement()->getElementFromId(MYGUI_ANTIALIAS,true); |
212 | bool aa = chk->isChecked(); | 212 | bool aa = chk->isChecked(); |
213 | 213 | ||
214 | // vector fonts disabled | 214 | // vector fonts disabled |
215 | //chk = (IGUICheckBox*)env->getRootGUIElement()->getElementFromId(MYGUI_VECTOR,true); | 215 | //chk = (IGUICheckBox*)env->getRootGUIElement()->getElementFromId(MYGUI_VECTOR,true); |
216 | bool vec = false;//chk->isChecked(); | 216 | bool vec = false;//chk->isChecked(); |
217 | 217 | ||
218 | FontTool->makeBitmapFont(fontname, charset, FontTool->FontSizes[fontsize], texturesizes[texwidth], texturesizes[texheight], bold, italic, aa, alpha); | 218 | FontTool->makeBitmapFont(fontname, charset, FontTool->FontSizes[fontsize], texturesizes[texwidth], texturesizes[texheight], bold, italic, aa, alpha); |
219 | 219 | ||
220 | IGUIScrollBar* scrl = (IGUIScrollBar*)env->getRootGUIElement()->getElementFromId(MYGUI_CURRENTIMAGE,true); | 220 | IGUIScrollBar* scrl = (IGUIScrollBar*)env->getRootGUIElement()->getElementFromId(MYGUI_CURRENTIMAGE,true); |
221 | scrl->setMax(FontTool->currentTextures.size() == 0 ? 0 : FontTool->currentTextures.size()-1); | 221 | scrl->setMax(FontTool->currentTextures.size() == 0 ? 0 : FontTool->currentTextures.size()-1); |
222 | 222 | ||
223 | if (FontTool->currentTextures.size() > 0) | 223 | if (FontTool->currentTextures.size() > 0) |
224 | { | 224 | { |
225 | IGUIImage* img = (IGUIImage*)env->getRootGUIElement()->getElementFromId(MYGUI_IMAGE,true); | 225 | IGUIImage* img = (IGUIImage*)env->getRootGUIElement()->getElementFromId(MYGUI_IMAGE,true); |
226 | img->setImage(FontTool->currentTextures[0]); | 226 | img->setImage(FontTool->currentTextures[0]); |
227 | scrl->setPos(0); | 227 | scrl->setPos(0); |
228 | } | 228 | } |
229 | 229 | ||
230 | // make sure users pick a file format that supports alpha channel | 230 | // make sure users pick a file format that supports alpha channel |
231 | cbo = (IGUIComboBox*)env->getRootGUIElement()->getElementFromId(MYGUI_FORMAT,true); | 231 | cbo = (IGUIComboBox*)env->getRootGUIElement()->getElementFromId(MYGUI_FORMAT,true); |
232 | cbo->clear(); | 232 | cbo->clear(); |
233 | 233 | ||
234 | if (vec) | 234 | if (vec) |
235 | { | 235 | { |
236 | // add vector formats | 236 | // add vector formats |
237 | for (s32 i=0; fileformats[i] != 0; ++i) | 237 | for (s32 i=0; fileformats[i] != 0; ++i) |
238 | cbo->addItem( core::stringw(vectorfileformats[i]).c_str()); | 238 | cbo->addItem( core::stringw(vectorfileformats[i]).c_str()); |
239 | } | 239 | } |
240 | else | 240 | else |
241 | { | 241 | { |
242 | if (!alpha) | 242 | if (!alpha) |
243 | { | 243 | { |
244 | // add non-alpha formats | 244 | // add non-alpha formats |
245 | for (s32 i=0; fileformats[i] != 0; ++i) | 245 | for (s32 i=0; fileformats[i] != 0; ++i) |
246 | cbo->addItem( core::stringw(fileformats[i]).c_str()); | 246 | cbo->addItem( core::stringw(fileformats[i]).c_str()); |
247 | } | 247 | } |
248 | // add formats which support alpha | 248 | // add formats which support alpha |
249 | for (s32 i=0; alphafileformats[i] != 0; ++i) | 249 | for (s32 i=0; alphafileformats[i] != 0; ++i) |
250 | cbo->addItem( core::stringw(alphafileformats[i]).c_str()); | 250 | cbo->addItem( core::stringw(alphafileformats[i]).c_str()); |
251 | } | 251 | } |
252 | if (VecTool) | 252 | if (VecTool) |
253 | { | 253 | { |
254 | delete VecTool; | 254 | delete VecTool; |
255 | VecTool = 0; | 255 | VecTool = 0; |
256 | } | 256 | } |
257 | if (vec) | 257 | if (vec) |
258 | { | 258 | { |
259 | VecTool = new CVectorFontTool(FontTool); | 259 | VecTool = new CVectorFontTool(FontTool); |
260 | } | 260 | } |
261 | 261 | ||
262 | /* Message box letting the user know the process is complete */ | 262 | /* Message box letting the user know the process is complete */ |
263 | env->addMessageBox(L"Create", completeText); | 263 | env->addMessageBox(L"Create", completeText); |
264 | 264 | ||
265 | return true; | 265 | return true; |
266 | } | 266 | } |
267 | 267 | ||
268 | if (id == MYGUI_SAVE) | 268 | if (id == MYGUI_SAVE) |
269 | { | 269 | { |
270 | IGUIEditBox *edt = (IGUIEditBox*)env->getRootGUIElement()->getElementFromId(MYGUI_FILENAME,true); | 270 | IGUIEditBox *edt = (IGUIEditBox*)env->getRootGUIElement()->getElementFromId(MYGUI_FILENAME,true); |
271 | core::stringc name = edt->getText(); | 271 | core::stringc name = edt->getText(); |
272 | 272 | ||
273 | IGUIComboBox *fmt = (IGUIComboBox*)env->getRootGUIElement()->getElementFromId(MYGUI_FORMAT,true); | 273 | IGUIComboBox *fmt = (IGUIComboBox*)env->getRootGUIElement()->getElementFromId(MYGUI_FORMAT,true); |
274 | core::stringc format = fmt->getItem(fmt->getSelected()); | 274 | core::stringc format = fmt->getItem(fmt->getSelected()); |
275 | 275 | ||
276 | // vector fonts disabled | 276 | // vector fonts disabled |
277 | IGUICheckBox *chk = (IGUICheckBox*)env->getRootGUIElement()->getElementFromId(MYGUI_VECTOR,true); | 277 | IGUICheckBox *chk = (IGUICheckBox*)env->getRootGUIElement()->getElementFromId(MYGUI_VECTOR,true); |
278 | bool vec = false; // chk->isChecked(); | 278 | bool vec = false; // chk->isChecked(); |
279 | 279 | ||
280 | if (vec && VecTool) | 280 | if (vec && VecTool) |
281 | VecTool->saveVectorFont(name.c_str(), format.c_str()); | 281 | VecTool->saveVectorFont(name.c_str(), format.c_str()); |
282 | else | 282 | else |
283 | FontTool->saveBitmapFont(name.c_str(), format.c_str()); | 283 | FontTool->saveBitmapFont(name.c_str(), format.c_str()); |
284 | 284 | ||
285 | return true; | 285 | return true; |
286 | } | 286 | } |
287 | 287 | ||
288 | if (id == MYGUI_HELPBUTTON) | 288 | if (id == MYGUI_HELPBUTTON) |
289 | { | 289 | { |
290 | env->addMessageBox(L"Irrlicht Unicode Font Tool", helptext); | 290 | env->addMessageBox(L"Irrlicht Unicode Font Tool", helptext); |
291 | return true; | 291 | return true; |
292 | } | 292 | } |
293 | 293 | ||
294 | break; | 294 | break; |
295 | } | 295 | } |
296 | } | 296 | } |
297 | 297 | ||
298 | return false; | 298 | return false; |
299 | } | 299 | } |
300 | 300 | ||
301 | IrrlichtDevice* Device; | 301 | IrrlichtDevice* Device; |
302 | CFontTool* FontTool; | 302 | CFontTool* FontTool; |
303 | CVectorFontTool* VecTool; | 303 | CVectorFontTool* VecTool; |
304 | 304 | ||
305 | }; | 305 | }; |
306 | 306 | ||
307 | void createGUI(IrrlichtDevice* device, CFontTool* fc) | 307 | void createGUI(IrrlichtDevice* device, CFontTool* fc) |
308 | { | 308 | { |
309 | gui::IGUIEnvironment *env = device->getGUIEnvironment(); | 309 | gui::IGUIEnvironment *env = device->getGUIEnvironment(); |
310 | 310 | ||
311 | // change transparency of skin | 311 | // change transparency of skin |
312 | for (s32 i=0; i<gui::EGDC_COUNT ; ++i) | 312 | for (s32 i=0; i<gui::EGDC_COUNT ; ++i) |
313 | { | 313 | { |
314 | video::SColor col = env->getSkin()->getColor((gui::EGUI_DEFAULT_COLOR)i); | 314 | video::SColor col = env->getSkin()->getColor((gui::EGUI_DEFAULT_COLOR)i); |
315 | col.setAlpha(255); | 315 | col.setAlpha(255); |
316 | env->getSkin()->setColor((gui::EGUI_DEFAULT_COLOR)i, col); | 316 | env->getSkin()->setColor((gui::EGUI_DEFAULT_COLOR)i, col); |
317 | } | 317 | } |
318 | 318 | ||
319 | IGUIWindow *win = env->addWindow( core::rect<s32>(10,10,200,500), false, L"Font Creator"); | 319 | IGUIWindow *win = env->addWindow( core::rect<s32>(10,10,200,500), false, L"Font Creator"); |
320 | win->getCloseButton()->setVisible(false); | 320 | win->getCloseButton()->setVisible(false); |
321 | 321 | ||
322 | s32 xs=10,xp=xs, yp=30, h=20; | 322 | s32 xs=10,xp=xs, yp=30, h=20; |
323 | 323 | ||
324 | env->addStaticText(L"Charset", core::rect<s32>(xp,yp,50,yp+h),false,false, win); | 324 | env->addStaticText(L"Charset", core::rect<s32>(xp,yp,50,yp+h),false,false, win); |
325 | 325 | ||
326 | xp+=60; | 326 | xp+=60; |
327 | 327 | ||
328 | // charset combo | 328 | // charset combo |
329 | gui::IGUIComboBox* cbo = env->addComboBox( core::rect<s32>(xp,yp,180,yp+h),win, MYGUI_CHARSET); | 329 | gui::IGUIComboBox* cbo = env->addComboBox( core::rect<s32>(xp,yp,180,yp+h),win, MYGUI_CHARSET); |
330 | for (u32 i=0; i < fc->CharSets.size(); ++i) | 330 | for (u32 i=0; i < fc->CharSets.size(); ++i) |
331 | cbo->addItem(fc->CharSets[i].c_str()); | 331 | cbo->addItem(fc->CharSets[i].c_str()); |
332 | 332 | ||
333 | yp += (s32)(h*1.5f); | 333 | yp += (s32)(h*1.5f); |
334 | xp = xs; | 334 | xp = xs; |
335 | 335 | ||
336 | env->addStaticText(L"Font", core::rect<s32>(xp,yp,50,yp+h),false,false, win); | 336 | env->addStaticText(L"Font", core::rect<s32>(xp,yp,50,yp+h),false,false, win); |
337 | 337 | ||
338 | xp+=60; | 338 | xp+=60; |
339 | 339 | ||
340 | // font name combo | 340 | // font name combo |
341 | cbo = env->addComboBox( core::rect<s32>(xp,yp,180,yp+h),win, MYGUI_FONTNAME); | 341 | cbo = env->addComboBox( core::rect<s32>(xp,yp,180,yp+h),win, MYGUI_FONTNAME); |
342 | for (u32 i=0; i < fc->FontNames.size(); ++i) | 342 | for (u32 i=0; i < fc->FontNames.size(); ++i) |
343 | cbo->addItem(fc->FontNames[i].c_str()); | 343 | cbo->addItem(fc->FontNames[i].c_str()); |
344 | 344 | ||
345 | yp += (s32)(h*1.5f); | 345 | yp += (s32)(h*1.5f); |
346 | xp = xs; | 346 | xp = xs; |
347 | 347 | ||
348 | env->addStaticText(L"Size", core::rect<s32>(xp,yp,50,yp+h),false,false, win); | 348 | env->addStaticText(L"Size", core::rect<s32>(xp,yp,50,yp+h),false,false, win); |
349 | 349 | ||
350 | xp += 60; | 350 | xp += 60; |
351 | 351 | ||
352 | // font size combo | 352 | // font size combo |
353 | cbo = env->addComboBox( core::rect<s32>(xp,yp,xp+50,yp+h),win, MYGUI_SIZE); | 353 | cbo = env->addComboBox( core::rect<s32>(xp,yp,xp+50,yp+h),win, MYGUI_SIZE); |
354 | for (s32 i=0; fc->FontSizes[i] != 0; ++i) | 354 | for (s32 i=0; fc->FontSizes[i] != 0; ++i) |
355 | cbo->addItem( ((core::stringw(fc->FontSizes[i])) + L"px").c_str()); | 355 | cbo->addItem( ((core::stringw(fc->FontSizes[i])) + L"px").c_str()); |
356 | 356 | ||
357 | xp = xs; | 357 | xp = xs; |
358 | yp += (s32)(h*1.5f); | 358 | yp += (s32)(h*1.5f); |
359 | 359 | ||
360 | // bold checkbox | 360 | // bold checkbox |
361 | env->addCheckBox(false, core::rect<s32>(xp,yp,xp+50,yp+h),win, MYGUI_BOLD, L"Bold"); | 361 | env->addCheckBox(false, core::rect<s32>(xp,yp,xp+50,yp+h),win, MYGUI_BOLD, L"Bold"); |
362 | 362 | ||
363 | xp += 45; | 363 | xp += 45; |
364 | 364 | ||
365 | // italic checkbox | 365 | // italic checkbox |
366 | env->addCheckBox(false, core::rect<s32>(xp,yp,xp+50,yp+h),win, MYGUI_ITALIC, L"Italic"); | 366 | env->addCheckBox(false, core::rect<s32>(xp,yp,xp+50,yp+h),win, MYGUI_ITALIC, L"Italic"); |
367 | 367 | ||
368 | xp += 45; | 368 | xp += 45; |
369 | 369 | ||
370 | // AA checkbox | 370 | // AA checkbox |
371 | env->addCheckBox(false, core::rect<s32>(xp,yp,xp+50,yp+h),win, MYGUI_ANTIALIAS, L"AA"); | 371 | env->addCheckBox(false, core::rect<s32>(xp,yp,xp+50,yp+h),win, MYGUI_ANTIALIAS, L"AA"); |
372 | 372 | ||
373 | xp +=40; | 373 | xp +=40; |
374 | 374 | ||
375 | // Alpha checkbox | 375 | // Alpha checkbox |
376 | env->addCheckBox(false, core::rect<s32>(xp,yp,xp+50,yp+h),win, MYGUI_ALPHA, L"Alpha"); | 376 | env->addCheckBox(false, core::rect<s32>(xp,yp,xp+50,yp+h),win, MYGUI_ALPHA, L"Alpha"); |
377 | 377 | ||
378 | xp = xs; | 378 | xp = xs; |
379 | yp += (s32)(h*1.5f); | 379 | yp += (s32)(h*1.5f); |
380 | 380 | ||
381 | /* | 381 | /* |
382 | // vector fonts can't be loaded yet | 382 | // vector fonts can't be loaded yet |
383 | env->addCheckBox(false, core::rect<s32>(xp,yp,xp+200,yp+h),win, MYGUI_VECTOR, L"Vector Font"); | 383 | env->addCheckBox(false, core::rect<s32>(xp,yp,xp+200,yp+h),win, MYGUI_VECTOR, L"Vector Font"); |
384 | */ | 384 | */ |
385 | 385 | ||
386 | yp += (s32)(h*1.5f); | 386 | yp += (s32)(h*1.5f); |
387 | 387 | ||
388 | env->addStaticText(L"Max Width:", core::rect<s32>(xp,yp,50,yp+h),false,false, win); | 388 | env->addStaticText(L"Max Width:", core::rect<s32>(xp,yp,50,yp+h),false,false, win); |
389 | 389 | ||
390 | xp += 60; | 390 | xp += 60; |
391 | 391 | ||
392 | // texture widths | 392 | // texture widths |
393 | cbo = env->addComboBox( core::rect<s32>(xp,yp,xp+70,yp+h),win, MYGUI_TEXWIDTH); | 393 | cbo = env->addComboBox( core::rect<s32>(xp,yp,xp+70,yp+h),win, MYGUI_TEXWIDTH); |
394 | for (s32 i=0; texturesizes[i] != 0; ++i) | 394 | for (s32 i=0; texturesizes[i] != 0; ++i) |
395 | cbo->addItem( ((core::stringw(texturesizes[i])) + L" wide").c_str()); | 395 | cbo->addItem( ((core::stringw(texturesizes[i])) + L" wide").c_str()); |
396 | 396 | ||
397 | xp=xs; | 397 | xp=xs; |
398 | yp += (s32)(h*1.5f); | 398 | yp += (s32)(h*1.5f); |
399 | 399 | ||
400 | env->addStaticText(L"Max Height:", core::rect<s32>(xp,yp,60,yp+h),false,false, win); | 400 | env->addStaticText(L"Max Height:", core::rect<s32>(xp,yp,60,yp+h),false,false, win); |
401 | 401 | ||
402 | xp += 60; | 402 | xp += 60; |
403 | 403 | ||
404 | // texture height | 404 | // texture height |
405 | cbo = env->addComboBox( core::rect<s32>(xp,yp,xp+70,yp+h),win, MYGUI_TEXHEIGHT); | 405 | cbo = env->addComboBox( core::rect<s32>(xp,yp,xp+70,yp+h),win, MYGUI_TEXHEIGHT); |
406 | for (s32 i=0; texturesizes[i] != 0; ++i) | 406 | for (s32 i=0; texturesizes[i] != 0; ++i) |
407 | cbo->addItem( ((core::stringw(texturesizes[i])) + L" tall").c_str()); | 407 | cbo->addItem( ((core::stringw(texturesizes[i])) + L" tall").c_str()); |
408 | 408 | ||
409 | // file name | 409 | // file name |
410 | xp = xs; | 410 | xp = xs; |
411 | yp += (s32)(h*1.5f); | 411 | yp += (s32)(h*1.5f); |
412 | env->addStaticText(L"Filename", core::rect<s32>(xp,yp,60,yp+h),false,false, win); | 412 | env->addStaticText(L"Filename", core::rect<s32>(xp,yp,60,yp+h),false,false, win); |
413 | xp += 60; | 413 | xp += 60; |
414 | env->addEditBox(L"myfont",core::rect<s32>(xp,yp,xp+70,yp+h), true, win, MYGUI_FILENAME); | 414 | env->addEditBox(L"myfont",core::rect<s32>(xp,yp,xp+70,yp+h), true, win, MYGUI_FILENAME); |
415 | 415 | ||
416 | // file format | 416 | // file format |
417 | xp = xs; | 417 | xp = xs; |
418 | yp += (s32)(h*1.5f); | 418 | yp += (s32)(h*1.5f); |
419 | env->addStaticText(L"File Format", core::rect<s32>(xp,yp,60,yp+h),false,false, win); | 419 | env->addStaticText(L"File Format", core::rect<s32>(xp,yp,60,yp+h),false,false, win); |
420 | xp += 60; | 420 | xp += 60; |
421 | 421 | ||
422 | cbo = env->addComboBox( core::rect<s32>(xp,yp,xp+70,yp+h),win, MYGUI_FORMAT); | 422 | cbo = env->addComboBox( core::rect<s32>(xp,yp,xp+70,yp+h),win, MYGUI_FORMAT); |
423 | for (s32 i=0; fileformats[i] != 0; ++i) | 423 | for (s32 i=0; fileformats[i] != 0; ++i) |
424 | cbo->addItem( core::stringw(fileformats[i]).c_str()); | 424 | cbo->addItem( core::stringw(fileformats[i]).c_str()); |
425 | for (s32 i=0; alphafileformats[i] != 0; ++i) | 425 | for (s32 i=0; alphafileformats[i] != 0; ++i) |
426 | cbo->addItem( core::stringw(alphafileformats[i]).c_str()); | 426 | cbo->addItem( core::stringw(alphafileformats[i]).c_str()); |
427 | 427 | ||
428 | xp = xs; | 428 | xp = xs; |
429 | yp += h*2; | 429 | yp += h*2; |
430 | 430 | ||
431 | // create button | 431 | // create button |
432 | env->addButton( core::rect<s32>(xp,yp,xp+50,yp+h),win, MYGUI_CREATE, L"Create"); | 432 | env->addButton( core::rect<s32>(xp,yp,xp+50,yp+h),win, MYGUI_CREATE, L"Create"); |
433 | 433 | ||
434 | xp += 60; | 434 | xp += 60; |
435 | 435 | ||
436 | // save button | 436 | // save button |
437 | env->addButton( core::rect<s32>(xp,yp,xp+50,yp+h),win, MYGUI_SAVE, L"Save"); | 437 | env->addButton( core::rect<s32>(xp,yp,xp+50,yp+h),win, MYGUI_SAVE, L"Save"); |
438 | 438 | ||
439 | xp += 60; | 439 | xp += 60; |
440 | 440 | ||
441 | // help button | 441 | // help button |
442 | env->addButton( core::rect<s32>(xp,yp,xp+50,yp+h),win, MYGUI_HELPBUTTON, L"Help"); | 442 | env->addButton( core::rect<s32>(xp,yp,xp+50,yp+h),win, MYGUI_HELPBUTTON, L"Help"); |
443 | 443 | ||
444 | // font image | 444 | // font image |
445 | gui::IGUIImage *img = env->addImage(0, core::position2d<s32>(0,0), true,0, MYGUI_IMAGE); | 445 | gui::IGUIImage *img = env->addImage(0, core::position2d<s32>(0,0), true,0, MYGUI_IMAGE); |
446 | img->setRelativePosition(core::rect<s32>(0,20,800,600)); | 446 | img->setRelativePosition(core::rect<s32>(0,20,800,600)); |
447 | 447 | ||
448 | // font scrollbar | 448 | // font scrollbar |
449 | IGUIScrollBar *scrl= env->addScrollBar(true,core::rect<s32>(0,0,800,20),0, MYGUI_CURRENTIMAGE); | 449 | IGUIScrollBar *scrl= env->addScrollBar(true,core::rect<s32>(0,0,800,20),0, MYGUI_CURRENTIMAGE); |
450 | scrl->setMax(0); | 450 | scrl->setMax(0); |
451 | scrl->setSmallStep(1); | 451 | scrl->setSmallStep(1); |
452 | 452 | ||
453 | yp += h*3; | 453 | yp += h*3; |
454 | 454 | ||
455 | env->getRootGUIElement()->bringToFront(win); | 455 | env->getRootGUIElement()->bringToFront(win); |
456 | win->setRelativePosition( core::rect<s32>(10,10,200,yp)); | 456 | win->setRelativePosition( core::rect<s32>(10,10,200,yp)); |
457 | } | 457 | } |
458 | 458 | ||
459 | int main() | 459 | int main() |
460 | { | 460 | { |
461 | IrrlichtDevice* device =createDevice(video::EDT_OPENGL, core::dimension2du(800, 600)); | 461 | IrrlichtDevice* device =createDevice(video::EDT_OPENGL, core::dimension2du(800, 600)); |
462 | video::IVideoDriver* driver = device->getVideoDriver(); | 462 | video::IVideoDriver* driver = device->getVideoDriver(); |
463 | scene::ISceneManager* smgr = device->getSceneManager(); | 463 | scene::ISceneManager* smgr = device->getSceneManager(); |
464 | gui::IGUIEnvironment *env = device->getGUIEnvironment(); | 464 | gui::IGUIEnvironment *env = device->getGUIEnvironment(); |
465 | 465 | ||
466 | // create font tool | 466 | // create font tool |
467 | CFontTool *fc = new CFontTool(device); | 467 | CFontTool *fc = new CFontTool(device); |
468 | CVectorFontTool *vc = 0; | 468 | CVectorFontTool *vc = 0; |
469 | 469 | ||
470 | IEventReceiver *events = new MyEventReceiver(device,fc,vc); | 470 | IEventReceiver *events = new MyEventReceiver(device,fc,vc); |
471 | 471 | ||
472 | createGUI(device, fc); | 472 | createGUI(device, fc); |
473 | 473 | ||
474 | while(device->run()) | 474 | while(device->run()) |
475 | { | 475 | { |
476 | if (device->isWindowActive()) | 476 | if (device->isWindowActive()) |
477 | { | 477 | { |
478 | 478 | ||
479 | driver->beginScene(true, true, video::SColor(0,200,200,200)); | 479 | driver->beginScene(true, true, video::SColor(0,200,200,200)); |
480 | smgr->drawAll(); | 480 | smgr->drawAll(); |
481 | env->drawAll(); | 481 | env->drawAll(); |
482 | driver->endScene(); | 482 | driver->endScene(); |
483 | } | 483 | } |
484 | } | 484 | } |
485 | 485 | ||
486 | // drop the font tool and resources | 486 | // drop the font tool and resources |
487 | fc->drop(); | 487 | fc->drop(); |
488 | 488 | ||
489 | device->drop(); | 489 | device->drop(); |
490 | 490 | ||
491 | return 0; | 491 | return 0; |
492 | } | 492 | } |
493 | 493 | ||