![]() |
Kukatz 3D
0.1
Török Attila szakdolgozata
|
00001 /* 00002 * windowmanager.cpp - Kukatz 3D 00003 * Copyright (c) 2011 - TÖRÖK Attila (torokati44@gmail.com) 00004 * 00005 * This software is provided 'as-is', without any express or implied 00006 * warranty. In no event will the authors be held liable for any damages 00007 * arising from the use of this software. 00008 * 00009 * Permission is granted to anyone to use this software for any purpose, 00010 * including commercial applications, and to alter it and redistribute it 00011 * freely, subject to the following restrictions: 00012 * 00013 * 1. The origin of this software must not be misrepresented; you must not 00014 * claim that you wrote the original software. If you use this software 00015 * in a product, an acknowledgment in the product documentation would be 00016 * appreciated but is not required. 00017 * 00018 * 2. Altered source versions must be plainly marked as such, and must not be 00019 * misrepresented as being the original software. 00020 * 00021 * 3. This notice may not be removed or altered from any source 00022 * distribution. 00023 */ 00024 00025 #include "windowmanager.hpp" 00026 00027 #include <iostream> 00028 00029 #include "resourcemanager.hpp" 00030 #include "statemanager.hpp" 00031 #include "configmanager.hpp" 00032 00033 WindowManager::WindowManager(): 00034 window_style(sf::Style::Close | sf::Style::Resize), window_settings(32, 0, 0), title("Kukatz 3D"), 00035 is_win_fullscreen(ConfigManager::instance().get_bool("fullscreen")), 00036 current_video_mode(1000000) // HACK... I don't care... 00037 { 00038 unsigned int config_w = ConfigManager::instance().get_int("width"); 00039 unsigned int config_h = ConfigManager::instance().get_int("height"); 00040 00041 sf::VideoMode desktop_mode = sf::VideoMode::GetDesktopMode(); 00042 00043 for (unsigned int i = 0; i < sf::VideoMode::GetModesCount(); ++i) 00044 { 00045 sf::VideoMode mode = sf::VideoMode::GetMode(i); 00046 if (mode.BitsPerPixel == 32) 00047 { 00048 if (current_video_mode == 1000000) 00049 { 00050 if ((mode.Width == desktop_mode.Width) && (mode.Height == desktop_mode.Height)) 00051 { 00052 current_video_mode = video_modes.size(); 00053 } 00054 } 00055 if ((mode.Width == config_w) && (mode.Height == config_h)) 00056 { 00057 current_video_mode = video_modes.size(); 00058 } 00059 video_modes.push_back(mode); 00060 } 00061 } 00062 00063 if (video_modes.empty()) 00064 { 00065 for (unsigned int i = 0; i < sf::VideoMode::GetModesCount(); ++i) 00066 { 00067 sf::VideoMode mode = sf::VideoMode::GetMode(i); 00068 if (mode.BitsPerPixel == 24) 00069 { 00070 if (current_video_mode == 1000000) 00071 { 00072 if ((mode.Width == desktop_mode.Width) && (mode.Height == desktop_mode.Height)) 00073 { 00074 current_video_mode = video_modes.size(); 00075 } 00076 } 00077 if ((mode.Width == config_w) && (mode.Height == config_h)) 00078 { 00079 current_video_mode = video_modes.size(); 00080 } 00081 video_modes.push_back(mode); 00082 } 00083 } 00084 } 00085 00086 recreate(); 00087 00088 ConfigManager::instance().set("width", (int)window.GetWidth()); 00089 ConfigManager::instance().set("height", (int)window.GetHeight()); 00090 } 00091 00092 void WindowManager::recreate() 00093 { 00094 window.Create(video_modes[current_video_mode], title, 00095 (is_win_fullscreen?(window_style | sf::Style::Fullscreen):window_style), 00096 window_settings); 00097 00098 window.UseVerticalSync(true); 00099 window.ShowMouseCursor(false); 00100 window.EnableKeyRepeat(false); 00101 //win.SetIcon(16, 16, icon_pixels); 00102 } 00103 00104 sf::Window& WindowManager::get_window() 00105 { 00106 return window; 00107 } 00108 00109 void WindowManager::set_fullscreen(bool fs) 00110 { 00111 if (fs != is_win_fullscreen) 00112 { 00113 toggle_fullscreen(); 00114 } 00115 } 00116 00117 void WindowManager::toggle_fullscreen() 00118 { 00119 ResourceManager::instance().uninit_gl(); 00120 00121 is_win_fullscreen = !is_win_fullscreen; 00122 recreate(); 00123 00124 StateManager::instance().resize_all(sf::Vector2i(window.GetWidth(), window.GetHeight())); 00125 ConfigManager::instance().set("fullscreen", is_win_fullscreen); 00126 00127 ResourceManager::instance().init_gl(); 00128 } 00129 00130 void WindowManager::set_videomode(const sf::VideoMode& vm) 00131 { 00132 ResourceManager::instance().uninit_gl(); 00133 00134 recreate(); 00135 00136 ResourceManager::instance().init_gl(); 00137 00138 StateManager::instance().resize_all(sf::Vector2i(vm.Width, vm.Height)); 00139 00140 ConfigManager::instance().set("width", (int)vm.Width); 00141 ConfigManager::instance().set("height", (int)vm.Height); 00142 } 00143 00144 void WindowManager::set_videomode(size_t vm) 00145 { 00146 if (vm != current_video_mode) 00147 { 00148 current_video_mode = vm; 00149 set_videomode(video_modes[vm]); 00150 } 00151 } 00152 00153 void WindowManager::set_videomode(size_t vm, bool fs) 00154 { 00155 if ((vm != current_video_mode) || (fs != is_win_fullscreen)) 00156 { 00157 current_video_mode = vm; 00158 is_win_fullscreen = fs; 00159 ConfigManager::instance().set("fullscreen", is_win_fullscreen); 00160 set_videomode(video_modes[vm]); 00161 } 00162 } 00163 00164 WindowManager::~WindowManager() 00165 { 00166 00167 }