terom@410: terom@410: #include "Display.hh" terom@410: terom@410: namespace graphics terom@410: { terom@410: terom@411: Display::Display (const DisplayConfig &config) : terom@411: CL_DisplayWindow(GRAPHICS_WINDOW_TITLE, config.resolution.width, config.resolution.height, config.fullscreen, true), terom@411: config(config), terom@411: fullscreen_resolution(0, 0), terom@411: update_timer(GRAPHICS_UPDATE_INTERVAL_MS), terom@411: target(NULL) terom@411: { terom@411: // connect timer signal terom@411: slots.connect(update_timer.sig_tick(), this, &Display::on_update); terom@411: slots.connect(this->sig_resize(), this, &Display::on_window_resize); terom@411: terom@411: // set correct fullscreen resolution terom@411: if (config.fullscreen) { terom@411: fullscreen_resolution = config.resolution; terom@411: terom@411: } else { terom@411: CL_DisplayMode best_mode = getBestMode(); terom@411: terom@411: fullscreen_resolution = PixelCoordinate(best_mode.get_resolution().width, best_mode.get_resolution().height); terom@411: } terom@411: } terom@411: terom@411: const std::vector & Display::getDisplayModes (void) { terom@410: return CL_DisplayMode::get_display_modes(); terom@410: } terom@410: terom@411: const CL_DisplayMode Display::getBestMode (void) { terom@410: const std::vector &modes = Graphics::getDisplayModes(); terom@410: terom@410: const CL_DisplayMode *best_mode = NULL; terom@410: terom@410: for (std::vector::const_iterator it = modes.begin(); it != modes.end(); it++) terom@410: if (best_mode == NULL || ( terom@410: it->get_resolution().width * it->get_resolution().height > terom@410: best_mode->get_resolution().width * best_mode->get_resolution().height terom@410: )) terom@410: best_mode = &*it; terom@410: terom@410: if (best_mode == NULL) terom@410: throw Error("No available video modes!"); terom@410: terom@410: return *best_mode; terom@410: } terom@410: terom@411: void Display::toggle_fullscreen (void) { terom@411: if (is_fullscreen()) { terom@411: // enter windowed mode terom@411: set_windowed(); terom@411: terom@411: } else { terom@411: // enter fullscreen mode terom@411: set_fullscreen(fullscreen_resolution.width, fullscreen_resolution.height); terom@411: } terom@410: } terom@410: terom@411: void Display::on_update (TimeMS dt) { terom@411: (void) dt; terom@411: terom@411: // do we have something to draw? terom@411: if (target) { terom@411: // draw it terom@411: target->draw(this); terom@411: terom@411: // flip buffers, sync terom@411: flip(1); terom@411: } terom@411: } terom@411: terom@411: void Display::on_window_resize (int new_x, int new_y) { terom@411: // ignore resize in fullscreen mode terom@411: if (is_fullscreen()) terom@411: return; terom@411: } terom@411: terom@411: terom@411: } terom@411: