1 // (_||_/
2 // ( ) Class de la Sourie
3 // ( o 0 )
4 //-OOO�--(_)---�OOO---------------------------------------
5 // Copyright (C) 2006 By Dominique Roux-Serret
6 // .OOOo oOOO. roux-serret@ifrance.com
7 //-( )------( )---------------------------------------
8 // ( ( ) / Le 23/03/2006
9 // (_) (_/
10
11 // This program is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU General Public License as published by
13 // the Free Software Foundation; either version 2 or version 3 of the License.
14
15 // This program is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19
20 // You should have received a copy of the GNU General Public License along
21 // with this program; if not, write to the Free Software Foundation, Inc.,
22 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23
24 #include <iostream>
25 #include <stdio.h>
26 #include "mouse.h"
27 #include "preference.h"
28 #include "ecran.h"
29 #include "audio.h"
30
31 /*** Variables Globales ***/
32 /**************************/
33 extern Audio Sons;
34 extern int Horloge;
35 extern Ecran Ec[2];
36
37 /*** Constructeur et Destructeur ***/
38 /***********************************/
Mouse(void)39 Mouse::Mouse(void)
40 {
41 Px=400;
42 Py=300;
43 }
44
~Mouse(void)45 Mouse::~Mouse(void)
46 {
47 }
48
49 /*** Initialise la sourie ***/
50 /****************************/
InitStart(void)51 void Mouse::InitStart(void)
52 {
53 // Initialise les coordonn�es de la sourie
54 Px=400;
55 Py=300;
56 SDL_WarpMouse(Px,Py);
57 }
58
59 /*** Initialise un bebut d'utilisation ***/
60 /*****************************************/
Init(struct mPy * TablePy,struct mBoutton * B)61 void Mouse::Init(struct mPy *TablePy,struct mBoutton *B)
62 {
63 // Sauve les adresses utils
64 tPy=TablePy;
65 Bo=B;
66 }
67
68 /*** Prend les evenements de la sourie ***/
69 /*****************************************/
GetEvent(SDL_Event & event,int & pPy)70 void Mouse::GetEvent(SDL_Event &event,int &pPy)
71 {
72 int i;
73
74 switch(event.type) {
75 case SDL_MOUSEMOTION: // Si mouvement de la sourie
76 Px=event.motion.x;
77 Py=event.motion.y;
78 // regarde si doit bouger la position de Py
79 if(tPy) { // Si bien une table
80 i=0;
81 while(tPy[i].DepX!=-1) { // Fait toutes les coordonn�es
82 if(Px>=tPy[i].DepX && Px<=tPy[i].FinX && Py>=tPy[i].DepY && Py<=tPy[i].FinY)
83 if(pPy!=tPy[i].Py) {
84 pPy=tPy[i].Py;
85 Sons.Play(sClic);
86 }
87 i++;
88 };
89 }
90 break;
91 case SDL_MOUSEBUTTONDOWN:
92 if(event.button.state==SDL_PRESSED) {
93 Px=event.button.x;
94 Py=event.button.y;
95
96 // regarde si doit valider un enter
97 if(tPy) { // Si bien une table
98 i=0;
99 while(tPy[i].DepX!=-1) { // Fait toutes les coordonn�es
100 if(Px>=tPy[i].DepX && Px<=tPy[i].FinX && Py>=tPy[i].DepY && Py<=tPy[i].FinY)
101 if(tPy[i].Valide==true) {
102 event.type=SDL_KEYDOWN;
103 event.key.state=SDL_PRESSED;
104 event.key.keysym.sym=SDLK_RETURN;
105 }
106 i++;
107 };
108 }
109
110 // Fait la gestion des bouttons
111 if(Bo) { // Si bien une table
112 i=0;
113 while(Bo[i].DepX!=-1) { // Fait toutes les coordonn�es
114 if(Px>=Bo[i].DepX && Px<=Bo[i].FinX && Py>=Bo[i].DepY && Py<=Bo[i].FinY) {
115 if(Bo[i].Adr==NULL) { // Si doit fair une touche
116 event.type=SDL_KEYDOWN;
117 event.key.state=SDL_PRESSED;
118 event.key.keysym.sym=(SDLKey)Bo[i].Valeur;
119 }
120 else { // Si doit changer une variable
121 *(Bo[i].Adr)=Bo[i].Valeur;
122 }
123 }
124 i++;
125 };
126 }
127 break;
128 }
129 }
130
131 }
132
133 /*** Affiche le curseur ***/
134 /**************************/
Affiche(int NumVideo)135 void Mouse::Affiche(int NumVideo)
136 {
137 int X=Px,Y=Py;
138 int NumSp=(Horloge/50)%20;
139
140 // Corrige la position du curseur au cas ou d�borde de l'�cran
141 if(X<5) X=5;
142 if(X>=800-38) X=800-39;
143 if(Y<10) Y=10;
144 if(Y>=600-35) Y=600-36;
145
146 // Affiche le curseur
147 Ec[NumVideo].Affiche(curseur,NumSp,X,Y);
148 }
149