src/Graphics.cc
changeset 408 e6cfc44266af
parent 394 82def222fe7d
child 409 1a03ff151abc
equal deleted inserted replaced
407:443f6f7abcfb 408:e6cfc44266af
    14             resolution.x,
    14             resolution.x,
    15             resolution.y
    15             resolution.y
    16     );
    16     );
    17 }
    17 }
    18 
    18 
    19 Graphics::Graphics (Engine &engine, GameState &state, PixelCoordinate resolution, bool fullscreen) :
    19 Graphics::Graphics (Engine &engine, GameState &state, const GraphicsConfiguration &config) :
    20     CL_DisplayWindow(GRAPHICS_WINDOW_TITLE, resolution.x, resolution.y, fullscreen, true),
    20     CL_DisplayWindow(GRAPHICS_WINDOW_TITLE, config.resolution.x, config.resolution.y, config.fullscreen, true),
    21     engine(engine), 
    21     engine(engine), 
    22     state(state), 
    22     state(state), 
    23     resolution(resolution),
    23     resolution(config.resolution),
    24     fullscreen_resolution(0, 0), window_resolution(0, 0),
    24     fullscreen_resolution(0, 0), window_resolution(0, 0),
    25     update_timer(GRAPHICS_UPDATE_INTERVAL_MS),
    25     update_timer(GRAPHICS_UPDATE_INTERVAL_MS),
    26     input(get_ic()->get_keyboard()),
    26     input(get_ic()->get_keyboard()),
    27     simple_font("Font2", engine.getResourceManager()),
    27     simple_font("Font2", engine.getResourceManager()),
    28     message_view(getMessageViewArea(resolution))
    28     message_view(getMessageViewArea(resolution))
    40 
    40 
    41     // GameState events....
    41     // GameState events....
    42     state.setEventHandler(this);
    42     state.setEventHandler(this);
    43 
    43 
    44     // set correct resolution
    44     // set correct resolution
    45     if (fullscreen) {
    45     if (config.fullscreen) {
    46         fullscreen_resolution = resolution;
    46         fullscreen_resolution = resolution;
    47 
    47 
    48     } else {
    48     } else {
    49         CL_DisplayMode best_mode = getBestMode();
    49         CL_DisplayMode best_mode = getBestMode();
    50 
    50 
   173     if ((player = state.getLocalPlayer()) != NULL) {
   173     if ((player = state.getLocalPlayer()) != NULL) {
   174         // try and center the screen on the player
   174         // try and center the screen on the player
   175         PixelCoordinate target = player->getCoordinate() - PixelCoordinate(resolution.x / 2, (resolution.y - 100) / 2);
   175         PixelCoordinate target = player->getCoordinate() - PixelCoordinate(resolution.x / 2, (resolution.y - 100) / 2);
   176 
   176 
   177         // ...but keep the world in view
   177         // ...but keep the world in view
   178         PixelCoordinate max = state.world.getDimensions() - resolution + PixelCoordinate(0, 100);
   178         PixelCoordinate max = state.terrain.getDimensions() - resolution + PixelCoordinate(0, 100);
   179         
   179         
   180         // ...by limiting the value to 0...max
   180         // ...by limiting the value to 0...max
   181         camera = PixelCoordinate(
   181         camera = PixelCoordinate(
   182             value_between(0, target.x, max.x),
   182             value_between(0, target.x, max.x),
   183             value_between(0, target.y, max.y)
   183             value_between(0, target.y, max.y)