commands.cpp
上传用户:jnfxsk
上传日期:2022-06-16
资源大小:3675k
文件大小:4k
源码类别:

游戏引擎

开发平台:

Visual C++

  1. /*
  2. ** Haaf's Game Engine 1.6
  3. ** Copyright (C) 2003, Relish Games
  4. ** hge.relishgames.com
  5. **
  6. ** Bitmap Font Builder
  7. */
  8. #include "fonted.h"
  9. #include <windows.h>
  10. #include <string>
  11. using namespace std;
  12. bool HandleKeys(int key)
  13. {
  14. switch(key)
  15. {
  16. case 0: return false;
  17. case HGEK_ESCAPE: return true;
  18. case HGEK_LBUTTON:
  19. if(state.mx > 168 && state.mx > psx-fw2 && state.mx < psx+fw2 &&
  20.    state.my > psy-fh2 && state.my < psy+fh2)
  21. {
  22. state.bDrag=true;
  23. state.nDragXOffset=state.mx;
  24. state.nDragYOffset=state.my;
  25. state.nDragOldX=psx;
  26. state.nDragOldY=psy;
  27. }
  28. }
  29. return false;
  30. }
  31. bool DoCommands(int id)
  32. {
  33. hgeGUIListbox *listbox;
  34. int f,l;
  35. switch(id)
  36. {
  37. case 0: return false;
  38. case CMD_EXIT: return true;
  39. case CMD_HELP: state.bHelp=ButtonGetState(CMD_HELP); break;
  40. case CMD_SAVE: cmdSaveFont(); break;
  41. case CMD_BOLD: state.bBold=ButtonGetState(CMD_BOLD); cmdGenerateFont(); break;
  42. case CMD_ITALIC: state.bItalic=ButtonGetState(CMD_ITALIC); cmdGenerateFont(); break;
  43. case CMD_ANTIALIAS: state.bAntialias=ButtonGetState(CMD_ANTIALIAS); cmdGenerateFont(); break;
  44. case CMD_BOUNDINGBOX: state.bBBox=ButtonGetState(CMD_BOUNDINGBOX); break;
  45. case CMD_FONTSIZE:
  46. state.nSize=int(SliderGetValue(CMD_FONTSIZE));
  47. GetTextCtrl(CMD_TFONTSIZE)->printf("%d",state.nSize);
  48. cmdGenerateFont();
  49. break;
  50. case CMD_FAMILYLIST:
  51. listbox=hgeGetListboxCtrl(gui, CMD_FAMILYLIST);
  52. state.FontFamily=listbox->GetItemText(listbox->GetSelectedItem());
  53. SliderSetValue(CMD_FAMILYSLIDER, listbox->GetTopItem());
  54. cmdGenerateFont();
  55. break;
  56. case CMD_FAMILYSLIDER:
  57. listbox=hgeGetListboxCtrl(gui, CMD_FAMILYLIST);
  58. listbox->SetTopItem(int(SliderGetValue(CMD_FAMILYSLIDER)));
  59. break;
  60. case CMD_CHARRANGE:
  61. ((hgeGUIRange*)gui->GetCtrl(CMD_CHARRANGE))->GetRange(&f, &l);
  62. state.sr.First=f;
  63. state.sr.Last=l;
  64. cmdGenerateFont();
  65. break;
  66. }
  67. return false;
  68. }
  69. void cmdGenerateFont()
  70. {
  71. if(sprFont) delete sprFont;
  72. if(texFont) hge->Texture_Free(texFont);
  73. texFont=FontGenerate(state.FontFamily, state.nSize, state.nPadTop, state.nPadBtm, state.nPadLft, state.nPadRgt, state.bBold, state.bItalic, state.bAntialias, &state.sr, 1);
  74. sprFont=new hgeSprite(texFont, 0.0f, 0.0f, (float)hge->Texture_GetWidth(texFont), (float)hge->Texture_GetHeight(texFont));
  75. }
  76. bool cmdSaveFont()
  77. {
  78. FILE *fp;
  79. OPENFILENAME ofn;
  80. char szFile[512]="";
  81. char szTemp[512];
  82. ZeroMemory(&ofn, sizeof(OPENFILENAME));
  83. ofn.lStructSize = sizeof(OPENFILENAME); 
  84. ofn.hwndOwner = hge->System_GetState(HGE_HWND); 
  85. ofn.lpstrFilter = "HGE Font Files*.fntAll Files*.*"; 
  86. ofn.lpstrFile= szFile; 
  87. ofn.nMaxFile = sizeof(szFile); 
  88. ofn.Flags = OFN_OVERWRITEPROMPT; // | OFN_NOCHANGEDIR
  89. ofn.lpstrDefExt="fnt";
  90. if(!GetSaveFileName(&ofn)) return true;
  91. fp=fopen(szFile,"w");
  92. if(!fp)
  93. {
  94. sprintf(szTemp, "Can't write to file:n%snProbaby it is write protected.",szFile);
  95. MessageBox(NULL, szTemp, "Can't write to file", MB_OK | MB_ICONEXCLAMATION | MB_TASKMODAL);
  96. return false;
  97. }
  98. strcpy(&szFile[ofn.nFileExtension],"png");
  99. fprintf(fp,"[HGEFONT]nnBitmap=%snn", &szFile[ofn.nFileOffset]);
  100. for(int i=state.sr.First; i<=state.sr.Last; i++)
  101. {
  102. char c=i;
  103. if(i>=32 && i<=126)
  104. fprintf(fp,"Char="%c",%d,%d,%d,%d,%d,%dn",
  105.   c, vChars[i].x, vChars[i].y, vChars[i].w, vChars[i].h,
  106.   vChars[i].a, vChars[i].c);
  107. else
  108. fprintf(fp,"Char=%2X,%d,%d,%d,%d,%d,%dn",
  109.   i, vChars[i].x, vChars[i].y, vChars[i].w, vChars[i].h,
  110.   vChars[i].a, vChars[i].c);
  111. }
  112. fclose(fp);
  113. return SavePNG(texFont, szFile);
  114. }