src/Graphics/GameView.cc
branchnew_graphics
changeset 411 106aaf6eadfe
parent 410 41fd46cffc52
child 412 721c60072091
equal deleted inserted replaced
410:41fd46cffc52 411:106aaf6eadfe
     1 
     1 
     2 #include "GameView.hh"
     2 #include "GameView.hh"
       
     3 #include "Graphics.hh"
       
     4 
       
     5 #include <cassert>
     3 
     6 
     4 namespace graphics
     7 namespace graphics
     5 {
     8 {
       
     9 
       
    10 GameView::GameView (GameState &state, LocalPlayer *player) :
       
    11     View(PixelArea(0, 0, graphics->display.get_width, graphics->display.get_height)),
       
    12     state(state), player(NULL), info_view(NULL), message_view(getMessageViewArea())
       
    13 {
       
    14     // have player?
       
    15     if (player)
       
    16         setPlayer(player);
       
    17 
       
    18     // insert message
       
    19     message_view.add_message("Hello World!");
       
    20 }
       
    21 
       
    22 void GameView::setPlayer (LocalPlayer *player) {
       
    23     assert(!this->player && player);
       
    24     
       
    25     // remember it
       
    26     this->player = player;
       
    27 
       
    28     // build the info_view as well
       
    29     info_view = new PlayerInfoView(getInfoViewArea(), player);
       
    30 }
     6 
    31 
     7 
    32 
     8 void GameView::draw (Display *display) {
    33 void GameView::draw (Display *display) {
     9     CL_GraphicContext *gc = display->get_gc();
    34     CL_GraphicContext *gc = display->get_gc();
    10 
    35 
    33     gc->clear(CL_Color::black);
    58     gc->clear(CL_Color::black);
    34 
    59 
    35     // Draw the game
    60     // Draw the game
    36     state.draw(this, camera, flags & GUI_INPUT_DISPLAY_WEAPON);
    61     state.draw(this, camera, flags & GUI_INPUT_DISPLAY_WEAPON);
    37     
    62     
    38     // draw player info box
    63     // draw info view?
    39     if (player != NULL) {
    64     if (info_view)
    40         draw_player_info(gc, player);
    65         info_view->draw(display);
    41     }
    66 
    42     
       
    43     // draw messages
    67     // draw messages
    44     message_view.draw(this);
    68     message_view.draw(this);
    45 }
    69 }
    46 
    70 
       
    71 void GameView::resize (const PixelArea &new_area) {
       
    72     View::resize(new_area);
       
    73     
       
    74     // resize subcomponents
       
    75     if (info_view)
       
    76         info_view->resize(getInfoViewArea());
       
    77     
       
    78     message_view.resize(getMessageViewArea());
    47 
    79 
    48 };
    80     // log message
       
    81     message_view.add_message(CL_Color::yellow, CL_String::format("[ Resized window to %1 x %2 ]", getWidth(), getHeight()));
       
    82 }
       
    83 
       
    84 
       
    85 }