# HG changeset patch # User Tero Marttila # Date 1232573129 -7200 # Node ID 7dddc163489a3adae5a88f79164ba9cddfc30269 # Parent 721c60072091c7f0d7e50ac0db64c40c8d81b7b3 drawing the GameView works diff -r 721c60072091 -r 7dddc163489a src/Engine.cc --- a/src/Engine.cc Wed Jan 21 23:07:22 2009 +0200 +++ b/src/Engine.cc Wed Jan 21 23:25:29 2009 +0200 @@ -75,7 +75,7 @@ // put graphics into GameView mode if (graphics) - graphics->displayGameView(*game_state, game_state->getLocalPlayer()); + graphics->displayGameView(*game_state, lp); } diff -r 721c60072091 -r 7dddc163489a src/Graphics/Display.cc --- a/src/Graphics/Display.cc Wed Jan 21 23:07:22 2009 +0200 +++ b/src/Graphics/Display.cc Wed Jan 21 23:25:29 2009 +0200 @@ -10,12 +10,15 @@ config(config), fullscreen_resolution(0, 0), update_timer(GRAPHICS_UPDATE_INTERVAL_MS), - target(NULL) + current_view(NULL) { // connect timer signal slots.connect(update_timer.sig_tick(), this, &Display::on_update); slots.connect(this->sig_resize(), this, &Display::on_window_resize); + // enable timer + update_timer.start(); + // set correct fullscreen resolution if (config.fullscreen) { fullscreen_resolution = config.resolution; @@ -49,6 +52,14 @@ return *best_mode; } +void Display::setView (View *view) { + this->current_view = view; + + // resize to fill display + if (view) + view->resize(PixelArea(0, 0, get_width(), get_height())); +} + void Display::toggle_fullscreen (void) { if (is_fullscreen()) { // enter windowed mode @@ -64,9 +75,9 @@ (void) dt; // do we have something to draw? - if (target) { + if (current_view) { // draw it - target->draw(*this); + current_view->draw(*this); // flip buffers, sync flip(1); @@ -80,6 +91,10 @@ // ignore resize in fullscreen mode if (is_fullscreen()) return; + + // resize view + if (current_view) + current_view->resize(PixelArea(0, 0, new_x, new_y)); } diff -r 721c60072091 -r 7dddc163489a src/Graphics/Display.hh --- a/src/Graphics/Display.hh Wed Jan 21 23:07:22 2009 +0200 +++ b/src/Graphics/Display.hh Wed Jan 21 23:25:29 2009 +0200 @@ -22,7 +22,7 @@ } -#include "Drawable.hh" +#include "View.hh" #include "../Timer.hh" #include @@ -53,7 +53,7 @@ /** * What we draw */ - Drawable *target; + View *current_view; CL_SlotContainer slots; @@ -85,11 +85,9 @@ } /** - * Set draw target + * Display the given view, this will initialize resize it to the right size */ - void setTarget (Drawable *target) { - this->target = target; - } + void setView (View *view); /** * Shift back and forth between fullscreen and windowed mode, retaining resolutions diff -r 721c60072091 -r 7dddc163489a src/Graphics/Graphics.hh --- a/src/Graphics/Graphics.hh Wed Jan 21 23:07:22 2009 +0200 +++ b/src/Graphics/Graphics.hh Wed Jan 21 23:25:29 2009 +0200 @@ -49,7 +49,7 @@ GameView *view = new GameView(state, player); // assign it to the display - display.setTarget(view); + display.setView(view); } }; diff -r 721c60072091 -r 7dddc163489a src/Graphics/PlayerInfoView.cc --- a/src/Graphics/PlayerInfoView.cc Wed Jan 21 23:07:22 2009 +0200 +++ b/src/Graphics/PlayerInfoView.cc Wed Jan 21 23:25:29 2009 +0200 @@ -59,7 +59,7 @@ area.left + 20 + 100 * bar_length, area.top + 10, sskills.str(), - display.get_gc() + gc ); // stats - deaths @@ -69,7 +69,7 @@ area.left + 20 + 100 * bar_length, area.top + 30, ssdeaths.str(), - display.get_gc() + gc ); // stats - ratio @@ -79,7 +79,7 @@ area.left + 20 + 100 * bar_length, area.top + 50, ssratio.str(), - display.get_gc() + gc ); @@ -116,7 +116,7 @@ area.left + 20 + 100 * bar_length, area.top + 70, player->getCurrentWeapon()->getName(), - display.get_gc() + gc ); } diff -r 721c60072091 -r 7dddc163489a src/Graphics/View.hh --- a/src/Graphics/View.hh Wed Jan 21 23:07:22 2009 +0200 +++ b/src/Graphics/View.hh Wed Jan 21 23:25:29 2009 +0200 @@ -1,7 +1,15 @@ #ifndef GRAPHICS_VIEW_HH #define GRAPHICS_VIEW_HH +namespace graphics +{ + +class View; + +} + #include "Drawable.hh" +#include "Display.hh" #include "../Types.hh" namespace graphics @@ -10,7 +18,7 @@ /** * A view is some area of the display that displays something */ -class View : public Drawable { +class View /* : public Drawable */ { protected: /** * The area of the screen that is ours to draw on @@ -28,6 +36,11 @@ } /** + * Draw into the view area + */ + virtual void draw (Display &display) = 0; + + /** * Update the view area */ virtual void resize (const PixelArea &new_area) {