Revert "oops, forgot something!"
[plastic-engine.git] / src / window.cpp
blob1fb688c43ca263db9f12dc823570728957cb182f
1 // Plastic Engine
2 // Copyright (C) 2008 Albert Brown
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 // Window subsystem: establish a buffer to draw in, handle input
19 #include <stdexcept>
20 #include <iostream>
21 #include <string>
22 #include "SDL.h"
24 #ifdef HAVE_CONFIG_H
25 #include "config.hpp"
26 #else
27 #define PACKAGE_STRING "Plastic"
28 #endif
30 #include "state.hpp"
31 #include "window.hpp"
35 window_subsystem::window_subsystem()
37 // TODO: we're going to have to implement commandline arguments and
38 // some sort of config interface before we can un-hardcode these values
39 _screen = SDL_SetVideoMode(640, 480, 32, SDL_DOUBLEBUF | SDL_OPENGL);
41 if(!_screen)
43 // Something went wrong
44 std::string msg = std::string("SDL failed to set video mode: ")
45 + SDL_GetError();
46 throw std::runtime_error(msg.c_str());
49 SDL_WM_SetCaption(PACKAGE_STRING, PACKAGE_STRING);
51 std::cout << "window_subsystem initialized." << std::endl;
54 window_subsystem::~window_subsystem()
56 // The way SDL is designed, we can't really close the window.
57 // TODO: maybe it would be possible if we init the SDL video subsystem
58 // here (in this class). This might allow us to close and restart
59 // it aswell, although this should not be neccesary (maybe on windows).
61 std::cout << "window_subsystem shut down." << std::endl;
64 void window_subsystem::tick(state &s)
66 SDL_Event event;
67 while(SDL_PollEvent(&event))
69 switch(event.type)
71 case SDL_KEYDOWN:
72 if(event.key.keysym.sym == SDLK_ESCAPE)
74 std::cout << "Escape" << std::endl;
75 s.running = false;
77 break;
78 case SDL_QUIT:
79 std::cout << "Close button" << std::endl;
80 s.running = false;
81 break;