├── .gitattributes ├── .gitignore ├── LICENCE ├── README.md ├── docs ├── CBFGHelp.chm └── media │ └── CBFG_Grab.jpg ├── examples └── BFF Example │ ├── BitmapFontClass.cpp │ ├── BitmapFontClass.h │ ├── Framework.h │ ├── OpenGLBase.cpp │ ├── Render.cpp │ └── TestFont.bff └── source ├── AppIcon.ico ├── BFG2.bmp ├── CBFG.cpp ├── CBFG.sln ├── CBFG.vcxproj ├── CBFG.vcxproj.filters ├── CBFGDefs.h ├── ConfigProc.cpp ├── ConfigWindow.h ├── FileRequest.cpp ├── FontMapClass.cpp ├── FontMapClass.h ├── MainProc.cpp ├── MainProc.h ├── PreviewProc.cpp ├── Procs.h ├── SBM-Util.cpp ├── SBM-Util.h ├── SaveOptProc.cpp ├── Script1.rc ├── SplashProc.cpp ├── SplashProc.h ├── StdAfx.cpp ├── StdAfx.h ├── TestWindow.h ├── TextWinProc.cpp ├── UtilFunctions.cpp ├── UtilFunctions.h ├── WriteFont.cpp ├── WriteFont.h ├── bfg.cfg ├── file-request.h ├── ico_down.ico ├── ico_left.ico ├── ico_right.ico ├── ico_up.ico └── resource.h /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.sln.docstates 8 | 9 | # Build results 10 | 11 | [Dd]ebug/ 12 | [Rr]elease/ 13 | x64/ 14 | build/ 15 | [Bb]in/ 16 | [Oo]bj/ 17 | 18 | # Enable "build/" folder in the NuGet Packages folder since NuGet packages use it for MSBuild targets 19 | !packages/*/build/ 20 | 21 | # MSTest test Results 22 | [Tt]est[Rr]esult*/ 23 | [Bb]uild[Ll]og.* 24 | 25 | *_i.c 26 | *_p.c 27 | *.ilk 28 | *.meta 29 | *.obj 30 | *.pch 31 | *.pdb 32 | *.pgc 33 | *.pgd 34 | *.rsp 35 | *.sbr 36 | *.tlb 37 | *.tli 38 | *.tlh 39 | *.tmp 40 | *.tmp_proj 41 | *.log 42 | *.vspscc 43 | *.vssscc 44 | .builds 45 | *.pidb 46 | *.log 47 | *.scc 48 | 49 | # Visual C++ cache files 50 | ipch/ 51 | *.aps 52 | *.ncb 53 | *.opensdf 54 | *.sdf 55 | *.cachefile 56 | 57 | # Visual Studio profiler 58 | *.psess 59 | *.vsp 60 | *.vspx 61 | 62 | # Guidance Automation Toolkit 63 | *.gpState 64 | 65 | # ReSharper is a .NET coding add-in 66 | _ReSharper*/ 67 | *.[Rr]e[Ss]harper 68 | 69 | # TeamCity is a build add-in 70 | _TeamCity* 71 | 72 | # DotCover is a Code Coverage Tool 73 | *.dotCover 74 | 75 | # NCrunch 76 | *.ncrunch* 77 | .*crunch*.local.xml 78 | 79 | # Installshield output folder 80 | [Ee]xpress/ 81 | 82 | # DocProject is a documentation generator add-in 83 | DocProject/buildhelp/ 84 | DocProject/Help/*.HxT 85 | DocProject/Help/*.HxC 86 | DocProject/Help/*.hhc 87 | DocProject/Help/*.hhk 88 | DocProject/Help/*.hhp 89 | DocProject/Help/Html2 90 | DocProject/Help/html 91 | 92 | # Click-Once directory 93 | publish/ 94 | 95 | # Publish Web Output 96 | *.Publish.xml 97 | 98 | # NuGet Packages Directory 99 | ## TODO: If you have NuGet Package Restore enabled, uncomment the next line 100 | #packages/ 101 | 102 | # Windows Azure Build Output 103 | csx 104 | *.build.csdef 105 | 106 | # Windows Store app package directory 107 | AppPackages/ 108 | 109 | # Others 110 | sql/ 111 | *.Cache 112 | ClientBin/ 113 | [Ss]tyle[Cc]op.* 114 | ~$* 115 | *~ 116 | *.dbmdl 117 | *.[Pp]ublish.xml 118 | *.pfx 119 | *.publishsettings 120 | 121 | # RIA/Silverlight projects 122 | Generated_Code/ 123 | 124 | # Backup & report files from converting an old project file to a newer 125 | # Visual Studio version. Backup files are not needed, because we have git ;-) 126 | _UpgradeReport_Files/ 127 | Backup*/ 128 | UpgradeLog*.XML 129 | UpgradeLog*.htm 130 | 131 | # SQL Server files 132 | App_Data/*.mdf 133 | App_Data/*.ldf 134 | 135 | 136 | #LightSwitch generated files 137 | GeneratedArtifacts/ 138 | _Pvt_Extensions/ 139 | ModelManifest.xml 140 | 141 | # ========================= 142 | # Windows detritus 143 | # ========================= 144 | 145 | # Windows image file caches 146 | Thumbs.db 147 | ehthumbs.db 148 | 149 | # Folder config file 150 | Desktop.ini 151 | 152 | # Recycle Bin used on file shares 153 | $RECYCLE.BIN/ 154 | 155 | # Mac desktop service store files 156 | .DS_Store 157 | *.opt 158 | -------------------------------------------------------------------------------- /LICENCE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015, Karl Walsh 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of CBFG nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Codehead's Bitmap Font Generator (CBFG) 2 | 3 | CBFG is a tool I developed to help with my OpenGL projects. It generates bitmap font textures with kerning information so that reasonably pretty, variable width text can be displayed in OpenGL applications. 4 | 5 | ![](docs/media/CBFG_Grab.jpg?raw=true) 6 | 7 | ### Features 8 | 9 | - DIB rendering of font gives best font output, regardless of users screen settings 10 | - Global or per character position and width adjustment 11 | - Texture Sizes from 16×16 up to 4096×4096 12 | - Zoom up to 400% for accurate tweaking of character positions 13 | - Anti-aliasing or ClearType (Win XP and up) for smoother looking fonts 14 | - Control of font width 15 | - Font preview option 16 | - TGA export option 17 | - BMP output option 18 | - BFF output in 8, 24 and 32bit colour depths 19 | - C++ example source code for loading and rendering BFF files 20 | - Binary font data export 21 | - Font info dump option 22 | - User configurable colours and startup parameters 23 | - Written for Win32 APIs (Windows only for now, although I'm told it runs fine under WINE) 24 | 25 | ### Open Release 26 | I haven't updated the tool for a good while, but I still get plenty of email about it from people who find it useful, which is nice. However, some of those people want new features which I just don't have time to add. So, I'm releasing the code under the BSD 3-clause licence so that people can hack on the code and add the features they need. 27 | 28 | ### Binaries 29 | Pre-built binaries are available at my site: http://www.codehead.co.uk/cbfg/ 30 | 31 | ### Notable Projects 32 | [Gabriele Giuseppini](https://github.com/GabrieleGiuseppini) is using CBFG in his [Floating Sandbox](https://github.com/GabrieleGiuseppini/Floating-Sandbox) 33 | 34 | [Flarn2006](https://github.com/flarn2006) has used CBFG in her [SF2DBmpFont](https://github.com/flarn2006/SF2DBmpFont) project 35 | 36 | -------------------------------------------------------------------------------- /docs/CBFGHelp.chm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeheadUK/CBFG/06084ec6f37c2525546b7d5b9f54c15896c2e5b9/docs/CBFGHelp.chm -------------------------------------------------------------------------------- /docs/media/CBFG_Grab.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeheadUK/CBFG/06084ec6f37c2525546b7d5b9f54c15896c2e5b9/docs/media/CBFG_Grab.jpg -------------------------------------------------------------------------------- /examples/BFF Example/BitmapFontClass.cpp: -------------------------------------------------------------------------------- 1 | #include "BitmapFontClass.h" 2 | 3 | using namespace std; 4 | 5 | CBitmapFont::CBitmapFont() 6 | { 7 | CurX=CurY=0; 8 | Rd=Gr=Bl=1.0f; 9 | InvertYAxis=false; 10 | } 11 | 12 | CBitmapFont::~CBitmapFont() 13 | { 14 | 15 | } 16 | 17 | bool CBitmapFont::Load(char *fname) 18 | { 19 | char *dat,*img; 20 | fstream in; 21 | unsigned long fileSize; 22 | char bpp; 23 | int ImgX,ImgY; 24 | 25 | in.open(fname, ios_base::binary | ios_base::in); 26 | 27 | if(in.fail()) 28 | return false; 29 | 30 | // Get Filesize 31 | in.seekg(0,ios_base::end); 32 | fileSize=in.tellg(); 33 | in.seekg(0,ios_base::beg); 34 | 35 | // allocate space for file data 36 | dat=new char[fileSize]; 37 | 38 | // Read filedata 39 | if(!dat) 40 | return false; 41 | 42 | in.read(dat,fileSize); 43 | 44 | if(in.fail()) 45 | { 46 | delete [] dat; 47 | in.close(); 48 | return false; 49 | } 50 | 51 | in.close(); 52 | 53 | // Check ID is 'BFF2' 54 | if((unsigned char)dat[0]!=0xBF || (unsigned char)dat[1]!=0xF2) 55 | { 56 | delete [] dat; 57 | return false; 58 | } 59 | 60 | // Grab the rest of the header 61 | memcpy(&ImgX,&dat[2],sizeof(int)); 62 | memcpy(&ImgY,&dat[6],sizeof(int)); 63 | memcpy(&CellX,&dat[10],sizeof(int)); 64 | memcpy(&CellY,&dat[14],sizeof(int)); 65 | bpp=dat[18]; 66 | Base=dat[19]; 67 | 68 | // Check filesize 69 | if(fileSize!=((MAP_DATA_OFFSET)+((ImgX*ImgY)*(bpp/8)))) 70 | return false; 71 | 72 | // Calculate font params 73 | RowPitch=ImgX/CellX; 74 | ColFactor=(float)CellX/(float)ImgX; 75 | RowFactor=(float)CellY/(float)ImgY; 76 | YOffset=CellY; 77 | 78 | // Determine blending options based on BPP 79 | switch(bpp) 80 | { 81 | case 8: // Greyscale 82 | RenderStyle=BFG_RS_ALPHA; 83 | break; 84 | 85 | case 24: // RGB 86 | RenderStyle=BFG_RS_RGB; 87 | break; 88 | 89 | case 32: // RGBA 90 | RenderStyle=BFG_RS_RGBA; 91 | break; 92 | 93 | default: // Unsupported BPP 94 | delete [] dat; 95 | return false; 96 | break; 97 | } 98 | 99 | // Allocate space for image 100 | img=new char[(ImgX*ImgY)*(bpp/8)]; 101 | 102 | if(!img) 103 | { 104 | delete [] dat; 105 | return false; 106 | } 107 | 108 | // Grab char widths 109 | memcpy(Width,&dat[WIDTH_DATA_OFFSET],256); 110 | 111 | // Grab image data 112 | memcpy(img,&dat[MAP_DATA_OFFSET],(ImgX*ImgY)*(bpp/8)); 113 | 114 | // Create Texture 115 | glGenTextures(1,&TexID); 116 | glBindTexture(GL_TEXTURE_2D,TexID); 117 | // Fonts should be rendered at native resolution so no need for texture filtering 118 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_NEAREST); 119 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_NEAREST); 120 | // Stop chararcters from bleeding over edges 121 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,GL_CLAMP_TO_EDGE); 122 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,GL_CLAMP_TO_EDGE); 123 | 124 | // Tex creation params are dependent on BPP 125 | switch(RenderStyle) 126 | { 127 | case BFG_RS_ALPHA: 128 | glTexImage2D(GL_TEXTURE_2D,0,GL_LUMINANCE,ImgX,ImgY,0,GL_LUMINANCE,GL_UNSIGNED_BYTE,img); 129 | break; 130 | 131 | case BFG_RS_RGB: 132 | glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,ImgX,ImgY,0,GL_RGB,GL_UNSIGNED_BYTE,img); 133 | break; 134 | 135 | case BFG_RS_RGBA: 136 | glTexImage2D(GL_TEXTURE_2D,0,GL_RGBA,ImgX,ImgY,0,GL_RGBA,GL_UNSIGNED_BYTE,img); 137 | break; 138 | } 139 | 140 | // Clean up 141 | delete [] img; 142 | delete [] dat; 143 | 144 | return true; 145 | } 146 | 147 | // Set the position for text output, this will be updated as text is printed 148 | void CBitmapFont::SetCursor(int x, int y) 149 | { 150 | CurX=x; 151 | CurY=y; 152 | } 153 | 154 | // The texture ID is a private member, so this function performs the texture bind 155 | void CBitmapFont::Bind() 156 | { 157 | glBindTexture(GL_TEXTURE_2D,TexID); 158 | } 159 | 160 | // Set the color and blending options based on the Renderstyle member 161 | void CBitmapFont::SetBlend() 162 | { 163 | glColor3f(Rd,Gr,Bl); 164 | 165 | switch(RenderStyle) 166 | { 167 | case BFG_RS_ALPHA: // 8Bit 168 | glBlendFunc(GL_SRC_ALPHA,GL_SRC_ALPHA); 169 | glEnable(GL_BLEND); 170 | break; 171 | 172 | case BFG_RS_RGB: // 24Bit 173 | glDisable(GL_BLEND); 174 | break; 175 | 176 | case BFG_RS_RGBA: // 32Bit 177 | glBlendFunc(GL_ONE,GL_ONE_MINUS_SRC_ALPHA); 178 | glEnable(GL_BLEND); 179 | break; 180 | } 181 | } 182 | 183 | // Shortcut, Enables Texturing and performs Bind and SetBlend 184 | void CBitmapFont::Select() 185 | { 186 | glEnable(GL_TEXTURE_2D); 187 | Bind(); 188 | SetBlend(); 189 | } 190 | 191 | // Set the font color NOTE this only sets the polygon color, the texture colors are fixed 192 | void CBitmapFont::SetColor(float Red, float Green, float Blue) 193 | { 194 | Rd=Red; 195 | Gr=Green; 196 | Bl=Blue; 197 | } 198 | 199 | // 200 | void CBitmapFont::ReverseYAxis(bool State) 201 | { 202 | if(State) 203 | YOffset=-CellY; 204 | else 205 | YOffset=CellY; 206 | 207 | InvertYAxis=State; 208 | } 209 | 210 | // Sets up an Ortho screen based on the supplied values 211 | void CBitmapFont::SetScreen(int x, int y) 212 | { 213 | glMatrixMode(GL_PROJECTION); 214 | glLoadIdentity(); 215 | if(InvertYAxis) 216 | glOrtho(0,x,y,0,-1,1); 217 | else 218 | glOrtho(0,x,0,y,-1,1); 219 | glMatrixMode(GL_MODELVIEW); 220 | glLoadIdentity(); 221 | } 222 | 223 | // Prints text at the cursor position, cursor is moved to end of text 224 | void CBitmapFont::Print(char* Text) 225 | { 226 | int sLen,Loop; 227 | int Row,Col; 228 | float U,V,U1,V1; 229 | 230 | sLen=(int)strnlen(Text,BFG_MAXSTRING); 231 | 232 | glBegin(GL_QUADS); 233 | 234 | for(Loop=0;Loop!=sLen;++Loop) 235 | { 236 | Row=(Text[Loop]-Base)/RowPitch; 237 | Col=(Text[Loop]-Base)-Row*RowPitch; 238 | 239 | U=Col*ColFactor; 240 | V=Row*RowFactor; 241 | U1=U+ColFactor; 242 | V1=V+RowFactor; 243 | 244 | glTexCoord2f(U, V1); glVertex2i(CurX, CurY); 245 | glTexCoord2f(U1,V1); glVertex2i(CurX+CellX,CurY); 246 | glTexCoord2f(U1,V ); glVertex2i(CurX+CellX,CurY+YOffset); 247 | glTexCoord2f(U, V ); glVertex2i(CurX, CurY+YOffset); 248 | 249 | CurX+=Width[Text[Loop]]; 250 | } 251 | glEnd(); 252 | 253 | } 254 | 255 | // Prints text at a specifed position, again cursor is updated 256 | void CBitmapFont::Print(char* Text, int x, int y) 257 | { 258 | int sLen,Loop; 259 | int Row,Col; 260 | float U,V,U1,V1; 261 | 262 | CurX=x; 263 | CurY=y; 264 | 265 | sLen=(int)strnlen(Text,BFG_MAXSTRING); 266 | 267 | glBegin(GL_QUADS); 268 | 269 | for(Loop=0;Loop!=sLen;++Loop) 270 | { 271 | Row=(Text[Loop]-Base)/RowPitch; 272 | Col=(Text[Loop]-Base)-Row*RowPitch; 273 | 274 | U=Col*ColFactor; 275 | V=Row*RowFactor; 276 | U1=U+ColFactor; 277 | V1=V+RowFactor; 278 | 279 | glTexCoord2f(U, V1); glVertex2i(CurX, CurY); 280 | glTexCoord2f(U1,V1); glVertex2i(CurX+CellX,CurY); 281 | glTexCoord2f(U1,V ); glVertex2i(CurX+CellX,CurY+CellY); 282 | glTexCoord2f(U, V ); glVertex2i(CurX, CurY+CellY); 283 | 284 | CurX+=Width[Text[Loop]]; 285 | } 286 | glEnd(); 287 | } 288 | 289 | // Lazy way to draw text. 290 | // Preserves all GL attributes and does everything for you. 291 | // Performance could be an issue. 292 | void CBitmapFont::ezPrint(char *Text, int x, int y) 293 | { 294 | GLint CurMatrixMode; 295 | GLint ViewPort[4]; 296 | 297 | // Save current setup 298 | glGetIntegerv(GL_MATRIX_MODE,&CurMatrixMode); 299 | glGetIntegerv(GL_VIEWPORT,ViewPort); 300 | glPushAttrib(GL_ALL_ATTRIB_BITS); 301 | 302 | // Setup projection 303 | glMatrixMode(GL_PROJECTION); 304 | glPushMatrix(); 305 | glLoadIdentity(); 306 | if(InvertYAxis) 307 | glOrtho(0,ViewPort[2],ViewPort[3],0,-1,1); 308 | else 309 | glOrtho(0,ViewPort[2],0,ViewPort[3],-1,1); 310 | glDisable(GL_DEPTH_TEST); 311 | glDepthMask(false); 312 | 313 | // Setup Modelview 314 | glMatrixMode(GL_MODELVIEW); 315 | glPushMatrix(); 316 | glLoadIdentity(); 317 | 318 | // Setup Texture, color and blend options 319 | glEnable(GL_TEXTURE_2D); 320 | glBindTexture(GL_TEXTURE_2D,TexID); 321 | SetBlend(); 322 | 323 | // Render text 324 | Print(Text,x,y); 325 | 326 | // Restore previous state 327 | glPopAttrib(); 328 | 329 | glMatrixMode(GL_PROJECTION); 330 | glPopMatrix(); 331 | glMatrixMode(GL_MODELVIEW); 332 | glPopMatrix(); 333 | 334 | glMatrixMode(CurMatrixMode); 335 | } 336 | 337 | // Returns the width in pixels of the specified text 338 | int CBitmapFont::GetWidth(char* Text) 339 | { 340 | int Loop,sLen,Size; 341 | 342 | // How many chars in string? 343 | sLen=(int)strnlen(Text,BFG_MAXSTRING); 344 | 345 | // Add up all width values 346 | for(Loop=0,Size=0;Loop!=sLen;++Loop) 347 | { 348 | Size+=Width[Text[Loop]]; 349 | } 350 | 351 | return Size; 352 | } -------------------------------------------------------------------------------- /examples/BFF Example/BitmapFontClass.h: -------------------------------------------------------------------------------- 1 | #ifndef _BITMAPFONTCLASS_H 2 | #define _BITMAPFONTCLASS_H 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | #define BFG_RS_NONE 0x0 // Blend flags 10 | #define BFG_RS_ALPHA 0x1 11 | #define BFG_RS_RGB 0x2 12 | #define BFG_RS_RGBA 0x4 13 | 14 | #define BFG_MAXSTRING 255 // Maximum string length 15 | 16 | #define WIDTH_DATA_OFFSET 20 // Offset to width data with BFF file 17 | #define MAP_DATA_OFFSET 276 // Offset to texture image data with BFF file 18 | 19 | // This definition is missing from some GL libs 20 | #ifndef GL_CLAMP_TO_EDGE 21 | #define GL_CLAMP_TO_EDGE 0x812F 22 | #endif 23 | 24 | typedef struct 25 | { 26 | unsigned char ID1,ID2; 27 | unsigned char BPP; 28 | int ImageWidth,ImageHeight,CellWidth,CellHeight; 29 | unsigned char StartPoint; 30 | }FontFileHeader; 31 | 32 | class CBitmapFont 33 | { 34 | public: 35 | CBitmapFont(); 36 | ~CBitmapFont(); 37 | bool Load(char *fname); 38 | void SetScreen(int x, int y); 39 | void SetCursor(int x, int y); 40 | void SetColor(float Red, float Green, float Blue); 41 | void ReverseYAxis(bool State); 42 | void Select(); 43 | void Bind(); 44 | void SetBlend(); 45 | void Print(char *Text); 46 | void Print(char *Text, int x, int y); 47 | void ezPrint(char *Text, int x, int y); 48 | int GetWidth(char *Text); 49 | 50 | 51 | private: 52 | int CellX,CellY,YOffset,RowPitch; 53 | char Base; 54 | char Width[256]; 55 | GLuint TexID; 56 | int CurX,CurY; 57 | float RowFactor,ColFactor; 58 | int RenderStyle; 59 | float Rd,Gr,Bl; 60 | bool InvertYAxis; 61 | }; 62 | 63 | #endif -------------------------------------------------------------------------------- /examples/BFF Example/Framework.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // Functions 6 | void FlipBuffers(); 7 | void Render(); 8 | 9 | // A struct to hold mouse data 10 | struct MouseInfo 11 | { 12 | int Mx,My; 13 | bool Mleft, Mright; 14 | }; 15 | 16 | // Globals 17 | extern int volatile RunLevel; 18 | extern bool Keys[256]; // Key monitor 19 | extern MouseInfo Mouse; // Mouse monitor -------------------------------------------------------------------------------- /examples/BFF Example/OpenGLBase.cpp: -------------------------------------------------------------------------------- 1 | // OpenGLBase.cpp - A multi-threaded OpenGL base application for GPWiki tutorials. 2 | // Windows version. 3 | 4 | #include "Framework.h" 5 | 6 | #pragma comment (lib , "opengl32.lib") // Makes VC link the GL libs, 7 | #pragma comment (lib , "glu32.lib") // other compliers will have to do it manually 8 | 9 | // Globals 10 | HINSTANCE gInst; 11 | HWND hGLWin; 12 | HDC GLDC; 13 | int volatile RunLevel = 1; 14 | bool Keys[256]; // Key monitor 15 | MouseInfo Mouse; // Mouse monitor 16 | 17 | bool RegisterWin(); 18 | bool StartGL(int ScrX, int ScrY, int BPP); 19 | bool RenderProc(LPVOID lpParam); 20 | 21 | int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) 22 | { 23 | MSG msg; 24 | DEVMODE ScrRes; 25 | HANDLE hThr; 26 | DWORD Res; 27 | 28 | // Set the global instance 29 | gInst=hInstance; 30 | 31 | // Store the current screen resolution 32 | EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,&ScrRes); 33 | 34 | // Register our Window Class 35 | if(!RegisterWin()) 36 | { 37 | MessageBox(NULL,"Register Window Class Failed!","Error",MB_OK | MB_ICONERROR); 38 | return 0; 39 | } 40 | 41 | // Start GL Window 42 | if(!StartGL(800,600,32)) 43 | { 44 | MessageBox(NULL,"GL Startup Failed!","Error",MB_OK | MB_ICONERROR); 45 | return 0; 46 | } 47 | 48 | // Launch rendering thread 49 | hThr=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)RenderProc,0,0,NULL); 50 | 51 | if(hThr) 52 | { 53 | RunLevel=1; 54 | // Main message loop: 55 | while(RunLevel) 56 | { 57 | GetMessage(&msg, NULL, 0, 0); 58 | TranslateMessage(&msg); 59 | DispatchMessage(&msg); 60 | } 61 | } 62 | 63 | 64 | // Shutdown and cleanup 65 | 66 | // Wait for thread to stop 67 | Res=STILL_ACTIVE; 68 | 69 | while(Res==STILL_ACTIVE) 70 | GetExitCodeThread(hThr,&Res); 71 | 72 | // Close window 73 | if(hGLWin) 74 | DestroyWindow(hGLWin); 75 | 76 | UnregisterClass("OpenGLBaseWin",gInst); 77 | 78 | // Restore Original Screen Mode 79 | //ChangeDisplaySettings(&ScrRes,CDS_RESET); 80 | 81 | return (int) msg.wParam; 82 | } 83 | 84 | 85 | // Message Handler for our Window 86 | LRESULT CALLBACK GLWinProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) 87 | { 88 | switch(Msg) 89 | { 90 | case WM_DESTROY: 91 | PostQuitMessage(0); 92 | break; 93 | 94 | // Grab inputs 95 | case WM_KEYDOWN: 96 | Keys[wParam] = TRUE; 97 | return 0; 98 | 99 | case WM_KEYUP: 100 | Keys[wParam] = FALSE; 101 | return 0; 102 | 103 | case WM_MOUSEMOVE: 104 | Mouse.Mx=LOWORD(lParam); 105 | Mouse.My=HIWORD(lParam); 106 | return 0; 107 | 108 | case WM_LBUTTONDOWN: 109 | Mouse.Mleft=TRUE; 110 | return 0; 111 | 112 | case WM_LBUTTONUP: 113 | Mouse.Mleft=FALSE; 114 | return 0; 115 | 116 | case WM_RBUTTONDOWN: 117 | Mouse.Mright=TRUE; 118 | return 0; 119 | 120 | case WM_RBUTTONUP: 121 | Mouse.Mright=FALSE; 122 | return 0; 123 | 124 | default: 125 | return DefWindowProc(hWnd, Msg, wParam, lParam); 126 | } 127 | 128 | return 0; 129 | } 130 | 131 | // Register a Window Class 132 | bool RegisterWin() 133 | { 134 | WNDCLASSEX glWin; 135 | 136 | glWin.cbSize=sizeof(WNDCLASSEX); 137 | glWin.style = CS_VREDRAW | CS_HREDRAW | CS_OWNDC; // Window has it's own context 138 | glWin.lpfnWndProc = GLWinProc; 139 | glWin.cbClsExtra = 0; 140 | glWin.cbWndExtra = 0; 141 | glWin.hInstance = gInst; 142 | glWin.hIcon = LoadIcon(NULL, IDI_WINLOGO); // Default icon 143 | glWin.hCursor = LoadCursor(NULL, IDC_ARROW); // Default pointer 144 | glWin.hbrBackground = NULL; 145 | glWin.lpszMenuName = NULL; 146 | glWin.lpszClassName = "OpenGLBaseWin"; 147 | glWin.hIconSm=NULL; 148 | 149 | if(RegisterClassEx(&glWin)) 150 | return TRUE; 151 | else 152 | return FALSE; 153 | } 154 | 155 | bool StartGL(int ScrX, int ScrY, int BPP) 156 | { 157 | DEVMODE ScrMode; 158 | PIXELFORMATDESCRIPTOR PixFmtReq; 159 | int PixFmt; 160 | HGLRC GLRC; 161 | 162 | 163 | // Set the screen mode 164 | ZeroMemory(&ScrMode,sizeof(DEVMODE)); 165 | ScrMode.dmSize=sizeof(DEVMODE); 166 | ScrMode.dmPelsWidth=ScrX; 167 | ScrMode.dmPelsHeight=ScrY; 168 | ScrMode.dmBitsPerPel=BPP; 169 | ScrMode.dmFields=DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; 170 | 171 | // if(ChangeDisplaySettings(&ScrMode,CDS_FULLSCREEN)!=DISP_CHANGE_SUCCESSFUL) 172 | //return FALSE; 173 | 174 | // Create our window 175 | hGLWin=CreateWindowEx(WS_EX_LEFT, 176 | "OpenGLBaseWin", 177 | "OpenGL Test", 178 | WS_POPUP | WS_VISIBLE, 179 | 0,0,ScrX,ScrY, 180 | NULL,NULL,gInst,NULL); 181 | if(hGLWin==NULL) 182 | return FALSE; 183 | 184 | 185 | // Define pixel format for our window 186 | ZeroMemory(&PixFmtReq,sizeof(PIXELFORMATDESCRIPTOR)); 187 | PixFmtReq.nSize=sizeof (PIXELFORMATDESCRIPTOR); 188 | PixFmtReq.nVersion=1; 189 | PixFmtReq.dwFlags= PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; 190 | PixFmtReq.iPixelType=PFD_TYPE_RGBA; 191 | PixFmtReq.cColorBits=BPP; // Color depth as specified in arguments 192 | PixFmtReq.cDepthBits=16; 193 | PixFmtReq.iLayerType=PFD_MAIN_PLANE; 194 | 195 | // Get the device context 196 | GLDC=GetDC(hGLWin); 197 | 198 | if(!GLDC) 199 | return FALSE; 200 | 201 | // Match our specified pixel format to device 202 | PixFmt=ChoosePixelFormat(GLDC,&PixFmtReq); 203 | 204 | if(PixFmt==0) 205 | return FALSE; 206 | 207 | // Set pixel format 208 | if(!SetPixelFormat(GLDC,PixFmt,&PixFmtReq)) 209 | return FALSE; 210 | 211 | // Create the OpenGL render context and bind to this thread current 212 | GLRC=wglCreateContext(GLDC); 213 | 214 | if(!GLRC) 215 | return FALSE; 216 | 217 | if(!wglMakeCurrent(GLDC,GLRC)) 218 | return FALSE; 219 | 220 | // Clear to black 221 | glClearColor(0,0,0,0); 222 | glClear(GL_COLOR_BUFFER_BIT); 223 | SwapBuffers(GLDC); 224 | 225 | return TRUE; 226 | } 227 | 228 | // The render thread start point 229 | bool RenderProc(LPVOID lpParam) 230 | { 231 | HGLRC glRC; 232 | 233 | // Re-aquire the context as we are in a different thread 234 | glRC=wglCreateContext(GLDC); 235 | wglMakeCurrent(GLDC,glRC); 236 | 237 | // Here's were we bring in the Render funtion 238 | Render(); 239 | 240 | RunLevel=0; // Make sure the app stops 241 | return 0; 242 | } 243 | 244 | void FlipBuffers() 245 | { 246 | SwapBuffers(GLDC); 247 | } -------------------------------------------------------------------------------- /examples/BFF Example/Render.cpp: -------------------------------------------------------------------------------- 1 | // This code will be executed by the OpenGL base app's render thread 2 | #include "Framework.h" 3 | #include "BitmapFontClass.h" 4 | 5 | void Render(void) 6 | { 7 | RunLevel=1; 8 | CBitmapFont Font; 9 | float Rot=0.0f,ScreenRatio; 10 | 11 | // Set the background to black 12 | glClearColor(0,0,0,0); 13 | glClear(GL_COLOR_BUFFER_BIT); 14 | 15 | if(!Font.Load("TestFont.bff")) 16 | RunLevel=0; 17 | 18 | // Set the font color (defaults to white if not set) 19 | Font.SetColor(0.6f,1.0f,0.4f); 20 | 21 | // Set the initial display size 22 | glViewport(0,0,800,600); 23 | ScreenRatio=600.0f/800.0f; 24 | 25 | // This loop will run until Esc is pressed 26 | while(RunLevel) 27 | { 28 | if(Keys[VK_ESCAPE]) // Esc Key 29 | RunLevel=0; 30 | 31 | // Set up a perspective display and draw something 32 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 33 | 34 | glMatrixMode(GL_PROJECTION); 35 | glLoadIdentity(); 36 | glFrustum(1.0f, -1.0f, -1.0f * ScreenRatio, 1.0f * ScreenRatio, 1.0f, 500.0f); 37 | 38 | glMatrixMode(GL_MODELVIEW); 39 | glLoadIdentity(); 40 | 41 | // Add some rotation 42 | glTranslatef(0.0f,0.0f,-2.0f); 43 | glRotatef(Rot,0,0,1); 44 | Rot-=0.5f; 45 | 46 | // Simple coloured triangle 47 | glDisable(GL_TEXTURE_2D); 48 | glBegin(GL_TRIANGLES); 49 | glColor3f(1,0,0); glVertex3f(-1.6f,-0.80f,0.0f); 50 | glColor3f(0,1,0); glVertex3f( 0.0f, 1.5f ,0.0f); 51 | glColor3f(0,0,1); glVertex3f( 1.6f,-0.80f,0.0f); 52 | glEnd(); 53 | 54 | 55 | // Draw text the easy (but inefficient) way 56 | Font.ezPrint("I'm an ezPrint text string",250,400); 57 | 58 | 59 | // Draw text using FontClass functions 60 | Font.SetScreen(800,600); 61 | Font.Select(); 62 | Font.Print("I'm a FontClass rendered string",100,100); 63 | 64 | 65 | // Draw text with manual setup 66 | glMatrixMode(GL_PROJECTION); 67 | glLoadIdentity(); 68 | glOrtho(0,800,0,600,-1,1); // Ortho screen with the origin at bottom left 69 | glMatrixMode(GL_MODELVIEW); 70 | glLoadIdentity(); 71 | 72 | glEnable(GL_TEXTURE_2D); 73 | Font.Bind(); 74 | 75 | glEnable(GL_BLEND); // We know this is a 32bit font so set blending to suit 76 | glBlendFunc(GL_SRC_ALPHA,GL_ONE_MINUS_SRC_ALPHA); 77 | 78 | glColor3f(1.0f,1.0f,1.0f); 79 | 80 | Font.SetCursor(400,250); 81 | Font.Print("I'm a manually set up string"); 82 | 83 | // Demo of results of incorrect Ortho handling 84 | glMatrixMode(GL_PROJECTION); 85 | glLoadIdentity(); 86 | glOrtho(0,800,600,0,-1,1); // Ortho screen with the origin at top left 87 | glMatrixMode(GL_MODELVIEW); 88 | glLoadIdentity(); 89 | 90 | Font.SetCursor(450,400); 91 | Font.Print("I have the wrong YAxis setting !"); 92 | 93 | 94 | 95 | 96 | // We're using double buffers, so we need to swap to see our results 97 | FlipBuffers(); 98 | } 99 | } -------------------------------------------------------------------------------- /examples/BFF Example/TestFont.bff: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeheadUK/CBFG/06084ec6f37c2525546b7d5b9f54c15896c2e5b9/examples/BFF Example/TestFont.bff -------------------------------------------------------------------------------- /source/AppIcon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeheadUK/CBFG/06084ec6f37c2525546b7d5b9f54c15896c2e5b9/source/AppIcon.ico -------------------------------------------------------------------------------- /source/BFG2.bmp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeheadUK/CBFG/06084ec6f37c2525546b7d5b9f54c15896c2e5b9/source/BFG2.bmp -------------------------------------------------------------------------------- /source/CBFG.cpp: -------------------------------------------------------------------------------- 1 | // CBFG.cpp 2 | 3 | #include "stdafx.h" 4 | #include "FontMapClass.h" 5 | #include "SBM-Util.h" 6 | #include "UtilFunctions.h" 7 | #include "CBFGDefs.h" 8 | #include "Procs.h" 9 | #include "file-request.h" 10 | 11 | #define SPLASH_DELAY 1000 12 | 13 | // Globals 14 | HWND hMain; 15 | HWND hText; 16 | HINSTANCE G_Inst; 17 | BFontMap *Fnt; 18 | AppInfo *info; 19 | LONG OldProc; 20 | void Msg(char *text); 21 | 22 | int APIENTRY WinMain(HINSTANCE hInstance, 23 | HINSTANCE hPrevInstance, 24 | LPSTR lpCmdLine, 25 | int nCmdShow) 26 | { 27 | MSG msg; 28 | int Ret; 29 | G_Inst=hInstance; 30 | AppInfo AppInf; 31 | BFontMap Bf; 32 | 33 | _CrtSetDbgFlag ( _CRTDBG_LEAK_CHECK_DF | _CRTDBG_ALLOC_MEM_DF | _CRTDBG_CHECK_ALWAYS_DF ); 34 | 35 | AppInf.hScr=0; 36 | AppInf.vScr=0; 37 | AppInf.Zoom=1.0f; 38 | AppInf.hScroll=FALSE; 39 | AppInf.vScroll=FALSE; 40 | AppInf.ModAll=TRUE; 41 | AppInf.Select=0; 42 | 43 | Fnt=&Bf; 44 | info=&AppInf; 45 | 46 | hText=CreateDialog(G_Inst,MAKEINTRESOURCE(DLG_SPLASH),NULL,(DLGPROC)SplashWinProc); 47 | SetWindowText(hText,"Codehead's Bitmap Font Generator"); 48 | SetWindowPos(hText,HWND_TOPMOST,0,0,0,0,SWP_NOMOVE | SWP_NOSIZE); 49 | 50 | // Load config or set defaults 51 | Ret=Fnt->LoadConfig("bfg.cfg"); 52 | if(Ret==-1) 53 | { 54 | AppInf.Grid=true; 55 | AppInf.wMarker=true; 56 | Fnt->SaveConfig("bfg.cfg",true,true); 57 | } 58 | else 59 | { 60 | info->Grid=Ret & SHOW_GRID; 61 | info->wMarker=Ret & SHOW_WIDTH; 62 | } 63 | 64 | Sleep(SPLASH_DELAY); 65 | 66 | hMain=CreateDialog(G_Inst,MAKEINTRESOURCE(DLG_MAIN),NULL,(DLGPROC)MainProc); 67 | Sleep(SPLASH_DELAY); 68 | 69 | hText=CreateWindow("STATIC","TextWin",WS_POPUP,0,0,100,100,hMain,NULL,hInstance,NULL); 70 | Sleep(SPLASH_DELAY/2); 71 | 72 | OldProc=GetWindowLong(GetDlgItem(hMain,IMG_TEXT),GWL_WNDPROC); 73 | SetWindowLong(GetDlgItem(hMain,IMG_TEXT),GWL_WNDPROC,(LPARAM)TextWinProc); 74 | 75 | SetClassLong(GetDlgItem(hMain,IMG_TEXT),GCL_HBRBACKGROUND,NULL); 76 | 77 | // Main Message Loop 78 | while(GetMessage(&msg,NULL,0,0)) 79 | { 80 | if(!IsDialogMessage(hMain,&msg)) 81 | { 82 | TranslateMessage(&msg); 83 | DispatchMessage(&msg); 84 | } 85 | } 86 | _CrtCheckMemory(); 87 | return 0; 88 | } 89 | -------------------------------------------------------------------------------- /source/CBFG.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2012 4 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CBFG", "CBFG.vcxproj", "{E3E4878D-7837-45A3-AF37-7ABF4182C55A}" 5 | EndProject 6 | Global 7 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 8 | Debug|Win32 = Debug|Win32 9 | Release|Win32 = Release|Win32 10 | EndGlobalSection 11 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 12 | {E3E4878D-7837-45A3-AF37-7ABF4182C55A}.Debug|Win32.ActiveCfg = Debug|Win32 13 | {E3E4878D-7837-45A3-AF37-7ABF4182C55A}.Debug|Win32.Build.0 = Debug|Win32 14 | {E3E4878D-7837-45A3-AF37-7ABF4182C55A}.Release|Win32.ActiveCfg = Release|Win32 15 | {E3E4878D-7837-45A3-AF37-7ABF4182C55A}.Release|Win32.Build.0 = Release|Win32 16 | EndGlobalSection 17 | GlobalSection(SolutionProperties) = preSolution 18 | HideSolutionNode = FALSE 19 | EndGlobalSection 20 | EndGlobal 21 | -------------------------------------------------------------------------------- /source/CBFG.vcxproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | 14 | {E3E4878D-7837-45A3-AF37-7ABF4182C55A} 15 | CBFG 16 | 17 | 18 | 19 | Application 20 | false 21 | MultiByte 22 | v110 23 | 24 | 25 | Application 26 | false 27 | NotSet 28 | v110 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | <_ProjectFileVersion>10.0.30319.1 44 | .\Debug\ 45 | .\Debug\ 46 | false 47 | .\Release\ 48 | .\Release\ 49 | false 50 | 51 | 52 | 53 | _DEBUG;%(PreprocessorDefinitions) 54 | true 55 | true 56 | Win32 57 | .\Debug/Testbed.tlb 58 | 59 | 60 | 61 | 62 | Disabled 63 | WIN32;_DEBUG;_WINDOWS;%(PreprocessorDefinitions) 64 | EnableFastChecks 65 | MultiThreadedDebug 66 | 1Byte 67 | Use 68 | stdafx.h 69 | .\Debug/CBFG.pch 70 | .\Debug/ 71 | .\Debug/ 72 | .\Debug/ 73 | Level3 74 | true 75 | EditAndContinue 76 | 77 | 78 | _DEBUG;%(PreprocessorDefinitions) 79 | 0x0809 80 | 81 | 82 | opengl32.lib;%(AdditionalDependencies) 83 | .\Debug/CBFG.exe 84 | 1.0 85 | true 86 | true 87 | .\Debug/CBFG.pdb 88 | Windows 89 | false 90 | 91 | 92 | MachineX86 93 | 94 | 95 | 96 | 97 | NDEBUG;%(PreprocessorDefinitions) 98 | true 99 | true 100 | Win32 101 | .\Release/Testbed.tlb 102 | 103 | 104 | 105 | 106 | MaxSpeed 107 | OnlyExplicitInline 108 | WIN32;NDEBUG;_WINDOWS;%(PreprocessorDefinitions) 109 | true 110 | MultiThreaded 111 | 1Byte 112 | true 113 | Use 114 | stdafx.h 115 | .\Release/CBFG.pch 116 | .\Release/ 117 | .\Release/ 118 | .\Release/ 119 | Level3 120 | true 121 | 122 | 123 | NDEBUG;%(PreprocessorDefinitions) 124 | 0x0809 125 | 126 | 127 | opengl32.lib;%(AdditionalDependencies) 128 | .\Release/CBFG.exe 129 | 1.0 130 | true 131 | .\Release/CBFG.pdb 132 | Windows 133 | false 134 | 135 | 136 | MachineX86 137 | 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | Disabled 151 | %(PreprocessorDefinitions) 152 | EnableFastChecks 153 | Create 154 | MaxSpeed 155 | %(PreprocessorDefinitions) 156 | Create 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | -------------------------------------------------------------------------------- /source/CBFG.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {3620daea-ddef-4fcd-8f78-a8cd8cdb2928} 6 | cpp;c;cxx;rc;def;r;odl;idl;hpj;bat 7 | 8 | 9 | {9e655e5c-30e4-44a4-a237-f39cd6ab2add} 10 | h;hpp;hxx;hm;inl 11 | 12 | 13 | {357a7a49-94e3-4fc8-98ff-c7dbde8e0006} 14 | ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe 15 | 16 | 17 | 18 | 19 | Source Files 20 | 21 | 22 | Source Files 23 | 24 | 25 | Source Files 26 | 27 | 28 | Source Files 29 | 30 | 31 | Source Files 32 | 33 | 34 | Source Files 35 | 36 | 37 | Source Files 38 | 39 | 40 | Source Files 41 | 42 | 43 | Source Files 44 | 45 | 46 | Source Files 47 | 48 | 49 | Source Files 50 | 51 | 52 | Source Files 53 | 54 | 55 | 56 | 57 | Header Files 58 | 59 | 60 | Header Files 61 | 62 | 63 | Header Files 64 | 65 | 66 | Header Files 67 | 68 | 69 | Header Files 70 | 71 | 72 | Header Files 73 | 74 | 75 | Header Files 76 | 77 | 78 | Resource Files 79 | 80 | 81 | 82 | 83 | Resource Files 84 | 85 | 86 | Resource Files 87 | 88 | 89 | Resource Files 90 | 91 | 92 | Resource Files 93 | 94 | 95 | Resource Files 96 | 97 | 98 | Resource Files 99 | 100 | 101 | 102 | 103 | 104 | 105 | Resource Files 106 | 107 | 108 | -------------------------------------------------------------------------------- /source/CBFGDefs.h: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | #ifndef _CBFGDEFS_H 4 | #define _CBFGDEFS_H 5 | 6 | #define APP_VERSION 1.41 7 | 8 | #define SHOW_GRID 0x1 9 | #define SHOW_WIDTH 0x2 10 | #define FONT_BOLD 0x4 11 | #define FONT_ITALIC 0x8 12 | 13 | #define WIDTH 1 14 | #define HEIGHT 2 15 | #define HOFFSET 3 16 | #define VOFFSET 4 17 | #define WOFFSET 5 18 | #define EWIDTH 6 19 | 20 | // SetSize Constants 21 | #define MAPWIDTH 1 22 | #define MAPHEIGHT 2 23 | #define CELLWIDTH 3 24 | #define CELLHEIGHT 4 25 | #define MAXCHARS 10 26 | 27 | // DrawFontMap Constants 28 | #define DFM_WIDTHLINE 2 29 | #define DFM_GRIDLINES 4 30 | #define DFM_ALPHA 8 31 | 32 | // Config Window Constants 33 | #define GRIDCOL 0 34 | #define WIDTHCOL 1 35 | #define SELCOL 2 36 | #define TEXTCOL 3 37 | #define BACKCOL 4 38 | 39 | // FontSave Constants 40 | #define SAVE_BFF8 101 41 | #define SAVE_BFF24 102 42 | #define SAVE_BFF32 103 43 | #define SAVE_CSV 110 44 | #define SAVE_BIN 120 45 | #define SAVE_BMP 130 46 | #define SAVE_TGA 140 47 | #define SAVE_TGA32 141 48 | 49 | #define SAVE_RGB_SAT 0x100 50 | #define SAVE_INV_ALPHA 0x200 51 | 52 | typedef struct 53 | { 54 | unsigned char Red,Green,Blue; 55 | }BFG_RGB; 56 | 57 | typedef struct 58 | { 59 | int hScr,vScr; 60 | bool Grid,wMarker,ModAll,vScroll,hScroll; 61 | float Zoom; 62 | int Select,MaxChars; 63 | }AppInfo; 64 | 65 | typedef struct 66 | { 67 | unsigned char ID1,ID2; 68 | int ImageWidth,ImageHeight,CellWidth,CellHeight; 69 | unsigned char BPP,StartPoint; 70 | }FontFileHeader; 71 | 72 | typedef struct 73 | { 74 | char ID[7]; 75 | int ImgWidth,ImgHeight,CellWidth,CellHeight,FontHeight,FontWidth; 76 | BFG_RGB BackCol,ForeCol,GridCol,WidthCol,SelCol; 77 | int Flags; 78 | }AppConfig; 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /source/ConfigProc.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Procs.h" 3 | #include "CBFGDefs.h" 4 | #include "FontMapClass.h" 5 | 6 | extern HINSTANCE G_Inst; 7 | extern HWND hMain; 8 | extern BFontMap *Fnt; 9 | extern AppInfo *info; 10 | 11 | 12 | void SetConfigRGB(HWND Win, BFG_RGB Cols) 13 | { 14 | char Text[256]; 15 | wsprintf(Text,"%d",Cols.Red); 16 | SendDlgItemMessage(Win,TXT_RED,WM_SETTEXT,0,(LPARAM)Text); 17 | SendDlgItemMessage(Win,SLD_RED,TBM_SETPOS,TRUE,(LPARAM)Cols.Red); 18 | wsprintf(Text,"%d",Cols.Green); 19 | SendDlgItemMessage(Win,TXT_GREEN,WM_SETTEXT,0,(LPARAM)Text); 20 | SendDlgItemMessage(Win,SLD_GREEN,TBM_SETPOS,TRUE,(LPARAM)Cols.Green); 21 | wsprintf(Text,"%d",Cols.Blue); 22 | SendDlgItemMessage(Win,TXT_BLUE,WM_SETTEXT,0,(LPARAM)Text); 23 | SendDlgItemMessage(Win,SLD_BLUE,TBM_SETPOS,TRUE,(LPARAM)Cols.Blue); 24 | InvalidateRect(GetDlgItem(Win,ODR_COLOR),NULL,FALSE); 25 | } 26 | 27 | 28 | BOOL CALLBACK ConfigWinProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) 29 | { 30 | HDC dc; 31 | RECT rcArea; 32 | HBRUSH hBr; 33 | int Sel,Val,Red,Green,Blue; 34 | char Text[256]; 35 | static AppConfig lCfg; 36 | 37 | switch(msg) 38 | { 39 | case WM_INITDIALOG: 40 | // Preserve Current Config 41 | lCfg.CellHeight=Fnt->GetSize(CELLHEIGHT); 42 | lCfg.CellWidth=Fnt->GetSize(CELLWIDTH); 43 | lCfg.FontHeight=Fnt->GetFontHeight(); 44 | lCfg.FontWidth=Fnt->GetFontWidth(); 45 | lCfg.ImgWidth=Fnt->GetSize(MAPWIDTH); 46 | lCfg.ImgHeight=Fnt->GetSize(MAPHEIGHT); 47 | lCfg.Flags=0; 48 | if(info->Grid) 49 | lCfg.Flags |= SHOW_GRID; 50 | if(info->wMarker) 51 | lCfg.Flags |= SHOW_WIDTH; 52 | lCfg.BackCol=Fnt->GetCol(BACKCOL); 53 | lCfg.ForeCol=Fnt->GetCol(TEXTCOL); 54 | lCfg.GridCol=Fnt->GetCol(GRIDCOL); 55 | lCfg.WidthCol=Fnt->GetCol(WIDTHCOL); 56 | lCfg.SelCol=Fnt->GetCol(SELCOL); 57 | 58 | // Populate item combo 59 | SendDlgItemMessage(hDlg,CBO_CFG_ITEM,CB_ADDSTRING,0,(LPARAM)"Grid Lines"); 60 | SendDlgItemMessage(hDlg,CBO_CFG_ITEM,CB_ADDSTRING,0,(LPARAM)"Width Marker"); 61 | SendDlgItemMessage(hDlg,CBO_CFG_ITEM,CB_ADDSTRING,0,(LPARAM)"Selection Marker"); 62 | SendDlgItemMessage(hDlg,CBO_CFG_ITEM,CB_ADDSTRING,0,(LPARAM)"Font Colour"); 63 | SendDlgItemMessage(hDlg,CBO_CFG_ITEM,CB_ADDSTRING,0,(LPARAM)"Background Colour"); 64 | SendDlgItemMessage(hDlg,CBO_CFG_ITEM,CB_SETCURSEL,0,0); 65 | 66 | // Set range of sliders 67 | SendDlgItemMessage(hDlg,SLD_RED,TBM_SETRANGE,TRUE,MAKELONG(0,255)); 68 | SendDlgItemMessage(hDlg,SLD_GREEN,TBM_SETRANGE,TRUE,MAKELONG(0,255)); 69 | SendDlgItemMessage(hDlg,SLD_BLUE,TBM_SETRANGE,TRUE,MAKELONG(0,255)); 70 | 71 | // Set initial slider pos 72 | SetConfigRGB(hDlg,lCfg.GridCol); 73 | 74 | // Populate image size combos 75 | SendDlgItemMessage(hDlg,CBO_CFG_IMGXSIZE,CB_ADDSTRING,0,(LPARAM)"16"); 76 | SendDlgItemMessage(hDlg,CBO_CFG_IMGXSIZE,CB_ADDSTRING,0,(LPARAM)"32"); 77 | SendDlgItemMessage(hDlg,CBO_CFG_IMGXSIZE,CB_ADDSTRING,0,(LPARAM)"64"); 78 | SendDlgItemMessage(hDlg,CBO_CFG_IMGXSIZE,CB_ADDSTRING,0,(LPARAM)"128"); 79 | SendDlgItemMessage(hDlg,CBO_CFG_IMGXSIZE,CB_ADDSTRING,0,(LPARAM)"256"); 80 | SendDlgItemMessage(hDlg,CBO_CFG_IMGXSIZE,CB_ADDSTRING,0,(LPARAM)"512"); 81 | SendDlgItemMessage(hDlg,CBO_CFG_IMGXSIZE,CB_ADDSTRING,0,(LPARAM)"1024"); 82 | SendDlgItemMessage(hDlg,CBO_CFG_IMGXSIZE,CB_ADDSTRING,0,(LPARAM)"2048"); 83 | SendDlgItemMessage(hDlg,CBO_CFG_IMGXSIZE,CB_ADDSTRING,0,(LPARAM)"4096"); 84 | 85 | SendDlgItemMessage(hDlg,CBO_CFG_IMGYSIZE,CB_ADDSTRING,0,(LPARAM)"16"); 86 | SendDlgItemMessage(hDlg,CBO_CFG_IMGYSIZE,CB_ADDSTRING,0,(LPARAM)"32"); 87 | SendDlgItemMessage(hDlg,CBO_CFG_IMGYSIZE,CB_ADDSTRING,0,(LPARAM)"64"); 88 | SendDlgItemMessage(hDlg,CBO_CFG_IMGYSIZE,CB_ADDSTRING,0,(LPARAM)"128"); 89 | SendDlgItemMessage(hDlg,CBO_CFG_IMGYSIZE,CB_ADDSTRING,0,(LPARAM)"256"); 90 | SendDlgItemMessage(hDlg,CBO_CFG_IMGYSIZE,CB_ADDSTRING,0,(LPARAM)"512"); 91 | SendDlgItemMessage(hDlg,CBO_CFG_IMGYSIZE,CB_ADDSTRING,0,(LPARAM)"1024"); 92 | SendDlgItemMessage(hDlg,CBO_CFG_IMGYSIZE,CB_ADDSTRING,0,(LPARAM)"2048"); 93 | SendDlgItemMessage(hDlg,CBO_CFG_IMGYSIZE,CB_ADDSTRING,0,(LPARAM)"4096"); 94 | 95 | if(lCfg.ImgWidth==32) 96 | SendDlgItemMessage(hDlg,CBO_CFG_IMGXSIZE,CB_SETCURSEL,1,0); 97 | else if(lCfg.ImgWidth==64) 98 | SendDlgItemMessage(hDlg,CBO_CFG_IMGXSIZE,CB_SETCURSEL,2,0); 99 | else if(lCfg.ImgWidth==128) 100 | SendDlgItemMessage(hDlg,CBO_CFG_IMGXSIZE,CB_SETCURSEL,3,0); 101 | else if(lCfg.ImgWidth==256) 102 | SendDlgItemMessage(hDlg,CBO_CFG_IMGXSIZE,CB_SETCURSEL,4,0); 103 | else if(lCfg.ImgWidth==512) 104 | SendDlgItemMessage(hDlg,CBO_CFG_IMGXSIZE,CB_SETCURSEL,5,0); 105 | else if(lCfg.ImgWidth==1024) 106 | SendDlgItemMessage(hDlg,CBO_CFG_IMGXSIZE,CB_SETCURSEL,6,0); 107 | else if(lCfg.ImgWidth==2048) 108 | SendDlgItemMessage(hDlg,CBO_CFG_IMGXSIZE,CB_SETCURSEL,7,0); 109 | else if(lCfg.ImgWidth==4096) 110 | SendDlgItemMessage(hDlg,CBO_CFG_IMGXSIZE,CB_SETCURSEL,8,0); 111 | else 112 | SendDlgItemMessage(hDlg,CBO_CFG_IMGXSIZE,CB_SETCURSEL,0,0); 113 | 114 | if(lCfg.ImgHeight==32) 115 | SendDlgItemMessage(hDlg,CBO_CFG_IMGYSIZE,CB_SETCURSEL,1,0); 116 | else if(lCfg.ImgHeight==64) 117 | SendDlgItemMessage(hDlg,CBO_CFG_IMGYSIZE,CB_SETCURSEL,2,0); 118 | else if(lCfg.ImgHeight==128) 119 | SendDlgItemMessage(hDlg,CBO_CFG_IMGYSIZE,CB_SETCURSEL,3,0); 120 | else if(lCfg.ImgHeight==256) 121 | SendDlgItemMessage(hDlg,CBO_CFG_IMGYSIZE,CB_SETCURSEL,4,0); 122 | else if(lCfg.ImgHeight==512) 123 | SendDlgItemMessage(hDlg,CBO_CFG_IMGYSIZE,CB_SETCURSEL,5,0); 124 | else if(lCfg.ImgHeight==1024) 125 | SendDlgItemMessage(hDlg,CBO_CFG_IMGYSIZE,CB_SETCURSEL,6,0); 126 | else if(lCfg.ImgHeight==2048) 127 | SendDlgItemMessage(hDlg,CBO_CFG_IMGYSIZE,CB_SETCURSEL,7,0); 128 | else if(lCfg.ImgHeight==4096) 129 | SendDlgItemMessage(hDlg,CBO_CFG_IMGYSIZE,CB_SETCURSEL,8,0); 130 | else 131 | SendDlgItemMessage(hDlg,CBO_CFG_IMGYSIZE,CB_SETCURSEL,0,0); 132 | 133 | // Set grid and width checks 134 | SendDlgItemMessage(hDlg,CHK_CFG_GRID,BM_SETCHECK,lCfg.Flags & SHOW_GRID,0); 135 | SendDlgItemMessage(hDlg,CHK_CFG_WIDTH,BM_SETCHECK,lCfg.Flags & SHOW_WIDTH,0); 136 | 137 | // Populate textboxes 138 | wsprintf(Text,"%d",lCfg.CellWidth); 139 | SendDlgItemMessage(hDlg,TXT_CFG_CELLWIDTH,WM_SETTEXT,0,(LPARAM)Text); 140 | wsprintf(Text,"%d",lCfg.CellHeight); 141 | SendDlgItemMessage(hDlg,TXT_CFG_CELLHEIGHT,WM_SETTEXT,0,(LPARAM)Text); 142 | wsprintf(Text,"%d",lCfg.FontHeight); 143 | SendDlgItemMessage(hDlg,TXT_CFG_FONTHEIGHT,WM_SETTEXT,0,(LPARAM)Text); 144 | wsprintf(Text,"%d",lCfg.FontWidth); 145 | SendDlgItemMessage(hDlg,TXT_CFG_FONTWIDTH,WM_SETTEXT,0,(LPARAM)Text); 146 | 147 | // Set spin ranges 148 | SendDlgItemMessage(hDlg,SPN_CFG_CELLWIDTH,UDM_SETRANGE,0,MAKELONG(128,8)); 149 | SendDlgItemMessage(hDlg,SPN_CFG_CELLHEIGHT,UDM_SETRANGE,0,MAKELONG(128,8)); 150 | SendDlgItemMessage(hDlg,SPN_CFG_FONTHEIGHT,UDM_SETRANGE,0,MAKELONG(100,1)); 151 | SendDlgItemMessage(hDlg,SPN_CFG_FONTWIDTH,UDM_SETRANGE,0,MAKELONG(100,0)); 152 | 153 | return 0; 154 | 155 | case WM_DRAWITEM: 156 | if(wParam==ODR_COLOR) 157 | { 158 | dc=((LPDRAWITEMSTRUCT)lParam)->hDC; 159 | Red=SendDlgItemMessage(hDlg,SLD_RED,TBM_GETPOS,0,0); 160 | Green=SendDlgItemMessage(hDlg,SLD_GREEN,TBM_GETPOS,0,0); 161 | Blue=SendDlgItemMessage(hDlg,SLD_BLUE,TBM_GETPOS,0,0); 162 | GetClientRect(hDlg, &rcArea); 163 | hBr=CreateSolidBrush(RGB(Red,Green,Blue)); 164 | FillRect(dc,&rcArea,hBr); 165 | DeleteObject(hBr); 166 | } 167 | return TRUE; 168 | 169 | case WM_CLOSE: 170 | EndDialog(hDlg,0); 171 | return 0; 172 | 173 | case WM_HSCROLL: 174 | Sel=SendDlgItemMessage(hDlg,CBO_CFG_ITEM,CB_GETCURSEL,0,0); 175 | 176 | if((HWND)lParam==GetDlgItem(hDlg,SLD_RED)) 177 | { 178 | Red=SendDlgItemMessage(hDlg,SLD_RED,TBM_GETPOS,0,0); 179 | wsprintf(Text,"%d",Red); 180 | SendDlgItemMessage(hDlg,TXT_RED,WM_SETTEXT,0,(LPARAM)Text); 181 | 182 | switch(Sel) 183 | { 184 | case GRIDCOL: 185 | lCfg.GridCol.Red=Red; 186 | break; 187 | 188 | case WIDTHCOL: 189 | lCfg.WidthCol.Red=Red; 190 | break; 191 | 192 | case SELCOL: 193 | lCfg.SelCol.Red=Red; 194 | break; 195 | 196 | case BACKCOL: 197 | lCfg.BackCol.Red=Red; 198 | break; 199 | 200 | case TEXTCOL: 201 | lCfg.ForeCol.Red=Red; 202 | break; 203 | } 204 | } 205 | 206 | if((HWND)lParam==GetDlgItem(hDlg,SLD_GREEN)) 207 | { 208 | Green=SendDlgItemMessage(hDlg,SLD_GREEN,TBM_GETPOS,0,0); 209 | wsprintf(Text,"%d",Green); 210 | SendDlgItemMessage(hDlg,TXT_GREEN,WM_SETTEXT,0,(LPARAM)Text); 211 | 212 | switch(Sel) 213 | { 214 | case GRIDCOL: 215 | lCfg.GridCol.Green=Green; 216 | break; 217 | 218 | case WIDTHCOL: 219 | lCfg.WidthCol.Green=Green; 220 | break; 221 | 222 | case SELCOL: 223 | lCfg.SelCol.Green=Green; 224 | break; 225 | 226 | case BACKCOL: 227 | lCfg.BackCol.Green=Green; 228 | break; 229 | 230 | case TEXTCOL: 231 | lCfg.ForeCol.Green=Green; 232 | break; 233 | } 234 | } 235 | 236 | if((HWND)lParam==GetDlgItem(hDlg,SLD_BLUE)) 237 | { 238 | Blue=SendDlgItemMessage(hDlg,SLD_BLUE,TBM_GETPOS,0,0); 239 | wsprintf(Text,"%d",Blue); 240 | SendDlgItemMessage(hDlg,TXT_BLUE,WM_SETTEXT,0,(LPARAM)Text); 241 | 242 | switch(Sel) 243 | { 244 | case GRIDCOL: 245 | lCfg.GridCol.Blue=Blue; 246 | break; 247 | 248 | case WIDTHCOL: 249 | lCfg.WidthCol.Blue=Blue; 250 | break; 251 | 252 | case SELCOL: 253 | lCfg.SelCol.Blue=Blue; 254 | break; 255 | 256 | case BACKCOL: 257 | lCfg.BackCol.Blue=Blue; 258 | break; 259 | 260 | case TEXTCOL: 261 | lCfg.ForeCol.Blue=Blue; 262 | break; 263 | } 264 | } 265 | 266 | InvalidateRect(GetDlgItem(hDlg,ODR_COLOR),NULL,FALSE); 267 | return TRUE; 268 | 269 | case WM_COMMAND: 270 | { 271 | switch(HIWORD(wParam))// Notifications 272 | { 273 | case EN_KILLFOCUS: 274 | if(LOWORD(wParam)==TXT_RED) 275 | { 276 | Sel=SendDlgItemMessage(hDlg,CBO_CFG_ITEM,CB_GETCURSEL,0,0); 277 | SendDlgItemMessage(hDlg,TXT_RED,WM_GETTEXT,256,(LPARAM)Text); 278 | Val=atoi(Text); 279 | if(Val<0) 280 | { 281 | Val=0; 282 | wsprintf(Text,"%d",Val); 283 | SendDlgItemMessage(hDlg,TXT_RED,WM_SETTEXT,256,(LPARAM)Text); 284 | } 285 | if(Val>255) 286 | { 287 | Val=255; 288 | wsprintf(Text,"%d",Val); 289 | SendDlgItemMessage(hDlg,TXT_RED,WM_SETTEXT,256,(LPARAM)Text); 290 | } 291 | 292 | switch(Sel) 293 | { 294 | case GRIDCOL: 295 | lCfg.GridCol.Red=Val; 296 | break; 297 | 298 | case WIDTHCOL: 299 | lCfg.WidthCol.Red=Val; 300 | break; 301 | 302 | case SELCOL: 303 | lCfg.SelCol.Red=Val; 304 | break; 305 | 306 | case BACKCOL: 307 | lCfg.BackCol.Red=Val; 308 | break; 309 | 310 | case TEXTCOL: 311 | lCfg.ForeCol.Red=Val; 312 | break; 313 | } 314 | 315 | SendDlgItemMessage(hDlg,SLD_RED,TBM_SETPOS,TRUE,(LPARAM)Val); 316 | InvalidateRect(GetDlgItem(hDlg,ODR_COLOR),NULL,FALSE); 317 | } 318 | 319 | if(LOWORD(wParam)==TXT_GREEN) 320 | { 321 | Sel=SendDlgItemMessage(hDlg,CBO_CFG_ITEM,CB_GETCURSEL,0,0); 322 | SendDlgItemMessage(hDlg,TXT_GREEN,WM_GETTEXT,256,(LPARAM)Text); 323 | Val=atoi(Text); 324 | if(Val<0) 325 | { 326 | Val=0; 327 | wsprintf(Text,"%d",Val); 328 | SendDlgItemMessage(hDlg,TXT_GREEN,WM_SETTEXT,256,(LPARAM)Text); 329 | } 330 | if(Val>255) 331 | { 332 | Val=255; 333 | wsprintf(Text,"%d",Val); 334 | SendDlgItemMessage(hDlg,TXT_GREEN,WM_SETTEXT,256,(LPARAM)Text); 335 | } 336 | 337 | switch(Sel) 338 | { 339 | case GRIDCOL: 340 | lCfg.GridCol.Green=Val; 341 | break; 342 | 343 | case WIDTHCOL: 344 | lCfg.WidthCol.Green=Val; 345 | break; 346 | 347 | case SELCOL: 348 | lCfg.SelCol.Green=Val; 349 | break; 350 | 351 | case BACKCOL: 352 | lCfg.BackCol.Green=Val; 353 | break; 354 | 355 | case TEXTCOL: 356 | lCfg.ForeCol.Green=Val; 357 | break; 358 | } 359 | 360 | SendDlgItemMessage(hDlg,SLD_GREEN,TBM_SETPOS,TRUE,(LPARAM)Val); 361 | InvalidateRect(GetDlgItem(hDlg,ODR_COLOR),NULL,FALSE); 362 | } 363 | 364 | if(LOWORD(wParam)==TXT_BLUE) 365 | { 366 | Sel=SendDlgItemMessage(hDlg,CBO_CFG_ITEM,CB_GETCURSEL,0,0); 367 | SendDlgItemMessage(hDlg,TXT_BLUE,WM_GETTEXT,256,(LPARAM)Text); 368 | Val=atoi(Text); 369 | if(Val<0) 370 | { 371 | Val=0; 372 | wsprintf(Text,"%d",Val); 373 | SendDlgItemMessage(hDlg,TXT_BLUE,WM_SETTEXT,256,(LPARAM)Text); 374 | } 375 | if(Val>255) 376 | { 377 | Val=255; 378 | wsprintf(Text,"%d",Val); 379 | SendDlgItemMessage(hDlg,TXT_BLUE,WM_SETTEXT,256,(LPARAM)Text); 380 | } 381 | 382 | switch(Sel) 383 | { 384 | case GRIDCOL: 385 | lCfg.GridCol.Blue=Val; 386 | break; 387 | 388 | case WIDTHCOL: 389 | lCfg.WidthCol.Blue=Val; 390 | break; 391 | 392 | case SELCOL: 393 | lCfg.SelCol.Blue=Val; 394 | break; 395 | 396 | case BACKCOL: 397 | lCfg.BackCol.Blue=Val; 398 | break; 399 | 400 | case TEXTCOL: 401 | lCfg.ForeCol.Blue=Val; 402 | break; 403 | } 404 | SendDlgItemMessage(hDlg,SLD_BLUE,TBM_SETPOS,TRUE,(LPARAM)Val); 405 | InvalidateRect(GetDlgItem(hDlg,ODR_COLOR),NULL,FALSE); 406 | } 407 | 408 | if(LOWORD(wParam)==TXT_CFG_CELLWIDTH) 409 | { 410 | SendDlgItemMessage(hDlg,TXT_CFG_CELLWIDTH,WM_GETTEXT,256,(LPARAM)Text); 411 | Val=atoi(Text); 412 | if(Val<8) 413 | { 414 | Val=8; 415 | wsprintf(Text,"%d",Val); 416 | SendDlgItemMessage(hDlg,TXT_CFG_CELLWIDTH,WM_SETTEXT,256,(LPARAM)Text); 417 | } 418 | 419 | if(Val>128) 420 | { 421 | Val=128; 422 | wsprintf(Text,"%d",Val); 423 | SendDlgItemMessage(hDlg,TXT_CFG_CELLWIDTH,WM_SETTEXT,256,(LPARAM)Text); 424 | } 425 | 426 | lCfg.CellWidth=Val; 427 | } 428 | 429 | if(LOWORD(wParam)==TXT_CFG_CELLHEIGHT) 430 | { 431 | SendDlgItemMessage(hDlg,TXT_CFG_CELLHEIGHT,WM_GETTEXT,256,(LPARAM)Text); 432 | Val=atoi(Text); 433 | if(Val<8) 434 | { 435 | Val=8; 436 | wsprintf(Text,"%d",Val); 437 | SendDlgItemMessage(hDlg,TXT_CFG_CELLHEIGHT,WM_SETTEXT,256,(LPARAM)Text); 438 | } 439 | 440 | if(Val>128) 441 | { 442 | Val=128; 443 | wsprintf(Text,"%d",Val); 444 | SendDlgItemMessage(hDlg,TXT_CFG_CELLHEIGHT,WM_SETTEXT,256,(LPARAM)Text); 445 | } 446 | 447 | lCfg.CellHeight=Val; 448 | } 449 | 450 | if(LOWORD(wParam)==TXT_CFG_FONTWIDTH) 451 | { 452 | SendDlgItemMessage(hDlg,TXT_CFG_FONTWIDTH,WM_GETTEXT,256,(LPARAM)Text); 453 | Val=atoi(Text); 454 | if(Val<0) 455 | { 456 | Val=0; 457 | wsprintf(Text,"%d",Val); 458 | SendDlgItemMessage(hDlg,TXT_CFG_FONTWIDTH,WM_SETTEXT,256,(LPARAM)Text); 459 | } 460 | 461 | if(Val>100) 462 | { 463 | Val=100; 464 | wsprintf(Text,"%d",Val); 465 | SendDlgItemMessage(hDlg,TXT_CFG_FONTWIDTH,WM_SETTEXT,256,(LPARAM)Text); 466 | } 467 | 468 | lCfg.FontWidth=Val; 469 | } 470 | 471 | if(LOWORD(wParam)==TXT_CFG_FONTHEIGHT) 472 | { 473 | SendDlgItemMessage(hDlg,TXT_CFG_FONTHEIGHT,WM_GETTEXT,256,(LPARAM)Text); 474 | Val=atoi(Text); 475 | if(Val<1) 476 | { 477 | Val=1; 478 | wsprintf(Text,"%d",Val); 479 | SendDlgItemMessage(hDlg,TXT_CFG_FONTHEIGHT,WM_SETTEXT,256,(LPARAM)Text); 480 | } 481 | 482 | if(Val>100) 483 | { 484 | Val=100; 485 | wsprintf(Text,"%d",Val); 486 | SendDlgItemMessage(hDlg,TXT_CFG_FONTHEIGHT,WM_SETTEXT,256,(LPARAM)Text); 487 | } 488 | 489 | lCfg.FontHeight=Val; 490 | } 491 | 492 | return TRUE; 493 | 494 | case CBN_SELCHANGE: 495 | switch(LOWORD(wParam)) 496 | { 497 | case CBO_CFG_ITEM: 498 | Sel=SendDlgItemMessage(hDlg,CBO_CFG_ITEM,CB_GETCURSEL,0,0); 499 | 500 | switch(Sel) 501 | { 502 | case GRIDCOL: 503 | SetConfigRGB(hDlg,lCfg.GridCol); 504 | break; 505 | 506 | case WIDTHCOL: 507 | SetConfigRGB(hDlg,lCfg.WidthCol); 508 | break; 509 | 510 | case SELCOL: 511 | SetConfigRGB(hDlg,lCfg.SelCol); 512 | break; 513 | 514 | case BACKCOL: 515 | SetConfigRGB(hDlg,lCfg.BackCol); 516 | break; 517 | 518 | case TEXTCOL: 519 | SetConfigRGB(hDlg,lCfg.ForeCol); 520 | break; 521 | } 522 | 523 | InvalidateRect(GetDlgItem(hDlg,ODR_COLOR),NULL,FALSE); 524 | return TRUE; 525 | 526 | case CBO_CFG_IMGXSIZE: 527 | Sel=SendDlgItemMessage(hDlg,CBO_CFG_IMGXSIZE,CB_GETCURSEL,0,0); 528 | if(Sel==0) 529 | { 530 | lCfg.ImgWidth=16; 531 | return TRUE; 532 | } 533 | else if(Sel==1) 534 | { 535 | lCfg.ImgWidth=32; 536 | return TRUE; 537 | } 538 | else if(Sel==2) 539 | { 540 | lCfg.ImgWidth=64; 541 | return TRUE; 542 | } 543 | else if(Sel==3) 544 | { 545 | lCfg.ImgWidth=128; 546 | return TRUE; 547 | } 548 | else if(Sel==4) 549 | { 550 | lCfg.ImgWidth=256; 551 | return TRUE; 552 | } 553 | else if(Sel==5) 554 | { 555 | lCfg.ImgWidth=512; 556 | return TRUE; 557 | } 558 | else if(Sel==6) 559 | { 560 | lCfg.ImgWidth=1024; 561 | return TRUE; 562 | } 563 | else if(Sel==7) 564 | { 565 | lCfg.ImgWidth=2048; 566 | return TRUE; 567 | } 568 | else if(Sel==8) 569 | { 570 | lCfg.ImgWidth=4096; 571 | return TRUE; 572 | } 573 | else 574 | return FALSE; 575 | 576 | case CBO_CFG_IMGYSIZE: 577 | Sel=SendDlgItemMessage(hDlg,CBO_CFG_IMGYSIZE,CB_GETCURSEL,0,0); 578 | if(Sel==0) 579 | { 580 | lCfg.ImgHeight=16; 581 | return TRUE; 582 | } 583 | else if(Sel==1) 584 | { 585 | lCfg.ImgHeight=32; 586 | return TRUE; 587 | } 588 | else if(Sel==2) 589 | { 590 | lCfg.ImgHeight=64; 591 | return TRUE; 592 | } 593 | else if(Sel==3) 594 | { 595 | lCfg.ImgHeight=128; 596 | return TRUE; 597 | } 598 | else if(Sel==4) 599 | { 600 | lCfg.ImgHeight=256; 601 | return TRUE; 602 | } 603 | else if(Sel==5) 604 | { 605 | lCfg.ImgHeight=512; 606 | return TRUE; 607 | } 608 | else if(Sel==6) 609 | { 610 | lCfg.ImgHeight=1024; 611 | return TRUE; 612 | } 613 | else if(Sel==7) 614 | { 615 | lCfg.ImgHeight=2048; 616 | return TRUE; 617 | } 618 | else if(Sel==8) 619 | { 620 | lCfg.ImgHeight=4096; 621 | return TRUE; 622 | } 623 | else 624 | return FALSE; 625 | } 626 | return FALSE; 627 | } 628 | 629 | switch(LOWORD(wParam)) // Buttons 630 | { 631 | case CHK_CFG_GRID: 632 | if(SendDlgItemMessage(hDlg,CHK_CFG_GRID,BM_GETCHECK,0,0)==BST_CHECKED) 633 | lCfg.Flags |= SHOW_GRID; 634 | else 635 | lCfg.Flags ^=SHOW_GRID; 636 | return TRUE; 637 | 638 | case CHK_CFG_WIDTH: 639 | if(SendDlgItemMessage(hDlg,CHK_CFG_WIDTH,BM_GETCHECK,0,0)==BST_CHECKED) 640 | lCfg.Flags |= SHOW_WIDTH; 641 | else 642 | lCfg.Flags ^=SHOW_WIDTH; 643 | return TRUE; 644 | 645 | case ID_OK: 646 | // Set config 647 | Fnt->SetSize(CELLHEIGHT,lCfg.CellHeight); 648 | Fnt->SetSize(CELLWIDTH,lCfg.CellWidth); 649 | Fnt->SetFontHeight(lCfg.FontHeight); 650 | Fnt->SetFontWidth(lCfg.FontWidth); 651 | Fnt->SetSize(MAPWIDTH,lCfg.ImgWidth); 652 | Fnt->SetSize(MAPHEIGHT,lCfg.ImgHeight); 653 | info->Grid=lCfg.Flags & SHOW_GRID; 654 | info->wMarker=lCfg.Flags & SHOW_WIDTH; 655 | Fnt->SetCol(BACKCOL,lCfg.BackCol); 656 | Fnt->SetCol(TEXTCOL,lCfg.ForeCol); 657 | Fnt->SetCol(GRIDCOL,lCfg.GridCol); 658 | Fnt->SetCol(WIDTHCOL,lCfg.WidthCol); 659 | Fnt->SetCol(SELCOL,lCfg.SelCol); 660 | 661 | EndDialog(hDlg,0); 662 | return 0; 663 | 664 | case IDSAVE: 665 | // Set config 666 | Fnt->SetSize(CELLHEIGHT,lCfg.CellHeight); 667 | Fnt->SetSize(CELLWIDTH,lCfg.CellWidth); 668 | Fnt->SetFontHeight(lCfg.FontHeight); 669 | Fnt->SetFontWidth(lCfg.FontWidth); 670 | Fnt->SetSize(MAPWIDTH,lCfg.ImgWidth); 671 | Fnt->SetSize(MAPHEIGHT,lCfg.ImgHeight); 672 | info->Grid=lCfg.Flags & SHOW_GRID; 673 | info->wMarker=lCfg.Flags & SHOW_WIDTH; 674 | Fnt->SetCol(BACKCOL,lCfg.BackCol); 675 | Fnt->SetCol(TEXTCOL,lCfg.ForeCol); 676 | Fnt->SetCol(GRIDCOL,lCfg.GridCol); 677 | Fnt->SetCol(WIDTHCOL,lCfg.WidthCol); 678 | Fnt->SetCol(SELCOL,lCfg.SelCol); 679 | 680 | if(!Fnt->SaveConfig("bfg.cfg",info->Grid,info->wMarker)) 681 | { 682 | MessageBox(hDlg,"Unable to save config file","File Error",MB_OK|MB_ICONERROR); 683 | return 0; 684 | } 685 | 686 | EndDialog(hDlg,0); 687 | return 0; 688 | 689 | case IDDEFAULT: 690 | if(MessageBox(hDlg,"Are you sure you want to revert to the default settings?", 691 | "Reset all?",MB_YESNO | MB_ICONQUESTION)==IDNO) 692 | return TRUE; 693 | 694 | lCfg.ImgWidth=256; 695 | SendDlgItemMessage(hDlg,CBO_CFG_IMGXSIZE,CB_SETCURSEL,2,0); 696 | 697 | lCfg.ImgHeight=256; 698 | SendDlgItemMessage(hDlg,CBO_CFG_IMGYSIZE,CB_SETCURSEL,2,0); 699 | 700 | lCfg.CellHeight=32; 701 | SendDlgItemMessage(hDlg,TXT_CFG_CELLHEIGHT,WM_SETTEXT,256,(LPARAM)"32"); 702 | lCfg.CellWidth=32; 703 | SendDlgItemMessage(hDlg,TXT_CFG_CELLWIDTH,WM_SETTEXT,256,(LPARAM)"32"); 704 | lCfg.FontHeight=20; 705 | SendDlgItemMessage(hDlg,TXT_CFG_FONTHEIGHT,WM_SETTEXT,256,(LPARAM)"20"); 706 | lCfg.FontWidth=0; 707 | SendDlgItemMessage(hDlg,TXT_CFG_FONTWIDTH,WM_SETTEXT,256,(LPARAM)"0"); 708 | 709 | lCfg.BackCol = MakeRGB(0,0,0); 710 | lCfg.ForeCol=MakeRGB(255,255,255); 711 | lCfg.GridCol=MakeRGB(170,0,170); 712 | lCfg.WidthCol=MakeRGB(170,170,0); 713 | lCfg.SelCol=MakeRGB(0,154,0); 714 | 715 | SendDlgItemMessage(hDlg,CBO_CFG_ITEM,CB_SETCURSEL,0,0); 716 | 717 | SetConfigRGB(hDlg,lCfg.GridCol); 718 | 719 | lCfg.Flags=SHOW_GRID | SHOW_WIDTH; 720 | SendDlgItemMessage(hDlg,CHK_CFG_GRID,BM_SETCHECK,BST_CHECKED,0); 721 | SendDlgItemMessage(hDlg,CHK_CFG_WIDTH,BM_SETCHECK,BST_CHECKED,0); 722 | return 0; 723 | 724 | case IDCANCEL: 725 | EndDialog(hDlg,0); 726 | return 0; 727 | } 728 | } 729 | 730 | default: 731 | return 0; 732 | } 733 | } 734 | -------------------------------------------------------------------------------- /source/ConfigWindow.h: -------------------------------------------------------------------------------- 1 | void SetConfigRGB(HWND Win, BFG_RGB Cols); 2 | 3 | BOOL CALLBACK ConfigWinProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) 4 | { 5 | HDC dc; 6 | RECT rcArea; 7 | HBRUSH hBr; 8 | BFG_RGB Col; 9 | int Sel,Val,Red,Green,Blue; 10 | char Text[256]; 11 | static AppConfig lCfg; 12 | extern AppInfo *info; 13 | 14 | switch(msg) 15 | { 16 | case WM_INITDIALOG: 17 | // Preserve Current Config 18 | lCfg.CellHeight=Fnt->GetSize(CELLHEIGHT); 19 | lCfg.CellWidth=Fnt->GetSize(CELLWIDTH); 20 | lCfg.FontHeight=Fnt->GetFontHeight(); 21 | lCfg.FontWidth=Fnt->GetFontWidth(); 22 | lCfg.ImgSize=Fnt->GetSize(MAPWIDTH); 23 | if(info->Grid) 24 | lCfg.Flags |= SHOW_GRID; 25 | if(info->wMarker) 26 | lCfg.Flags |= SHOW_WIDTH; 27 | lCfg.BackCol=Fnt->GetCol(BACKCOL); 28 | lCfg.ForeCol=Fnt->GetCol(TEXTCOL); 29 | lCfg.GridCol=Fnt->GetCol(GRIDCOL); 30 | lCfg.WidthCol=Fnt->GetCol(WIDTHCOL); 31 | lCfg.SelCol=Fnt->GetCol(SELCOL); 32 | 33 | // Populate item combo 34 | SendDlgItemMessage(hDlg,CBO_CFG_ITEM,CB_ADDSTRING,0,(LPARAM)"Grid Lines"); 35 | SendDlgItemMessage(hDlg,CBO_CFG_ITEM,CB_ADDSTRING,0,(LPARAM)"Width Marker"); 36 | SendDlgItemMessage(hDlg,CBO_CFG_ITEM,CB_ADDSTRING,0,(LPARAM)"Selection Marker"); 37 | SendDlgItemMessage(hDlg,CBO_CFG_ITEM,CB_ADDSTRING,0,(LPARAM)"Font Colour"); 38 | SendDlgItemMessage(hDlg,CBO_CFG_ITEM,CB_ADDSTRING,0,(LPARAM)"Background Colour"); 39 | SendDlgItemMessage(hDlg,CBO_CFG_ITEM,CB_SETCURSEL,0,0); 40 | 41 | // Set range of sliders 42 | SendDlgItemMessage(hDlg,SLD_RED,TBM_SETRANGE,TRUE,MAKELONG(0,255)); 43 | SendDlgItemMessage(hDlg,SLD_GREEN,TBM_SETRANGE,TRUE,MAKELONG(0,255)); 44 | SendDlgItemMessage(hDlg,SLD_BLUE,TBM_SETRANGE,TRUE,MAKELONG(0,255)); 45 | 46 | // Set initial slider pos 47 | SetConfigRGB(hDlg,lCfg.GridCol); 48 | 49 | // Populate image size combo 50 | SendDlgItemMessage(hDlg,CBO_CFG_IMGSIZE,CB_ADDSTRING,0,(LPARAM)"64x64"); 51 | SendDlgItemMessage(hDlg,CBO_CFG_IMGSIZE,CB_ADDSTRING,0,(LPARAM)"128x128"); 52 | SendDlgItemMessage(hDlg,CBO_CFG_IMGSIZE,CB_ADDSTRING,0,(LPARAM)"256x256"); 53 | SendDlgItemMessage(hDlg,CBO_CFG_IMGSIZE,CB_ADDSTRING,0,(LPARAM)"512x512"); 54 | if(lCfg.ImgSize==128) 55 | SendDlgItemMessage(hDlg,CBO_CFG_IMGSIZE,CB_SETCURSEL,1,0); 56 | else if(lCfg.ImgSize==256) 57 | SendDlgItemMessage(hDlg,CBO_CFG_IMGSIZE,CB_SETCURSEL,2,0); 58 | else if(lCfg.ImgSize==512) 59 | SendDlgItemMessage(hDlg,CBO_CFG_IMGSIZE,CB_SETCURSEL,3,0); 60 | else 61 | SendDlgItemMessage(hDlg,CBO_CFG_IMGSIZE,CB_SETCURSEL,0,0); 62 | 63 | // Set grid and width checks 64 | SendDlgItemMessage(hDlg,CHK_CFG_GRID,BM_SETCHECK,lCfg.Flags & SHOW_GRID,0); 65 | SendDlgItemMessage(hDlg,CHK_CFG_WIDTH,BM_SETCHECK,lCfg.Flags & SHOW_WIDTH,0); 66 | 67 | // Populate textboxes 68 | wsprintf(Text,"%d",lCfg.CellWidth); 69 | SendDlgItemMessage(hDlg,TXT_CFG_CELLWIDTH,WM_SETTEXT,0,(LPARAM)Text); 70 | wsprintf(Text,"%d",lCfg.CellHeight); 71 | SendDlgItemMessage(hDlg,TXT_CFG_CELLHEIGHT,WM_SETTEXT,0,(LPARAM)Text); 72 | wsprintf(Text,"%d",lCfg.FontHeight); 73 | SendDlgItemMessage(hDlg,TXT_CFG_FONTHEIGHT,WM_SETTEXT,0,(LPARAM)Text); 74 | wsprintf(Text,"%d",lCfg.FontWidth); 75 | SendDlgItemMessage(hDlg,TXT_CFG_FONTWIDTH,WM_SETTEXT,0,(LPARAM)Text); 76 | 77 | // Set spin ranges 78 | SendDlgItemMessage(hDlg,SPN_CFG_CELLWIDTH,UDM_SETRANGE,0,MAKELONG(128,8)); 79 | SendDlgItemMessage(hDlg,SPN_CFG_CELLHEIGHT,UDM_SETRANGE,0,MAKELONG(128,8)); 80 | SendDlgItemMessage(hDlg,SPN_CFG_FONTHEIGHT,UDM_SETRANGE,0,MAKELONG(100,1)); 81 | SendDlgItemMessage(hDlg,SPN_CFG_FONTWIDTH,UDM_SETRANGE,0,MAKELONG(100,0)); 82 | return 0; 83 | 84 | case WM_DRAWITEM: 85 | if(wParam==ODR_COLOR) 86 | { 87 | dc=((LPDRAWITEMSTRUCT)lParam)->hDC; 88 | Red=SendDlgItemMessage(hDlg,SLD_RED,TBM_GETPOS,0,0); 89 | Green=SendDlgItemMessage(hDlg,SLD_GREEN,TBM_GETPOS,0,0); 90 | Blue=SendDlgItemMessage(hDlg,SLD_BLUE,TBM_GETPOS,0,0); 91 | GetClientRect(hDlg, &rcArea); 92 | hBr=CreateSolidBrush(RGB(Red,Green,Blue)); 93 | FillRect(dc,&rcArea,hBr); 94 | DeleteObject(hBr); 95 | } 96 | return TRUE; 97 | 98 | case WM_CLOSE: 99 | EndDialog(hDlg,0); 100 | return 0; 101 | 102 | case WM_HSCROLL: 103 | if((HWND)lParam==GetDlgItem(hDlg,SLD_RED)) 104 | { 105 | Red=SendDlgItemMessage(hDlg,SLD_RED,TBM_GETPOS,0,0); 106 | wsprintf(Text,"%d",Red); 107 | SendDlgItemMessage(hDlg,TXT_RED,WM_SETTEXT,0,(LPARAM)Text); 108 | } 109 | 110 | if((HWND)lParam==GetDlgItem(hDlg,SLD_GREEN)) 111 | { 112 | Green=SendDlgItemMessage(hDlg,SLD_GREEN,TBM_GETPOS,0,0); 113 | wsprintf(Text,"%d",Green); 114 | SendDlgItemMessage(hDlg,TXT_GREEN,WM_SETTEXT,0,(LPARAM)Text); 115 | } 116 | 117 | if((HWND)lParam==GetDlgItem(hDlg,SLD_BLUE)) 118 | { 119 | Blue=SendDlgItemMessage(hDlg,SLD_BLUE,TBM_GETPOS,0,0); 120 | wsprintf(Text,"%d",Blue); 121 | SendDlgItemMessage(hDlg,TXT_BLUE,WM_SETTEXT,0,(LPARAM)Text); 122 | } 123 | InvalidateRect(GetDlgItem(hDlg,ODR_COLOR),NULL,FALSE); 124 | cfgChange=TRUE; 125 | return TRUE; 126 | 127 | case WM_COMMAND: 128 | { 129 | switch(HIWORD(wParam))// Notifications 130 | { 131 | case EN_CHANGE: 132 | if(LOWORD(wParam)==TXT_RED) 133 | { 134 | Sel=SendDlgItemMessage(hDlg,CBO_CFG_ITEM,CB_GETCURSEL,0,0); 135 | SendDlgItemMessage(hDlg,TXT_RED,WM_GETTEXT,256,(LPARAM)Text); 136 | Val=atoi(Text); 137 | if(Val<0) 138 | { 139 | Val=0; 140 | wsprintf(Text,"%d",Val); 141 | SendDlgItemMessage(hDlg,TXT_RED,WM_SETTEXT,256,(LPARAM)Text); 142 | } 143 | if(Val>255) 144 | { 145 | Val=255; 146 | wsprintf(Text,"%d",Val); 147 | SendDlgItemMessage(hDlg,TXT_RED,WM_SETTEXT,256,(LPARAM)Text); 148 | } 149 | 150 | 151 | switch(Sel) 152 | { 153 | case GRIDCOL: 154 | lCfg.GridCol.Red=Val; 155 | break; 156 | 157 | case WIDTHCOL: 158 | lCfg.WidthCol.Red=Val; 159 | break; 160 | 161 | case SELCOL: 162 | lCfg.SelCol.Red=Val; 163 | break; 164 | 165 | case BACKCOL: 166 | lCfg.BackCol.Red=Val; 167 | break; 168 | 169 | case TEXTCOL: 170 | lCfg.ForeCol.Red=Val; 171 | break; 172 | } 173 | 174 | SendDlgItemMessage(hDlg,SLD_RED,TBM_SETPOS,TRUE,(LPARAM)Val); 175 | InvalidateRect(GetDlgItem(hDlg,ODR_COLOR),NULL,FALSE); 176 | } 177 | 178 | if(LOWORD(wParam)==TXT_GREEN) 179 | { 180 | Sel=SendDlgItemMessage(hDlg,CBO_CFG_ITEM,CB_GETCURSEL,0,0); 181 | SendDlgItemMessage(hDlg,TXT_GREEN,WM_GETTEXT,256,(LPARAM)Text); 182 | Val=atoi(Text); 183 | if(Val<0) 184 | { 185 | Val=0; 186 | wsprintf(Text,"%d",Val); 187 | SendDlgItemMessage(hDlg,TXT_GREEN,WM_SETTEXT,256,(LPARAM)Text); 188 | } 189 | if(Val>255) 190 | { 191 | Val=255; 192 | wsprintf(Text,"%d",Val); 193 | SendDlgItemMessage(hDlg,TXT_GREEN,WM_SETTEXT,256,(LPARAM)Text); 194 | } 195 | 196 | switch(Sel) 197 | { 198 | case GRIDCOL: 199 | lCfg.GridCol.Green=Val; 200 | break; 201 | 202 | case WIDTHCOL: 203 | lCfg.WidthCol.Green=Val; 204 | break; 205 | 206 | case SELCOL: 207 | lCfg.SelCol.Green=Val; 208 | break; 209 | 210 | case BACKCOL: 211 | lCfg.BackCol.Green=Val; 212 | break; 213 | 214 | case TEXTCOL: 215 | lCfg.ForeCol.Green=Val; 216 | break; 217 | } 218 | 219 | SendDlgItemMessage(hDlg,SLD_GREEN,TBM_SETPOS,TRUE,(LPARAM)Val); 220 | InvalidateRect(GetDlgItem(hDlg,ODR_COLOR),NULL,FALSE); 221 | } 222 | 223 | if(LOWORD(wParam)==TXT_BLUE) 224 | { 225 | Sel=SendDlgItemMessage(hDlg,CBO_CFG_ITEM,CB_GETCURSEL,0,0); 226 | SendDlgItemMessage(hDlg,TXT_BLUE,WM_GETTEXT,256,(LPARAM)Text); 227 | Val=atoi(Text); 228 | if(Val<0) 229 | { 230 | Val=0; 231 | wsprintf(Text,"%d",Val); 232 | SendDlgItemMessage(hDlg,TXT_BLUE,WM_SETTEXT,256,(LPARAM)Text); 233 | } 234 | if(Val>255) 235 | { 236 | Val=255; 237 | wsprintf(Text,"%d",Val); 238 | SendDlgItemMessage(hDlg,TXT_BLUE,WM_SETTEXT,256,(LPARAM)Text); 239 | } 240 | 241 | switch(Sel) 242 | { 243 | case GRIDCOL: 244 | lCfg.GridCol.Blue=Val; 245 | break; 246 | 247 | case WIDTHCOL: 248 | lCfg.WidthCol.Blue=Val; 249 | break; 250 | 251 | case SELCOL: 252 | lCfg.SelCol.Blue=Val; 253 | break; 254 | 255 | case BACKCOL: 256 | lCfg.BackCol.Blue=Val; 257 | break; 258 | 259 | case TEXTCOL: 260 | lCfg.ForeCol.Blue=Val; 261 | break; 262 | } 263 | SendDlgItemMessage(hDlg,SLD_BLUE,TBM_SETPOS,TRUE,(LPARAM)Val); 264 | InvalidateRect(GetDlgItem(hDlg,ODR_COLOR),NULL,FALSE); 265 | } 266 | 267 | if(LOWORD(wParam)==TXT_CFG_CELLWIDTH) 268 | { 269 | SendDlgItemMessage(hDlg,TXT_CFG_CELLWIDTH,WM_GETTEXT,256,(LPARAM)Text); 270 | Val=atoi(Text); 271 | if(Val<8) 272 | { 273 | Val=8; 274 | wsprintf(Text,"%d",Val); 275 | SendDlgItemMessage(hDlg,TXT_CFG_CELLWIDTH,WM_SETTEXT,256,(LPARAM)Text); 276 | } 277 | 278 | if(Val>128) 279 | { 280 | Val=128; 281 | wsprintf(Text,"%d",Val); 282 | SendDlgItemMessage(hDlg,TXT_CFG_CELLWIDTH,WM_SETTEXT,256,(LPARAM)Text); 283 | } 284 | 285 | lCfg.CellWidth=Val; 286 | } 287 | 288 | if(LOWORD(wParam)==TXT_CFG_CELLHEIGHT) 289 | { 290 | SendDlgItemMessage(hDlg,TXT_CFG_CELLHEIGHT,WM_GETTEXT,256,(LPARAM)Text); 291 | Val=atoi(Text); 292 | if(Val<8) 293 | { 294 | Val=8; 295 | wsprintf(Text,"%d",Val); 296 | SendDlgItemMessage(hDlg,TXT_CFG_CELLHEIGHT,WM_SETTEXT,256,(LPARAM)Text); 297 | } 298 | 299 | if(Val>128) 300 | { 301 | Val=128; 302 | wsprintf(Text,"%d",Val); 303 | SendDlgItemMessage(hDlg,TXT_CFG_CELLHEIGHT,WM_SETTEXT,256,(LPARAM)Text); 304 | } 305 | 306 | lCfg.CellHeight=Val; 307 | } 308 | 309 | if(LOWORD(wParam)==TXT_CFG_FONTWIDTH) 310 | { 311 | SendDlgItemMessage(hDlg,TXT_CFG_FONTWIDTH,WM_GETTEXT,256,(LPARAM)Text); 312 | Val=atoi(Text); 313 | if(Val<0) 314 | { 315 | Val=0; 316 | wsprintf(Text,"%d",Val); 317 | SendDlgItemMessage(hDlg,TXT_CFG_FONTWIDTH,WM_SETTEXT,256,(LPARAM)Text); 318 | } 319 | 320 | if(Val>100) 321 | { 322 | Val=100; 323 | wsprintf(Text,"%d",Val); 324 | SendDlgItemMessage(hDlg,TXT_CFG_FONTWIDTH,WM_SETTEXT,256,(LPARAM)Text); 325 | } 326 | 327 | lCfg.FontWidth=Val; 328 | } 329 | 330 | if(LOWORD(wParam)==TXT_CFG_FONTHEIGHT) 331 | { 332 | SendDlgItemMessage(hDlg,TXT_CFG_FONTHEIGHT,WM_GETTEXT,256,(LPARAM)Text); 333 | Val=atoi(Text); 334 | if(Val<1) 335 | { 336 | Val=1; 337 | wsprintf(Text,"%d",Val); 338 | SendDlgItemMessage(hDlg,TXT_CFG_FONTHEIGHT,WM_SETTEXT,256,(LPARAM)Text); 339 | } 340 | 341 | if(Val>100) 342 | { 343 | Val=100; 344 | wsprintf(Text,"%d",Val); 345 | SendDlgItemMessage(hDlg,TXT_CFG_FONTHEIGHT,WM_SETTEXT,256,(LPARAM)Text); 346 | } 347 | 348 | lCfg.FontHeight=Val; 349 | } 350 | 351 | return TRUE; 352 | 353 | case CBN_SELCHANGE: 354 | switch(LOWORD(wParam)) 355 | { 356 | case CBO_CFG_ITEM: 357 | Sel=SendDlgItemMessage(hDlg,CBO_CFG_ITEM,CB_GETCURSEL,0,0); 358 | 359 | switch(Sel) 360 | { 361 | case GRIDCOL: 362 | SetConfigRGB(hDlg,lCfg.GridCol); 363 | break; 364 | 365 | case WIDTHCOL: 366 | SetConfigRGB(hDlg,lCfg.WidthCol); 367 | break; 368 | 369 | case SELCOL: 370 | SetConfigRGB(hDlg,lCfg.SelCol); 371 | break; 372 | 373 | case BACKCOL: 374 | SetConfigRGB(hDlg,lCfg.BackCol); 375 | break; 376 | 377 | case TEXTCOL: 378 | SetConfigRGB(hDlg,lCfg.ForeCol); 379 | break; 380 | } 381 | 382 | return TRUE; 383 | 384 | case CBO_CFG_IMGSIZE: 385 | cfgChange=TRUE; 386 | Sel=SendDlgItemMessage(hDlg,CBO_CFG_IMGSIZE,CB_GETCURSEL,0,0); 387 | if(Sel==0) 388 | { 389 | lCfg.ImgSize=64; 390 | return TRUE; 391 | } 392 | else if(Sel==1) 393 | { 394 | lCfg.ImgSize=128; 395 | return TRUE; 396 | } 397 | else if(Sel==2) 398 | { 399 | lCfg.ImgSize=256; 400 | return TRUE; 401 | } 402 | else if(Sel==3) 403 | { 404 | lCfg.ImgSize=512; 405 | return TRUE; 406 | } 407 | else 408 | return FALSE; 409 | 410 | } 411 | return FALSE; 412 | } 413 | 414 | switch(LOWORD(wParam)) // Buttons 415 | { 416 | case CHK_CFG_GRID: 417 | if(SendDlgItemMessage(hDlg,CHK_CFG_GRID,BM_GETCHECK,0,0)==BST_CHECKED) 418 | lCfg.Flags |= SHOW_GRID; 419 | else 420 | lCfg.Flags ^=SHOW_GRID; 421 | 422 | cfgChange=TRUE; 423 | return TRUE; 424 | 425 | case CHK_CFG_WIDTH: 426 | if(SendDlgItemMessage(hDlg,CHK_CFG_WIDTH,BM_GETCHECK,0,0)==BST_CHECKED) 427 | lCfg.Flags |= SHOW_WIDTH; 428 | else 429 | lCfg.Flags ^=SHOW_WIDTH; 430 | 431 | cfgChange=TRUE; 432 | return TRUE; 433 | 434 | case ID_OK: 435 | //memcpy(AppCfg,&lCfg,sizeof(AppConfig)); 436 | EndDialog(hDlg,0); 437 | return 0; 438 | 439 | case IDSAVE: 440 | /*memcpy(AppCfg,&lCfg,sizeof(AppConfig)); 441 | if(!SaveConfig("bfg.cfg",&lCfg)) 442 | { 443 | MessageBox(hDlg,"Unable to save config file","File Error",MB_OK|MB_ICONERROR); 444 | return 0; 445 | }*/ 446 | EndDialog(hDlg,0); 447 | cfgChange=FALSE; 448 | return 0; 449 | 450 | case IDDEFAULT: 451 | if(MessageBox(hDlg,"Are you sure you want to revert to the default settings?", 452 | "Reset all?",MB_YESNO | MB_ICONQUESTION)==IDNO) 453 | return TRUE; 454 | 455 | cfgChange=TRUE; 456 | 457 | lCfg.ImgSize=256; 458 | SendDlgItemMessage(hDlg,CBO_CFG_IMGSIZE,CB_SETCURSEL,2,0); 459 | 460 | lCfg.CellHeight=32; 461 | SendDlgItemMessage(hDlg,TXT_CFG_CELLHEIGHT,WM_SETTEXT,256,(LPARAM)"32"); 462 | lCfg.CellWidth=32; 463 | SendDlgItemMessage(hDlg,TXT_CFG_CELLWIDTH,WM_SETTEXT,256,(LPARAM)"32"); 464 | lCfg.FontHeight=20; 465 | SendDlgItemMessage(hDlg,TXT_CFG_FONTHEIGHT,WM_SETTEXT,256,(LPARAM)"20"); 466 | lCfg.FontWidth=0; 467 | SendDlgItemMessage(hDlg,TXT_CFG_FONTWIDTH,WM_SETTEXT,256,(LPARAM)"0"); 468 | 469 | Fnt->SetCol(BACKCOL,0,0,0); 470 | Fnt->SetCol(TEXTCOL,255,255,255); 471 | Fnt->SetCol(GRIDCOL,170,0,170); 472 | Fnt->SetCol(WIDTHCOL,170,170,0); 473 | Fnt->SetCol(SELCOL,0,154,0); 474 | 475 | SendDlgItemMessage(hDlg,CBO_CFG_ITEM,CB_SETCURSEL,0,0); 476 | SetConfigRGB(hDlg,Fnt->GetCol(BACKCOL)); 477 | 478 | lCfg.Flags=SHOW_GRID | SHOW_WIDTH; 479 | SendDlgItemMessage(hDlg,CHK_CFG_GRID,BM_SETCHECK,BST_CHECKED,0); 480 | SendDlgItemMessage(hDlg,CHK_CFG_WIDTH,BM_SETCHECK,BST_CHECKED,0); 481 | 482 | return 0; 483 | 484 | case IDCANCEL: 485 | EndDialog(hDlg,0); 486 | return 0; 487 | } 488 | } 489 | 490 | default: 491 | return 0; 492 | } 493 | } 494 | 495 | void SetConfigRGB(HWND Win, BFG_RGB Cols) 496 | { 497 | char Text[256]; 498 | 499 | wsprintf(Text,"%d",Cols.Red); 500 | SendDlgItemMessage(Win,TXT_RED,WM_SETTEXT,0,(LPARAM)Text); 501 | wsprintf(Text,"%d",Cols.Green); 502 | SendDlgItemMessage(Win,TXT_GREEN,WM_SETTEXT,0,(LPARAM)Text); 503 | wsprintf(Text,"%d",Cols.Blue); 504 | SendDlgItemMessage(Win,TXT_BLUE,WM_SETTEXT,0,(LPARAM)Text); 505 | } -------------------------------------------------------------------------------- /source/FileRequest.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | extern HINSTANCE G_Inst; 4 | extern HWND hMain; 5 | 6 | BOOL GetSourceName(char* fname, char* title, char *filter, char* DefExt) 7 | { 8 | BOOL res; 9 | OPENFILENAME fileopeninfo; 10 | fname[0]=NULL; 11 | 12 | fileopeninfo.lStructSize=sizeof(OPENFILENAME); 13 | fileopeninfo.hwndOwner=hMain; 14 | fileopeninfo.hInstance=G_Inst; 15 | fileopeninfo.lpstrFilter=filter; 16 | fileopeninfo.lpstrCustomFilter=NULL; 17 | fileopeninfo.nMaxCustFilter=0; 18 | fileopeninfo.nFilterIndex=1; 19 | fileopeninfo.lpstrFile=fname; 20 | fileopeninfo.nMaxFile=255; 21 | fileopeninfo.lpstrFileTitle=NULL; 22 | fileopeninfo.nMaxFileTitle=0; 23 | fileopeninfo.lpstrInitialDir=NULL; 24 | fileopeninfo.lpstrTitle=title; 25 | fileopeninfo.Flags=OFN_HIDEREADONLY | OFN_NONETWORKBUTTON; 26 | fileopeninfo.nFileOffset=0; 27 | fileopeninfo.nFileExtension=0; 28 | fileopeninfo.lpstrDefExt=DefExt; 29 | 30 | res=GetOpenFileName(&fileopeninfo); 31 | return res; 32 | } 33 | 34 | BOOL GetTargetName(char* fname, char* Title, char *filter, char* DefExt) 35 | { 36 | BOOL res; 37 | OPENFILENAME fileopeninfo; 38 | 39 | fileopeninfo.lStructSize=sizeof(OPENFILENAME); 40 | fileopeninfo.hwndOwner=hMain; 41 | fileopeninfo.hInstance=G_Inst; 42 | fileopeninfo.lpstrFilter=filter; 43 | fileopeninfo.lpstrCustomFilter=NULL; 44 | fileopeninfo.nMaxCustFilter=0; 45 | fileopeninfo.nFilterIndex=1; 46 | fileopeninfo.lpstrFile=fname; 47 | fileopeninfo.nMaxFile=255; 48 | fileopeninfo.lpstrFileTitle=NULL; 49 | fileopeninfo.nMaxFileTitle=0; 50 | fileopeninfo.lpstrInitialDir=NULL; 51 | fileopeninfo.lpstrTitle=Title; 52 | fileopeninfo.Flags=OFN_HIDEREADONLY | OFN_NONETWORKBUTTON; 53 | fileopeninfo.nFileOffset=0; 54 | fileopeninfo.nFileExtension=0; 55 | fileopeninfo.lpstrDefExt=DefExt; 56 | 57 | res=GetSaveFileName(&fileopeninfo); 58 | return res; 59 | } -------------------------------------------------------------------------------- /source/FontMapClass.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include 3 | #include "FontMapClass.h" 4 | #include "UtilFunctions.h" 5 | 6 | BFontMap::BFontMap() 7 | { 8 | int loop; 9 | 10 | BaseChar=32; 11 | 12 | MapWidth=256; 13 | MapHeight=256; 14 | CellHeight=32; 15 | CellWidth=32; 16 | gHMod=0; 17 | gVMod=0; 18 | gWidthMod=0; 19 | 20 | for(loop=0;loop!=256;loop++) 21 | { 22 | HMod[loop]=0; 23 | VMod[loop]=0; 24 | WidthMod[loop]=0; 25 | } 26 | 27 | fnt=NULL; 28 | 29 | FntDef.lfHeight=20; 30 | FntDef.lfWidth=0; 31 | FntDef.lfEscapement=0; 32 | FntDef.lfOrientation=0; 33 | FntDef.lfWeight=FW_NORMAL; 34 | FntDef.lfItalic=FALSE; 35 | FntDef.lfUnderline=FALSE; 36 | FntDef.lfStrikeOut=FALSE; 37 | FntDef.lfCharSet=DEFAULT_CHARSET; 38 | FntDef.lfOutPrecision=OUT_DEFAULT_PRECIS; 39 | FntDef.lfClipPrecision=CLIP_DEFAULT_PRECIS; 40 | FntDef.lfQuality=NONANTIALIASED_QUALITY; 41 | FntDef.lfPitchAndFamily=DEFAULT_PITCH; 42 | FntDef.lfFaceName[0]=NULL; 43 | 44 | BkCol.Red=0; 45 | BkCol.Green=0; 46 | BkCol.Blue=0; 47 | 48 | TextCol.Red=255; 49 | TextCol.Green=255; 50 | TextCol.Blue=255; 51 | 52 | GridCol.Red=170; 53 | GridCol.Green=0; 54 | GridCol.Blue=170; 55 | 56 | WidthCol.Red=170; 57 | WidthCol.Green=170; 58 | WidthCol.Blue=0; 59 | 60 | SelCol.Red=0; 61 | SelCol.Green=154; 62 | SelCol.Blue=0; 63 | } 64 | 65 | BFontMap::~BFontMap() 66 | { 67 | DeleteObject(fnt); 68 | } 69 | 70 | int BFontMap::SetSize(int Which, int NewSize) 71 | { 72 | switch(Which) 73 | { 74 | case MAPWIDTH: 75 | if(!IsPower(NewSize)) 76 | NewSize=256; 77 | 78 | MapWidth=NewSize; 79 | return MapWidth; 80 | 81 | 82 | case MAPHEIGHT: 83 | if(!IsPower(NewSize)) 84 | NewSize=256; 85 | 86 | MapHeight=NewSize; 87 | return MapHeight; 88 | 89 | 90 | case CELLWIDTH: 91 | if(NewSize<8) 92 | CellWidth=8; 93 | else if(NewSize>256) 94 | CellWidth=256; 95 | else 96 | CellWidth=NewSize; 97 | 98 | return CellWidth; 99 | 100 | 101 | case CELLHEIGHT: 102 | if(NewSize<8) 103 | CellHeight=8; 104 | else if(NewSize>256) 105 | CellHeight=256; 106 | else 107 | CellHeight=NewSize; 108 | 109 | return CellHeight; 110 | } 111 | 112 | return 0; 113 | } 114 | 115 | int BFontMap::GetSize(int Which) 116 | { 117 | switch(Which) 118 | { 119 | case MAPWIDTH: 120 | return MapWidth; 121 | 122 | case MAPHEIGHT: 123 | return MapHeight; 124 | 125 | case CELLWIDTH: 126 | return CellWidth; 127 | 128 | case CELLHEIGHT: 129 | return CellHeight; 130 | 131 | case MAXCHARS: 132 | return (MapWidth/CellWidth)*(MapHeight/CellHeight); 133 | } 134 | 135 | return 0; 136 | } 137 | 138 | unsigned char BFontMap::SetBaseChar(int NewBase) 139 | { 140 | if(NewBase<0) 141 | NewBase=0; 142 | 143 | if(NewBase>255) 144 | NewBase=255; 145 | 146 | BaseChar=NewBase; 147 | return BaseChar; 148 | } 149 | 150 | unsigned char BFontMap::GetBaseChar() 151 | { 152 | return BaseChar; 153 | } 154 | 155 | char BFontMap::SetGlobal(int Which, char Value) 156 | { 157 | switch(Which) 158 | { 159 | case VOFFSET: 160 | gVMod=Value; 161 | break; 162 | 163 | case HOFFSET: 164 | gHMod=Value; 165 | break; 166 | 167 | case WIDTH: 168 | gWidthMod=Value; 169 | break; 170 | } 171 | 172 | return Value; 173 | } 174 | 175 | char BFontMap::GetGlobal(int Which) 176 | { 177 | switch(Which) 178 | { 179 | case VOFFSET: 180 | return gVMod; 181 | 182 | case HOFFSET: 183 | return gHMod; 184 | 185 | case WIDTH: 186 | return gWidthMod; 187 | } 188 | 189 | return 0; 190 | } 191 | 192 | char BFontMap::SetCharVal(int Char, int Which, char NewVal) 193 | { 194 | switch(Which) 195 | { 196 | case WOFFSET: 197 | WidthMod[Char]=NewVal; 198 | break; 199 | 200 | case HOFFSET: 201 | HMod[Char]=NewVal; 202 | break; 203 | 204 | case VOFFSET: 205 | VMod[Char]=NewVal; 206 | break; 207 | } 208 | 209 | return NewVal; 210 | } 211 | 212 | 213 | char BFontMap::GetCharVal(int Char, int Which) 214 | { 215 | switch(Which) 216 | { 217 | case WIDTH: 218 | return BaseWidth[Char]; 219 | 220 | case HOFFSET: 221 | return HMod[Char]; 222 | 223 | case VOFFSET: 224 | return VMod[Char]; 225 | 226 | case WOFFSET: 227 | return WidthMod[Char]; 228 | 229 | case EWIDTH: 230 | return WidthMod[Char]+BaseWidth[Char]+gWidthMod; 231 | } 232 | return 0; 233 | } 234 | 235 | long BFontMap::SetFontHeight(long NewHeight) 236 | { 237 | if(NewHeight<1) 238 | NewHeight=1; 239 | if(NewHeight>256) 240 | NewHeight=256; 241 | 242 | FntDef.lfHeight=NewHeight; 243 | return FntDef.lfHeight; 244 | } 245 | 246 | long BFontMap::GetFontHeight() 247 | { 248 | return FntDef.lfHeight; 249 | } 250 | 251 | long BFontMap::SetFontWidth(long NewWidth) 252 | { 253 | if(NewWidth<0) 254 | NewWidth=0; 255 | if(NewWidth>256) 256 | NewWidth=256; 257 | 258 | 259 | FntDef.lfWidth=NewWidth; 260 | return FntDef.lfWidth; 261 | } 262 | 263 | long BFontMap::GetFontWidth() 264 | { 265 | return FntDef.lfWidth; 266 | } 267 | 268 | bool BFontMap::SetFontName(char* NewName) 269 | { 270 | if(lstrcpy(FntDef.lfFaceName,NewName)) 271 | return true; 272 | else 273 | return false; 274 | } 275 | 276 | char* BFontMap::GetFontName() 277 | { 278 | return FntDef.lfFaceName; 279 | } 280 | 281 | long BFontMap::SetFontWeight(long NewWeight) 282 | { 283 | FntDef.lfWeight=NewWeight; 284 | return FntDef.lfWeight; 285 | } 286 | 287 | long BFontMap::GetFontWeight() 288 | { 289 | return FntDef.lfWeight; 290 | } 291 | 292 | long BFontMap::SetFontQuality(long NewQual) 293 | { 294 | FntDef.lfQuality=(BYTE)NewQual; 295 | return FntDef.lfQuality; 296 | } 297 | 298 | long BFontMap::GetFontQuality() 299 | { 300 | return FntDef.lfQuality; 301 | } 302 | 303 | long BFontMap::SetFontItalic(long NewItal) 304 | { 305 | FntDef.lfItalic=(BYTE)NewItal; 306 | return FntDef.lfItalic; 307 | } 308 | 309 | long BFontMap::GetFontItalic() 310 | { 311 | return FntDef.lfItalic; 312 | } 313 | 314 | void BFontMap::SetCol(int Which, BFG_RGB NewCol) 315 | { 316 | BFG_RGB *Tgt; 317 | 318 | switch(Which) 319 | { 320 | case GRIDCOL: 321 | Tgt=&GridCol; 322 | break; 323 | 324 | case WIDTHCOL: 325 | Tgt=&WidthCol; 326 | break; 327 | 328 | case SELCOL: 329 | Tgt=&SelCol; 330 | break; 331 | 332 | case TEXTCOL: 333 | Tgt=&TextCol; 334 | break; 335 | 336 | case BACKCOL: 337 | Tgt=&BkCol; 338 | break; 339 | 340 | default: 341 | return; 342 | } 343 | 344 | Tgt->Red=NewCol.Red; 345 | Tgt->Green=NewCol.Green; 346 | Tgt->Blue=NewCol.Blue; 347 | } 348 | 349 | 350 | void BFontMap::SetCol(int Which, unsigned char Red, unsigned char Green, unsigned char Blue) 351 | { 352 | BFG_RGB *Tgt; 353 | 354 | switch(Which) 355 | { 356 | case GRIDCOL: 357 | Tgt=&GridCol; 358 | break; 359 | 360 | case WIDTHCOL: 361 | Tgt=&WidthCol; 362 | break; 363 | 364 | case SELCOL: 365 | Tgt=&SelCol; 366 | break; 367 | 368 | case TEXTCOL: 369 | Tgt=&TextCol; 370 | break; 371 | 372 | case BACKCOL: 373 | Tgt=&BkCol; 374 | break; 375 | 376 | default: 377 | return; 378 | } 379 | 380 | Tgt->Red=Red; 381 | Tgt->Green=Green; 382 | Tgt->Blue=Blue; 383 | } 384 | 385 | BFG_RGB BFontMap::GetCol(int Which) 386 | { 387 | switch(Which) 388 | { 389 | case GRIDCOL: 390 | return GridCol; 391 | break; 392 | 393 | case WIDTHCOL: 394 | return WidthCol; 395 | break; 396 | 397 | case SELCOL: 398 | return SelCol; 399 | break; 400 | 401 | case TEXTCOL: 402 | return TextCol; 403 | break; 404 | 405 | case BACKCOL: 406 | return BkCol; 407 | break; 408 | } 409 | 410 | return BkCol; // Default 411 | } 412 | 413 | bool BFontMap::CalcWidths(HDC hdc) 414 | { 415 | BOOL Test; 416 | int Letter; 417 | ABC CharWidth[256]; 418 | int nttWidth[256]; 419 | 420 | // Populate Width data 421 | Test=GetCharABCWidths(hdc,0,255,CharWidth); 422 | 423 | if(Test) 424 | { 425 | for(Letter=0;Letter!=256;Letter++) 426 | BaseWidth[Letter]=(unsigned char)(CharWidth[Letter].abcA+ 427 | CharWidth[Letter].abcB+ 428 | CharWidth[Letter].abcC); 429 | } 430 | else 431 | { 432 | // GetCharWidth32 for non truetype fonts 433 | Test=GetCharWidth32(hdc,0,255,nttWidth); 434 | 435 | if(Test) 436 | for(Letter=0;Letter!=256;Letter++) 437 | BaseWidth[Letter]=(unsigned char)nttWidth[Letter]; 438 | } 439 | 440 | return true; 441 | } 442 | 443 | 444 | HBITMAP* BFontMap::DrawFontMap(int Flags, int Sel) 445 | { 446 | HDC wDC,mDC; 447 | HBITMAP *fDIB; 448 | BITMAPINFO BMDat; 449 | HBRUSH Brush; 450 | HPEN Pen; 451 | int RowDex,ColDex,Letter; 452 | HRGN ClipRgn; 453 | RECT CharArea; 454 | char Symbol[2]; 455 | unsigned char eVal; 456 | 457 | // Create Device context 458 | wDC=CreateDC("DISPLAY",NULL,NULL,NULL); 459 | mDC=CreateCompatibleDC(wDC); 460 | 461 | if(!wDC || !mDC) 462 | return NULL; 463 | 464 | // Create bitmap for font rendering 465 | fDIB=new HBITMAP; 466 | if(!fDIB) 467 | return NULL; 468 | 469 | BMDat.bmiHeader.biSize=sizeof(BITMAPINFOHEADER); 470 | BMDat.bmiHeader.biWidth=MapWidth; 471 | BMDat.bmiHeader.biHeight=MapHeight; 472 | BMDat.bmiHeader.biPlanes=1; 473 | BMDat.bmiHeader.biBitCount=24; 474 | BMDat.bmiHeader.biCompression=BI_RGB; 475 | BMDat.bmiHeader.biSizeImage=(MapWidth*MapHeight)*3; 476 | 477 | *fDIB=CreateDIBSection(mDC,&BMDat,DIB_RGB_COLORS,NULL,NULL,0); 478 | 479 | if(!fDIB) 480 | return NULL; 481 | 482 | if(!SelectObject(mDC,*fDIB)) 483 | return NULL; 484 | 485 | // Fill background 486 | if(Flags & DFM_ALPHA) 487 | { 488 | Brush=CreateSolidBrush(RGB(0,0,0)); 489 | Pen=CreatePen(PS_SOLID,0,RGB(0,0,0)); 490 | } 491 | else 492 | { 493 | Brush=CreateSolidBrush(RGB(BkCol.Red,BkCol.Green,BkCol.Blue)); 494 | Pen=CreatePen(PS_SOLID,0,RGB(BkCol.Red,BkCol.Green,BkCol.Blue)); 495 | } 496 | 497 | SelectObject(mDC,Brush); 498 | SelectObject(mDC,Pen); 499 | 500 | Rectangle(mDC,0,0,MapWidth,MapHeight); 501 | 502 | DeleteObject(Pen); 503 | DeleteObject(Brush); 504 | 505 | // Draw Selection 506 | Pen=CreatePen(PS_SOLID,0,RGB(SelCol.Red,SelCol.Green,SelCol.Blue)); 507 | Brush=CreateSolidBrush(RGB(SelCol.Red,SelCol.Green,SelCol.Blue)); 508 | 509 | if(Sel>-1) 510 | { 511 | SelectObject(mDC,Pen); 512 | SelectObject(mDC,Brush); 513 | RowDex=(Sel/(MapWidth/CellWidth)); 514 | ColDex=(Sel-((MapWidth/CellWidth)*RowDex)); 515 | ColDex*=CellWidth; 516 | RowDex*=CellHeight; 517 | Rectangle(mDC,ColDex,RowDex,ColDex+CellWidth,RowDex+CellHeight); 518 | } 519 | 520 | DeleteObject(Brush); 521 | DeleteObject(Pen); 522 | 523 | // Draw letters 524 | // Create the font 525 | if(fnt) 526 | DeleteObject(fnt); 527 | 528 | fnt=CreateFontIndirect(&FntDef); 529 | 530 | SelectObject(mDC,fnt); 531 | 532 | CalcWidths(mDC); 533 | 534 | if(Flags & DFM_ALPHA) 535 | { 536 | SetTextColor(mDC,RGB(255,255,255)); 537 | SetBkColor(mDC,RGB(0,0,0)); 538 | } 539 | else 540 | { 541 | SetTextColor(mDC,RGB(TextCol.Red,TextCol.Green,TextCol.Blue)); 542 | SetBkColor(mDC,RGB(BkCol.Red,BkCol.Green,BkCol.Blue)); 543 | } 544 | 545 | SetBkMode(mDC,TRANSPARENT); 546 | 547 | Pen=CreatePen(PS_SOLID,0,RGB(WidthCol.Red,WidthCol.Green,WidthCol.Blue)); 548 | SelectObject(mDC,Pen); 549 | 550 | Letter=BaseChar; 551 | 552 | for(RowDex=0;RowDex<(MapHeight-CellHeight)+1;RowDex+=CellHeight) 553 | { 554 | for(ColDex=0;ColDex<(MapWidth-CellWidth)+1 && Letter<256;ColDex+=CellWidth) 555 | { 556 | // Set Clipping Region 557 | ClipRgn=CreateRectRgn(ColDex,RowDex,ColDex+CellWidth,RowDex+CellHeight); 558 | SelectClipRgn(mDC,ClipRgn); 559 | 560 | // Draw width marker 561 | if(Flags & DFM_WIDTHLINE) 562 | { 563 | eVal=BaseWidth[Letter]+WidthMod[Letter]+gWidthMod; 564 | MoveToEx(mDC,ColDex+eVal,RowDex,NULL); 565 | LineTo(mDC,ColDex+eVal,RowDex+CellHeight); 566 | } 567 | 568 | // Render Char 569 | CharArea.left=ColDex+HMod[Letter]+gHMod; 570 | CharArea.right=ColDex+CellWidth; 571 | CharArea.top=RowDex+VMod[Letter]+gVMod; 572 | CharArea.bottom=RowDex+CellHeight; 573 | wsprintf(Symbol,"%c",Letter); 574 | Letter++; 575 | DrawText(mDC,Symbol,-1,&CharArea,DT_LEFT | DT_NOPREFIX | DT_NOCLIP); 576 | 577 | 578 | // Remove clip region 579 | SelectClipRgn(mDC,NULL); 580 | DeleteObject(ClipRgn); 581 | } 582 | } 583 | 584 | DeleteObject(Pen); 585 | 586 | // Draw grid lines 587 | Pen=CreatePen(PS_SOLID,0,RGB(GridCol.Red,GridCol.Green,GridCol.Blue)); 588 | 589 | if(Flags & DFM_GRIDLINES) 590 | { 591 | SelectObject(mDC,Pen); 592 | 593 | for(RowDex=CellHeight-1;RowDexImgSize)); 992 | 993 | 994 | // Image Height 995 | while(data[datptr]!=',') 996 | ++datptr; 997 | 998 | datptr++; 999 | sscanf(&data[datptr],"%d",&(cfg->ImgSize)); 1000 | 1001 | 1002 | // Cell Width 1003 | while(data[datptr]!=',') 1004 | ++datptr; 1005 | 1006 | datptr++; 1007 | sscanf(&data[datptr],"%d",&(cfg->CellHeight)); 1008 | 1009 | 1010 | // Cell Height 1011 | while(data[datptr]!=',') 1012 | ++datptr; 1013 | 1014 | datptr++; 1015 | sscanf(&data[datptr],"%d",&(cfg->CellHeight)); 1016 | 1017 | 1018 | // Start char 1019 | while(data[datptr]!=',') 1020 | ++datptr; 1021 | 1022 | datptr++; 1023 | sscanf(&data[datptr],"%d",&(cfg->CharBase)); 1024 | 1025 | 1026 | // Font Name 1027 | while(data[datptr]!=',') 1028 | ++datptr; 1029 | 1030 | datptr++; 1031 | Index=0; 1032 | while(data[datptr]!='\n') 1033 | { 1034 | cfg->FntDef.lfFaceName[Index]=data[datptr]; 1035 | ++Index; 1036 | ++datptr; 1037 | } 1038 | cfg->FntDef.lfFaceName[Index]=NULL; 1039 | 1040 | 1041 | // Font Height 1042 | while(data[datptr]!=',') 1043 | ++datptr; 1044 | 1045 | datptr++; 1046 | sscanf(&data[datptr],"%d",&(cfg->FntDef.lfHeight)); 1047 | 1048 | 1049 | // Font Width 1050 | while(data[datptr]!=',') 1051 | ++datptr; 1052 | 1053 | datptr++; 1054 | sscanf(&data[datptr],"%d",&(cfg->FntDef.lfWidth)); 1055 | 1056 | 1057 | // Char Widths 1058 | for(Index=0;Index!=256;++Index) 1059 | { 1060 | while(data[datptr]!=',') 1061 | ++datptr; 1062 | 1063 | datptr++; 1064 | sscanf(&data[datptr],"%d",&Val); 1065 | cfg->width[Index]=Val; // Prevents stack damage 1066 | } 1067 | 1068 | 1069 | // Char X Offsets 1070 | for(Index=0;Index!=256;++Index) 1071 | { 1072 | while(data[datptr]!=',') 1073 | ++datptr; 1074 | 1075 | datptr++; 1076 | sscanf(&data[datptr],"%d",&Val); 1077 | cfg->hAdj[Index]=Val; 1078 | } 1079 | 1080 | 1081 | // Char Y Offsets 1082 | for(Index=0;Index!=256;++Index) 1083 | { 1084 | while(data[datptr]!=',') 1085 | ++datptr; 1086 | 1087 | datptr++; 1088 | sscanf(&data[datptr],"%d",&Val); 1089 | cfg->vAdj[Index]=Val; 1090 | } 1091 | 1092 | 1093 | // Global Width Offset 1094 | while(data[datptr]!=',') 1095 | ++datptr; 1096 | 1097 | datptr++; 1098 | sscanf(&data[datptr],"%d",&Val); 1099 | cfg->gwAdj=Val; 1100 | 1101 | 1102 | // Global X Offset 1103 | while(data[datptr]!=',') 1104 | ++datptr; 1105 | 1106 | datptr++; 1107 | sscanf(&data[datptr],"%d",&Val); 1108 | cfg->ghAdj=Val; 1109 | 1110 | 1111 | // Global Y Offset 1112 | while(data[datptr]!=',') 1113 | ++datptr; 1114 | 1115 | datptr++; 1116 | sscanf(&data[datptr],"%d",&Val); 1117 | cfg->gvAdj=Val; 1118 | 1119 | 1120 | // Bold Value 1121 | while(data[datptr]!=',') 1122 | ++datptr; 1123 | 1124 | datptr++; 1125 | sscanf(&data[datptr],"%d",&Val); 1126 | cfg->FntDef.lfWeight=Val; 1127 | 1128 | 1129 | // Italic Value 1130 | while(data[datptr]!=',') 1131 | ++datptr; 1132 | 1133 | datptr++; 1134 | sscanf(&data[datptr],"%d",&Val); 1135 | cfg->FntDef.lfItalic=Val; 1136 | 1137 | 1138 | // AntiAlias Value 1139 | while(data[datptr]!=',') 1140 | ++datptr; 1141 | 1142 | datptr++; 1143 | sscanf(&data[datptr],"%d",&Val); 1144 | cfg->FntDef.lfQuality=Val; 1145 | 1146 | 1147 | delete [] data;*/ 1148 | 1149 | return TRUE; 1150 | } 1151 | 1152 | 1153 | bool BFontMap::ExportCSVData(char *fname) 1154 | { 1155 | ofstream out; 1156 | int Loop; 1157 | 1158 | out.open(fname, ios::out | ios::trunc); 1159 | if(out.fail()) 1160 | return false; 1161 | 1162 | out<<"Image Width,"<=2.0f) 1245 | { 1246 | if(Val==2.0f) 1247 | Ret=TRUE; 1248 | 1249 | Val=Val/2.0f; 1250 | } 1251 | 1252 | return Ret; 1253 | } -------------------------------------------------------------------------------- /source/FontMapClass.h: -------------------------------------------------------------------------------- 1 | #ifndef _FONTMAPCLASS_H 2 | #define _FONTMAPCLASS_H 3 | 4 | #include 5 | #include "cbfgdefs.h" 6 | #include "UtilFunctions.h" 7 | 8 | class BFontMap 9 | { 10 | public: 11 | BFontMap(); 12 | ~BFontMap(); 13 | int GetSize(int Which); 14 | int SetSize(int Which, int NewSize); 15 | unsigned char GetBaseChar(); 16 | unsigned char SetBaseChar(int); 17 | char GetGlobal(int Which); 18 | char SetGlobal(int Which, char NewVal); 19 | char GetCharVal(int Char, int Which); 20 | char SetCharVal(int Char, int Which, char NewVal ); 21 | long GetFontHeight(); 22 | long SetFontHeight(long); 23 | long GetFontWidth(); 24 | long SetFontWidth(long); 25 | long GetFontWeight(); 26 | long SetFontWeight(long); 27 | long GetFontQuality(); 28 | long SetFontQuality(long); 29 | long GetFontItalic(); 30 | long SetFontItalic(long); 31 | char* GetFontName(); 32 | bool SetFontName(char*); 33 | bool CalcWidths(HDC); 34 | HBITMAP* DrawFontMap(int Flags, int Sel); 35 | 36 | int LoadConfig(char *fname); 37 | bool SaveConfig(char *fname, bool Grid, bool Width); 38 | void ResetOffsets(); 39 | 40 | bool SaveFont(int Format, char *fname, int Flags=0); 41 | int ExportMap(char* fname, int fmt); 42 | bool ImportData(char *fname); 43 | 44 | void SetCol(int Which, BYTE Red, BYTE Green, BYTE Blue); 45 | void SetCol(int Which, BFG_RGB Col); 46 | BFG_RGB GetCol(int Which); 47 | 48 | private: 49 | LOGFONT FntDef; 50 | HFONT fnt; 51 | int MapWidth,MapHeight; 52 | int CellHeight,CellWidth; 53 | unsigned char BaseChar; 54 | unsigned char BaseWidth[256]; 55 | char WidthMod[256]; 56 | char VMod[256]; 57 | char HMod[256]; 58 | char gWidthMod,gHMod,gVMod; 59 | BFG_RGB BkCol,TextCol,GridCol,WidthCol,SelCol; 60 | 61 | bool IsPower(int TestVal); 62 | bool SaveBFF2(char *fname, char OutputBPP, bool Invert, bool RGBSat); 63 | bool ExportCSVData(char *fname); 64 | bool ExportBinData(char *fname); 65 | }; 66 | 67 | #endif -------------------------------------------------------------------------------- /source/PreviewProc.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Procs.h" 3 | #include "CBFGDefs.h" 4 | #include "FontMapClass.h" 5 | #include "SBM-Util.h" 6 | #include 7 | #include 8 | 9 | GLuint TexName; 10 | HDC glDC; 11 | HGLRC glRC; 12 | HWND hGL; 13 | 14 | extern HINSTANCE G_Inst; 15 | extern HWND hMain; 16 | extern BFontMap *Fnt; 17 | extern AppInfo *info; 18 | 19 | BOOL CALLBACK PreviewWinProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) 20 | { 21 | int nLines,Loop,chLoop,offset; 22 | int CurX,CurY; 23 | float RowFactor,ColFactor,U,V; 24 | int SrcCol,SrcRow,RowPitch; 25 | unsigned char Text[255]; 26 | HBITMAP *hBMP; 27 | DIBSECTION bmInfo; 28 | SBM_Image FntImg; 29 | RECT glRect; 30 | BFG_RGB BkCol; 31 | WORD BufSz=1023; 32 | LRESULT lTxt; 33 | 34 | PIXELFORMATDESCRIPTOR pfd, *ppfd; 35 | int pixelformat; 36 | 37 | static char PText[1024]; 38 | char Sample[13][128] = {{"THE QUICK BROWN FOX JUMPS OVER A LAZY DOG"}, 39 | {"JACKDAWS LOVE MY BIG SPHINX OF QUARTZ"}, 40 | {"QUICK WAFTING ZEPHYRS VEX BOLD JIM"}, 41 | {"PACK MY BOX WITH FIVE DOZEN LIQUOR JUGS"}, 42 | {"SIX BIG DEVILS FROM JAPAN QUICKLY FORGOT HOW TO WALTZ"}, 43 | {"CRAZY FREDERICKA BOUGHT MANY VERY EXQUISITE OPAL JEWELS"}, 44 | {"FEW QUIPS GALVANIZED THE MOCK JURY BOX"}, 45 | {"THE FIVE BOXING WIZARDS JUMP QUICKLY"}, 46 | {"A SHORT BRIMLESS FELT HAT BARELY BLOCKS OUT THE SOUND OF A CELTIC VIOLIN"}, 47 | {"BEING BOUNCED AROUND QUICKLY ANNOYED THE DISHEVELED TAXI DRIVERS"}, 48 | {"MY GIRL WOVE SIX DOZEN PLAID JACKETS BEFORE SHE QUIT"}, 49 | {"SIXTY ZIPPERS WERE QUICKLY PICKED FROM THE WOVEN JUTE BAG"}, 50 | {"MY FAXED JOKE WON A PAGER IN THE CABLE TV QUIZ SHOW"}}; 51 | 52 | switch(msg) 53 | { 54 | case WM_INITDIALOG: 55 | // Init random text string 56 | if(!lstrlen(PText)) 57 | { 58 | srand((unsigned)time(NULL)); 59 | offset=rand()%13; 60 | lstrcpy(PText,&Sample[offset][0]); 61 | } 62 | 63 | // Limit text length 64 | SendDlgItemMessage(hDlg,TXT_PREVIEW,EM_LIMITTEXT,254,0); 65 | 66 | // Init GL Window 67 | hGL=GetDlgItem(hDlg,IDC_GL); 68 | glDC=GetDC(hGL); 69 | if(glDC==NULL) 70 | MessageBox(NULL,"GetDC failed","Error",MB_OK); 71 | 72 | ppfd = &pfd; 73 | ZeroMemory(ppfd,sizeof(PIXELFORMATDESCRIPTOR)); 74 | 75 | ppfd->nSize = sizeof(PIXELFORMATDESCRIPTOR); 76 | ppfd->nVersion = 1; 77 | ppfd->dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL | PFD_DOUBLEBUFFER; 78 | ppfd->dwLayerMask = PFD_MAIN_PLANE; 79 | ppfd->iPixelType = PFD_TYPE_RGBA; 80 | ppfd->cColorBits = 32; 81 | ppfd->cDepthBits = 8; 82 | ppfd->cAccumBits = 0; 83 | ppfd->cStencilBits = 0; 84 | 85 | pixelformat=ChoosePixelFormat(glDC,ppfd); 86 | 87 | if(pixelformat==0) 88 | { 89 | MessageBox(NULL,"ChoosePixelFormat failed", "Error", MB_OK); 90 | return FALSE; 91 | } 92 | 93 | if(SetPixelFormat(glDC,pixelformat,ppfd)==FALSE) 94 | { 95 | MessageBox(NULL, "SetPixelFormat failed", "Error", MB_OK); 96 | return FALSE; 97 | } 98 | 99 | glRC=wglCreateContext(glDC); 100 | wglMakeCurrent(glDC, glRC); 101 | 102 | glEnable(GL_TEXTURE_2D); 103 | 104 | // Build Texture 105 | hBMP=Fnt->DrawFontMap(FALSE,-1); 106 | GetObject(*hBMP,sizeof(DIBSECTION),&bmInfo); 107 | FntImg.Create(Fnt->GetSize(MAPWIDTH),Fnt->GetSize(MAPHEIGHT),24); 108 | memcpy(FntImg.GetImg(),bmInfo.dsBm.bmBits,(Fnt->GetSize(MAPWIDTH)*Fnt->GetSize(MAPHEIGHT)*3)); 109 | FntImg.FlipImg(); 110 | 111 | glGenTextures(1,&TexName); 112 | glBindTexture(GL_TEXTURE_2D,TexName); 113 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); 114 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); 115 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_S,0x812F); 116 | glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_WRAP_T,0x812F); 117 | glTexImage2D(GL_TEXTURE_2D,0,GL_RGB,Fnt->GetSize(MAPWIDTH),Fnt->GetSize(MAPHEIGHT),0,GL_BGR_EXT,GL_UNSIGNED_BYTE,FntImg.GetImg()); 118 | 119 | DeleteObject(*hBMP); 120 | SendDlgItemMessage(hDlg,TXT_PREVIEW,WM_SETTEXT,0,(LPARAM)PText); 121 | return 0; 122 | 123 | 124 | case WM_APP: 125 | CurX=CurY=0; 126 | 127 | GetClientRect(hGL,&glRect); 128 | glViewport(0,0,glRect.right,glRect.bottom); 129 | BkCol=Fnt->GetCol(BACKCOL); 130 | glClearColor(((float)BkCol.Red/255.0f),((float)BkCol.Green/255.0f),((float)BkCol.Blue/255.0f),0.0f); 131 | 132 | glMatrixMode(GL_PROJECTION); 133 | glLoadIdentity(); 134 | glOrtho(0.0f,glRect.right,glRect.bottom,0.0f,-10.0f,10.0f); 135 | glMatrixMode(GL_MODELVIEW); 136 | glLoadIdentity(); 137 | 138 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); 139 | 140 | nLines=SendDlgItemMessage(hDlg,TXT_PREVIEW,EM_GETLINECOUNT,0,0); 141 | 142 | RowPitch=Fnt->GetSize(MAPWIDTH)/Fnt->GetSize(CELLWIDTH); 143 | RowFactor=(float)Fnt->GetSize(CELLHEIGHT)/(float)Fnt->GetSize(MAPHEIGHT); 144 | ColFactor=(float)Fnt->GetSize(CELLWIDTH)/(float)Fnt->GetSize(MAPWIDTH); 145 | 146 | glBegin(GL_QUADS); 147 | for(Loop=0;Loop!=nLines;++Loop) 148 | { 149 | Text[0]=0xFF; 150 | Text[1]=0; 151 | lTxt=SendDlgItemMessage(hDlg,TXT_PREVIEW,EM_GETLINE,Loop,(LPARAM)Text); 152 | Text[lTxt]=NULL; 153 | 154 | for(chLoop=0;chLoop!=lTxt;++chLoop) 155 | { 156 | SrcRow=(Text[chLoop]-Fnt->GetBaseChar())/RowPitch; 157 | SrcCol=(Text[chLoop]-Fnt->GetBaseChar())-(SrcRow*RowPitch); 158 | U=ColFactor*SrcCol; 159 | V=RowFactor*SrcRow; 160 | 161 | glTexCoord2f(U,V); glVertex2i(CurX,CurY); 162 | glTexCoord2f(U+ColFactor,V); glVertex2i(CurX+Fnt->GetSize(CELLWIDTH),CurY); 163 | glTexCoord2f(U+ColFactor,V+RowFactor); glVertex2i(CurX+Fnt->GetSize(CELLWIDTH),CurY+Fnt->GetSize(CELLHEIGHT)); 164 | glTexCoord2f(U,V+RowFactor); glVertex2i(CurX,CurY+Fnt->GetSize(CELLHEIGHT)); 165 | CurX+=Fnt->GetCharVal(Text[chLoop],EWIDTH); 166 | } 167 | CurX=0; 168 | CurY+=Fnt->GetSize(CELLHEIGHT); 169 | } 170 | 171 | glEnd(); 172 | 173 | SwapBuffers(glDC); 174 | return 0; 175 | 176 | case WM_DRAWITEM: 177 | if(wParam==IDC_GL) 178 | { 179 | SendMessage(hDlg,WM_APP,0,0); 180 | } 181 | return TRUE; 182 | 183 | case WM_CLOSE: 184 | SendDlgItemMessage(hDlg,TXT_PREVIEW,WM_GETTEXT,1024,(LPARAM)PText); 185 | EndDialog(hDlg,0); 186 | return 0; 187 | 188 | case WM_COMMAND: 189 | { 190 | switch(HIWORD(wParam)) 191 | { 192 | case EN_CHANGE: 193 | SendMessage(hDlg,WM_APP,0,0); 194 | return 0; 195 | } 196 | 197 | switch(LOWORD(wParam)) // Buttons & Menu items 198 | { 199 | case CMD_OK: 200 | SendDlgItemMessage(hDlg,TXT_PREVIEW,WM_GETTEXT,1024,(LPARAM)PText); 201 | wglDeleteContext(glRC); 202 | EndDialog(hDlg,0); 203 | return 0; 204 | 205 | case CMD_TEST_CLEAR: 206 | SendDlgItemMessage(hDlg,TXT_PREVIEW,WM_SETTEXT,0,(LPARAM)""); 207 | SendMessage(hDlg,WM_APP,0,0); 208 | return 0; 209 | 210 | case CMD_TEST_PANGRAM: 211 | offset=rand()%13; 212 | SendDlgItemMessage(hDlg,TXT_PREVIEW,WM_SETTEXT,0,(LPARAM)&Sample[offset][0]); 213 | SendMessage(hDlg,WM_APP,0,0); 214 | return 0; 215 | } 216 | 217 | } 218 | 219 | default: 220 | return 0; 221 | } 222 | } -------------------------------------------------------------------------------- /source/Procs.h: -------------------------------------------------------------------------------- 1 | #ifndef _PROCS_H 2 | #define _PROCS_H 3 | 4 | BOOL CALLBACK SplashWinProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam); 5 | BOOL CALLBACK MainProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam); 6 | BOOL CALLBACK TextWinProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam); 7 | BOOL CALLBACK ConfigWinProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam); 8 | BOOL CALLBACK PreviewWinProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam); 9 | BOOL CALLBACK AboutProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam); 10 | BOOL CALLBACK SaveOptProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam); 11 | 12 | #endif -------------------------------------------------------------------------------- /source/SBM-Util.cpp: -------------------------------------------------------------------------------- 1 | #include "StdAfx.h" 2 | #include "SBM-Util.h" 3 | 4 | SBM_Image::SBM_Image() 5 | { 6 | Width=Height=0; 7 | FileSize=ImageSize=0; 8 | BPP=Encode=0; 9 | ImgData=PalData=FileData=NULL; 10 | } 11 | 12 | SBM_Image::~SBM_Image() 13 | { 14 | FreeMem((void**)&ImgData); 15 | FreeMem((void**)&PalData); 16 | FreeMem((void**)&FileData); 17 | } 18 | 19 | // Create an empty image with specified size and colour depth 20 | int SBM_Image::Create(int width, int height, int bpp) 21 | { 22 | switch(bpp) 23 | { 24 | case 24: 25 | case 32: 26 | FreeMem((void**)&ImgData); 27 | FreeMem((void**)&PalData); 28 | FreeMem((void**)&FileData); 29 | 30 | ImgData=new unsigned char[(width*height)*(bpp/8)]; 31 | 32 | if(ImgData==NULL) 33 | return SBM_ERR_MEM_FAIL; 34 | 35 | Width=width; 36 | Height=height; 37 | BPP=bpp; 38 | 39 | break; 40 | 41 | default: 42 | return SBM_ERR_UNSUPPORTED; 43 | } 44 | 45 | return SBM_OK; 46 | } 47 | 48 | void SBM_Image::Reset() 49 | { 50 | Width=Height=0; 51 | FileSize=ImageSize=0; 52 | BPP=Encode=0; 53 | 54 | FreeMem((void**)&ImgData); 55 | FreeMem((void**)&PalData); 56 | FreeMem((void**)&FileData); 57 | } 58 | 59 | // Get file into memory, find extension and call relevant loader 60 | int SBM_Image::Load(char* filename) 61 | { 62 | bool MyStrCmp(char* Str1, char* Str2); 63 | 64 | ifstream In; 65 | char *StrPtr; 66 | int RetVal; 67 | 68 | // Clear any existing image 69 | FreeMem((void**)&ImgData); 70 | FreeMem((void**)&PalData); 71 | FreeMem((void**)&FileData); 72 | 73 | // Open the specified file 74 | In.open(filename,ios::binary); 75 | 76 | if(!In) 77 | return SBM_ERR_NO_FILE; 78 | 79 | // Get file size 80 | In.seekg(0,ios_base::end); 81 | FileSize=In.tellg(); 82 | In.seekg(0,ios_base::beg); 83 | 84 | // Allocate some space 85 | FileData=new unsigned char[FileSize]; 86 | 87 | if(FileData==NULL) 88 | { 89 | In.close(); 90 | return SBM_ERR_MEM_FAIL; 91 | } 92 | 93 | // Read the file into memory 94 | In.read((char*)FileData,FileSize); 95 | In.close(); 96 | 97 | 98 | StrPtr=filename; 99 | 100 | while(*StrPtr!=NULL) // Seek end of string 101 | ++StrPtr; 102 | 103 | while(*StrPtr!='.') // Wind back to first '.' 104 | { 105 | if(StrPtr==filename) // Prevent rewind past start of filename 106 | return SBM_ERR_UNSUPPORTED; 107 | 108 | --StrPtr; 109 | } 110 | 111 | // Check extensions and call loader 112 | if(MyStrCmp(StrPtr,".bmp")) 113 | { 114 | return LoadBMP(); 115 | } 116 | else if(MyStrCmp(StrPtr,".pcx")) 117 | { 118 | return LoadPCX(); 119 | } 120 | else if(MyStrCmp(StrPtr,".tga")) 121 | { 122 | RetVal=LoadTGA(); 123 | } 124 | else if(MyStrCmp(StrPtr,".sbm")) 125 | { 126 | return LoadSBM(); 127 | } 128 | else 129 | { 130 | return SBM_ERR_UNSUPPORTED; 131 | } 132 | 133 | // Free the filedata memory 134 | FreeMem((void**)&FileData); 135 | 136 | if(RetVal!=SBM_OK) 137 | return RetVal; 138 | 139 | return SBM_OK; 140 | } 141 | 142 | 143 | bool MyStrCmp(char* Str1, char* Str2) // Case insenstive string comparison 144 | { 145 | while((*Str1 > 96 ? *Str1-32 : *Str1)==(*Str2 > 96 ? *Str2-32 : *Str2)) 146 | { 147 | if(*Str1==NULL) 148 | return 1; 149 | Str1++; 150 | Str2++; 151 | } 152 | return 0; 153 | } 154 | 155 | 156 | int SBM_Image::LoadBMP() 157 | { 158 | int iRet; 159 | 160 | // Process the header 161 | iRet=ReadBMPHeader(); 162 | 163 | if(iRet!=SBM_OK) 164 | return iRet; 165 | 166 | if(BPP<8) // We'll only bother with 8 bit and above 167 | return SBM_ERR_UNSUPPORTED; 168 | 169 | // Get the image data 170 | switch(Encode) 171 | { 172 | case 0: // Uncompressed 173 | iRet=LoadBMPRawData(); // 8 / 24 Bit. (24 bit is in BGR order) 174 | BGRtoRGB(); 175 | break; 176 | 177 | case 1: // RLE 8 (Indexed 256 colour only) 178 | iRet=LoadBMPRLE8Data(); 179 | break; 180 | 181 | case 2: // RLE 4 (16 Colour indexed, Outdated, not covered here) 182 | return SBM_ERR_UNSUPPORTED; 183 | 184 | case 3: // Bitfields (16/32 bit only, Rare, not covered here) 185 | return SBM_ERR_UNSUPPORTED; 186 | 187 | default: 188 | return SBM_ERR_UNSUPPORTED; 189 | } 190 | 191 | if(iRet!=SBM_OK) 192 | return iRet; 193 | 194 | // Flip image to correct scanline reversal 195 | FlipImg(); 196 | 197 | // Load palette if present 198 | iRet=LoadBMPPalette(); 199 | 200 | if(iRet!=SBM_OK) 201 | return iRet; 202 | 203 | return SBM_OK; 204 | } 205 | 206 | 207 | int SBM_Image::ReadBMPHeader() 208 | { 209 | int iInfo,iImgOffset,iEnc; 210 | unsigned int iWidth,iHeight; 211 | short iPlanes,iBPP; 212 | 213 | if(FileData==NULL) 214 | return SBM_ERR_NO_FILE; 215 | 216 | if(FileData[0x0]!='B' || FileData[0x1]!='M') // BMP ID Bytes, should be 'BM' 217 | return SBM_ERR_BAD_FORMAT; 218 | 219 | memcpy(&iImgOffset,&FileData[0xA],4); // Offset to image data 220 | Offset=iImgOffset; 221 | 222 | memcpy(&iInfo,&FileData[0xE],4); // Info header size, should be 0x28 223 | if(iInfo!=0x28) 224 | return SBM_ERR_BAD_FORMAT; 225 | 226 | memcpy(&iWidth,&FileData[0x12],4); // Image width 227 | Width=(short)iWidth; 228 | memcpy(&iHeight,&FileData[0x16],4); // Image height 229 | Height=(short)iHeight; 230 | memcpy(&iPlanes,&FileData[0x1A],2); // Colour planes 231 | Planes=(char)iPlanes; 232 | memcpy(&iBPP,&FileData[0x1C],2); // BPP 233 | BPP=(char)iBPP; 234 | memcpy(&iEnc,&FileData[0x1E],4); // Encoding 235 | Encode=(char)iEnc; 236 | 237 | ImageSize=(iWidth*iHeight*(iBPP/8)); // Calculate Image Data size 238 | 239 | return SBM_OK; 240 | } 241 | 242 | 243 | int SBM_Image::LoadBMPRawData() 244 | { 245 | FreeMem((void**)&ImgData); 246 | 247 | // Allocate space for the image data 248 | ImgData=new unsigned char[ImageSize]; 249 | 250 | if(ImgData==NULL) 251 | return SBM_ERR_MEM_FAIL; 252 | 253 | memcpy(ImgData,&FileData[Offset],ImageSize); 254 | 255 | return SBM_OK; 256 | } 257 | 258 | 259 | int SBM_Image::LoadBMPRLE8Data() 260 | { 261 | unsigned char bOpCode,bVal; 262 | unsigned char *pSrc; 263 | int iDcode=1,iCount,iPos; 264 | unsigned long iIndex; 265 | 266 | FreeMem((void**)ImgData); 267 | 268 | ImgData=new unsigned char[ImageSize]; 269 | 270 | if(ImgData==NULL) 271 | return SBM_ERR_MEM_FAIL; 272 | 273 | // Get the start of the RLE data 274 | pSrc=&FileData[Offset]; 275 | 276 | iPos=0; 277 | iIndex=0; 278 | 279 | while(iDcode) 280 | { 281 | // Stay on even bytes 282 | while(iPos%2) 283 | { 284 | iPos++; 285 | } 286 | 287 | bOpCode=pSrc[iPos]; 288 | bVal=pSrc[iPos+1]; 289 | iPos+=2; 290 | 291 | if(bOpCode>0) // Run mode, Repeat 'bVal' 'OpCode' times 292 | { 293 | for(iCount=0;iCount!=bOpCode;iCount++) 294 | { 295 | ImgData[iIndex]=bVal; 296 | ++iIndex; 297 | } 298 | } 299 | else // Absolute Mode (Opcode=0), various options 300 | { 301 | switch(bVal) 302 | { 303 | case 0: // EOL, no action 304 | break; 305 | 306 | case 1: // EOF, STOP! 307 | iDcode=0; 308 | break; 309 | 310 | case 2: // Reposition, Never used 311 | break; 312 | 313 | default: // Copy the next 'bVal' bytes direct to the image 314 | for(iCount=bVal;iCount!=0;iCount--) 315 | { 316 | ImgData[iIndex]=pSrc[iPos]; 317 | ++iIndex; 318 | ++iPos; 319 | } 320 | break; 321 | } 322 | 323 | } 324 | 325 | if(iIndex>ImageSize) // Stop if image size exceeded. 326 | iDcode=0; 327 | } 328 | 329 | return SBM_OK; 330 | } 331 | 332 | 333 | int SBM_Image::LoadBMPPalette() 334 | { 335 | int iIndex; 336 | unsigned char *pPalPos, *pDatPos; 337 | 338 | FreeMem((void**)&PalData); 339 | 340 | if(BPP>8) // NULL Palette for RGB images 341 | return SBM_OK; 342 | 343 | // Create space for palette 344 | PalData=new unsigned char[768]; 345 | 346 | if(PalData==NULL) 347 | return SBM_ERR_MEM_FAIL; 348 | 349 | // Set starting position for pointers 350 | pPalPos=PalData; 351 | pDatPos=&FileData[0x36]; 352 | 353 | // Get colour values, skip redundant 4th value 354 | for(iIndex=0;iIndex!=256;++iIndex) 355 | { 356 | pPalPos[0]=pDatPos[2]; // Red 357 | pPalPos[1]=pDatPos[1]; // Green 358 | pPalPos[2]=pDatPos[0]; // Blue 359 | 360 | pPalPos+=3; 361 | pDatPos+=4; 362 | } 363 | 364 | return SBM_OK; 365 | } 366 | 367 | int SBM_Image::SaveBMP(char* fname) 368 | { 369 | ofstream out; 370 | int Res=SBM_ERR_UNSUPPORTED; 371 | DWORD Data; 372 | WORD wData; 373 | 374 | switch(BPP) 375 | { 376 | case 24: 377 | out.open(fname,ios::binary | ios::trunc); 378 | if(out.fail()) 379 | { 380 | Res=SBM_ERR_NO_FILE; 381 | break; 382 | } 383 | 384 | // Write ID 385 | out.write("BM",2); 386 | 387 | // Write filesize 388 | Data=/*0x436*/54+((Width*Height)*(BPP/8)); 389 | out.write((char*)&Data,4); 390 | 391 | // Write reserved area 392 | Data=0; 393 | out.write((char*)&Data,4); 394 | 395 | // Write offset 396 | Data=0x36; 397 | out.write((char*)&Data,4); 398 | 399 | // Write header size 400 | Data=0x28; 401 | out.write((char*)&Data,4); 402 | 403 | // Write width 404 | Data=Width; 405 | out.write((char*)&Data,4); 406 | 407 | // Write height 408 | Data=Height; 409 | out.write((char*)&Data,4); 410 | 411 | // Write planes 412 | wData=1; 413 | out.write((char*)&wData,2); 414 | 415 | // Write BPP 416 | wData=BPP; 417 | out.write((char*)&wData,2); 418 | 419 | // Write Compression 420 | Data=0; 421 | out.write((char*)&Data,4); 422 | 423 | // Write data size 424 | Data=(Width*Height)*(BPP/8); 425 | out.write((char*)&Data,4); 426 | 427 | // Write Resolutions and Colors 428 | Data=0; 429 | out.write((char*)&Data,4); 430 | out.write((char*)&Data,4); 431 | out.write((char*)&Data,4); 432 | out.write((char*)&Data,4); 433 | 434 | // Write image data 435 | out.write((char*)ImgData,(Width*Height)*(BPP/8)); 436 | 437 | out.close(); 438 | 439 | Res=SBM_OK; 440 | break; 441 | 442 | default: 443 | Res=SBM_ERR_UNSUPPORTED; 444 | break; 445 | } 446 | 447 | return Res; 448 | } 449 | 450 | 451 | int SBM_Image::LoadPCX() 452 | { 453 | int iRet; 454 | 455 | if(FileData==NULL) 456 | return SBM_ERR_NO_FILE; 457 | 458 | // Process the header 459 | iRet=ReadPCXHeader(); 460 | 461 | if(iRet!=SBM_OK) 462 | return iRet; 463 | 464 | if(BPP!=8) // We'll only bother with 8 bit indexed and 24 bit RGB images 465 | return SBM_ERR_UNSUPPORTED; 466 | 467 | if(Encode!=1) // We only know about RLE compressed images 468 | return SBM_ERR_UNSUPPORTED; 469 | 470 | // Get the image data 471 | iRet=LoadPCXRLEData(); 472 | 473 | if(iRet!=SBM_OK) 474 | return iRet; 475 | 476 | // Load palette if present 477 | iRet=LoadPCXPalette(); 478 | 479 | if(iRet!=SBM_OK) 480 | return iRet; 481 | 482 | // Update the BPP value to reflect the image format 483 | BPP*=Planes; 484 | 485 | return SBM_OK; 486 | } 487 | 488 | 489 | int SBM_Image::ReadPCXHeader() 490 | { 491 | int x1,x2,y1,y2; 492 | 493 | if(FileData==NULL) 494 | return SBM_ERR_NO_FILE; 495 | 496 | if(FileData[0]!=0xA) // PCX ID Byte, should be 0xA 497 | return SBM_ERR_BAD_FORMAT; 498 | 499 | if(FileData[1]>5) // Version, we don't know about anything after v5 500 | return SBM_ERR_UNSUPPORTED; 501 | 502 | Encode=FileData[2]; // Encode flag 1 = RLE Compression 503 | 504 | if(FileData[3]==1 || FileData[3]==2 || FileData[3]==4 || FileData[3]==8) // BPP value 505 | BPP=FileData[3]; 506 | else 507 | return SBM_ERR_BAD_FORMAT; 508 | 509 | // Get image window and produce width & height values 510 | memcpy(&x1,&FileData[4],2); 511 | memcpy(&y1,&FileData[6],2); 512 | memcpy(&x2,&FileData[8],2); 513 | memcpy(&y2,&FileData[10],2); 514 | 515 | Width=(x2-x1)+1; 516 | Height=(y2-y1)+1; 517 | 518 | if(Width<1 || Height<1) 519 | return SBM_ERR_BAD_FORMAT; 520 | 521 | // Planes byte. 1 = Indexed, 3 = RGB 522 | Planes=FileData[65]; 523 | 524 | // Bits per line for decoding purposes, 525 | memcpy(&BPL,&FileData[66],2); 526 | 527 | return SBM_OK; 528 | } 529 | 530 | 531 | int SBM_Image::LoadPCXRLEData() 532 | { 533 | int iLineCount,iBufferLineLen,iImageLineLen; 534 | long lLinePos=0; 535 | unsigned char bRunLen; 536 | unsigned char *pCur,*pLine,*pInterLine; 537 | 538 | // Set our pointer to the beginning of the image data 539 | pCur=&FileData[128]; 540 | 541 | // Calculate line lengths for image and buffer, Allocate the buffer scan line 542 | iBufferLineLen=BPL*Planes; 543 | iImageLineLen =Width*Planes; 544 | pLine=new unsigned char[iBufferLineLen]; 545 | 546 | if(pLine==NULL) 547 | return SBM_ERR_MEM_FAIL; 548 | 549 | FreeMem((void**)&ImgData); 550 | 551 | ImgData=new unsigned char[(iImageLineLen * Height)+1]; 552 | 553 | if(ImgData==NULL) 554 | return SBM_ERR_MEM_FAIL; 555 | 556 | // Decode each scanline 557 | for(iLineCount=0;iLineCount 0xC0) // First 2 bits indicate run of next byte value 563 | { 564 | bRunLen=*pCur & 0x3F; // Remaining 6 bits indicate run length 565 | ++pCur; // Repeated value 566 | for( ;bRunLen!=0;bRunLen--,lLinePos++) 567 | pLine[lLinePos]=*pCur; 568 | 569 | ++pCur; 570 | } 571 | else 572 | { 573 | pLine[lLinePos]=*pCur; // Other bytes are directly copied 574 | ++lLinePos; 575 | ++pCur; 576 | } 577 | } 578 | 579 | // Once we've decoded a line, copy it to the image. 580 | // This disregards any end-of-line padding inserted during the compression 581 | 582 | if(Planes==1) // 8 bit images, straight copy 583 | { 584 | memcpy(&ImgData[iLineCount*iImageLineLen],pLine,iImageLineLen); 585 | } 586 | else if(Planes==3) // for 24 bit, We have to interleave the RGB values 587 | { 588 | pInterLine=&ImgData[iLineCount*iImageLineLen]; 589 | for(lLinePos=0;lLinePos!=Width;++lLinePos,pInterLine+=3) 590 | { 591 | pInterLine[0]=pLine[lLinePos]; 592 | pInterLine[1]=pLine[lLinePos+Width]; 593 | pInterLine[2]=pLine[lLinePos+(Width*2)]; 594 | } 595 | } 596 | 597 | } 598 | 599 | return SBM_OK; 600 | } 601 | 602 | 603 | int SBM_Image::LoadPCXPalette() 604 | { 605 | // Load a 256 color palette 606 | 607 | FreeMem((void**)&PalData); 608 | 609 | if(Planes==3) // NULL Palette for RGB images 610 | return SBM_OK; 611 | 612 | // Create space for palette 613 | PalData=new unsigned char[768]; 614 | 615 | if(PalData==NULL) 616 | return SBM_ERR_MEM_FAIL; 617 | 618 | // Start of palette entries should be 769 bytes back from the end of the file 619 | // First byte is 0x0C 620 | if(FileData[FileSize-769]!=0x0C) 621 | return SBM_ERR_BAD_FORMAT; 622 | 623 | memcpy(PalData,&FileData[FileSize-768],768); 624 | 625 | return SBM_OK; 626 | } 627 | 628 | 629 | int SBM_Image::SavePCX(char* fname) 630 | { 631 | return SBM_ERR_UNSUPPORTED; 632 | } 633 | 634 | 635 | int SBM_Image::LoadTGA() 636 | { 637 | int iRet,ImageType,ImgDataOffset; 638 | 639 | iRet=ReadTGAHeader(); 640 | 641 | if(iRet!=SBM_OK) 642 | return iRet; 643 | 644 | ImgDataOffset=FileData[0]; 645 | ImageType=FileData[1]; 646 | 647 | switch(Encode) 648 | { 649 | case 1: // Raw Indexed 650 | { 651 | // Check filesize against header values 652 | if((ImageSize+18+ImgDataOffset+768)>FileSize) 653 | return SBM_ERR_BAD_FORMAT; 654 | 655 | // Double check image type field 656 | if(ImageType!=1) 657 | return SBM_ERR_BAD_FORMAT; 658 | 659 | // Load image data 660 | iRet=LoadTGARawData(); 661 | if(iRet!=SBM_OK) 662 | return iRet; 663 | 664 | // Load palette 665 | iRet=LoadTGAPalette(); 666 | if(iRet!=SBM_OK) 667 | return iRet; 668 | 669 | break; 670 | } 671 | 672 | case 2: // Raw RGB 673 | { 674 | // Check filesize against header values 675 | if((ImageSize+18+ImgDataOffset)>FileSize) 676 | return SBM_ERR_BAD_FORMAT; 677 | 678 | // Double check image type field 679 | if(ImageType!=0) 680 | return SBM_ERR_BAD_FORMAT; 681 | 682 | // Load image data 683 | iRet=LoadTGARawData(); 684 | if(iRet!=SBM_OK) 685 | return iRet; 686 | 687 | BGRtoRGB(); // Convert to RGB 688 | break; 689 | } 690 | 691 | case 9: // RLE Indexed 692 | { 693 | // Double check image type field 694 | if(ImageType!=1) 695 | return SBM_ERR_BAD_FORMAT; 696 | 697 | // Load image data 698 | iRet=LoadTGARLEData(); 699 | if(iRet!=SBM_OK) 700 | return iRet; 701 | 702 | // Load palette 703 | iRet=LoadTGAPalette(); 704 | if(iRet!=SBM_OK) 705 | return iRet; 706 | 707 | break; 708 | } 709 | 710 | case 10: // RLE RGB 711 | { 712 | // Double check image type field 713 | if(ImageType!=0) 714 | return SBM_ERR_BAD_FORMAT; 715 | 716 | // Load image data 717 | iRet=LoadTGARLEData(); 718 | if(iRet!=SBM_OK) 719 | return iRet; 720 | 721 | BGRtoRGB(); // Convert to RGB 722 | break; 723 | } 724 | 725 | default: 726 | return SBM_ERR_UNSUPPORTED; 727 | } 728 | 729 | // Check flip bit 730 | if((FileData[17] & 0x20)==0) 731 | FlipImg(); 732 | 733 | return SBM_OK; 734 | } 735 | 736 | int SBM_Image::ReadTGAHeader() 737 | { 738 | short ColMapStart,ColMapLen; 739 | short x1,y1,x2,y2; 740 | 741 | if(FileData==NULL) 742 | return SBM_ERR_NO_FILE; 743 | 744 | if(FileData[1]>1) // 0 (RGB) and 1 (Indexed) are the only types we know about 745 | return SBM_ERR_UNSUPPORTED; 746 | 747 | Encode=FileData[2];// Encoding flag 1 = Raw indexed image 748 | // 2 = Raw RGB 749 | // 3 = Raw greyscale 750 | // 9 = RLE indexed 751 | // 10 = RLE RGB 752 | // 11 = RLE greyscale 753 | // 32 & 33 Other compression, indexed 754 | 755 | if(Encode>11) // We don't want 32 or 33 756 | return SBM_ERR_UNSUPPORTED; 757 | 758 | // Get palette info 759 | memcpy(&ColMapStart,&FileData[3],2); 760 | memcpy(&ColMapLen,&FileData[5],2); 761 | 762 | // Reject indexed images if not a VGA palette (256 entries with 24 bits per entry) 763 | if(FileData[1]==1) // Indexed 764 | { 765 | if(ColMapStart!=0 || ColMapLen!=256 || FileData[7]!=24) 766 | return SBM_ERR_UNSUPPORTED; 767 | } 768 | 769 | // Get image window and produce width & height values 770 | memcpy(&x1,&FileData[8],2); 771 | memcpy(&y1,&FileData[10],2); 772 | memcpy(&x2,&FileData[12],2); 773 | memcpy(&y2,&FileData[14],2); 774 | 775 | Width=(x2-x1); 776 | Height=(y2-y1); 777 | 778 | if(Width<1 || Height<1) 779 | return SBM_ERR_BAD_FORMAT; 780 | 781 | // Bits per Pixel 782 | BPP=FileData[16]; 783 | 784 | // Check flip / interleave byte 785 | if(FileData[17]>32) // Interleaved data 786 | return SBM_ERR_UNSUPPORTED; 787 | 788 | // Calculate image size 789 | ImageSize=(Width * Height * (BPP/8)); 790 | 791 | return SBM_OK; 792 | } 793 | 794 | int SBM_Image::LoadTGARawData() 795 | { 796 | short iOffset; 797 | 798 | FreeMem((void**)&ImgData); 799 | 800 | ImgData=new unsigned char[ImageSize]; 801 | 802 | if(ImgData==NULL) 803 | return SBM_ERR_MEM_FAIL; 804 | 805 | iOffset=FileData[0]+18; // Add header to ident field size 806 | 807 | if(FileData[1]==1) // Indexed images 808 | iOffset+=768; // Add palette offset 809 | 810 | memcpy(ImgData,&FileData[iOffset],ImageSize); 811 | 812 | return SBM_OK; 813 | } 814 | 815 | 816 | int SBM_Image::LoadTGARLEData() 817 | { 818 | short iOffset,iPixelSize; 819 | unsigned char *pCur; 820 | unsigned long Index=0; 821 | unsigned char bLength,bLoop; 822 | 823 | // Calculate offset to image data 824 | iOffset=FileData[0]+18; 825 | 826 | // Add palette offset for indexed images 827 | if(FileData[1]==1) 828 | iOffset+=768; 829 | 830 | // Get pixel size in bytes 831 | iPixelSize=BPP/8; 832 | 833 | // Set our pointer to the beginning of the image data 834 | pCur=&FileData[iOffset]; 835 | 836 | // Allocate space for the image data 837 | FreeMem((void**)&ImgData); 838 | ImgData=new unsigned char[ImageSize]; 839 | 840 | if(ImgData==NULL) 841 | return SBM_ERR_MEM_FAIL; 842 | 843 | // Decode 844 | while(Index 29 | #include 30 | using namespace std; 31 | 32 | class SBM_Image 33 | { 34 | public: 35 | SBM_Image(); 36 | ~SBM_Image(); 37 | int Create(int width, int height, int bpp); 38 | void Reset(); // Clear Image 39 | int Load(char* filename); // Load BMP,PCX,TGA or SBM image 40 | int GetBPP(); 41 | int GetWidth(); 42 | int GetHeight(); 43 | unsigned char* GetImg(); // Return a pointer to image data 44 | unsigned char* GetPalette(); // Return a pointer to VGA palette 45 | 46 | // Utility Functions 47 | void FlipImg(); // Invert image vertically 48 | int InsertAlpha(unsigned char *Alpha); // Adds an alpha channel to image 49 | int Grayscale(); // Converts image to 8 bit gray 50 | int InvertCol(); // Inverts colour values 51 | void BGRtoRGB(); // Convert between RGB and BGR formats 52 | 53 | // Sets all non-KeyCol pixels to SatCol 54 | int Saturate(unsigned char KeyR, unsigned char KeyG, unsigned char KeyB, 55 | unsigned char SatR, unsigned char SatG, unsigned char SatB); 56 | 57 | 58 | int SaveBMP(char *filename); 59 | int SavePCX(char *filename); 60 | int SaveTGA(char *filename); 61 | int SaveRaw(char *filename); 62 | 63 | private: 64 | short Width,Height; 65 | char BPP,Encode,Planes; 66 | unsigned long FileSize,ImageSize,Offset; 67 | unsigned char *ImgData,*PalData,*FileData; 68 | short BPL; 69 | 70 | int LoadBMP(); 71 | int ReadBMPHeader(); 72 | int LoadBMPRawData(); 73 | int LoadBMPRLE8Data(); 74 | int LoadBMPPalette(); 75 | 76 | int LoadPCX(); 77 | int ReadPCXHeader(); 78 | int LoadPCXRLEData(); 79 | int LoadPCXPalette(); 80 | 81 | int LoadTGA(); 82 | int ReadTGAHeader(); 83 | int LoadTGARawData(); 84 | int LoadTGARLEData(); 85 | int LoadTGAPalette(); 86 | 87 | int LoadSBM(); 88 | 89 | void FreeMem(void **Ptr); // Safe delete [] 90 | }; 91 | 92 | #endif -------------------------------------------------------------------------------- /source/SaveOptProc.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "CBFGDefs.h" 3 | #include "Procs.h" 4 | 5 | BOOL CALLBACK SaveOptProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) 6 | { 7 | static int BPP,Flags; 8 | 9 | switch(msg) 10 | { 11 | case WM_INITDIALOG: 12 | SendDlgItemMessage(hDlg,CMD_SAVEOPT_32,BM_SETCHECK,BST_CHECKED,0); 13 | BPP=32; 14 | Flags=0; 15 | return false; 16 | 17 | case WM_COMMAND: 18 | { 19 | switch(LOWORD(wParam)) // Buttons & Menu items 20 | { 21 | case IDOK: 22 | switch(BPP) 23 | { 24 | case 8: 25 | if(SendDlgItemMessage(hDlg,CHK_SAVEOPT_INVERT,BM_GETCHECK,0,0)==BST_CHECKED) 26 | Flags |= SAVE_INV_ALPHA; 27 | break; 28 | 29 | case 24: 30 | Flags=0; 31 | break; 32 | 33 | case 32: 34 | if(SendDlgItemMessage(hDlg,CHK_SAVEOPT_INVERT,BM_GETCHECK,0,0)==BST_CHECKED) 35 | Flags |= SAVE_INV_ALPHA; 36 | 37 | if(SendDlgItemMessage(hDlg,CHK_SAVEOPT_SATURATE,BM_GETCHECK,0,0)==BST_CHECKED) 38 | Flags |= SAVE_RGB_SAT; 39 | break; 40 | } 41 | EndDialog(hDlg,(int)(BPP | Flags)); 42 | return true; 43 | 44 | case IDCANCEL: 45 | EndDialog(hDlg,0); 46 | return true; 47 | 48 | case CMD_SAVEOPT_8: 49 | BPP=8; 50 | EnableWindow(GetDlgItem(hDlg,CHK_SAVEOPT_SATURATE),false); 51 | SendDlgItemMessage(hDlg,CHK_SAVEOPT_SATURATE,BM_SETCHECK,BST_UNCHECKED,0); 52 | SendDlgItemMessage(hDlg,CHK_SAVEOPT_INVERT,WM_SETTEXT,0,(LPARAM)"Invert"); 53 | 54 | EnableWindow(GetDlgItem(hDlg,CHK_SAVEOPT_INVERT),true); 55 | return true; 56 | 57 | case CMD_SAVEOPT_24: 58 | BPP=24; 59 | EnableWindow(GetDlgItem(hDlg,CHK_SAVEOPT_SATURATE),false); 60 | SendDlgItemMessage(hDlg,CHK_SAVEOPT_SATURATE,BM_SETCHECK,BST_UNCHECKED,0); 61 | 62 | EnableWindow(GetDlgItem(hDlg,CHK_SAVEOPT_INVERT),false); 63 | SendDlgItemMessage(hDlg,CHK_SAVEOPT_INVERT,BM_SETCHECK,BST_UNCHECKED,0); 64 | return true; 65 | 66 | case CMD_SAVEOPT_32: 67 | BPP=32; 68 | EnableWindow(GetDlgItem(hDlg,CHK_SAVEOPT_SATURATE),true); 69 | EnableWindow(GetDlgItem(hDlg,CHK_SAVEOPT_INVERT),true); 70 | SendDlgItemMessage(hDlg,CHK_SAVEOPT_INVERT,WM_SETTEXT,0,(LPARAM)"Invert Alpha Channel"); 71 | return true; 72 | } 73 | } 74 | } 75 | return FALSE; 76 | } -------------------------------------------------------------------------------- /source/Script1.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeheadUK/CBFG/06084ec6f37c2525546b7d5b9f54c15896c2e5b9/source/Script1.rc -------------------------------------------------------------------------------- /source/SplashProc.cpp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeheadUK/CBFG/06084ec6f37c2525546b7d5b9f54c15896c2e5b9/source/SplashProc.cpp -------------------------------------------------------------------------------- /source/SplashProc.h: -------------------------------------------------------------------------------- 1 | 2 | BOOL CALLBACK SplashWinProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) 3 | { 4 | extern HWND hMain; 5 | 6 | switch(msg) 7 | { 8 | case WM_INITDIALOG: 9 | SetTimer(hDlg,246,3000,NULL); 10 | return true; 11 | 12 | case WM_MOUSEACTIVATE: 13 | KillTimer(hDlg,246); 14 | EndDialog(hDlg,0); 15 | InvalidateRgn(hMain,NULL,true); 16 | return 0; 17 | 18 | case WM_TIMER: 19 | KillTimer(hDlg,246); 20 | EndDialog(hDlg,0); 21 | InvalidateRgn(hMain,NULL,true); 22 | return 0; 23 | 24 | default: 25 | return 0; 26 | } 27 | 28 | } -------------------------------------------------------------------------------- /source/StdAfx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // Testbed.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | 7 | // TODO: reference any additional headers you need in STDAFX.H 8 | // and not in this file 9 | -------------------------------------------------------------------------------- /source/StdAfx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, but 3 | // are changed infrequently 4 | // 5 | 6 | #if !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_) 7 | #define AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_ 8 | 9 | #if _MSC_VER > 1000 10 | #pragma once 11 | #endif // _MSC_VER > 1000 12 | 13 | #define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers 14 | 15 | #include 16 | #include 17 | #include 18 | #include 19 | #include 20 | #include "resource.h" 21 | #define _CRTDBG_MAP_ALLOC 22 | #include 23 | 24 | // TODO: reference additional headers your program requires here 25 | 26 | //{{AFX_INSERT_LOCATION}} 27 | // Microsoft Visual C++ will insert additional declarations immediately before the previous line. 28 | 29 | #endif // !defined(AFX_STDAFX_H__A9DB83DB_A9FD_11D0_BFD1_444553540000__INCLUDED_) 30 | -------------------------------------------------------------------------------- /source/TestWindow.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | BOOL CALLBACK TestWinProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) 5 | { 6 | HDC dc,fdc; 7 | RECT rcArea; 8 | int nLines,Loop,chLoop,lTxt,offset; 9 | int CurX,CurY; 10 | int SrcCol,SrcRow; 11 | char Text[1024]; 12 | HBITMAP *hBMP; 13 | BFG_RGB TransCol; 14 | static char PText[1024]; 15 | char Sample[13][128] = {{"THE QUICK BROWN FOX JUMPS OVER A LAZY DOG"}, 16 | {"JACKDAWS LOVE MY BIG SPHINX OF QUARTZ"}, 17 | {"QUICK WAFTING ZEPHYRS VEX BOLD JIM"}, 18 | {"PACK MY BOX WITH FIVE DOZEN LIQUOR JUGS"}, 19 | {"SIX BIG DEVILS FROM JAPAN QUICKLY FORGOT HOW TO WALTZ"}, 20 | {"CRAZY FREDERICKA BOUGHT MANY VERY EXQUISITE OPAL JEWELS"}, 21 | {"FEW QUIPS GALVANIZED THE MOCK JURY BOX"}, 22 | {"THE FIVE BOXING WIZARDS JUMP QUICKLY"}, 23 | {"A SHORT BRIMLESS FELT HAT BARELY BLOCKS OUT THE SOUND OF A CELTIC VIOLIN"}, 24 | {"BEING BOUNCED AROUND QUICKLY ANNOYED THE DISHEVELED TAXI DRIVERS"}, 25 | {"MY GIRL WOVE SIX DOZEN PLAID JACKETS BEFORE SHE QUIT"}, 26 | {"SIXTY ZIPPERS WERE QUICKLY PICKED FROM THE WOVEN JUTE BAG"}, 27 | {"MY FAXED JOKE WON A PAGER IN THE CABLE TV QUIZ SHOW"}}; 28 | 29 | switch(msg) 30 | { 31 | case WM_INITDIALOG: 32 | if(!lstrlen(PText)) 33 | { 34 | srand((unsigned)time(NULL)); 35 | offset=rand()%13; 36 | lstrcpy(PText,&Sample[offset][0]); 37 | } 38 | SendDlgItemMessage(hDlg,TXT_PREVIEW,WM_SETTEXT,0,(LPARAM)PText); 39 | return 0; 40 | 41 | case EN_CHANGE: 42 | UpdateWindow(GetDlgItem(hDlg,OWN_MAIN)); 43 | return 1; 44 | 45 | case WM_DRAWITEM: 46 | if(wParam==OWN_MAIN) 47 | { 48 | TransCol=Fnt->GetCol(BACKCOL); 49 | 50 | dc=((LPDRAWITEMSTRUCT)lParam)->hDC; 51 | GetClientRect(hDlg, &rcArea); 52 | FillRect(dc,&rcArea,(HBRUSH)CreateSolidBrush(RGB(TransCol.Red,TransCol.Green,TransCol.Blue))); 53 | 54 | hBMP=Fnt->DrawFontMap(FALSE,0); 55 | 56 | fdc=CreateCompatibleDC(dc); 57 | 58 | SelectObject(fdc,*hBMP); 59 | 60 | nLines=SendDlgItemMessage(hDlg,TXT_PREVIEW,EM_GETLINECOUNT,0,0); 61 | 62 | Text[0]=NULL; 63 | CurX=CurY=0; 64 | 65 | for(Loop=0;LoopGetBaseChar())/(Fnt->GetSize(MAPWIDTH)/Fnt->GetSize(CELLWIDTH)); 76 | SrcCol=(Text[chLoop]-Fnt->GetBaseChar())-((Fnt->GetSize(MAPWIDTH)/Fnt->GetSize(CELLWIDTH))*SrcRow); 77 | 78 | TransparentBlt(dc,CurX,CurY,Fnt->GetSize(CELLWIDTH),Fnt->GetSize(CELLHEIGHT),fdc,SrcCol*Fnt->GetSize(CELLWIDTH),SrcRow*Fnt->GetSize(CELLHEIGHT),Fnt->GetSize(CELLWIDTH),Fnt->GetSize(CELLHEIGHT),RGB(TransCol.Red,TransCol.Green,TransCol.Blue)); 79 | CurX+=Fnt->GetCharVal(Text[chLoop],WIDTH); 80 | } 81 | 82 | CurY+=Fnt->GetSize(CELLHEIGHT); 83 | 84 | } 85 | 86 | ReleaseDC(hDlg,fdc); 87 | 88 | delete hBMP; 89 | } 90 | return TRUE; 91 | 92 | case WM_CLOSE: 93 | SendDlgItemMessage(hDlg,TXT_PREVIEW,WM_GETTEXT,1024,(LPARAM)PText); 94 | EndDialog(hDlg,0); 95 | return 0; 96 | 97 | case WM_COMMAND: 98 | { 99 | switch(HIWORD(wParam)) 100 | { 101 | case EN_CHANGE: 102 | InvalidateRect(GetDlgItem(hDlg,OWN_MAIN),NULL,FALSE); 103 | return 0; 104 | } 105 | 106 | switch(LOWORD(wParam)) // Buttons & Menu items 107 | { 108 | case CMD_OK: 109 | SendDlgItemMessage(hDlg,TXT_PREVIEW,WM_GETTEXT,1024,(LPARAM)PText); 110 | EndDialog(hDlg,0); 111 | return 0; 112 | 113 | case CMD_TEST_CLEAR: 114 | SendDlgItemMessage(hDlg,TXT_PREVIEW,WM_SETTEXT,0,(LPARAM)""); 115 | InvalidateRect(GetDlgItem(hDlg,OWN_MAIN),NULL,FALSE); 116 | return 0; 117 | 118 | case CMD_TEST_PANGRAM: 119 | offset=rand()%13; 120 | SendDlgItemMessage(hDlg,TXT_PREVIEW,WM_SETTEXT,0,(LPARAM)&Sample[offset][0]); 121 | InvalidateRect(GetDlgItem(hDlg,OWN_MAIN),NULL,FALSE); 122 | return 0; 123 | } 124 | 125 | } 126 | 127 | default: 128 | return 0; 129 | } 130 | } -------------------------------------------------------------------------------- /source/TextWinProc.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "Procs.h" 3 | #include "CBFGDefs.h" 4 | #include "FontMapClass.h" 5 | 6 | extern HINSTANCE G_Inst; 7 | extern HWND hMain; 8 | extern BFontMap *Fnt; 9 | extern AppInfo *info; 10 | 11 | BOOL CALLBACK TextWinProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) 12 | { 13 | extern long OldProc; 14 | 15 | int Row,Col,Sel; 16 | 17 | switch(msg) 18 | { 19 | case WM_ERASEBKGND: 20 | return TRUE; 21 | break; 22 | 23 | case WM_LBUTTONDOWN: 24 | SetFocus(hDlg); 25 | if((LOWORD(lParam)/info->Zoom)<=Fnt->GetSize(MAPWIDTH) && (HIWORD(lParam)/info->Zoom)<=Fnt->GetSize(MAPHEIGHT)) 26 | { 27 | Row=(int)((HIWORD(lParam)+info->vScr)/info->Zoom)/Fnt->GetSize(CELLHEIGHT); 28 | Col=(int)((LOWORD(lParam)+info->hScr)/info->Zoom)/Fnt->GetSize(CELLWIDTH); 29 | 30 | // Limit selection 31 | Sel=(Row*(Fnt->GetSize(MAPWIDTH)/Fnt->GetSize(CELLWIDTH)))+Col; 32 | if(Sel+Fnt->GetBaseChar()>255) 33 | info->Select=255-Fnt->GetBaseChar(); 34 | else 35 | info->Select=Sel; 36 | 37 | if(info->ModAll==TRUE) 38 | { 39 | SendDlgItemMessage(hMain,RAD_SEL,BM_SETCHECK,BST_CHECKED,0); 40 | SendDlgItemMessage(hMain,RAD_ALL,BM_SETCHECK,BST_UNCHECKED,0); 41 | EnableWindow(GetDlgItem(hMain,TXT_WIDTH),TRUE); 42 | EnableWindow(GetDlgItem(hMain,STA_WIDTH),TRUE); 43 | info->ModAll=FALSE; 44 | } 45 | 46 | SendMessage(hMain,WM_APP+1,0,0); 47 | CreateFontMap(); 48 | } 49 | return TRUE; 50 | } 51 | 52 | return CallWindowProc((WNDPROC)OldProc,hDlg,msg,wParam,lParam); 53 | } -------------------------------------------------------------------------------- /source/UtilFunctions.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "stdio.h" 3 | #include 4 | #include "FontMapClass.h" 5 | #include "UtilFunctions.h" 6 | #include 7 | #include 8 | 9 | #pragma comment (lib,"ws2_32.lib") 10 | 11 | extern HWND hMain; 12 | extern BFontMap *Fnt; 13 | extern AppInfo *info; 14 | 15 | using namespace std; 16 | 17 | BFG_RGB MakeRGB(unsigned char Red,unsigned char Green,unsigned char Blue) 18 | { 19 | BFG_RGB Pack; 20 | 21 | Pack.Red=Red; 22 | Pack.Green=Green; 23 | Pack.Blue=Blue; 24 | 25 | return Pack; 26 | } 27 | 28 | char Limit(int Val) 29 | { 30 | if(Val<-128) 31 | Val=-128; 32 | if(Val>127) 33 | Val=127; 34 | 35 | return (char) Val; 36 | } 37 | 38 | int LimitSelection(int Sel, int MaxChar) 39 | { 40 | if(Sel>MaxChar) 41 | Sel=MaxChar-1; 42 | 43 | return Sel; 44 | } 45 | 46 | void CreateFontMap() 47 | { 48 | HDC Wdc,Mdc,Fdc; 49 | HWND hImgWin; 50 | HBITMAP *FntMap; 51 | HBITMAP mMap; 52 | BITMAPINFO BMDat; 53 | RECT ClipArea; 54 | HRGN ClipRgn; 55 | int Opt=0,Selection; 56 | 57 | const int MapWidth=Fnt->GetSize(MAPWIDTH); 58 | const int MapHeight=Fnt->GetSize(MAPHEIGHT); 59 | 60 | 61 | // Get the target window 62 | hImgWin=GetDlgItem(hMain,IMG_TEXT); 63 | if(hImgWin==NULL) 64 | return; 65 | 66 | // Get target's DC 67 | Wdc=GetDC(hImgWin); 68 | if(Wdc==NULL) 69 | return; 70 | 71 | // Create memory DC 72 | Mdc=CreateCompatibleDC(Wdc); 73 | if(Mdc==NULL) 74 | return; 75 | 76 | // Create DC for font 77 | Fdc=CreateCompatibleDC(Wdc); 78 | if(Fdc==NULL) 79 | return; 80 | 81 | // Get size of target window 82 | GetClientRect(hImgWin, &ClipArea); 83 | 84 | // Specify bitmap type and size 85 | BMDat.bmiHeader.biSize=sizeof(BITMAPINFOHEADER); 86 | BMDat.bmiHeader.biWidth=ClipArea.right; 87 | BMDat.bmiHeader.biHeight=ClipArea.right; 88 | BMDat.bmiHeader.biPlanes=1; 89 | BMDat.bmiHeader.biBitCount=24; 90 | BMDat.bmiHeader.biCompression=BI_RGB; 91 | BMDat.bmiHeader.biSizeImage=(ClipArea.right*ClipArea.right)*3; 92 | 93 | // Create the bitmap 94 | mMap=CreateDIBSection(Mdc,&BMDat,DIB_RGB_COLORS,NULL,NULL,0); 95 | if(!mMap) 96 | return; 97 | 98 | // Select into memory DC 99 | if(!SelectObject(Mdc,mMap)) 100 | return; 101 | 102 | // Render the font 103 | if(info->Grid) 104 | Opt|=DFM_GRIDLINES; 105 | 106 | if(info->wMarker) 107 | Opt|=DFM_WIDTHLINE; 108 | 109 | if(info->ModAll) 110 | Selection=-1; 111 | else 112 | Selection=info->Select; 113 | 114 | FntMap=Fnt->DrawFontMap(Opt,Selection); 115 | 116 | // Select Font Map into Font DC 117 | SelectObject(Fdc,*FntMap); 118 | 119 | // Gray out bitmap 120 | FillRect(Mdc, &ClipArea,(HBRUSH)GetStockObject(GRAY_BRUSH)); 121 | 122 | // Set Clipping Region 123 | ClipRgn=CreateRectRgn(ClipArea.left,ClipArea.top,ClipArea.right,ClipArea.bottom); 124 | SelectClipRgn(Mdc,ClipRgn); 125 | 126 | // Copy Font into buffer 127 | SetStretchBltMode(Mdc,WHITEONBLACK); 128 | StretchBlt(Mdc,0,0,(int)(MapWidth*info->Zoom),(int)(MapHeight*info->Zoom), 129 | Fdc,(int)(info->hScr/info->Zoom),(int)(info->vScr/info->Zoom), 130 | MapWidth,MapHeight,SRCCOPY); 131 | 132 | // Copy Font into window 133 | SetStretchBltMode(Wdc,WHITEONBLACK); 134 | BitBlt(Wdc,0,0,(int)ClipArea.right,(int)ClipArea.bottom, 135 | Mdc,0,0,SRCCOPY); 136 | 137 | // Clean up 138 | DeleteObject(*FntMap); 139 | DeleteObject(mMap); 140 | DeleteObject(ClipRgn); 141 | DeleteObject(mMap); 142 | ReleaseDC(hImgWin,Wdc); 143 | DeleteDC(Mdc); 144 | DeleteDC(Fdc); 145 | } 146 | 147 | void CalcScroll() 148 | { 149 | extern BFontMap *Fnt; 150 | extern AppConfig *AppCfg; 151 | extern AppInfo *info; 152 | 153 | RECT WinSize; 154 | int XDelta,YDelta; 155 | SCROLLINFO sInf; 156 | int TexWidth,TexHt; 157 | int CharRow,CharCol,RowPitch; 158 | 159 | TexWidth=Fnt->GetSize(MAPWIDTH); 160 | TexHt=Fnt->GetSize(MAPHEIGHT); 161 | RowPitch=TexWidth/Fnt->GetSize(CELLWIDTH); 162 | 163 | GetClientRect(GetDlgItem(hMain,IMG_TEXT), &WinSize); 164 | 165 | if(!info->ModAll) // Check for active selection 166 | { 167 | // Calculate position of char 168 | CharCol=info->Select; 169 | CharRow=CharCol/RowPitch; 170 | CharCol-=CharRow*RowPitch; 171 | 172 | // Convert to pixels (Zoom?) 173 | CharCol*=Fnt->GetSize(CELLWIDTH); 174 | CharRow*=Fnt->GetSize(CELLHEIGHT); 175 | } 176 | 177 | // Calculate something? 178 | XDelta=(int)(TexWidth*info->Zoom)-WinSize.right; 179 | YDelta=(int)(TexHt*info->Zoom)-WinSize.bottom; 180 | 181 | if(XDelta>0) 182 | { 183 | SetScrollRange(GetDlgItem(hMain,SCR_HOR),SB_CTL,0,XDelta,FALSE); 184 | 185 | sInf.cbSize=sizeof(SCROLLINFO); 186 | sInf.fMask=SIF_RANGE; 187 | GetScrollInfo(GetDlgItem(hMain,SCR_HOR),SB_CTL,&sInf); 188 | if(info->hScr>sInf.nMax) 189 | info->hScr=sInf.nMax; 190 | 191 | SetScrollPos(GetDlgItem(hMain,SCR_HOR),SB_CTL,info->hScr,TRUE); 192 | info->hScroll=TRUE; 193 | } 194 | else // Prevent offset pushing texture off left edge of window 195 | { 196 | SetScrollPos(GetDlgItem(hMain,SCR_HOR),SB_CTL,0,TRUE); 197 | info->hScr=0; 198 | EnableWindow(GetDlgItem(hMain,SCR_HOR),FALSE); 199 | info->hScroll=FALSE; 200 | } 201 | 202 | if(YDelta>0) 203 | { 204 | SetScrollRange(GetDlgItem(hMain,SCR_VERT),SB_CTL,0,YDelta,FALSE); 205 | 206 | sInf.cbSize=sizeof(SCROLLINFO); 207 | sInf.fMask=SIF_RANGE; 208 | GetScrollInfo(GetDlgItem(hMain,SCR_VERT),SB_CTL,&sInf); 209 | if(info->vScr>sInf.nMax) 210 | info->vScr=sInf.nMax; 211 | 212 | SetScrollPos(GetDlgItem(hMain,SCR_VERT),SB_CTL,info->vScr,TRUE); 213 | info->vScroll=TRUE; 214 | } 215 | else // Prevent offset pushing texture off top edge of window 216 | { 217 | SetScrollPos(GetDlgItem(hMain,SCR_VERT),SB_CTL,0,TRUE); 218 | info->vScr=0; 219 | EnableWindow(GetDlgItem(hMain,SCR_VERT),FALSE); 220 | info->vScroll=FALSE; 221 | } 222 | } 223 | 224 | 225 | BOOL CheckOverwrite(char *fname) 226 | { 227 | ifstream testfile; 228 | 229 | 230 | testfile.open(fname); 231 | 232 | if(!testfile.fail()) 233 | { 234 | testfile.close(); 235 | if(MessageBox(hMain,"Overwrite existing file?","Filename already exists",MB_YESNO | MB_ICONQUESTION)==IDNO) 236 | return FALSE; 237 | } 238 | 239 | return TRUE; 240 | } 241 | -------------------------------------------------------------------------------- /source/UtilFunctions.h: -------------------------------------------------------------------------------- 1 | #ifndef _FONT_TOOL_UTIL_H 2 | #define _FONT_TOOL_UTIL_H 3 | 4 | #include "SBM-Util.h" 5 | #include "FontMapClass.h" 6 | 7 | #define EXPORT_TGA 1 8 | #define EXPORT_BMP 2 9 | #define EXPORT_TXT 3 10 | #define EXPORT_TGA32 4 11 | 12 | typedef struct 13 | { 14 | int CellWidth,CellHeight,ImgSize; 15 | LOGFONT FntDef; 16 | HFONT fnt; 17 | int CharBase; 18 | char width[256]; 19 | char wAdj[256]; 20 | char hAdj[256]; 21 | char vAdj[256]; 22 | char ghAdj,gvAdj,gwAdj; 23 | }Config; 24 | 25 | BFG_RGB MakeRGB(unsigned char Red,unsigned char Green,unsigned char Blue); 26 | char Limit(int Val); 27 | int LimitSelection(int Sel, int MaxChar); 28 | void CreateFontMap(); 29 | HBITMAP* RenderFont(bool Markers); 30 | unsigned char* MakeAlpha(); 31 | void CalcScroll(); 32 | int ExportMap(char* fname, int fmt); 33 | BOOL CheckOverwrite(char *fname); 34 | 35 | 36 | #endif -------------------------------------------------------------------------------- /source/WriteFont.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | #include "WriteFont.h" 3 | 4 | int SaveFont(char *fname) 5 | { 6 | //extern HWND hMain; 7 | extern BFontMap *Fnt; 8 | extern AppConfig *AppCfg; 9 | extern AppInfo *info; 10 | 11 | FILE *out; 12 | FontFileHeader Hdr; 13 | HBITMAP *hBMP; 14 | unsigned char *Alpha; 15 | DIBSECTION bmInfo; 16 | SBM_Image Bits; 17 | 18 | // Populate header 19 | lstrcpy(Hdr.ID,"CBFG"); 20 | Hdr.VerMaj=1; 21 | Hdr.VerMin=0; 22 | Hdr.BPP=32; 23 | Hdr.ImageWidth=Fnt->GetSize(MAPWIDTH); 24 | Hdr.ImageHeight=Fnt->GetSize(MAPHEIGHT); 25 | Hdr.CellHeight=Fnt->GetSize(CELLHEIGHT); 26 | Hdr.CellWidth=Fnt->GetSize(CELLWIDTH); 27 | Hdr.StartPoint=Fnt->GetBaseChar(); 28 | 29 | //GetWidths(); 30 | 31 | //hBMP=RenderFont(FALSE); 32 | 33 | Bits.Create(Hdr.ImageWidth,Hdr.ImageHeight,24); 34 | 35 | if(!GetObject(*hBMP,sizeof(DIBSECTION),&bmInfo)) 36 | return FALSE; 37 | 38 | // Copy bitmap to img 39 | memcpy(Bits.GetImg(),bmInfo.dsBm.bmBits,(Hdr.ImageWidth*Hdr.ImageHeight)*(24/8)); 40 | 41 | delete hBMP; 42 | 43 | // Add in Alpha Channel 44 | //Alpha=MakeAlpha(); 45 | Bits.InsertAlpha(Alpha); 46 | 47 | // Invert image 48 | Bits.FlipImg(); 49 | 50 | out=fopen(fname,"wb"); 51 | 52 | if(out==NULL) 53 | return FALSE; 54 | 55 | // Write header data 56 | fwrite(&Hdr,sizeof(Hdr),1,out); 57 | 58 | // Write char widths 59 | //fwrite(cfg->width,256,1,out); 60 | 61 | // Write bitmap 62 | fwrite(Bits.GetImg(),(Hdr.ImageWidth*Hdr.ImageHeight)*(Hdr.BPP/8),1,out); 63 | 64 | fclose(out); 65 | 66 | return TRUE; 67 | } -------------------------------------------------------------------------------- /source/WriteFont.h: -------------------------------------------------------------------------------- 1 | #ifndef _SAVEFONT_H 2 | #define _SAVEFONT_H 3 | 4 | #include "stdafx.h" 5 | #include "SBM-Util.h" 6 | #include "UtilFunctions.h" 7 | 8 | int SaveFont(char *fname); 9 | 10 | #endif -------------------------------------------------------------------------------- /source/bfg.cfg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeheadUK/CBFG/06084ec6f37c2525546b7d5b9f54c15896c2e5b9/source/bfg.cfg -------------------------------------------------------------------------------- /source/file-request.h: -------------------------------------------------------------------------------- 1 | // Creates standard open and save requesters 2 | #ifndef _FILE_REQUEST_H 3 | #define _FILE_REQUEST_H 4 | 5 | BOOL GetTargetName(char* fname, char* Title, char *filter, char* DefExt); 6 | BOOL GetSourceName(char* fname, char* title, char *filter, char* DefExt); 7 | 8 | #endif -------------------------------------------------------------------------------- /source/ico_down.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeheadUK/CBFG/06084ec6f37c2525546b7d5b9f54c15896c2e5b9/source/ico_down.ico -------------------------------------------------------------------------------- /source/ico_left.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeheadUK/CBFG/06084ec6f37c2525546b7d5b9f54c15896c2e5b9/source/ico_left.ico -------------------------------------------------------------------------------- /source/ico_right.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeheadUK/CBFG/06084ec6f37c2525546b7d5b9f54c15896c2e5b9/source/ico_right.ico -------------------------------------------------------------------------------- /source/ico_up.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CodeheadUK/CBFG/06084ec6f37c2525546b7d5b9f54c15896c2e5b9/source/ico_up.ico -------------------------------------------------------------------------------- /source/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by Script1.rc 4 | // 5 | #define CMD_TEST_CLEAR 2 6 | #define IDSAVE 3 7 | #define CMD_TEST_CLEAR2 3 8 | #define CMD_TEST_PANGRAM 3 9 | #define IDDEFAULT 4 10 | #define APP_ICON 101 11 | #define DLG_MAIN 103 12 | #define MNU_MAIN 104 13 | #define ICO_UP 105 14 | #define ICO_DOWN 106 15 | #define DLG_ABOUT 106 16 | #define ICO_RIGHT 107 17 | #define ICO_LEFT 108 18 | #define DLG_SAVEOPT 113 19 | #define DLG_CONFIG 114 20 | #define DLG_PREVIEW 115 21 | #define IDB_BITMAP1 117 22 | #define BFG_LOGO 117 23 | #define DLG_SPLASH 119 24 | #define IMG_TEXT 1000 25 | #define IDC_COMBO1 1001 26 | #define CBO_FONTS 1001 27 | #define CBO_CFG_ITEM 1001 28 | #define IDC_CHECK1 1002 29 | #define CHK_BOLD 1002 30 | #define CHK_SAVEOPT_SATURATE 1002 31 | #define IDC_CHECK2 1003 32 | #define CHK_ITAL 1003 33 | #define CHK_CFG_WIDTH 1003 34 | #define CHK_SAVEOPT_INVERT 1003 35 | #define IDC_SPIN1 1004 36 | #define SPN_FONTHEIGHT 1004 37 | #define SPN_CFG_CELLWIDTH 1004 38 | #define ID_TEST_BUTTON 1005 39 | #define IDC_EDIT1 1005 40 | #define TXT_FONTHEIGHT 1005 41 | #define TXT_PREVIEW 1005 42 | #define IDC_SPIN2 1006 43 | #define SPN_FONTWIDTH 1006 44 | #define TXT_GREEN 1006 45 | #define IDC_EDIT2 1007 46 | #define TXT_FONTWIDTH 1007 47 | #define TXT_BLUE 1007 48 | #define IDC_EDIT3 1008 49 | #define TXT_CELLWIDTH 1008 50 | #define TXT_CFG_CELLWIDTH 1008 51 | #define IDC_EDIT4 1009 52 | #define TXT_CELLHEIGHT 1009 53 | #define TXT_CFG_CELLHEIGHT 1009 54 | #define IDC_COMBO2 1010 55 | #define CBO_ALIAS 1010 56 | #define TXT_CFG_FONTHEIGHT 1010 57 | #define IDC_SPIN3 1011 58 | #define SPN_CELLWIDTH 1011 59 | #define TXT_CFG_FONTWIDTH 1011 60 | #define IDC_SPIN4 1012 61 | #define SPN_CELLHEIGHT 1012 62 | #define SPN_CFG_CELLHEIGHT 1012 63 | #define SPN_CFG_FONTHEIGHT 1013 64 | #define CBO_IMGXRES 1013 65 | #define IDC_SCROLLBAR1 1014 66 | #define SCR_VERT 1014 67 | #define SPN_CFG_FONTWIDTH 1014 68 | #define CMD_UP 1015 69 | #define CMD_RIGHT 1016 70 | #define CMD_DOWN 1017 71 | #define CMD_LEFT 1018 72 | #define IDC_SCROLLBAR2 1019 73 | #define SCR_HOR 1019 74 | #define CBO_IMGXRES2 1020 75 | #define CBO_IMGYRES 1020 76 | #define CBO_ZOOM 1022 77 | #define CHK_GRID 1023 78 | #define RAD_ALL 1024 79 | #define RAD_SEL 1025 80 | #define IDC_EDIT5 1026 81 | #define TXT_XADJ 1026 82 | #define IDC_EDIT6 1027 83 | #define TXT_YADJ 1027 84 | #define IDC_RADIO1 1027 85 | #define CMD_SAVEOPT_8 1027 86 | #define IDC_RADIO2 1028 87 | #define TXT_WADJ 1028 88 | #define CMD_SAVEOPT_24 1028 89 | #define IDC_RADIO3 1029 90 | #define ODR_COLOR 1029 91 | #define TXT_WIDTH 1029 92 | #define CMD_SAVEOPT_32 1029 93 | #define CHK_WIDTH 1030 94 | #define SLD_RED 1030 95 | #define SLD_GREEN 1031 96 | #define SLD_BLUE 1032 97 | #define CBO_CFG_IMGXSIZE 1033 98 | #define SPN_WIDTH 1034 99 | #define CBO_CFG_IMGYSIZE 1034 100 | #define SPN_START 1035 101 | #define TXT_START 1036 102 | #define OWN_MAIN 1037 103 | #define STA_WIDTH 1038 104 | #define TXT_RED 1039 105 | #define CHK_CFG_GRID 1040 106 | #define ID_OK 1041 107 | #define CMD_OK 1042 108 | #define IDC_GL3 1045 109 | #define IDC_GL 1045 110 | #define ODR_FORECOL 1046 111 | #define ODR_BACKCOL 1047 112 | #define IDC_LIST1 1049 113 | #define LST_CREDITS 1049 114 | #define ID_FILE_SAVEAS 40004 115 | #define ID_FILE_EXIT 40005 116 | #define ID_FONT_RESET 40006 117 | #define ID_HELP_ABOUT 40007 118 | #define ID_VIEW_ZOOMIN 40008 119 | #define ID_VIEW_ZOOMOUT 40009 120 | #define ID_VIEW_SHOWGRID 40010 121 | #define ID_FONT_ANTIALIAS 40011 122 | #define ID_ANTIALIAS_NONE 40012 123 | #define ID_ANTIALIAS_NORMAL 40013 124 | #define ID_ANTIALIAS_CLEARTYPE 40014 125 | #define ID_Menu 40015 126 | #define ID_FILE_EXPORT 40016 127 | #define ID_EXPORT_TARGA 40017 128 | #define ID_EXPORT_BITMAP 40018 129 | #define ID_EXPORT_FONTDATA 40019 130 | #define ID_FILE_RESET 40024 131 | #define ID_FONT_TEST 40025 132 | #define ID_TOOLS_EXTRACTIMAGE 40027 133 | #define ID_TOOLS_IMPORTIMAGE 40028 134 | #define ID_HELP_CONTENTS 40029 135 | #define ID_TOOLS_CONFIGURATION 40030 136 | #define ID_VIEW_WIDTHMARKERS 40032 137 | #define ID_FILE_SAVEBFF 40033 138 | #define ID_EXPORT_TARGA32 40034 139 | #define ID_FILE_IMPORT 40035 140 | #define ID_IMPORT_FONTDATA 40036 141 | #define ID_TOOLS_PREVIEW 40040 142 | #define ID_EXPORT_BIN 40041 143 | #define ID_SAVE_BFF8 40042 144 | #define ID_SAVE_BFF24 40043 145 | #define ID_SAVE_BFF32 40044 146 | #define ID_HELP_CHECKFORUPDATES 40046 147 | #define ID_FONT_COLOUR 40047 148 | #define ID_COLOUR_SETTEXTCOLOUR 40048 149 | #define ID_COLOUR_SETBACKGROUNDCOLOUR 40049 150 | 151 | // Next default values for new objects 152 | // 153 | #ifdef APSTUDIO_INVOKED 154 | #ifndef APSTUDIO_READONLY_SYMBOLS 155 | #define _APS_NEXT_RESOURCE_VALUE 121 156 | #define _APS_NEXT_COMMAND_VALUE 40050 157 | #define _APS_NEXT_CONTROL_VALUE 1050 158 | #define _APS_NEXT_SYMED_VALUE 103 159 | #endif 160 | #endif 161 | --------------------------------------------------------------------------------