Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C/C++ - [C] Problema dell'esecuzione di programmi scritti con la libreria graphics.h
Forum - C/C++ - [C] Problema dell'esecuzione di programmi scritti con la libreria graphics.h

Pagine: [ 1 2 3 ] Precedente | Prossimo
Avatar
tullio1995 (Normal User)
Rookie


Messaggi: 59
Iscritto: 20/03/2011

Segnala al moderatore
Postato alle 3:40
Sabato, 27/12/2014
Salve a tutti, utilizzo come sistema operativo windows 8.1. Volevo provare a creare qualche gioco utilizzando la libreria winBGIm. Compilo questo codice,
Codice sorgente - presumibilmente C/C++

  1. #include <graphics.h>
  2.  
  3.   int main()
  4.   {
  5.       initwindow(400,300); //apre una finestra 400x300
  6.       moveto(0,0);        
  7.       lineto(50,50);      
  8.       while(!kbhit())      //aspetta la pressione di un tasto
  9.       closegraph();        //chiude la finestra
  10.       return 0;
  11.   }


da terminale con winMG utilizzando questo comando: "g++ prova.c -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32".
Il programma viene compilato correttamente senza errori, ma quando lo vado ad eseguire si blooca e mi esce la finestra con scritto "Il programma ha smesso di funzionare". Ho provato ad eseguirlo in modalità di compatibilità con gli altri sistemi operaviti, ma il risultato è sempre lo stesso. Spero che qualcuno di voi sappia risolvere questo problema :hail:

PM Quote
Avatar
Poggi Marco (Member)
Guru


Messaggi: 969
Iscritto: 05/01/2010

Segnala al moderatore
Postato alle 11:59
Sabato, 27/12/2014
Ciao!

Che compilatore utilizzi?

