2 Copyright SSW Team 2010
5 /*SENI, Search for Extra Nibiru Intelligence*/
8 This program is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program. If not, see <http://www.gnu.org/licenses/>.
23 Copyright SSW Team 2010
32 void defaultEvent(SDL_Event
*, Engine
*);
34 int Engine::initVideo(int resx
, int resy
, int bitres
, int flags
)
36 if(SDL_Init(SDL_INIT_TIMER
| SDL_INIT_AUDIO
| SDL_INIT_VIDEO
)){
37 strcpy(this->engineError
, "Error: SDL_Init(SDL_INIT_TIMER | SDL_INIT_AUDIO | SDL_INIT_VIDEO): ");
38 strcat(this->engineError
, SDL_GetError());
41 SDL_GL_SetAttribute(SDL_GL_RED_SIZE
, 5);
42 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE
, 5);
43 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE
, 5);
44 SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE
, bitres
);
45 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER
, 1);
46 this->screen
= SDL_SetVideoMode(resx
, resy
, bitres
, flags
);
48 strcpy(this->engineError
, "Error: SDL_SetVideoMode(sc.resx, sc.resy, sc.bitres, sc.sdlflags): ");
49 strcat(this->engineError
, SDL_GetError());
52 strcpy(this->engineError
, "No hay errores");
53 return ENGINE_NO_ERROR
;
56 void Engine::quit(void)
63 void Engine::setOnQuit(quit_event qe
)
68 char *Engine::getError()
70 return this->engineError
;
73 void Engine::setError(char *e
)
75 strcpy(this->engineError
, e
);
80 this->engineError
[0] = 0;
81 this->setEventInAll(defaultEvent
);
86 void Engine::setEvent(int i
, engine_event ee
)
94 void Engine::setEventInAll(engine_event ee
)
99 for(i
= 0; i
< MAX_EVENTS
; i
++)
100 this->events
[i
] = ee
;
103 void Engine::startEvents(void)
107 while(SDL_WaitEvent(&ev
)){
110 this->events
[EVENT_QUIT
](&ev
, this);
112 case SDL_MOUSEMOTION
:
113 this->events
[EVENT_MOUSEMOTION
](&ev
, this);
115 case SDL_MOUSEBUTTONDOWN
:
116 case SDL_MOUSEBUTTONUP
:
117 if(ev
.button
.button
== SDL_BUTTON_LEFT
&& this->menu
!= 0){
118 for(i
= 0; i
< MAX_OPTIONS
; ++i
){
119 Option
*o
= this->menu
->getOption(i
);
120 if(o
!= WITHOUT_OPTION
){
121 int x
= ev
.button
.x
, y
= ev
.button
.y
;
122 if(x
>= o
->getX() && x
<= o
->getX() + o
->getW()
123 && y
>= o
->getY() && y
<= o
->getY() + o
->getH())
124 o
->execEvent(&ev
, this, this->menu
, o
);
128 this->events
[EVENT_MOUSEBUTTON
](&ev
, this);
132 this->events
[EVENT_KEYBOARD
](&ev
, this);
134 case SDL_VIDEORESIZE
:
135 this->events
[EVENT_RESIZE
](&ev
, this);
138 this->events
[EVENT_DEFAULT
](&ev
, this);
143 void Engine::update(void)
145 SDL_GL_SwapBuffers();
148 void Engine::update(int xi
, int yi
, int xf
, int yf
)
150 SDL_UpdateRect(screen
, xi
, yi
, xf
, yf
);
154 int Engine::show(SDL_Surface
*s
, int x
, int y
, int w
, int h
)
164 if(SDL_BlitSurface(s
, NULL
, screen
, &dest
))
166 return ENGINE_NO_ERROR
;
169 int Engine::showMenu(Menu
*m
)
171 if(m
->show() == MENU_ERROR
){
172 strcpy(this->engineError
, "Error: m->show(screen): ");
173 strcat(this->engineError
, SDL_GetError());
178 strcpy(this->engineError
, "No hay errores");
179 return ENGINE_NO_ERROR
;
182 void defaultEvent(SDL_Event
*e
, Engine
*engine
)
188 case SDL_VIDEOEXPOSE
: