123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- // Jovian Hersemeule
- #include <iostream>
- #include <SDL/SDL.h>
- #include "edit.h"
- int main( int argc, char** argv )
- {
- /// [1] Démarrage
- // [1.1] Démarrages SDL
- if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
- {
- std::cout << "Impossible d'initialiser la SDL: " << SDL_GetError() << std::endl;
- return 1;
- }
- // [1.2] Préparation de fermeture
- atexit(SDL_Quit);
- // [1.3] Para-fenêtre
- SDL_WM_SetCaption("Boundy Driver - Éditeur", 0);
- /// [2] Préparation des composants
- // [2.2] Préparation
- int ix(-500), iy(-500); // Origine
- int mx( 700 ), my( 384 ); // Souris
- // [2.3] Préparation du Terrain
- Editor myEditor;
- myEditor.init();
- // [2.4] Évènements
- bool right_click( false );
- /// [3] Boucle principale
- bool done(false);
- SDL_Event event;
- while (!done)
- {
- // [3.1] Gestion évènements
- SDL_WaitEvent(&event);
- switch (event.type)
- {
- case SDL_QUIT:
- done = true;
- break;
- case SDL_KEYDOWN:
- switch ( event.key.keysym.sym )
- {
- case SDLK_ESCAPE :
- done = true;
- break;
- case SDLK_z :
- myEditor.removePlot();
- break;
- case SDLK_s :
- myEditor.save();
- break;
- case SDLK_h :
- myEditor.toggleHelp();
- break;
- case SDLK_c :
- myEditor.load();
- ix = iy = -500;
- break;
- default:
- break;
- }
- break;
- case SDL_MOUSEMOTION:
- mx = event.motion.x;
- my = event.motion.y;
- if ( right_click )
- {
- ix -= event.motion.xrel ;
- iy -= event.motion.yrel ;
- }
- break;
- case SDL_MOUSEBUTTONDOWN:
- switch ( event.button.button )
- {
- case 3 : // Clic droit
- right_click = true;
- break;
- case 1 : // Clic gauche
- myEditor.addPlot( mx + ix, my + iy );
- break;
- case 4 : // Bouton
- myEditor.zoomIn();
- break;
- case 5 : // Bouton
- myEditor.zoomOut();
- break;
- }
- break;
- case SDL_MOUSEBUTTONUP:
- if ( event.button.button == 3 )
- right_click = false;
- break;
- }
- // [3.2] Calculs
- // [3.3] Dessin des composants
- myEditor.draw( ix, iy );
- } //fin bcl principale
- ///[4] Destruction des composants
- std::cout << "Aucune erreur détectée." << std::endl;
- return 0;
- }
|