Molto probabilmente, non hai installato la libreria WinBGIm. ( http://winbgim.codecutter.org/ )

PM Quote
Avatar
SamIAm (Normal User)
Newbie


Messaggi: 16
Iscritto: 09/09/2012

Segnala al moderatore
Postato alle 15:14
Sabato, 27/12/2014
Ciao,
Se anche tu hai scaricato la libreria da qui http://winbgim.codecutter.org/
Avrai notato un errore nell'header "graphics.h" alla riga 302
Codice sorgente - presumibilmente C++

  1. [CODE]
  2.     int left=0, int right=0, int right=INT_MAX, int bottom=INT_MAX,
  3. [/CODE]


in realtà deve essere
Codice sorgente - presumibilmente C++

  1. [CODE]
  2.     int left=0, int top=0, int right=INT_MAX, int bottom=INT_MAX,
  3. [/CODE]


sistema questa 'svista' e ricompila la libreria (lavorando un poco per eliminare alcuni warning)
sposta i file "graphics.h" e "libbgi.a" nella cartella del MinGW, e vedrai che il tutto torna a funzionare.

PM Quote
Avatar
tullio1995 (Normal User)
Rookie


Messaggi: 59
Iscritto: 20/03/2011

Segnala al moderatore
Postato alle 16:14
Sabato, 27/12/2014
Come compilatore utilizzo minGW compilando da terminale. Il problema della riga 302 lo avevo già risolto, infatti il compilatore mi crea l'eseguibile senza errori, il problema e quando lo mando in esecuzione che non si avvia. Quando vado ad eseguire il sorgente compilato mi si apre un terminale e poi una finestra con scritto il programma ha smesso di funzionare. Ho provato a compilare la libreria graphics.h e non mi da ne errori ne warning, credo sia un problema del sistema operativo :yup:

PM Quote
Avatar
SamIAm (Normal User)
Newbie


Messaggi: 16
Iscritto: 09/09/2012

Segnala al moderatore
Postato alle 16:44
Sabato, 27/12/2014
Io ho Windows Seven, ed ho compilato tutto da riga di comando. (g++  4.7.1)
E nel mio caso la libreria ha funzionato solo dopo averla ricompilata.

PM Quote
Avatar
tullio1995 (Normal User)
Rookie


Messaggi: 59
Iscritto: 20/03/2011

Segnala al moderatore
Postato alle 16:50
Sabato, 27/12/2014
Io ho g++ 4.8.1 e ho provato a ricompilare la libreria, ma il risultato è lo stesso. Ho dato il comando "g++ graphics.h" nella cartella include di MinGW

PM Quote
Avatar
SamIAm (Normal User)
Newbie


Messaggi: 16
Iscritto: 09/09/2012

Segnala al moderatore
Postato alle 18:29
Sabato, 27/12/2014
Testo quotato

Postato originariamente da tullio1995:

Io ho g++ 4.8.1 e ho provato a ricompilare la libreria, ma il risultato è lo stesso. Ho dato il comando "g++ graphics.h" nella cartella include di MinGW



Un momento, "graphics.h" è soltanto un header e non è compilabile ...

Io ho creato un file .BAT nella cartella dove ho estratto i file sorgenti della libreria "WinBGIm"

Codice sorgente - presumibilmente C/C++

  1. SET "PATH=C:\Program Files (x86)\CodeBlocks\MinGW\bin;%PATH%"
  2. mingw32-make.exe -f makefile
  3. PAUSE



eseguendolo generi la libreria "libbgi.a"

copi il file  "graphics.h" nella cartella "\MinGW\include"
e sposti il file "libbgi.a" nella cartella "\MinGW\lib"

Infine per compilare il programma ho creato un'altro file .BAT nella cartella del progetto.

Codice sorgente - presumibilmente C/C++

  1. SET "PATH=C:\Program Files (x86)\CodeBlocks\MinGW\bin;%PATH%"
  2. g++ sample.cpp -o sample.exe -lbgi -lgdi32 -lcomdlg32 -luuid -loleaut32 -lole32
  3. PAUSE



:yup:

Ultima modifica effettuata da SamIAm il 27/12/2014 alle 18:36
PM Quote
Avatar
tullio1995 (Normal User)
Rookie


Messaggi: 59
Iscritto: 20/03/2011

Segnala al moderatore
Postato alle 18:57
Sabato, 27/12/2014
SET "PATH=C:\MinGW\bin;%PATH%"
mingw32-make.exe -f makefile
PAUSE

Codice sorgente - presumibilmente Delphi

  1. C:\Users\Tullio\Desktop\WinBGIm6_0_Nov2005_src>SET "PATH=C:\MinGW\bin;C:\Windows
  2. \system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerSh
  3. ell\v1.0\;C:\Program Files\ATI Technologies\ATI.ACE\Core-Static;C:\MinGW\bin"
  4.  
  5. C:\Users\Tullio\Desktop\WinBGIm6_0_Nov2005_src>mingw32-make.exe -f makefile
  6. g++ -c -O3 -fno-rtti -fno-exceptions drawing.cxx
  7. g++ -c -O3 -fno-rtti -fno-exceptions misc.cxx
  8. g++ -c -O3 -fno-rtti -fno-exceptions mouse.cxx
  9. g++ -c -O3 -fno-rtti -fno-exceptions palette.cxx
  10. g++ -c -O3 -fno-rtti -fno-exceptions text.cxx
  11. text.cxx:71:1: warning: deprecated conversion from string constant to 'char*' [-
  12. Wwrite-strings]
  13.  };
  14.  ^
  15. text.cxx:71:1: warning: deprecated conversion from string constant to 'char*' [-
  16. Wwrite-strings]
  17. text.cxx:71:1: warning: deprecated conversion from string constant to 'char*' [-
  18. Wwrite-strings]
  19. text.cxx:71:1: warning: deprecated conversion from string constant to 'char*' [-
  20. Wwrite-strings]
  21. text.cxx:71:1: warning: deprecated conversion from string constant to 'char*' [-
  22. Wwrite-strings]
  23. text.cxx:71:1: warning: deprecated conversion from string constant to 'char*' [-
  24. Wwrite-strings]
  25. text.cxx:71:1: warning: deprecated conversion from string constant to 'char*' [-
  26. Wwrite-strings]
  27. text.cxx:71:1: warning: deprecated conversion from string constant to 'char*' [-
  28. Wwrite-strings]
  29. text.cxx:71:1: warning: deprecated conversion from string constant to 'char*' [-
  30. Wwrite-strings]
  31. text.cxx:71:1: warning: deprecated conversion from string constant to 'char*' [-
  32. Wwrite-strings]
  33. text.cxx:71:1: warning: deprecated conversion from string constant to 'char*' [-
  34. Wwrite-strings]
  35. text.cxx: In function 'void outstreamxy(int, int, std::ostringstream&)':
  36. text.cxx:354:25: warning: deprecated conversion from string constant to 'char*'
  37. [-Wwrite-strings]
  38.       y += textheight("X");
  39.                          ^
  40. g++ -c -O3 -fno-rtti -fno-exceptions winbgi.cxx
  41. winbgi.cxx: In function 'char* getdrivername()':
  42. winbgi.cxx:464:12: warning: deprecated conversion from string constant to 'char*
  43. ' [-Wwrite-strings]
  44.      return "EGAVGA";
  45.             ^
  46. winbgi.cxx: In function 'char* grapherrormsg(int)':
  47. winbgi.cxx:570:56: warning: deprecated conversion from string constant to 'char*
  48. ' [-Wwrite-strings]
  49.          "Invalid font number", "Invalid device number" };
  50.                                                         ^
  51. winbgi.cxx:570:56: warning: deprecated conversion from string constant to 'char*
  52. ' [-Wwrite-strings]
  53. winbgi.cxx:570:56: warning: deprecated conversion from string constant to 'char*
  54. ' [-Wwrite-strings]
  55. winbgi.cxx:570:56: warning: deprecated conversion from string constant to 'char*
  56. ' [-Wwrite-strings]
  57. winbgi.cxx:570:56: warning: deprecated conversion from string constant to 'char*
  58. ' [-Wwrite-strings]
  59. winbgi.cxx:570:56: warning: deprecated conversion from string constant to 'char*
  60. ' [-Wwrite-strings]
  61. winbgi.cxx:570:56: warning: deprecated conversion from string constant to 'char*
  62. ' [-Wwrite-strings]
  63. winbgi.cxx:570:56: warning: deprecated conversion from string constant to 'char*
  64. ' [-Wwrite-strings]
  65. winbgi.cxx:570:56: warning: deprecated conversion from string constant to 'char*
  66. ' [-Wwrite-strings]
  67. winbgi.cxx:570:56: warning: deprecated conversion from string constant to 'char*
  68. ' [-Wwrite-strings]
  69. winbgi.cxx:570:56: warning: deprecated conversion from string constant to 'char*
  70. ' [-Wwrite-strings]
  71. winbgi.cxx:570:56: warning: deprecated conversion from string constant to 'char*
  72. ' [-Wwrite-strings]
  73. winbgi.cxx:570:56: warning: deprecated conversion from string constant to 'char*
  74. ' [-Wwrite-strings]
  75. winbgi.cxx:570:56: warning: deprecated conversion from string constant to 'char*
  76. ' [-Wwrite-strings]
  77. winbgi.cxx:570:56: warning: deprecated conversion from string constant to 'char*
  78. ' [-Wwrite-strings]
  79. winbgi.cxx:570:56: warning: deprecated conversion from string constant to 'char*
  80. ' [-Wwrite-strings]
  81. g++ -c -O3 -fno-rtti -fno-exceptions winthread.cxx
  82. g++ -c -O3 -fno-rtti -fno-exceptions -c file.cxx
  83. g++ -c -O3 -fno-rtti -fno-exceptions dibutil.cxx
  84. rm graphics.h
  85. process_begin: CreateProcess(NULL, rm graphics.h, ...) failed.
  86. make (e=2): Impossibile trovare il file specificato.
  87. makefile:37: recipe for target 'graphics.h' failed
  88. mingw32-make.exe: *** [graphics.h] Error 2
  89.  
  90. C:\Users\Tullio\Desktop\WinBGIm6_0_Nov2005_src>PAUSE
  91. Premere un tasto per continuare . . .


