main.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. // Jovian Hersemeule
  2. #include <iostream>
  3. #include <SDL/SDL.h>
  4. #include "edit.h"
  5. int main( int argc, char** argv )
  6. {
  7. /// [1] Démarrage
  8. // [1.1] Démarrages SDL
  9. if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
  10. {
  11. std::cout << "Impossible d'initialiser la SDL: " << SDL_GetError() << std::endl;
  12. return 1;
  13. }
  14. // [1.2] Préparation de fermeture
  15. atexit(SDL_Quit);
  16. // [1.3] Para-fenêtre
  17. SDL_WM_SetCaption("Boundy Driver - Éditeur", 0);
  18. /// [2] Préparation des composants
  19. // [2.2] Préparation
  20. int ix(-500), iy(-500); // Origine
  21. int mx( 700 ), my( 384 ); // Souris
  22. // [2.3] Préparation du Terrain
  23. Editor myEditor;
  24. myEditor.init();
  25. // [2.4] Évènements
  26. bool right_click( false );
  27. /// [3] Boucle principale
  28. bool done(false);
  29. SDL_Event event;
  30. while (!done)
  31. {
  32. // [3.1] Gestion évènements
  33. SDL_WaitEvent(&event);
  34. switch (event.type)
  35. {
  36. case SDL_QUIT:
  37. done = true;
  38. break;
  39. case SDL_KEYDOWN:
  40. switch ( event.key.keysym.sym )
  41. {
  42. case SDLK_ESCAPE :
  43. done = true;
  44. break;
  45. case SDLK_z :
  46. myEditor.removePlot();
  47. break;
  48. case SDLK_s :
  49. myEditor.save();
  50. break;
  51. case SDLK_h :
  52. myEditor.toggleHelp();
  53. break;
  54. case SDLK_c :
  55. myEditor.load();
  56. ix = iy = -500;
  57. break;
  58. default:
  59. break;
  60. }
  61. break;
  62. case SDL_MOUSEMOTION:
  63. mx = event.motion.x;
  64. my = event.motion.y;
  65. if ( right_click )
  66. {
  67. ix -= event.motion.xrel ;
  68. iy -= event.motion.yrel ;
  69. }
  70. break;
  71. case SDL_MOUSEBUTTONDOWN:
  72. switch ( event.button.button )
  73. {
  74. case 3 : // Clic droit
  75. right_click = true;
  76. break;
  77. case 1 : // Clic gauche
  78. myEditor.addPlot( mx + ix, my + iy );
  79. break;
  80. case 4 : // Bouton
  81. myEditor.zoomIn();
  82. break;
  83. case 5 : // Bouton
  84. myEditor.zoomOut();
  85. break;
  86. }
  87. break;
  88. case SDL_MOUSEBUTTONUP:
  89. if ( event.button.button == 3 )
  90. right_click = false;
  91. break;
  92. }
  93. // [3.2] Calculs
  94. // [3.3] Dessin des composants
  95. myEditor.draw( ix, iy );
  96. } //fin bcl principale
  97. ///[4] Destruction des composants
  98. std::cout << "Aucune erreur détectée." << std::endl;
  99. return 0;
  100. }