try and implement resize in a sane way, but changeing from windowed mode to fullscreen mode is now kind of weird
--- a/src/GameMessageView.hh Tue Jan 13 23:15:47 2009 +0200
+++ b/src/GameMessageView.hh Tue Jan 13 23:54:47 2009 +0200
@@ -29,6 +29,11 @@
GameMessageView (PixelArea area);
/**
+ * Update draw area
+ */
+ void on_resize (PixelArea new_area) { this->area = new_area; }
+
+ /**
* Add a message to the list of messages displayed
*/
void add_message (CL_Color color, std::string message);
--- a/src/Graphics.cc Tue Jan 13 23:15:47 2009 +0200
+++ b/src/Graphics.cc Tue Jan 13 23:54:47 2009 +0200
@@ -17,10 +17,11 @@
}
Graphics::Graphics (Engine &engine, GameState &state, PixelCoordinate resolution, bool fullscreen) :
- CL_DisplayWindow(GRAPHICS_WINDOW_TITLE, resolution.x, resolution.y, fullscreen),
+ CL_DisplayWindow(GRAPHICS_WINDOW_TITLE, resolution.x, resolution.y, fullscreen, true),
engine(engine),
state(state),
resolution(resolution),
+ fullscreen_resolution(0, 0), window_resolution(0, 0),
update_timer(GRAPHICS_UPDATE_INTERVAL_MS),
input(get_ic()->get_keyboard()),
simple_font("Font2", engine.getResourceManager()),
@@ -29,6 +30,7 @@
// connect timer signal
slots.connect(update_timer.sig_tick(), this, &Graphics::on_update);
+ slots.connect(this->sig_resize(), this, &Graphics::on_window_resize);
// enable
update_timer.start();
@@ -38,6 +40,18 @@
// GameState events....
state.setEventHandler(this);
+
+ // set correct resolution
+ if (fullscreen) {
+ fullscreen_resolution = resolution;
+
+ } else {
+ CL_DisplayMode best_mode = getBestMode();
+
+ fullscreen_resolution = PixelCoordinate(best_mode.get_resolution().width, best_mode.get_resolution().height);
+ window_resolution = resolution;
+ }
+
}
const std::vector<CL_DisplayMode> & Graphics::getDisplayModes (void) {
@@ -82,6 +96,35 @@
player->handleInput(input_mask, input_dt);
}
+void Graphics::toggle_fullscreen (void) {
+ if (is_fullscreen()) {
+ // remember current fullscreen resolution
+ fullscreen_resolution = resolution;
+
+ // enter windowed mode
+ set_windowed();
+
+/*
+ // do we have a window-mode resolution stored?
+ if (window_resolution.x && window_resolution.y)
+ set_size(window_resolution.x, window_resolution.y);
+*/
+ } else {
+ // remember current window resolution
+ window_resolution = resolution;
+
+ // enter fullscreen mode
+ set_fullscreen(fullscreen_resolution.x, fullscreen_resolution.y);
+
+ // update resolution
+ resolution = fullscreen_resolution;
+
+ // log
+ message_view.add_message(CL_Color::yellow, CL_String::format("[ Enter fullscreen mode with %1 x %2 resolution ]",
+ (int) resolution.x, (int) resolution.y));
+ }
+}
+
void Graphics::handle_input (GuiInput flags) {
// update flags
this->flags = flags;
@@ -101,12 +144,8 @@
}
// toggle fullscreen?
- if (flags & GUI_INPUT_TOGGLE_FULLSCREEN) {
- if (is_fullscreen())
- set_windowed();
- else
- set_fullscreen();
- }
+ if (flags & GUI_INPUT_TOGGLE_FULLSCREEN)
+ toggle_fullscreen();
}
static PixelDimension value_between (PixelDimension low, PixelDimension value, PixelDimension high) {
@@ -289,6 +328,20 @@
}
+void Graphics::on_window_resize (int new_x, int new_y) {
+ // ignore resize in fullscreen mode
+ if (is_fullscreen())
+ return;
+
+ // update resolution
+ resolution = PixelCoordinate(new_x, new_y);
+
+ // resize components
+ message_view.on_resize(getMessageViewArea(resolution));
+
+ // log message
+ message_view.add_message(CL_Color::yellow, CL_String::format("[ Resized window to %1 x %2 ]", new_x, new_y));
+}
void Graphics::on_player_joined (Player *p) {
message_view.add_message(CL_Color::white, " *** Player joined");
--- a/src/Graphics.hh Tue Jan 13 23:15:47 2009 +0200
+++ b/src/Graphics.hh Tue Jan 13 23:54:47 2009 +0200
@@ -21,27 +21,60 @@
*/
class Graphics : public GameStateEventHandler, public CL_DisplayWindow {
private:
+ /**
+ * Our engine reference
+ */
Engine &engine;
+
+ /**
+ * GameState we are associated with
+ */
GameState &state;
+
+ /**
+ * Current window resolution
+ */
+ PixelCoordinate resolution;
- PixelCoordinate resolution;
+ /**
+ * Target resolution in fullscreen/windowed mode
+ */
+ PixelCoordinate fullscreen_resolution, window_resolution;
+ /**
+ * ClanLib signal slots
+ */
CL_SlotContainer slots;
+ /**
+ * Our timer that drives redraws
+ */
Timer update_timer;
-
+
+ /**
+ * Our input handler for GUI and Player input
+ */
Input input;
- // current GUI input state
+ /**
+ * Current GUI input state
+ */
GuiInput flags;
- // basic fonts
+ /**
+ * A basic font
+ */
CL_Font simple_font;
- // view components
+ /**
+ * View components
+ */
GameMessageView message_view;
public:
+ /**
+ *
+ */
Graphics (Engine &engine, GameState &state, PixelCoordinate resolution, bool fullscreen);
/**
@@ -63,6 +96,11 @@
private:
/**
+ * Shift back and forth between fullscreen and windowed mode, retaining resolutions
+ */
+ void toggle_fullscreen (void);
+
+ /**
* Reads current input events from Input and applies them, using LocalPlayer::handleInput and
* Graphics::handle_input.
*/
@@ -72,12 +110,26 @@
* Handles GuiInput flags read from Input.
*/
void handle_input (GuiInput flags);
-
+
+ /**
+ * Redraws entire screen
+ */
void do_redraw (void);
+ /**
+ * Handles input and redraws screen
+ */
void on_update (TimeMS tick_length);
- void draw_player_info(CL_GraphicContext *gc, Player *p);
+ /**
+ * Draws status view
+ */
+ void draw_player_info (CL_GraphicContext *gc, Player *p);
+
+ /**
+ * Handles window resize. This just updates resolution
+ */
+ void on_window_resize (int new_x, int new_y);
protected:
/* GameStateEventHandler */