mi da questi errori

Ultima modifica effettuata da tullio1995 il 27/12/2014 alle 19:11
PM Quote
Avatar
SamIAm (Normal User)
Newbie


Messaggi: 16
Iscritto: 09/09/2012

Segnala al moderatore
Postato alle 19:15
Sabato, 27/12/2014
Esattamente come succedeva a me :)

Copia e incolla questo codice nel tuo file "text.cxx"
Codice sorgente - presumibilmente C++

  1. // File: text.cpp
  2. // Written by:
  3. //      Grant Macklem (Grant.Macklem@colorado.edu)
  4. //      Gregory Schmelter (Gregory.Schmelter@colorado.edu)
  5. //      Alan Schmidt (Alan.Schmidt@colorado.edu)
  6. //      Ivan Stashak (Ivan.Stashak@colorado.edu)
  7. // CSCI 4830/7818: API Programming
  8. // University of Colorado at Boulder, Spring 2003
  9. // http://www.cs.colorado.edu/~main/bgi
  10. //
  11. // This file contains the code necessary to draw/modify text
  12. //
  13.  
  14. #include <windows.h>        // Provides the Win32 API
  15. #include <windowsx.h>       // Provides GDI helper macros
  16. #include <iostream>
  17. #include <sstream>          // Provides ostringstream
  18. #include <string>           // Provides string
  19. #include "winbgim.h"         // API routines
  20. #include "winbgitypes.h"    // Internal structure data
  21.  
  22.  
  23. /*****************************************************************************
  24. *
  25. *   Some very useful arrays -- Same as previous version for consistency
  26. *   Also, the exported definition of bgiout.
  27. *
  28. *****************************************************************************/
  29. std::ostringstream bgiout;
  30. static int font_weight[] =
  31. {
  32.     FW_BOLD,    // DefaultFont
  33.     FW_NORMAL,  // TriplexFont
  34.     FW_NORMAL,  // SmallFont
  35.     FW_NORMAL,  // SansSerifFont
  36.     FW_NORMAL,  // GothicFont
  37.     FW_NORMAL,  // ScriptFont
  38.     FW_NORMAL,  // SimplexFont
  39.     FW_NORMAL,  // TriplexScriptFont
  40.     FW_NORMAL,  // ComplexFont
  41.     FW_NORMAL,  // EuropeanFont
  42.     FW_BOLD     // BoldFont
  43. };
  44. static int font_family[] =
  45. {
  46.     FIXED_PITCH|FF_DONTCARE,     // DefaultFont
  47.     VARIABLE_PITCH|FF_ROMAN,     // TriplexFont
  48.     VARIABLE_PITCH|FF_MODERN,    // SmallFont
  49.     VARIABLE_PITCH|FF_DONTCARE,  // SansSerifFont
  50.     VARIABLE_PITCH|FF_SWISS,     // GothicFont
  51.     VARIABLE_PITCH|FF_SCRIPT,    // ScriptFont
  52.     VARIABLE_PITCH|FF_DONTCARE,  // SimplexFont
  53.     VARIABLE_PITCH|FF_SCRIPT,    // TriplexScriptFont
  54.     VARIABLE_PITCH|FF_DONTCARE,  // ComplexFont
  55.     VARIABLE_PITCH|FF_DONTCARE,  // EuropeanFont
  56.     VARIABLE_PITCH|FF_DONTCARE   // BoldFont
  57. };
  58. static const char* font_name[] =
  59. {
  60.     "Console",          // DefaultFont
  61.     "Times New Roman",  // TriplexFont
  62.     "Small Fonts",      // SmallFont
  63.     "MS Sans Serif",    // SansSerifFont
  64.     "Arial",            // GothicFont
  65.     "Script",           // ScriptFont
  66.     "Times New Roman",  // SimplexFont
  67.     "Script",           // TriplexScriptFont
  68.     "Courier New",      // ComplexFont
  69.     "Times New Roman",  // EuropeanFont
  70.     "Courier New Bold", // BoldFont
  71. };
  72.  
  73. static struct { int width; int height; } font_metrics[][11] = {
  74.     {{0,0},{8,8},{16,16},{24,24},{32,32},{40,40},{48,48},{56,56},{64,64},{72,72},{80,80}}, // DefaultFont
  75.     {{0,0},{13,18},{14,20},{16,23},{22,31},{29,41},{36,51},{44,62},{55,77},{66,93},{88,124}}, // TriplexFont
  76.     {{0,0},{3,5},{4,6},{4,6},{6,9},{8,12},{10,15},{12,18},{15,22},{18,27},{24,36}}, // SmallFont
  77.     {{0,0},{11,19},{12,21},{14,24},{19,32},{25,42},{31,53},{38,64},{47,80},{57,96},{76,128}}, // SansSerifFont
  78.     {{0,0},{13,19},{14,21},{16,24},{22,32},{29,42},{36,53},{44,64},{55,80},{66,96},{88,128}}, // GothicFont
  79.  
  80.     // These may not be 100% correct
  81.     {{0,0},{11,19},{12,21},{14,24},{19,32},{25,42},{31,53},{38,64},{47,80},{57,96},{76,128}}, // ScriptFont
  82.     {{0,0},{11,19},{12,21},{14,24},{19,32},{25,42},{31,53},{38,64},{47,80},{57,96},{76,128}}, // SimplexFont
  83.     {{0,0},{13,18},{14,20},{16,23},{22,31},{29,41},{36,51},{44,62},{55,77},{66,93},{88,124}}, // TriplexScriptFont
  84.     {{0,0},{11,19},{12,21},{14,24},{19,32},{25,42},{31,53},{38,64},{47,80},{57,96},{76,128}}, // ComplexFont
  85.     {{0,0},{11,19},{12,21},{14,24},{19,32},{25,42},{31,53},{38,64},{47,80},{57,96},{76,128}}, // EuropeanFont
  86.     {{0,0},{11,19},{12,21},{14,24},{19,32},{25,42},{31,53},{38,64},{47,80},{57,96},{76,128}} // BoldFont
  87. };
  88.  
  89. // horiz     LEFT_TEXT   0  left-justify text  
  90. //           CENTER_TEXT 1  center text  
  91. //           RIGHT_TEXT  2  right-justify text  
  92. // vertical  BOTTOM_TEXT 0  bottom-justify text  
  93. //           CENTER_TEXT 1  center text  
  94. //           TOP_TEXT    2  top-justify text
  95. static UINT horiz_align[3] = {TA_LEFT, TA_CENTER, TA_RIGHT};
  96. static UINT vert_align[3] = {TA_BOTTOM, TA_BASELINE, TA_TOP};
  97.  
  98. /*****************************************************************************
  99. *
  100. *   Some helper functions
  101. *
  102. *****************************************************************************/
  103.  
  104. // This function
  105. // POSTCONDITION:
  106. //
  107. static void set_align(WindowData* pWndData)
  108. {
  109.     UINT alignment = pWndData->alignment;
  110.  
  111.     // if we are vertical, things are swapped.
  112.     if (pWndData->textInfo.direction == HORIZ_DIR)
  113.     {
  114.         alignment |= horiz_align[pWndData->textInfo.horiz];
  115.         alignment |= vert_align[pWndData->textInfo.vert];
  116.     }
  117.     else
  118.     {
  119.         alignment |= horiz_align[pWndData->textInfo.vert];
  120.         alignment |= vert_align[pWndData->textInfo.horiz];
  121.     }
  122.  
  123.     // set the alignment for all valid pages.
  124.     for ( int i = 0; i < MAX_PAGES; i++ )
  125.         SetTextAlign(pWndData->hDC[i], alignment);
  126. }
  127.  
  128. // This function updates the current hdc with the user defined font
  129. // POSTCONDITION: text written to the current hdc will be in the new font
  130. //
  131. static void set_font(WindowData* pWndData)
  132. {
  133.     int mindex;
  134.     double xscale, yscale;
  135.     HFONT hFont;
  136.    
  137.     // get the scaling factors based on charsize
  138.     if(pWndData->textInfo.charsize == 0)
  139.     {
  140.         xscale = pWndData->t_scale[0] / pWndData->t_scale[1];
  141.         yscale = pWndData->t_scale[2] / pWndData->t_scale[3];
  142.                
  143.         // if font zero, only use factors.. else also multiply by 4
  144.         if (pWndData->textInfo.font == 0)
  145.             mindex = 0;
  146.         else
  147.             mindex = 4;
  148.     }
  149.     else
  150.     {
  151.         xscale = 1.0;
  152.         yscale = 1.0;
  153.         mindex = pWndData->textInfo.charsize;
  154.     }
  155.  
  156.     // with the scaling decided, make a font.
  157.     hFont = CreateFont(
  158.         int(font_metrics[pWndData->textInfo.font][mindex].height * yscale),
  159.         int(font_metrics[pWndData->textInfo.font][mindex].width  * xscale),
  160.         pWndData->textInfo.direction * 900,
  161.         (pWndData->textInfo.direction & 1) * 900,
  162.         font_weight[pWndData->textInfo.font],
  163.         FALSE,
  164.         FALSE,
  165.         FALSE,
  166.         DEFAULT_CHARSET,
  167.         OUT_DEFAULT_PRECIS,
  168.         CLIP_DEFAULT_PRECIS,
  169.         DEFAULT_QUALITY,
  170.         font_family[pWndData->textInfo.font],
  171.         font_name[pWndData->textInfo.font]
  172.         );
  173.  
  174.     // assign the fonts to each of the hdcs
  175.     for ( int i = 0; i < MAX_PAGES; i++ )
  176.         SelectObject( pWndData->hDC[i], hFont );
  177. }
  178.  
  179.  
  180. /*****************************************************************************
  181. *
  182. *   The actual API calls are implemented below
  183. *
  184. *****************************************************************************/
  185. // This function fills the textsettingstype structure pointed to by textinfo
  186. // with information about the current text font, direction, size, and
  187. // justification.
  188. // POSTCONDITION: texttypeinfo has been filled with the proper information
  189. //
  190. void gettextsettings(struct textsettingstype *texttypeinfo)
  191. {
  192.     // if its null, leave.
  193.     if (!texttypeinfo)
  194.         return;
  195.        
  196.     WindowData* pWndData = BGI__GetWindowDataPtr( );
  197.  
  198.     *texttypeinfo = pWndData->textInfo;
  199. }
  200.  
  201. // This function prints textstring to the screen at the current position
  202. // POSTCONDITION: text has been written to the screen using the current font,
  203. //                direction, and size.  In addition, the current position has
  204. //                been modified to reflect the text that was just output.
  205. //
  206. void outtext(char *textstring)
  207. {
  208.     HDC hDC = BGI__GetWinbgiDC( );
  209.     WindowData* pWndData = BGI__GetWindowDataPtr( );
  210.  
  211.     // so we can clear the screen
  212.     POINT cp;
  213.     GetCurrentPositionEx( hDC, &cp );
  214.  
  215.     // check cp alignment
  216.     if (pWndData->alignment != TA_UPDATECP)
  217.     {
  218.         pWndData->alignment = TA_UPDATECP;
  219.         set_align(pWndData);
  220.     }
  221.  
  222.     TextOut(hDC, 0, 0, (LPCTSTR)textstring, strlen(textstring));
  223.     BGI__ReleaseWinbgiDC( );
  224.     RefreshWindow( NULL );
  225.     // Todo: Change to refresh only the needed part.
  226. }
  227.  
  228. // This function prints textstring to x,y
  229. // POSTCONDITION: text has been written to the screen using the current font,
  230. //                direction, and size. If a string is printed with the default
  231. //                font using outtext or outtextxy, any part of the string that
  232. //                extends outside the current viewport is truncated.
  233. //
  234. void outtextxy(int x, int y, char *textstring)
  235. {
  236.     HDC hDC = BGI__GetWinbgiDC( );
  237.     WindowData* pWndData = BGI__GetWindowDataPtr( );
  238.  
  239.     // check alignment
  240.     if (pWndData->alignment != TA_NOUPDATECP)
  241.     {
  242.         pWndData->alignment = TA_NOUPDATECP;
  243.         set_align(pWndData);
  244.     }
  245.  
  246.     TextOut(hDC, x, y, (LPCTSTR)textstring, strlen(textstring));
  247.     BGI__ReleaseWinbgiDC( );
  248.  
  249.     RefreshWindow( NULL );
  250.     // Todo: Change to refresh only the needed part.
  251. }
  252.  
  253.  
  254.  
  255. // This function sets the vertical and horizontal justification based on CP
  256. // POSTCONDITION: Text output is justified around the current position as
  257. //                has been specified.
  258. //
  259. void settextjustify(int horiz, int vert)
  260. {
  261.     WindowData* pWndData = BGI__GetWindowDataPtr( );
  262.  
  263.     pWndData->textInfo.horiz = horiz;
  264.     pWndData->textInfo.vert  = vert;
  265.  
  266.     WaitForSingleObject(pWndData->hDCMutex, 5000);
  267.     set_align(pWndData);
  268.     ReleaseMutex(pWndData->hDCMutex);
  269. }
  270.  
  271.  
  272. // This function sets the font and it's properties that will be used
  273. // by all text output related functions.
  274. // POSTCONDITION: text output after a call to settextstyle should be
  275. //                in the newly specified format.
  276. //
  277. void settextstyle(int font, int direction, int charsize)
  278. {
  279.     WindowData* pWndData = BGI__GetWindowDataPtr( );
  280.  
  281.     pWndData->textInfo.font = font;
  282.     pWndData->textInfo.direction = direction;
  283.     pWndData->textInfo.charsize = charsize;
  284.  
  285.     WaitForSingleObject(pWndData->hDCMutex, 5000);
  286.     set_font(pWndData);
  287.     ReleaseMutex(pWndData->hDCMutex);
  288. }
  289.  
  290. // This function sets the size of stroked fonts
  291. // POSTCONDITION: these values will be used when charsize is zero in the
  292. //                settextstyle assignments.  consequently output text will
  293. //                be scaled by the appropriate x and y values when output.
  294. //
  295. void setusercharsize(int multx, int divx, int multy, int divy)
  296. {
  297.     WindowData* pWndData = BGI__GetWindowDataPtr( );
  298.     pWndData->t_scale[0] = multx;
  299.     pWndData->t_scale[1] = divx;
  300.     pWndData->t_scale[2] = multy;
  301.     pWndData->t_scale[3] = divy;
  302.  
  303.     WaitForSingleObject(pWndData->hDCMutex, 5000);
  304.     set_font(pWndData);
  305.     ReleaseMutex(pWndData->hDCMutex);
  306. }
  307.  
  308. // This function returns the height in pixels of textstring using the current
  309. // text output settings.
  310. // POSTCONDITION: the height of the string in pixels has been returned.
  311. //
  312. int textheight( const char *textstring)
  313. {
  314.     HDC hDC = BGI__GetWinbgiDC( );
  315.     SIZE tb;
  316.  
  317.     GetTextExtentPoint32(hDC, (LPCTSTR) textstring, strlen(textstring), &tb);
  318.     BGI__ReleaseWinbgiDC( );
  319.  
  320.     return tb.cy;
  321. }
  322.  
  323. // This function returns the width in pixels of textstring using the current
  324. // text output settings.
  325. // POSTCONDITION: the width of the string in pixels has been returned.
  326. //
  327. int textwidth(char *textstring)
  328. {
  329.     HDC hDC = BGI__GetWinbgiDC( );
  330.     SIZE tb;
  331.  
  332.     GetTextExtentPoint32(hDC, (LPCTSTR) textstring, strlen(textstring), &tb);
  333.     BGI__ReleaseWinbgiDC( );
  334.  
  335.     return tb.cx;
  336. }
  337.  
  338. void outstreamxy(int x, int y, std::ostringstream& out)
  339. {
  340.     std::string all, line;
  341.     int i;
  342.     int startx = x;
  343.  
  344.     all = out.str( );
  345.     out.str("");
  346.  
  347.     moveto(x,y);
  348.     for (i = 0; i < all.length( ); i++)
  349.     {
  350.         if (all[i] == '\n')
  351.         {
  352.             if (line.length( ) > 0)
  353.                 outtext((char *) line.c_str( ));
  354.             y += textheight("X");
  355.             x = startx;
  356.             line.clear( );
  357.             moveto(x,y);
  358.         }
  359.         else
  360.             line += all[i];
  361.     }
  362.     if (line.length( ) > 0)
  363.         outtext((char *) line.c_str( ));
  364. }
  365.  
  366. void outstream(std::ostringstream& out)
  367. {
  368.     outstreamxy(getx( ), gety( ), out);
  369. }


PM Quote
Pagine: [ 1 2 3 ] Precedente | Prossimo