=== modified file 'driver/src/VideoDriver.cpp' --- driver/src/VideoDriver.cpp 2010-03-01 20:10:51 +0000 +++ driver/src/VideoDriver.cpp 2010-03-08 20:18:25 +0000 @@ -94,7 +94,7 @@ * * @author FloSoft */ -VideoDriver::VideoDriver(VideoDriverLoaderInterface * CallBack) : CallBack(CallBack), initialized(false), fullscreen(false) +VideoDriver::VideoDriver(VideoDriverLoaderInterface * CallBack) : CallBack(CallBack), initialized(false), screenWidth(0), screenHeight(0), fullscreen(false) { memset(keyboard, 0, 512); } === modified file 'driver/src/VideoDriver.h' --- driver/src/VideoDriver.h 2010-03-01 20:10:51 +0000 +++ driver/src/VideoDriver.h 2010-03-08 20:18:25 +0000 @@ -99,6 +99,11 @@ /// Funktion zum Auslesen ob die Rechte Maustaste gedrückt ist. virtual bool GetMouseStateR(void) const; + + // + unsigned short GetScreenWidth() const { return screenWidth; } + unsigned short GetScreenHeight() const { return screenHeight; } + bool IsFullscreen() const { return fullscreen; } /// Gibt Pointer auf ein Fenster zurück (device-dependent!), HWND unter Windows virtual void * GetWindowPointer() const = 0; @@ -108,10 +113,11 @@ protected: VideoDriverLoaderInterface * CallBack; ///< Das DriverCallback für Rückmeldungen. - bool initialized; ///< Initialisierungsstatus. - MouseCoords mouse_xy; ///< Status der Maus. - bool keyboard[512]; ///< Status der Tastatur; - bool fullscreen; ///< Vollbild an/aus? + bool initialized; ///< Initialisierungsstatus. + MouseCoords mouse_xy; ///< Status der Maus. + bool keyboard[512]; ///< Status der Tastatur; + unsigned short screenWidth; ///< aktuelle Bildschirm-/Fensterbreite + unsigned short screenHeight; ///< aktuelle Bildschirm-/Fensterhöhe + bool fullscreen; ///< Vollbild an/aus? }; - #endif // !VIDEODRIVER_H_INCLUDED === modified file 'driver/video/GLFW/src/GLFW.cpp' --- driver/video/GLFW/src/GLFW.cpp 2010-03-01 20:10:51 +0000 +++ driver/video/GLFW/src/GLFW.cpp 2010-03-08 20:18:25 +0000 @@ -183,6 +183,8 @@ glfwSetKeyCallback(OnKeyAction); memset(keyboard, false, sizeof(bool) * 512); + this->screenWidth = width; + this->screenHeight = height; this->fullscreen = fullscreen; // buggy im Fenstermodus @@ -229,9 +231,11 @@ glfwGetWindowSize(&w, &h); *width = w; *height = h; - - // @todo Vollbild ändern? - // this->fullscreen = fullscreen; + + + this->screenWidth = *width; + this->screenHeight = *height; + this->fullscreen = fullscreen; return true; } === modified file 'driver/video/SDL/src/SDL.cpp' --- driver/video/SDL/src/SDL.cpp 2010-03-01 20:10:51 +0000 +++ driver/video/SDL/src/SDL.cpp 2010-03-08 20:18:25 +0000 @@ -190,7 +190,11 @@ // TODO: Icon setzen // Videomodus setzen +#ifdef _WIN32 if(!(screen = SDL_SetVideoMode( width, height, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_OPENGL | ((fullscreen) ? SDL_FULLSCREEN : 0) ))) +#else + if(!(screen = SDL_SetVideoMode( width, height, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_OPENGL | ((!fullscreen) ? SDL_RESIZABLE : 0) | ((fullscreen) ? SDL_FULLSCREEN : 0) ))) +#endif { fprintf(stderr, "%s\n", SDL_GetError()); return false; @@ -211,6 +215,9 @@ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); memset(keyboard, false, sizeof(bool) * 512); + + this->screenWidth = width; + this->screenHeight = height; this->fullscreen = fullscreen; SDL_ShowCursor(SDL_DISABLE); @@ -237,6 +244,10 @@ if(!initialized) return false; + this->screenWidth = width; + this->screenHeight = height; + this->fullscreen = fullscreen; + // Die SDL-Implementierung kann das noch nicht direkt, also umweg über WinAPI! #ifdef WIN32 SDL_SysWMinfo info; @@ -285,8 +296,6 @@ ChangeDisplaySettings(&dm, CDS_FULLSCREEN); } - this->fullscreen = fullscreen; - // Das Fenster anzeigen ShowWindow(info.window, SW_SHOW); // Das Fenster in den Vordergrund rcken @@ -296,7 +305,7 @@ } #else // unter anderen Platformen kann SDL das ohne den OpenGL-Kontext zu killen // Videomodus setzen - if(!(screen = SDL_SetVideoMode( width, height, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_OPENGL | ((fullscreen) ? SDL_FULLSCREEN : 0) ))) + if(!(screen = SDL_SetVideoMode( width, height, 32, SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_OPENGL | ((!fullscreen) ? SDL_RESIZABLE : 0) | ((fullscreen) ? SDL_FULLSCREEN : 0) ))) { fprintf(stderr, "%s\n", SDL_GetError()); return false; @@ -359,6 +368,14 @@ case SDL_QUIT: return false; + case SDL_VIDEORESIZE: + { + screenWidth = ev.resize.w; + screenHeight = ev.resize.h; + + CallBack->ScreenResized(screenWidth, screenHeight); + } break; + case SDL_KEYDOWN: { KeyEvent ke = { KT_INVALID, 0, false, false, false }; === modified file 'driver/video/WinAPI/src/WinAPI.cpp' --- driver/video/WinAPI/src/WinAPI.cpp 2010-03-01 20:10:51 +0000 +++ driver/video/WinAPI/src/WinAPI.cpp 2010-03-08 20:18:25 +0000 @@ -326,6 +326,8 @@ ChangeDisplaySettings(&dm, CDS_FULLSCREEN); } + this->screenWidth = width; + this->screenHeight = height; this->fullscreen = fullscreen; // Das Fenster anzeigen @@ -390,6 +392,8 @@ ChangeDisplaySettings(&dm, CDS_FULLSCREEN); } + this->screenWidth = width; + this->screenHeight = height; this->fullscreen = fullscreen; // Das Fenster anzeigen === modified file 'src/Desktop.cpp' --- src/Desktop.cpp 2010-03-01 20:10:51 +0000 +++ src/Desktop.cpp 2010-03-08 20:18:25 +0000 @@ -45,6 +45,7 @@ : Window(), background(background) { SetScale(true); + Resize(VideoDriverWrapper::inst().GetScreenWidth(), VideoDriverWrapper::inst().GetScreenWidth()); } /////////////////////////////////////////////////////////////////////////////// @@ -76,3 +77,42 @@ { WindowManager::inst().Switch(this); } + +/////////////////////////////////////////////////////////////////////////////// +/* + * Reagiert auf Spielfenstergrößenänderung + * + * @author Divan + */ +void Desktop::Msg_ScreenResize(const ScreenResizeEvent& sr) +{ +// Keep the following block the same as in ctrlGroup class: + // Für skalierte Desktops ist alles einfach, die brauchen im besten Fall gar nichts selbst implementieren + if (scale) + { + //Zunächst an die Kinder weiterleiten + for(std::map::iterator it = idmap.begin(); it != idmap.end(); ++it) + if(it->second) + { + Window* ctrl = it->second; + // unskalierte Position und Größe bekommen + unsigned realx = ctrl->GetX() * 800 / sr.oldWidth; + unsigned realy = ctrl->GetY() * 600 / sr.oldHeight; + unsigned realwidth = ctrl->GetWidth() * 800 / sr.oldWidth; + unsigned realheight = ctrl->GetHeight() * 600 / sr.oldHeight; + // Rundungsfehler? + if (realx * sr.oldWidth / 800 < ctrl->GetX()) ++realx; + if (realy * sr.oldHeight / 600 < ctrl->GetY()) ++realy; + if (realwidth * sr.oldWidth / 800 < ctrl->GetWidth()) ++realwidth; + if (realheight * sr.oldHeight / 600 < ctrl->GetHeight()) ++realheight; + // Und los + ctrl->Move(realx * sr.newWidth / 800, realy * sr.newHeight / 600); + ctrl->Msg_ScreenResize(sr); + ctrl->Resize(realwidth * sr.newWidth / 800, realheight * sr.newHeight / 600); + } + } + + // Individuelle Reaktion ist auch erlaubt + Resize(sr.newWidth, sr.newHeight); +} + === modified file 'src/Desktop.h' --- src/Desktop.h 2010-03-01 20:10:51 +0000 +++ src/Desktop.h 2010-03-08 20:18:25 +0000 @@ -30,6 +30,8 @@ Desktop(glArchivItem_Bitmap *background); void Show(void); + void Msg_ScreenResize(const ScreenResizeEvent& sr); + protected: bool Draw_(void); === modified file 'src/GameWorld.h' --- src/GameWorld.h 2010-03-01 20:10:51 +0000 +++ src/GameWorld.h 2010-03-08 20:18:25 +0000 @@ -530,6 +530,12 @@ /// Gibt die verfügbar Anzahl der Angreifer für einen Seeangriff zurück unsigned GetAvailableSoldiersForSeaAttackCount(const unsigned char player_attacker, const MapCoord x, const MapCoord y) const; + void Resize(unsigned short displayWidth, unsigned short displayHeight); + +protected: + unsigned short displayWidth, displayHeight; + + // debug ai private: unsigned d_what; @@ -542,7 +548,6 @@ } - }; /// "Interface-Klasse" für das Spiel === modified file 'src/GameWorldViewer.cpp' --- src/GameWorldViewer.cpp 2010-03-01 20:10:51 +0000 +++ src/GameWorldViewer.cpp 2010-03-08 20:18:25 +0000 @@ -43,6 +43,8 @@ GameWorldViewer::GameWorldViewer() : show_bq(false), show_names(false), show_productivity(false), xoffset(0), yoffset(0), selx(0), sely(0), sx(0), sy(0), scroll(false), last_xoffset(0), last_yoffset(0), show_coordinates(false), d_what(0), d_player(0), d_active(false) { + displayWidth = VideoDriverWrapper::inst().GetScreenWidth(); + displayHeight = VideoDriverWrapper::inst().GetScreenHeight(); } void GameWorldViewer::Draw(const unsigned char player, unsigned * water, const bool draw_selected, const MapCoord selected_x, const MapCoord selected_y,const RoadsBuilding& rb) @@ -544,8 +546,8 @@ last_yoffset = yoffset; MoveTo(static_cast(GetTerrainX(x, y)) - - VideoDriverWrapper::inst().GetScreenWidth() / 2, static_cast(GetTerrainY(x, y)) - - VideoDriverWrapper::inst().GetScreenHeight() / 2, true); + - displayWidth / 2, static_cast(GetTerrainY(x, y)) + - displayHeight / 2, true); } /// Springt zur letzten Position, bevor man "weggesprungen" ist @@ -566,15 +568,15 @@ xoffset = width * TR_W + xoffset; if(yoffset < 0) yoffset = height * TR_H + yoffset; - if(xoffset > width * TR_W + VideoDriverWrapper::inst().GetScreenWidth()) + if(xoffset > width * TR_W + displayWidth) xoffset -= (width * TR_W); - if(yoffset > height * TR_H + VideoDriverWrapper::inst().GetScreenHeight()) + if(yoffset > height * TR_H + displayHeight) yoffset -= (height * TR_H); fx = xoffset / TR_W-1; fy = (yoffset-0x20*HEIGHT_FACTOR) / TR_H; - lx = (xoffset+VideoDriverWrapper::inst().GetScreenWidth())/TR_W+2; - ly = (yoffset+VideoDriverWrapper::inst().GetScreenHeight()+0x20*HEIGHT_FACTOR)/TR_H; + lx = (xoffset+displayWidth)/TR_W+2; + ly = (yoffset+displayHeight+0x20*HEIGHT_FACTOR)/TR_H; } // Höhe wurde Verändert: TerrainRenderer Bescheid sagen, damit es entsprechend verändert werden kann @@ -651,4 +653,9 @@ return unsigned(attackers.size()); } - +void GameWorldViewer::Resize(unsigned short displayWidth, unsigned short displayHeight) +{ + this->displayWidth = displayWidth; + this->displayHeight = displayHeight; + CalcFxLx(); +} === modified file 'src/IngameWindow.cpp' --- src/IngameWindow.cpp 2010-03-08 18:49:44 +0000 +++ src/IngameWindow.cpp 2010-03-08 20:18:25 +0000 @@ -42,8 +42,8 @@ * @author OLiver */ IngameWindow::IngameWindow(unsigned int id, unsigned short x, unsigned short y, unsigned short width, unsigned short height, const std::string& title, glArchivItem_Bitmap *background, bool modal) - : Window(x, y, id, NULL), - width(width), height(height), title(title), background(background), last_x(0), last_y(0), + : Window(x, y, id, NULL, width, height), + iwHeight(height), title(title), background(background), last_x(0), last_y(0), last_down(false), last_down2(false), modal(modal), closeme(false), minimized(false), move(false) { memset(button_state, BUTTON_UP, sizeof(ButtonState)*2); @@ -69,6 +69,12 @@ { } +void IngameWindow::SetMinimized(bool minimized) +{ + this->minimized = minimized; + SetHeight(minimized ? 31 : iwHeight); +} + void IngameWindow::MouseLeftDown(const MouseCoords& mc) { // Maus muss sich auf der Titelleiste befinden @@ -118,7 +124,7 @@ { if(i) { - minimized = !minimized; + SetMinimized(!GetMinimized()); LOADER.GetSoundN("sound", 113)->Play(255,false); } else if(!modal) @@ -153,10 +159,10 @@ NewMouseX -= nx - (VideoDriverWrapper::inst().GetScreenWidth() - width); nx = VideoDriverWrapper::inst().GetScreenWidth() - width; } - if(ny > VideoDriverWrapper::inst().GetScreenHeight() - GetHeight()) + if(ny > VideoDriverWrapper::inst().GetScreenHeight() - height) { - NewMouseY -= ny - (VideoDriverWrapper::inst().GetScreenHeight() - GetHeight()); - ny = VideoDriverWrapper::inst().GetScreenHeight() - GetHeight(); + NewMouseY -= ny - (VideoDriverWrapper::inst().GetScreenHeight() - height); + ny = VideoDriverWrapper::inst().GetScreenHeight() - height; } // Fix mouse position if moved too far @@ -277,12 +283,12 @@ title_count = side_width / LOADER.GetImageN("resource", 40)->getWidth(); for(unsigned short i = 0;iDraw(x+LOADER.GetImageN("resource", 45)->getWidth()+i*LOADER.GetImageN("resource", 40)->getWidth(),y+height-LOADER.GetImageN("resource", 40)->getHeight(), 0, 0, 0, 0, 0, 0); + LOADER.GetImageN("resource", 40)->Draw(x+LOADER.GetImageN("resource", 45)->getWidth()+i*LOADER.GetImageN("resource", 40)->getWidth(),y+iwHeight-LOADER.GetImageN("resource", 40)->getHeight(), 0, 0, 0, 0, 0, 0); rest = side_width % LOADER.GetImageN("resource", 40)->getWidth(); if(rest) - LOADER.GetImageN("resource", 40)->Draw(x+LOADER.GetImageN("resource", 45)->getWidth()+title_count*LOADER.GetImageN("resource", 40)->getWidth(),y+height-LOADER.GetImageN("resource", 40)->getHeight(), rest, 0, 0, 0, rest, 0); + LOADER.GetImageN("resource", 40)->Draw(x+LOADER.GetImageN("resource", 45)->getWidth()+title_count*LOADER.GetImageN("resource", 40)->getWidth(),y+iwHeight-LOADER.GetImageN("resource", 40)->getHeight(), rest, 0, 0, 0, rest, 0); // Clientbereich @@ -291,14 +297,14 @@ { // Bereich ausrechnen unsigned client_width = width - 20; - unsigned client_height = height - 31; + unsigned client_height = iwHeight - 31; background->Draw(this->x + LOADER.GetImageN("resource", 38)->getWidth(), this->y + LOADER.GetImageN("resource", 36)->getHeight(), client_width, client_height, 0, 0, client_width, client_height); } // Links und rechts unten die 2 kleinen Knäufe - LOADER.GetImageN("resource", 45)->Draw(x, y + height-LOADER.GetImageN("resource", 45)->getHeight(), 0, 0, 0, 0, 0, 0); - LOADER.GetImageN("resource", 45)->Draw(x + width - LOADER.GetImageN("resource", 45)->getWidth(), y + height-LOADER.GetImageN("resource", 45)->getHeight(), 0, 0, 0, 0, 0, 0); + LOADER.GetImageN("resource", 45)->Draw(x, y + iwHeight-LOADER.GetImageN("resource", 45)->getHeight(), 0, 0, 0, 0, 0, 0); + LOADER.GetImageN("resource", 45)->Draw(x + width - LOADER.GetImageN("resource", 45)->getWidth(), y + iwHeight-LOADER.GetImageN("resource", 45)->getHeight(), 0, 0, 0, 0, 0, 0); // Msg_PaintBefore aufrufen vor den Controls Msg_PaintBefore(); === modified file 'src/IngameWindow.h' --- src/IngameWindow.h 2010-03-01 20:10:51 +0000 +++ src/IngameWindow.h 2010-03-08 20:18:25 +0000 @@ -47,15 +47,10 @@ /// liefert den Fenstertitel. const std::string& GetTitle(void) { return title; } - /// setzt die Breite des Fensters. - void SetWidth(unsigned short width) { this->width = width; } - /// liefert die Breite des Fensters. - unsigned short GetWidth(void) const { return width; } - - /// setzt die Höhe des Fensters. - void SetHeight(unsigned short height) { this->height = height; } - /// liefert die Höhe des Fensters. - unsigned short GetHeight(void) const { return (minimized?31:height); } + /// setzt die ausgeklappte Höhe des Fensters. + void SetIwHeight(unsigned short height) { this->iwHeight = height; if(!minimized) this->height = height; } + /// liefert die ausgeklappte Höhe des Fensters. + unsigned short GetIwHeight(void) const { return iwHeight; } /// merkt das Fenster zum Schließen vor. void Close(bool closeme = true) { this->closeme = closeme; } @@ -63,7 +58,7 @@ bool ShouldBeClosed() { return closeme; } /// minimiert das Fenster. - void SetMinimized(bool minimized = true) { this->minimized = minimized; } + void SetMinimized(bool minimized = true); /// ist das Fenster minimiert? bool GetMinimized() { return minimized; } @@ -88,8 +83,7 @@ bool IsMessageRelayAllowed() const; protected: - unsigned short width; - unsigned short height; + unsigned short iwHeight; std::string title; glArchivItem_Bitmap *background; unsigned short last_x; === modified file 'src/MouseAndKeys.h' --- src/MouseAndKeys.h 2010-03-01 20:10:51 +0000 +++ src/MouseAndKeys.h 2010-03-08 20:18:25 +0000 @@ -72,4 +72,13 @@ bool ctrl,shift,alt; }; +/// ScreenResize-Event +struct ScreenResizeEvent +{ + unsigned short oldWidth; + unsigned short oldHeight; + unsigned short newWidth; + unsigned short newHeight; +}; + #endif //!MOUSEANDKEYS_H_INCLUDED === modified file 'src/VideoDriverLoaderInterface.h' --- src/VideoDriverLoaderInterface.h 2010-03-01 20:10:51 +0000 +++ src/VideoDriverLoaderInterface.h 2010-03-08 20:18:25 +0000 @@ -37,6 +37,8 @@ virtual void Msg_MouseMove(const MouseCoords& mc) = 0; virtual void Msg_KeyDown(const KeyEvent& ke) = 0; + + virtual void ScreenResized(unsigned short width, unsigned short height) = 0; }; #endif // !DRIVERLOADERINTERFACE_H_INCLUDED === modified file 'src/VideoDriverWrapper.cpp' --- src/VideoDriverWrapper.cpp 2010-03-01 20:10:51 +0000 +++ src/VideoDriverWrapper.cpp 2010-03-08 20:18:25 +0000 @@ -44,7 +44,7 @@ * * @author FloSoft */ -VideoDriverWrapper::VideoDriverWrapper() : videodriver(NULL), screen_width(0), screen_height(0), fullscreen(false), texture_pos(0) +VideoDriverWrapper::VideoDriverWrapper() : videodriver(NULL), texture_pos(0) { memset(texture_list, 0, sizeof(unsigned int)*100000); } @@ -122,17 +122,16 @@ return false; } - this->screen_width = screen_width; - this->screen_height = screen_height; - this->fullscreen = fullscreen; - // DriverWrapper Initialisieren - if(!Initialize(screen_width, screen_height)) + if(!Initialize()) { fatal_error("Initialisieren des OpenGL-Kontexts fehlgeschlagen!\n"); return false; } + // WindowManager informieren + WindowManager::inst().Msg_ScreenResize(screen_width, screen_height); + // VSYNC ggf abschalten/einschalten if(GLOBALVARS.ext_swapcontrol) wglSwapIntervalEXT((SETTINGS.video.vsync == 1)); @@ -144,39 +143,22 @@ /** * Verändert Auflösung, Fenster/Fullscreen * - * @param[in] screen_width neue Breite des Fensters - * @param[in] screen_height neue Höhe des Fensters + * @param[in] screenWidth neue Breite des Fensters + * @param[in] screenHeight neue Höhe des Fensters * @param[in] fullscreen Vollbild oder nicht * * @return Bei Erfolg @p true ansonsten @p false * * @author FloSoft */ -bool VideoDriverWrapper::ResizeScreen(const unsigned short screen_width, const unsigned short screen_height, const bool fullscreen) +bool VideoDriverWrapper::ResizeScreen(const unsigned short screenWidth, const unsigned short screenHeight, const bool fullscreen) { - if(!videodriver->ResizeScreen(screen_width, screen_height, fullscreen)) + if(!videodriver->ResizeScreen(screenWidth, screenHeight, fullscreen)) return false; - this->screen_width = screen_width; - this->screen_height = screen_height; - this->fullscreen = fullscreen; - - // Viewport mit widthxheight setzen - glViewport(0, 0, screen_width, screen_height); - - // Orthogonale Matrix erstellen - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - // ... und laden - glOrtho(0,screen_width,0,screen_height,-100,100); - - // 0; 0 soll obere linke Ecke sein - glRotated(180,1,0,0); - glTranslated(0,-screen_height,0); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); + RenewViewport(); + + WindowManager::inst().Msg_ScreenResize(screenWidth, screenHeight); return true; } @@ -325,10 +307,9 @@ * * @author FloSoft */ -bool VideoDriverWrapper::Initialize(const short width, const short height) +bool VideoDriverWrapper::Initialize() { - // Viewport mit widthxheight setzen - glViewport(0, 0, width, height); + RenewViewport(); // Depthbuffer und Colorbuffer einstellen glClearColor(0.0, 0.0, 0.0, 0.5); @@ -352,20 +333,6 @@ // Nur obere Seite von Dreiecke rendern --> Performance glEnable(GL_CULL_FACE); - // Orthogonale Matrix erstellen - glMatrixMode(GL_PROJECTION); - glLoadIdentity(); - - // ... und laden - glOrtho(0,width,0,height,-100,100); - - // 0; 0 soll obere linke Ecke sein - glRotated(180,1,0,0); - glTranslated(0,-height,0); - - glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - // Extensions laden if(!LoadAllExtensions()) return false; @@ -381,10 +348,39 @@ /////////////////////////////////////////////////////////////////////////////// /** - * Lädt die DriverWrapper-Extensions. + * Viewport (neu) setzen * * @author FloSoft */ +void VideoDriverWrapper::RenewViewport(bool onlyRenew) +{ + const unsigned short width = GetScreenWidth(); + const unsigned short height = GetScreenHeight(); + + // Viewport mit widthxheight setzen + glViewport(0, 0, width, height); + + // Orthogonale Matrix erstellen + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + + // ... und laden + glOrtho(0,width,0,height,-100,100); + + // 0; 0 soll obere linke Ecke sein + glRotated(180,1,0,0); + glTranslated(0,-height,0); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); +} + +/////////////////////////////////////////////////////////////////////////////// +/** + * lädt die driverwrapper-extensions. + * + * @author flosoft + */ bool VideoDriverWrapper::LoadAllExtensions() { // auf VSync-Extension testen === modified file 'src/VideoDriverWrapper.h' --- src/VideoDriverWrapper.h 2010-03-01 20:10:51 +0000 +++ src/VideoDriverWrapper.h 2010-03-08 20:18:25 +0000 @@ -44,6 +44,8 @@ bool CreateScreen(const unsigned short screen_width, const unsigned short screen_height, const bool fullscreen); /// Verändert Auflösung, Fenster/Fullscreen bool ResizeScreen(const unsigned short screen_width, const unsigned short screen_height, const bool fullscreen); + // Viewport (neu) setzen + void RenewViewport(bool onlyRenew = false); // zerstört das Fenster. bool DestroyScreen(); // räumt die Texturen auf @@ -63,9 +65,12 @@ /// Gibt Pointer auf ein Fenster zurück (device-dependent!), HWND unter Windows void * GetWindowPointer() const; - unsigned short GetScreenWidth() const { return screen_width; } - unsigned short GetScreenHeight() const { return screen_height; } - bool IsFullscreen() const { return fullscreen; } + unsigned short GetScreenWidth() const + { return videodriver->GetScreenWidth(); } + unsigned short GetScreenHeight() const + { return videodriver->GetScreenHeight(); } + bool IsFullscreen() const + { return videodriver->IsFullscreen(); } bool IsLeftDown(); bool IsRightDown(); @@ -80,7 +85,7 @@ private: // Viewpoint und Co initialisieren - bool Initialize(const short width, const short height); + bool Initialize(); // prüft ob eine Extension verfügbar ist bool hasExtension(const char *extension); @@ -96,10 +101,6 @@ DriverWrapper driver_wrapper; VideoDriver *videodriver; - unsigned short screen_width; - unsigned short screen_height; - bool fullscreen; - unsigned int texture_list[100000]; unsigned int texture_pos; }; === modified file 'src/Window.cpp' --- src/Window.cpp 2010-03-05 23:00:50 +0000 +++ src/Window.cpp 2010-03-08 20:18:25 +0000 @@ -41,7 +41,7 @@ * @author OLiver */ Window::Window(void) - : x(0), y(0), id(0), parent(NULL), active(false), visible(true), scale(false), tooltip("") + : x(0), y(0), width(0), height(0), id(0), parent(NULL), active(false), visible(true), scale(false), tooltip("") { } @@ -60,8 +60,10 @@ unsigned short y, unsigned int id, Window *parent, + unsigned short width, + unsigned short height, const std::string& tooltip) - : x(x), y(y), id(id), parent(parent), active(false), visible(true), scale(false), tooltip(tooltip) + : x(x), y(y), width(width), height(height), id(id), parent(parent), active(false), visible(true), scale(false), tooltip(tooltip) { } @@ -445,7 +447,7 @@ unsigned short height, TextureColor tc, glArchivItem_Font *font, - unsigned short list_height, + unsigned short max_list_height, bool readonly) { if(scale) @@ -454,10 +456,9 @@ y = ScaleY(y); width = ScaleX(width); height = ScaleY(height); - list_height = ScaleY(list_height); } - return AddCtrl(id, new ctrlComboBox(this, id, x, y, width, height, tc, font, list_height, readonly)); + return AddCtrl(id, new ctrlComboBox(this, id, x, y, width, height, tc, font, max_list_height, readonly)); } /////////////////////////////////////////////////////////////////////////////// @@ -1319,6 +1320,17 @@ /** * * + * @author Divan + */ +void Window::Msg_ScreenResize(const ScreenResizeEvent& sr) +{ +} + + +/////////////////////////////////////////////////////////////////////////////// +/** + * + * * @author OLiver */ void Window::Msg_EditEnter(const unsigned int ctrl_id) === modified file 'src/Window.h' --- src/Window.h 2010-03-05 23:00:50 +0000 +++ src/Window.h 2010-03-08 20:18:25 +0000 @@ -67,7 +67,7 @@ /// Konstruktor von @p Window. Window(void); /// Konstruktor von @p Window mit Parametern. - Window(unsigned short x, unsigned short y, unsigned int id, Window *parent, const std::string& tooltip = ""); + Window(unsigned short x, unsigned short y, unsigned int id, Window *parent, unsigned short width = 0, unsigned short height = 0, const std::string& tooltip = ""); /// virtueller Destruktor von @p Window. virtual ~Window(void); /// zeichnet das Fenster. @@ -76,6 +76,16 @@ unsigned short GetX(bool absolute = true) const; /// liefert die Y-Koordinate. unsigned short GetY(bool absolute = true) const; + /// liefert die Breite des Fensters. + unsigned short GetWidth(const bool scale = false) const { return (scale) ? ScaleX(width) : width; } + /// liefert die Höhe des Fensters. + unsigned short GetHeight(const bool scale = false) const { return (scale) ? ScaleY(height) : height; } + /// setzt die Größe des Fensters + void Resize(unsigned short width, unsigned short height) { Resize_(width, height); this->width = width; this->height = height; } + /// setzt die Breite des Fensters + void SetWidth(unsigned short width) { Resize(width, this->height); } + /// setzt die Höhe des Fensters + void SetHeight(unsigned short height) { Resize(this->width, height); } /// Sendet eine Tastaturnachricht an die Steuerelemente. bool RelayKeyboardMessage(bool (Window::*msg)(const KeyEvent&),const KeyEvent& ke); /// Sendet eine Mausnachricht weiter an alle Steuerelemente @@ -88,6 +98,7 @@ void LockRegion(Window *window, const Rect &rect); /// Gibt eine gesperrte Region wieder frei. void FreeRegion(Window *window); + /// Größe verändern oder überhaupt setzen /// setzt das Parentfenster. void SetParent(Window *parent) { this->parent = parent; } @@ -151,7 +162,7 @@ /// fügt ein CheckBoxCtrl hinzu. ctrlCheck *AddCheckBox(unsigned int id, unsigned short x, unsigned short y, unsigned short width, unsigned short height, TextureColor tc,const std::string& text, glArchivItem_Font *font, bool readonly = false); /// fügt eine ComboBox hinzu. - ctrlComboBox *AddComboBox(unsigned int id, unsigned short x, unsigned short y, unsigned short width, unsigned short height, TextureColor tc, glArchivItem_Font *font, unsigned short list_height, bool readonly = false); + ctrlComboBox *AddComboBox(unsigned int id, unsigned short x, unsigned short y, unsigned short width, unsigned short height, TextureColor tc, glArchivItem_Font *font, unsigned short max_list_height, bool readonly = false); /// fügt ein vertieftes TextCtrl hinzu. ctrlDeepening *AddDeepening(unsigned int id, unsigned short x, unsigned short y, unsigned short width, unsigned short height, TextureColor tc, const std::string& text, glArchivItem_Font *font, unsigned int color); /// Deepening fille with a color @@ -221,6 +232,7 @@ // NUR VORÜBERGEHEND für Edit-Controls, bis richtiger Steuerelement-Fokus // eingebaut wurde! virtual bool Msg_LeftDown_After(const MouseCoords& mc); + virtual void Msg_ScreenResize(const ScreenResizeEvent& sr); // Nachrichten, die von unten (Controls) nach oben (Fenster) gereicht werden virtual void Msg_ButtonClick(const unsigned int ctrl_id); @@ -272,6 +284,8 @@ virtual bool Draw_() = 0; /// Weiterleitung von Nachrichten von abgeleiteten Klassen erlaubt oder nicht? virtual bool IsMessageRelayAllowed() const; + /// Auf Größe verändern evtl. auch individuell reagieren? + virtual void Resize_(unsigned short width, unsigned short height) {} template T *AddCtrl(unsigned int id, T *ctrl) @@ -279,6 +293,9 @@ // ID auf control mappen idmap.insert(std::make_pair(id, ctrl)); + // scale-Eigenschaft weitervererben + ctrl->scale = scale; + //// Control zur Liste hinzufügen. //controls.push_back(ctrl); @@ -296,6 +313,8 @@ unsigned short x; ///< X-Position des Fensters. unsigned short y; ///< Y-Position des Fensters. + unsigned short width; ///< Breite des Fensters. + unsigned short height; ///< Höhe des Fensters. unsigned int id; ///< ID des Fensters. Window *parent; ///< Handle auf das Parentfenster. bool active; ///< Fenster aktiv? === modified file 'src/WindowManager.cpp' --- src/WindowManager.cpp 2010-03-01 20:10:51 +0000 +++ src/WindowManager.cpp 2010-03-08 20:18:25 +0000 @@ -45,7 +45,7 @@ * @author OLiver */ WindowManager::WindowManager(void) - : desktop(NULL), nextdesktop(NULL), nextdesktop_data(NULL), disable_mouse(false), mc(NULL) + : desktop(NULL), nextdesktop(NULL), nextdesktop_data(NULL), disable_mouse(false), mc(NULL), screenWidth(0), screenHeight(0), lastScreenWidthSignal(0), lastScreenHeightSignal(0), lastScreenSignalCount(0) { } @@ -857,6 +857,112 @@ /////////////////////////////////////////////////////////////////////////////// /** + * Verarbeitung Spielfenstergröße verändert (vom Betriebssystem aus) + * Liefert evtl. eine Größe die wir nicht wollen und daher korrigieren + * oder falls ok durchlassen. + * Eigentliche Verarbeitung dann in Msg_ScreenResize. + * + * @param[in] width neue Breite + * @param[in] height neue Höhe + * + * @author Divan + */ +void WindowManager::ScreenResized(unsigned short width, unsigned short height) +{ + unsigned short newWidth = width; + unsigned short newHeight = height; + + bool mustResize = false; + // Minimale Ausdehnung erfüllt? + if(newWidth < 800 || newHeight < 600) + { + mustResize = true; + if(newWidth < 800) newWidth = 800; + if(newHeight < 600) newHeight = 600; + } + + // Es kann passieren dass wir versuchen ein 800x600-Fenster zu erstellen, + // aber das Betriebssystem es immer wieder verkleinert. Hier sollten wir + // uns nicht auf einen endlosen Kampf einlassen, denn der Klügere gibt nach. + // Problem: Böse Windowmanager wie Metacity feuern ständig Resize-Events, + // wenn man den die Fenstergröße zieht und wir sie wieder zu vergrößern + // versuchen. + // Wir müssen also durch Warten halbwegs ausschließen, dass wir es + // mit dem Nutzer zu tun haben. + // TODO: Dann den Treiber zwingen, ein nicht resizable Fenster zu öffnen + // und erst wieder, wenn der Nutzer im Menü nochmal eine Auflösung einstellt, + // das Resizen zulassen. + if(width < 800 || height < 600) + if(lastScreenWidthSignal == width) + if(lastScreenHeightSignal == height) + if(lastScreenSignalCount == 500) + { + VideoDriverWrapper::inst().ResizeScreen(width, height, VideoDriverWrapper::inst().IsFullscreen()); + return; + } + + // Letzten Wert merken + if(lastScreenWidthSignal == width + && lastScreenHeightSignal == height) + { + ++lastScreenSignalCount; + } + else + { + lastScreenWidthSignal = width; + lastScreenHeightSignal = height; + lastScreenSignalCount = 0; + } + + // Und los + VideoDriverWrapper::inst().ResizeScreen(newWidth, newHeight, VideoDriverWrapper::inst().IsFullscreen()); +} + +/////////////////////////////////////////////////////////////////////////////// +/** + * Verarbeitung Spielfenstergröße verändert (vom Spiel aus) + * Liefert immer eine sinnvolle Größe, mind. 800x600. + * + * @param[in] width neue Breite + * @param[in] height neue Höhe + * + * @author Divan + */ +void WindowManager::Msg_ScreenResize(unsigned short width, unsigned short height) +{ + // Falls sich nichts ändert, brauchen wir auch nicht reagieren + // (Evtl hat sich ja nur der Modus Fenster/Vollbild geändert) + if(screenWidth == width && screenHeight == height) + return; + + ScreenResizeEvent sr; + sr.oldWidth = screenWidth; + sr.oldHeight = screenHeight; + sr.newWidth = screenWidth = width; + sr.newHeight = screenHeight = height; + // Wenn es absolut nicht anders geht, lassen wir im temporär doch + // kleiner als 800x600 zu, abspeichern tun wir die aber nie. + if(width >= 800) SETTINGS.video.width = width; + if(height >= 600) SETTINGS.video.height = height; + + // ist unser Desktop gültig? + if(!desktop) + return; + + desktop->Msg_ScreenResize(sr); + + // IngameWindow verschieben falls nötig, so dass sie komplett sichtbar sind + for(IngameWindowListIterator it = windows.begin(); it.valid(); ++it) + { + const short dx = (*it)->GetX()+(*it)->GetWidth() - sr.newWidth; + const short dy = (*it)->GetY()+(*it)->GetHeight() - sr.newHeight; + if(dx > 0 || dy > 0) + (*it)->Move((dx > 0 ? -dx : 0), (dy > 0 ? -dy : 0) , /*absolute=*/false); + } +} + +/////////////////////////////////////////////////////////////////////////////// +/** * schliesst ein IngameWindow und entfernt es aus der Fensterliste. * * @param[in] it Iterator auf das Fenster in der Fensterliste === modified file 'src/WindowManager.h' --- src/WindowManager.h 2010-03-01 20:10:51 +0000 +++ src/WindowManager.h 2010-03-08 20:18:25 +0000 @@ -80,6 +80,12 @@ // setzt den Tooltip void SetToolTip(Window *ttw, const std::string& tooltip); + /// Verarbeitung Spielfenstergröße verändert (vom Betriebssystem aus) + void ScreenResized(unsigned short width, unsigned short height); + /// Verarbeitung Spielfenstergröße verändert (vom Spiel aus) + // Achtung: nicht dieselbe Nachricht, die die Window-Klasse empfängt + void Msg_ScreenResize(unsigned short width, unsigned short height); + protected: void DrawToolTip(); @@ -98,6 +104,13 @@ IngameWindowList windows; ///< Fensterliste const MouseCoords *mc; std::string tooltip; + unsigned short screenWidth; /// letzte gültige Bildschirm-/Fensterbreite + unsigned short screenHeight; /// letzte gültige Bildschirm-/Fensterhöhe + + // um Schleifen abzufangen, die entstehen, weil wir mindestens 800x600 haben wollen. + unsigned short lastScreenWidthSignal; + unsigned short lastScreenHeightSignal; + unsigned short lastScreenSignalCount; }; #endif // !WINDOWMANAGER_H_INCLUDED === modified file 'src/ctrlButton.cpp' --- src/ctrlButton.cpp 2010-03-01 20:10:51 +0000 +++ src/ctrlButton.cpp 2010-03-08 20:18:25 +0000 @@ -41,7 +41,7 @@ */ ctrlButton::ctrlButton(Window *parent, unsigned int id, unsigned short x, unsigned short y, unsigned short width, unsigned short height, TextureColor tc, const std::string& tooltip) - : ctrlRectangle(parent, id, x, y, width, height), tc(tc), state(BUTTON_UP), border(true), + : Window(x, y, id, parent, width, height), tc(tc), state(BUTTON_UP), border(true), check(false), illuminated(false), enabled(true) { SetTooltip(tooltip); @@ -234,8 +234,6 @@ unsigned short width, unsigned short height, const TextureColor tc, unsigned int fillColor, const std::string& tooltip) : ctrlButton(parent,id,x,y,width,height,tc,tooltip), - width(width), - height(height), fillColor(fillColor) { } === modified file 'src/ctrlButton.h' --- src/ctrlButton.h 2010-03-01 20:10:51 +0000 +++ src/ctrlButton.h 2010-03-08 20:18:25 +0000 @@ -25,7 +25,7 @@ #include "ctrlText.h" /// Buttonklasse -class ctrlButton : public ctrlRectangle +class ctrlButton : public Window { public: ctrlButton(Window *parent, unsigned int id, unsigned short x, unsigned short y, unsigned short width, unsigned short height, @@ -148,7 +148,6 @@ protected: - unsigned short width, height; unsigned int fillColor; }; === modified file 'src/ctrlChat.cpp' --- src/ctrlChat.cpp 2010-03-08 18:49:44 +0000 +++ src/ctrlChat.cpp 2010-03-08 20:18:25 +0000 @@ -60,8 +60,8 @@ unsigned short height, TextureColor tc, glArchivItem_Font *font) - : Window(x, y, id, parent), - width(width), height(height), tc(tc), font(font), time_color(0xFFFFFFFF) + : Window(x, y, id, parent, width, height), + tc(tc), font(font), time_color(0xFFFFFFFF) { // Zeilen pro Seite festlegen errechnen page_size = (height - 4) / (font->getHeight() + 2); @@ -89,6 +89,66 @@ /////////////////////////////////////////////////////////////////////////////// /** + * Größe ändern + * + * @author Divan + */ +void ctrlChat::Resize_(unsigned short width, unsigned short height) +{ + + ctrlScrollBar *scroll = GetCtrl(0); + scroll->Move(width - SCROLLBAR_WIDTH, 0); + scroll->Resize(SCROLLBAR_WIDTH, height); + + // Remember some things + const bool was_on_bottom = (scroll->GetPos() + page_size == chat_lines.size()); + const bool width_changed = (this->width != width && chat_lines.size()); + unsigned short position=0; + // Remember the entry on top + for(unsigned short i=1; i <= scroll->GetPos(); ++i) + if(!chat_lines[i].secondary) + ++position; + + // Rewrap + if(width_changed) + { + this->width = width; + chat_lines.clear(); + for(unsigned short i = 0; i < raw_chat_lines.size(); ++i) + WrapLine(i); + } + + // Zeilen pro Seite festlegen errechnen + page_size = (height - 4) / (font->getHeight() + 2); + + scroll->SetPageSize(page_size); + + // If we are were on the last line, keep + if(was_on_bottom) + { + scroll->SetPos(((chat_lines.size() > page_size) ? chat_lines.size() - page_size : 0)); + } + else if(width_changed) + { + unsigned short i; + for(i=0; position > 0; ++i) + if(!chat_lines[i].secondary) + --position; + scroll->SetPos(i); + } + + // Don't display empty lines at the end if there are this is + // not necessary because of a lack of lines in total + if(chat_lines.size() < page_size) + { + scroll->SetPos(0); + } + else if(scroll->GetPos() + page_size > chat_lines.size()) + scroll->SetPos(chat_lines.size() - page_size); + +} +/////////////////////////////////////////////////////////////////////////////// +/** * Zeichnet das Chat-Control. * * @author OLiver @@ -149,17 +209,18 @@ return true; } - /////////////////////////////////////////////////////////////////////////////// /** * * - * @author OLiver + * @author Divan */ -void ctrlChat::AddMessage(const std::string& time_string,const std::string& player, const unsigned int player_color, const std::string& msg, const unsigned int msg_color) +void ctrlChat::WrapLine(unsigned short i) { + ChatLine line = raw_chat_lines[i]; + // Breite von Zeitstring und Spielername berechnen (falls vorhanden) - unsigned short prefix_width = ( time_string.length() ? font->getWidth(time_string) : 0) + (player.length() ? (bracket1_size + bracket2_size + font->getWidth(player)) : 0 ); + unsigned short prefix_width = ( line.time_string.length() ? font->getWidth(line.time_string) : 0) + (line.player.length() ? (bracket1_size + bracket2_size + font->getWidth(line.player)) : 0 ); // Reicht die Breite des Textfeldes noch nichtmal dafür aus? if(prefix_width > width - 2 - SCROLLBAR_WIDTH) @@ -171,50 +232,70 @@ glArchivItem_Font::WrapInfo wi; // Zeilen ggf. wrappen, falls der Platz nich reicht und die Zeilenanfanänge in wi speichern - font->GetWrapInfo(msg, width - prefix_width - 2 - SCROLLBAR_WIDTH, width - 2 - SCROLLBAR_WIDTH, wi); + font->GetWrapInfo(line.msg, width - prefix_width - 2 - SCROLLBAR_WIDTH, width - 2 - SCROLLBAR_WIDTH, wi); // Message-Strings erzeugen aus den WrapInfo std::string * strings = new std::string[wi.positions.size()]; - wi.CreateSingleStrings(msg, strings); - - unsigned old_size = unsigned(chat_lines.size()); - chat_lines.resize(old_size+wi.positions.size()); + wi.CreateSingleStrings(line.msg, strings); // Zeilen hinzufügen for(unsigned int i = 0; i < wi.positions.size(); ++i) { + ChatLine wrap_line; // Nur bei den ersten Zeilen müssen ja Zeit und Spielername mit angegeben werden - if(!(chat_lines[old_size+i].secondary = (i ? true : false))) + if(!(wrap_line.secondary = (i ? true : false))) { - chat_lines[old_size+i].time_string = time_string; - chat_lines[old_size+i].player = player; - chat_lines[old_size+i].player_color = player_color; - - LOG.lprintf("%s <", time_string.c_str()); - LOG.lcprintf(player_color, "%s", player.c_str()); - LOG.lprintf(">: "); + wrap_line.time_string = line.time_string; + wrap_line.player = line.player; + wrap_line.player_color = line.player_color; } - else - LOG.lprintf(" "); - - chat_lines[old_size+i].msg = strings[i]; - chat_lines[old_size+i].msg_color = msg_color; - - LOG.lcprintf(msg_color, "%s", strings[i].c_str()); - LOG.lprintf("\n"); + + wrap_line.msg = strings[i]; + wrap_line.msg_color = line.msg_color; + + chat_lines.push_back(wrap_line); } delete [] strings; - - ctrlScrollBar *scrollbar = GetCtrl(0); +} + +/////////////////////////////////////////////////////////////////////////////// +/** + * + * + * @author OLiver + */ +void ctrlChat::AddMessage(const std::string& time_string,const std::string& player, const unsigned int player_color, const std::string& msg, const unsigned int msg_color) +{ + ChatLine line; + + line.time_string = time_string; + line.player = player; + line.player_color = player_color; + line.msg = msg; + line.msg_color = msg_color; + raw_chat_lines.push_back(line); + + const unsigned short oldlength = chat_lines.size(); + + // Loggen + LOG.lprintf("%s <", time_string.c_str()); + LOG.lcprintf(player_color, "%s", player.c_str()); + LOG.lprintf(">: "); + LOG.lcprintf(msg_color, "%s", msg.c_str()); + LOG.lprintf("\n"); + + // Umbrechen + WrapLine(raw_chat_lines.size()-1); // Scrollbar Bescheid sagen + ctrlScrollBar *scrollbar = GetCtrl(0); scrollbar->SetRange(unsigned(chat_lines.size())); - // Waren wir am Ende? Dann mit runterscrollen - if(scrollbar->GetPos() == (unsigned(chat_lines.size()) - wi.positions.size()) - page_size) - scrollbar->SetPos(scrollbar->GetPos() + wi.positions.size()); + // Waren wir am Ende? Dann mit runterscrollen + if(scrollbar->GetPos() + page_size == oldlength) + scrollbar->SetPos(chat_lines.size() - page_size); } /////////////////////////////////////////////////////////////////////////////// === modified file 'src/ctrlChat.h' --- src/ctrlChat.h 2010-03-01 20:10:51 +0000 +++ src/ctrlChat.h 2010-03-08 20:18:25 +0000 @@ -32,6 +32,8 @@ /// Destruktor von @p ctrlChat. virtual ~ctrlChat(); + /// Größe ändern + void Resize_(unsigned short width, unsigned short height); /// Fügt eine Chatnachricht hinzu. void AddMessage(const std::string& time_string, const std::string& player, const unsigned int player_color, const std::string& msg, unsigned int msg_color); /// Setzt Farbe der Zeitangaben. @@ -48,6 +50,8 @@ virtual bool Draw_(); /// Vergrößert die Anzahl der Chatzeilen. void ExtendMemory(const unsigned int count); + /// Converts an unwrapped line into a wrapped one and appends it + void WrapLine(unsigned short i); private: // Struktur für eine Chatzeile. @@ -68,12 +72,11 @@ }; private: - unsigned short width; ///< Breite des Controls. - unsigned short height; ///< Höhe des Controls. TextureColor tc; ///< Hintergrundtextur. glArchivItem_Font *font; ///< Schriftart. - std::vector chat_lines; ///< Chatzeilen*/ + std::vector raw_chat_lines; ///< Chatzeilen, noch nicht umgebrochen + std::vector chat_lines; ///< Chatzeilen unsigned int page_size; ///< Chatzeilen pro Seite unsigned int time_color; ///< Farbe der Zeitangaben === modified file 'src/ctrlCheck.cpp' --- src/ctrlCheck.cpp 2010-03-01 20:10:51 +0000 +++ src/ctrlCheck.cpp 2010-03-08 20:18:25 +0000 @@ -46,8 +46,8 @@ const std::string& text, glArchivItem_Font *font, bool readonly) - : Window(x, y, id, parent), - width(width), height(height), tc(tc), text(text), font(font), check(false), readonly(readonly) + : Window(x, y, id, parent, width, height), + tc(tc), text(text), font(font), check(false), readonly(readonly) { } === modified file 'src/ctrlCheck.h' --- src/ctrlCheck.h 2010-03-01 20:10:51 +0000 +++ src/ctrlCheck.h 2010-03-08 20:18:25 +0000 @@ -39,8 +39,6 @@ virtual bool Draw_(void); private: - unsigned short width; - unsigned short height; TextureColor tc; std::string text; glArchivItem_Font *font; === modified file 'src/ctrlComboBox.cpp' --- src/ctrlComboBox.cpp 2010-03-01 20:10:51 +0000 +++ src/ctrlComboBox.cpp 2010-03-08 20:18:25 +0000 @@ -47,18 +47,63 @@ unsigned short height, TextureColor tc, glArchivItem_Font *font, - unsigned short list_height, + unsigned short max_list_height, bool readonly) - : Window(x, y, id, parent), - width(width), height(height), tc(tc), font(font), list_height(list_height), readonly(readonly), selection(0), last_show(false) + : Window(x, y, id, parent, width, height), + tc(tc), font(font), max_list_height(max_list_height), readonly(readonly), selection(0), last_show(false) { - ctrlList *liste = AddList(0, 0, height, width, height, tc, font); + ctrlList *liste = AddList(0, 0, height, width, 4, tc, font); // Liste am Anfang nicht anzeigen liste->SetVisible(false); if(!readonly) AddImageButton(1, width-height, 0, height, height, tc, LOADER.GetImageN("io", 34)); + + Resize_(width, height); +} + +/////////////////////////////////////////////////////////////////////////////// +/** + * Größe verändern + * + * @author Divan + * @author OLiver + */ +void ctrlComboBox::Resize_(unsigned short width, unsigned short height) +{ + ctrlButton *button = GetCtrl(1); + if(button) + { + button->Move(width-height, 0); + button->Resize(height, height); + } + + ctrlList *list = GetCtrl(0); + + unsigned short list_height = 4; + + // Langsam die Höhe der maximalen annähern + for(unsigned int i = 0; i < list->GetLineCount(); ++i) + { + // zu große geworden? + list_height += font->getHeight(); + + if(list_height > (scale ? ScaleY(max_list_height) : max_list_height)) + { + // kann nicht mal ein Item aufnehmen, dann raus + if(i == 0) + return; + + // Höhe um eins erniedrigen, damits wieder kleiner ist als die maximale + list_height -= font->getHeight();; + + break; + } + } + + list->Move(0, height); + list->Resize(width, list_height); } /////////////////////////////////////////////////////////////////////////////// @@ -237,32 +282,8 @@ */ void ctrlComboBox::AddString(const std::string& text) { - ctrlList *liste = GetCtrl(0); - - liste->AddString(text); - - unsigned short height = 4; - - // Langsam die Höhe der maximalen annähern - for(unsigned int i = 0; i < liste->GetLineCount(); ++i) - { - // zu große geworden? - height += font->getHeight(); - - if(height > list_height) - { - // kann nicht mal ein Item aufnehmen, dann raus - if(i == 0) - return; - - // Höhe um eins erniedrigen, damits wieder kleiner ist als die maximale - height -= font->getHeight();; - - break; - } - } - - liste->SetHeight(height); + GetCtrl(0)->AddString(text); + Resize_(width, height); } /////////////////////////////////////////////////////////////////////////////// @@ -274,6 +295,7 @@ void ctrlComboBox::DeleteAllItems() { GetCtrl(0)->DeleteAllItems(); + Resize_(width, height); } /////////////////////////////////////////////////////////////////////////////// === modified file 'src/ctrlComboBox.h' --- src/ctrlComboBox.h 2010-03-01 20:10:51 +0000 +++ src/ctrlComboBox.h 2010-03-08 20:18:25 +0000 @@ -27,8 +27,10 @@ class ctrlComboBox : public Window { public: - ctrlComboBox(Window *parent, unsigned int id, unsigned short x, unsigned short y, unsigned short width, unsigned short height, TextureColor tc, glArchivItem_Font *font, unsigned short list_height, bool readonly); + ctrlComboBox(Window *parent, unsigned int id, unsigned short x, unsigned short y, unsigned short width, unsigned short height, TextureColor tc, glArchivItem_Font *font, unsigned short max_list_height, bool readonly); + void Resize_(unsigned short width, unsigned short height); + void AddString(const std::string& text); void DeleteAllItems(); @@ -52,11 +54,9 @@ void ShowList(bool show); private: - unsigned short width; - unsigned short height; TextureColor tc; glArchivItem_Font *font; - unsigned short list_height; + unsigned short max_list_height; bool readonly; unsigned short selection; bool last_show; === modified file 'src/ctrlDeepening.cpp' --- src/ctrlDeepening.cpp 2010-03-01 20:10:51 +0000 +++ src/ctrlDeepening.cpp 2010-03-08 20:18:25 +0000 @@ -47,8 +47,14 @@ glArchivItem_Font *font, unsigned int color) : ctrlText(parent, id, x, y, text, color, 0, font), - tc(tc), width(width), height(height) + tc(tc) { + // We don't want to pass these through all those constructors + // of only-text objects down to the Window class. This is a special + // situation, as we are a Deepening _and_ a VarText instead + // of owning the VarText. + this->width = width; + this->height = height; } /////////////////////////////////////////////////////////////////////////////// === modified file 'src/ctrlDeepening.h' --- src/ctrlDeepening.h 2010-03-01 20:10:51 +0000 +++ src/ctrlDeepening.h 2010-03-08 20:18:25 +0000 @@ -36,8 +36,6 @@ private: TextureColor tc; - unsigned short width; - unsigned short height; }; /// Colored Deepening === modified file 'src/ctrlEdit.cpp' --- src/ctrlEdit.cpp 2010-03-01 20:10:51 +0000 +++ src/ctrlEdit.cpp 2010-03-08 20:18:25 +0000 @@ -50,8 +50,8 @@ bool password, bool disabled, bool notify) - : Window(x, y, id, parent), - width(width), height(height), maxlength(maxlength), tc(tc), font(font), password(password), disabled(disabled), + : Window(x, y, id, parent, width, height), + maxlength(maxlength), tc(tc), font(font), password(password), disabled(disabled), focus(false), newfocus(false), notify(notify) { SetText(""); === modified file 'src/ctrlEdit.h' --- src/ctrlEdit.h 2010-03-01 20:10:51 +0000 +++ src/ctrlEdit.h 2010-03-08 20:18:25 +0000 @@ -55,8 +55,6 @@ void CursorRight() { if(cursor_pos == text.length()) return; ++cursor_pos; Notify(); }; private: - unsigned short width; - unsigned short height; unsigned short maxlength; TextureColor tc; glArchivItem_Font *font; === modified file 'src/ctrlGroup.cpp' --- src/ctrlGroup.cpp 2010-03-01 20:10:51 +0000 +++ src/ctrlGroup.cpp 2010-03-08 20:18:25 +0000 @@ -59,6 +59,40 @@ } /////////////////////////////////////////////////////////////////////////////// +/* + * Reagiert auf Spielfenstergrößenänderung + * + * @author Divan + */ +void ctrlGroup::Msg_ScreenResize(const ScreenResizeEvent& sr) +{ +// Keep the following block the same as in Desktop class: + // Für skalierte Desktops ist alles einfach, die brauchen im besten Fall gar nichts selbst implementieren + if (scale) + { + //Zunächst an die Kinder weiterleiten + for(std::map::iterator it = idmap.begin(); it != idmap.end(); ++it) + if(it->second) + { + Window* ctrl = it->second; + // unskalierte Position und Größe bekommen + unsigned realx = ctrl->GetX() * 800 / sr.oldWidth; + unsigned realy = ctrl->GetY() * 600 / sr.oldHeight; + unsigned realwidth = ctrl->GetWidth() * 800 / sr.oldWidth; + unsigned realheight = ctrl->GetHeight() * 600 / sr.oldHeight; + // Rundungsfehler? + if (realx * sr.oldWidth / 800 < ctrl->GetX()) ++realx; + if (realy * sr.oldHeight / 600 < ctrl->GetY()) ++realy; + if (realwidth * sr.oldWidth / 800 < ctrl->GetWidth()) ++realwidth; + if (realheight * sr.oldHeight / 600 < ctrl->GetHeight()) ++realheight; + // Und los + ctrl->Move(realx * sr.newWidth / 800, realy * sr.newHeight / 600); + ctrl->Msg_ScreenResize(sr); + ctrl->Resize(realwidth * sr.newWidth / 800, realheight * sr.newHeight / 600); + } + } +} +/////////////////////////////////////////////////////////////////////////////// /** * * === modified file 'src/ctrlGroup.h' --- src/ctrlGroup.h 2010-03-01 20:10:51 +0000 +++ src/ctrlGroup.h 2010-03-08 20:18:25 +0000 @@ -28,6 +28,8 @@ public: ctrlGroup(Window *parent, unsigned int id, bool scale = false); + void Msg_ScreenResize(const ScreenResizeEvent& sr); + virtual void Msg_ButtonClick(const unsigned int ctrl_id); virtual void Msg_EditEnter(const unsigned int ctrl_id); virtual void Msg_EditChange(const unsigned int ctrl_id); === modified file 'src/ctrlIngameMinimap.cpp' --- src/ctrlIngameMinimap.cpp 2010-03-01 20:10:51 +0000 +++ src/ctrlIngameMinimap.cpp 2010-03-08 20:18:25 +0000 @@ -62,54 +62,7 @@ bool ctrlIngameMinimap::Draw_() { DrawMap(*minimap); - return true; -} - -/////////////////////////////////////////////////////////////////////////////// -/** - * - * - * @author OLiver - */ -bool ctrlIngameMinimap::Msg_LeftDown(const MouseCoords& mc) -{ - return Msg_MouseMove(mc); -} - -/////////////////////////////////////////////////////////////////////////////// -/** - * - * - * @author OLiver - */ -bool ctrlIngameMinimap::Msg_MouseMove(const MouseCoords& mc) -{ - if(mc.ldown) - { - // Mauszeiger auf der Karte? - if(Coll(mc.x,mc.y,GetX()+GetLeft(),GetY()+GetTop(),width_show,height_show)) - { - // Koordinate feststellen - unsigned short map_x = (mc.x-(GetX()+GetLeft()))*minimap->GetMapWidth()/width_show; - unsigned short map_y = (mc.y-(GetY()+GetTop()))*minimap->GetMapHeight()/height_show; - - gwv.MoveToMapObject(map_x,map_y); - - return true; - } - } - - return false; -} - -/////////////////////////////////////////////////////////////////////////////// -/** - * - * - * @author OLiver - */ -void ctrlIngameMinimap::Msg_PaintAfter() -{ + // Mittleren Punkt berechnen und dort hinscrollen int middle_x = (gwv.GetLastX()+gwv.GetFirstX())/2; int middle_y = (gwv.GetLastY()+gwv.GetFirstY())/2; @@ -153,6 +106,45 @@ // Zeichnen image->Draw(GetX()+GetLeft()+xpos,GetY()+GetTop()+ypos,0,0,src_x,src_y,draw_width,draw_height); + + return true; +} + +/////////////////////////////////////////////////////////////////////////////// +/** + * + * + * @author OLiver + */ +bool ctrlIngameMinimap::Msg_LeftDown(const MouseCoords& mc) +{ + return Msg_MouseMove(mc); +} + +/////////////////////////////////////////////////////////////////////////////// +/** + * + * + * @author OLiver + */ +bool ctrlIngameMinimap::Msg_MouseMove(const MouseCoords& mc) +{ + if(mc.ldown) + { + // Mauszeiger auf der Karte? + if(Coll(mc.x,mc.y,GetX()+GetLeft(),GetY()+GetTop(),width_show,height_show)) + { + // Koordinate feststellen + unsigned short map_x = (mc.x-(GetX()+GetLeft()))*minimap->GetMapWidth()/width_show; + unsigned short map_y = (mc.y-(GetY()+GetTop()))*minimap->GetMapHeight()/height_show; + + gwv.MoveToMapObject(map_x,map_y); + + return true; + } + } + + return false; } /////////////////////////////////////////////////////////////////////////////// === modified file 'src/ctrlIngameMinimap.h' --- src/ctrlIngameMinimap.h 2010-03-01 20:10:51 +0000 +++ src/ctrlIngameMinimap.h 2010-03-08 20:18:25 +0000 @@ -50,7 +50,6 @@ bool Msg_LeftDown(const MouseCoords& mc); bool Msg_MouseMove(const MouseCoords& mc); - void Msg_PaintAfter(); /// Setzt Breite und Höhe des Controls void SetDisplaySize(const unsigned short width, const unsigned short height); === modified file 'src/ctrlList.cpp' --- src/ctrlList.cpp 2010-03-01 20:10:51 +0000 +++ src/ctrlList.cpp 2010-03-08 20:18:25 +0000 @@ -47,8 +47,8 @@ unsigned short height, TextureColor tc, glArchivItem_Font *font) - : Window(x, y, id, parent), - width(width), height(height), tc(tc), font(font), selection(0xFFFF), mouseover(0xFFFF) + : Window(x, y, id, parent, width, height), + tc(tc), font(font), selection(0xFFFF), mouseover(0xFFFF) { pagesize = (height - 4) / font->getHeight(); @@ -299,21 +299,30 @@ /////////////////////////////////////////////////////////////////////////////// /** - * setzt die Höhe. + * Größe ändern. * - * @param[in] height Die neue Höhe der Listbox + * @param[in] width Neue Breite + * @param[in] height Neue Höhe * * @author OLiver */ -void ctrlList::SetHeight(const unsigned short height) +void ctrlList::Resize_(unsigned short width, unsigned short height) { ctrlScrollBar *scrollbar = GetCtrl(0); + scrollbar->Move(width - 20, 0); + scrollbar->Resize(20, height); pagesize = (height-4) / font->getHeight(); - this->height = height; scrollbar->SetPageSize(pagesize); - scrollbar->SetHeight(height); + + // If the size was enlarged we have to check that we don't try to + // display more lines than present + if(height > this->height) + while(lines.size() - scrollbar->GetPos() < pagesize + && scrollbar->GetPos() > 0) + scrollbar->SetPos(scrollbar->GetPos()-1); + } /////////////////////////////////////////////////////////////////////////////// === modified file 'src/ctrlList.h' --- src/ctrlList.h 2010-03-01 20:10:51 +0000 +++ src/ctrlList.h 2010-03-08 20:18:25 +0000 @@ -31,6 +31,9 @@ /// Destruktor von @p ctrlList. virtual ~ctrlList(void); + /// Größe verändern + void Resize_(unsigned short width, unsigned short height); + /// Neuen String zur Listbox hinzufügen. void AddString(const std::string& text); /// Verändert einen String @@ -41,8 +44,6 @@ const std::string& GetItemText(unsigned short line) const; /// liefert den Wert der aktuell gewählten Zeile. const std::string& GetSelItemText(void) const { return GetItemText(selection); }; - /// setzt die Höhe. - void SetHeight(unsigned short height); /// Vertauscht zwei Zeilen. void Swap(unsigned short first, unsigned short second); /// Löscht ein Element @@ -51,9 +52,6 @@ unsigned short GetLineCount(void) const { return static_cast(lines.size()); } unsigned short GetSelection(void) const { return static_cast(selection); }; void SetSelection(unsigned short selection) { if(selection < lines.size()) this->selection = selection; } - void SetWidth(unsigned short width) { this->width = width; } - unsigned short GetWidth() const { return width; } - unsigned short GetHeight() const { return height; } virtual bool Msg_MouseMove(const MouseCoords& mc); virtual bool Msg_LeftDown(const MouseCoords& mc); @@ -66,8 +64,6 @@ virtual bool Draw_(void); private: - unsigned short width; - unsigned short height; TextureColor tc; glArchivItem_Font *font; === modified file 'src/ctrlMinimap.cpp' --- src/ctrlMinimap.cpp 2010-03-01 20:10:51 +0000 +++ src/ctrlMinimap.cpp 2010-03-08 20:18:25 +0000 @@ -47,8 +47,19 @@ const unsigned short padding_x, const unsigned short padding_y, const unsigned short map_width, - const unsigned short map_height) - : ctrlRectangle(parent, id, x, y, width, height), padding_x(padding_x), padding_y(padding_y) + const unsigned short map_height) + : Window(x,y,id,parent,width,height), padding_x(padding_x), padding_y(padding_y), map_width(map_width), map_height(map_height) +{ + SetDisplaySize(width, height, map_width, map_height); +} + +/////////////////////////////////////////////////////////////////////////////// +/** + * Größe ändern + * + * @author Divan + */ +void ctrlMinimap::Resize_(unsigned short width, unsigned short height) { SetDisplaySize(width, height, map_width, map_height); } @@ -64,6 +75,9 @@ this->width = width; this->height = height; + this->map_width = map_width; + this->map_height = map_height; + unsigned short scaled_map_width = static_cast(map_width * MINIMAP_SCALE_X); double x_scale = double(scaled_map_width) / double(width - padding_x * 2); double y_scale = double(map_height) / double(height - padding_y * 2); === modified file 'src/ctrlMinimap.h' --- src/ctrlMinimap.h 2010-03-01 20:10:51 +0000 +++ src/ctrlMinimap.h 2010-03-08 20:18:25 +0000 @@ -26,7 +26,7 @@ class Minimap; /// Übersichtskarte (MapPreview) -class ctrlMinimap : public ctrlRectangle +class ctrlMinimap : public Window { protected: /// Größe der Anzeige der Minimap @@ -51,18 +51,20 @@ unsigned short GetHeightShow() const { return height_show; } /// Gibt die entsprechenden Kanten relativ zur oberen linken Ecke der Bounding-Box - unsigned short GetLeft() const { return padding_x+(width-width_show-2*padding_x)/2; } - unsigned short GetTop() const { return padding_y+(height-height_show-2*padding_y)/2; } - unsigned short GetRight() const { return GetLeft() + width_show + padding_x; } - unsigned short GetBottom() const { return GetTop() + height_show + padding_y; } + inline unsigned short GetLeft() const { return padding_x+(width-width_show-2*padding_x)/2; } + inline unsigned short GetTop() const { return padding_y+(height-height_show-2*padding_y)/2; } + inline unsigned short GetRight() const { return GetLeft() + width_show + padding_x; } + inline unsigned short GetBottom() const { return GetTop() + height_show + padding_y; } - void SetDisplaySize(const unsigned short width, const unsigned short height, const unsigned short map_width, - const unsigned short map_height); + /// Größe ändern + virtual void Resize_(unsigned short width, unsigned short heigth); + void SetDisplaySize(const unsigned short width, const unsigned short height, + const unsigned short map_width, const unsigned short map_height); /// Liefert für einen gegebenen Map-Punkt die Pixel-Koordinaten relativ zur Bounding-Box - unsigned short CalcMapCoordX(const unsigned short x, const unsigned short map_width) const + inline unsigned short CalcMapCoordX(const unsigned short x) const { return GetLeft()+width_show*x/map_width; } - unsigned short CalcMapCoordY(const unsigned short y, const unsigned short map_height) const + inline unsigned short CalcMapCoordY(const unsigned short y) const { return GetTop()+height_show*y/map_height; } /// Verkleinert Minimap soweit es geht (entfernt Bounding-Box) in Y-Richtung und gibt neue Höhe zurück @@ -77,6 +79,11 @@ //unsigned short GetLeft() const { return x+minimap.GetLeft(); } ///// Berechnet Y-Koordinate der unteren Kante //unsigned short GetBottom() const { return y+minimap.GetBottom(); } + +protected: + + unsigned short map_width; + unsigned short map_height; }; === modified file 'src/ctrlMultiline.cpp' --- src/ctrlMultiline.cpp 2010-03-01 20:10:51 +0000 +++ src/ctrlMultiline.cpp 2010-03-08 20:18:25 +0000 @@ -47,7 +47,7 @@ TextureColor tc, glArchivItem_Font *font, unsigned int format) - : ctrlRectangle(parent, id, x, y, width, height), + : Window(x, y, id, parent, width, height), tc(tc), font(font), format(format), lines_in_control((height-4) / font->getHeight()), draw_box(true) { AddScrollBar(0, width - SCROLLBAR_WIDTH, 0, SCROLLBAR_WIDTH, height, SCROLLBAR_WIDTH, tc, lines_in_control); @@ -207,16 +207,10 @@ } -/// SetWidth überschreiben, damit auch die Scrollbar-Position angepasst werden kann -void ctrlMultiline::SetWidth(const unsigned short width) +void ctrlMultiline::Resize_(unsigned short width, unsigned short height) { - // Breite der Basisklasse richtig setzen - ctrlRectangle::SetWidth(width); - // Zusätzlich Position der Scrollbar anpassen + // Position der Scrollbar anpassen GetCtrl(0)->Move(width - SCROLLBAR_WIDTH,0); - - - } /// Textzeile ersetzen. Klappt bestimmt nicht mit Scrollbar-Kram === modified file 'src/ctrlMultiline.h' --- src/ctrlMultiline.h 2010-03-01 20:10:51 +0000 +++ src/ctrlMultiline.h 2010-03-08 20:18:25 +0000 @@ -21,7 +21,7 @@ #include "ctrlRectangle.h" -class ctrlMultiline : public ctrlRectangle +class ctrlMultiline : public Window { public: @@ -47,12 +47,11 @@ virtual bool Msg_WheelDown(const MouseCoords& mc); virtual bool Msg_MouseMove(const MouseCoords& mc); - /// SetWidth überschreiben, damit auch die Scrollbar-Position angepasst werden kann - void SetWidth(const unsigned short width); - protected: virtual bool Draw_(void); + void Resize_(unsigned short width, unsigned short height); + private: TextureColor tc; === modified file 'src/ctrlPercent.cpp' --- src/ctrlPercent.cpp 2010-03-01 20:10:51 +0000 +++ src/ctrlPercent.cpp 2010-03-08 20:18:25 +0000 @@ -46,8 +46,8 @@ unsigned int text_color, glArchivItem_Font *font, const unsigned short *percentage) - : Window(x, y, id, parent), - width(width), height(height), tc(tc), text_color(text_color), font(font), percentage(percentage) + : Window(x, y, id, parent, width, height), + tc(tc), text_color(text_color), font(font), percentage(percentage) { } === modified file 'src/ctrlPercent.h' --- src/ctrlPercent.h 2010-03-01 20:10:51 +0000 +++ src/ctrlPercent.h 2010-03-08 20:18:25 +0000 @@ -36,8 +36,6 @@ virtual bool Draw_(void); private: - unsigned short width; - unsigned short height; TextureColor tc; unsigned int text_color; glArchivItem_Font *font; === modified file 'src/ctrlPreviewMinimap.cpp' --- src/ctrlPreviewMinimap.cpp 2010-03-01 20:10:51 +0000 +++ src/ctrlPreviewMinimap.cpp 2010-03-08 20:18:25 +0000 @@ -74,8 +74,8 @@ { unsigned player = s2map->GetMapDataAt(MAP_LANDSCAPE, x, y); assert(player < 8); - players[player].x = CalcMapCoordX(x, map_width); - players[player].y = CalcMapCoordY(y, map_height); + players[player].x = x; + players[player].y = y; } } } @@ -103,7 +103,8 @@ if(players[i].color) { // Zeichnen - DrawRectangle(GetX()+players[i].x-2,GetY()+players[i].y-2,4,4,players[i].color); + DrawRectangle(GetX()+CalcMapCoordX(players[i].x)-2, + GetY()+CalcMapCoordY(players[i].y)-2,4,4,players[i].color); } } === modified file 'src/ctrlPreviewMinimap.h' --- src/ctrlPreviewMinimap.h 2010-03-01 20:10:51 +0000 +++ src/ctrlPreviewMinimap.h 2010-03-08 20:18:25 +0000 @@ -34,7 +34,7 @@ struct Player { Player(); - /// Koordinaten relativ zur Control-Position + /// Map-Koordinaten der Startposition unsigned short x,y; /// Farbe unsigned color; === modified file 'src/ctrlProgress.cpp' --- src/ctrlProgress.cpp 2010-03-01 20:10:51 +0000 +++ src/ctrlProgress.cpp 2010-03-08 20:18:25 +0000 @@ -56,8 +56,8 @@ const std::string& button_minus_tooltip, const std::string& button_plus_tooltip, unsigned short * const write_val) - : Window(x, y, id, parent, tooltip), - width(width), height(height), tc(tc), position(0), maximum(maximum), x_padding(x_padding), y_padding(y_padding), force_color(force_color) + : Window(x, y, id, parent, width, height, tooltip), + tc(tc), position(0), maximum(maximum), x_padding(x_padding), y_padding(y_padding), force_color(force_color) { AddImageButton(0, 0, 0, height, height, tc, LOADER.GetImageN("io", button_minus), (button_minus_tooltip.length() ? button_minus_tooltip : _("Less")) ); AddImageButton(1, width - height, 0, height, height, tc, LOADER.GetImageN("io", button_plus), (button_plus_tooltip.length( ) ? button_plus_tooltip : _("More")) ); === modified file 'src/ctrlProgress.h' --- src/ctrlProgress.h 2010-03-01 20:10:51 +0000 +++ src/ctrlProgress.h 2010-03-08 20:18:25 +0000 @@ -58,8 +58,6 @@ virtual bool Draw_(void); private: - unsigned short width; - unsigned short height; TextureColor tc; unsigned short position; === modified file 'src/ctrlRectangle.cpp' --- src/ctrlRectangle.cpp 2010-03-01 20:10:51 +0000 +++ src/ctrlRectangle.cpp 2010-03-08 20:18:25 +0000 @@ -22,9 +22,3 @@ #include "main.h" #include "ctrlRectangle.h" - -ctrlRectangle::ctrlRectangle(Window *parent, unsigned int id, unsigned short x, unsigned short y, - unsigned short width, unsigned short height) : Window(x, y, id, parent), width(width), - height(height) -{ -} === modified file 'src/ctrlRectangle.h' --- src/ctrlRectangle.h 2010-03-01 20:10:51 +0000 +++ src/ctrlRectangle.h 2010-03-08 20:18:25 +0000 @@ -21,28 +21,6 @@ #include "Window.h" -/// Control, welche ein eine feste Breite und Höhe besitzen -class ctrlRectangle : public Window -{ -public: - - ctrlRectangle(Window *parent, unsigned int id, unsigned short x, unsigned short y, - unsigned short width, unsigned short height); - - /// Setzt Breite und Höhe - virtual void SetWidth(const unsigned short width) { this->width = width; } - virtual void SetHeight(const unsigned short height) { this->height = height; } - - /// Liefert Breite und Höhe zurück - unsigned short GetWidth(const bool scale = false) const { return (scale) ? ScaleX(width) : width; } - unsigned short GetHeight(const bool scale = false) const { return (scale) ? ScaleY(height) : height; } - -protected: - - /// Breite und Höhe des Controls - unsigned short width, height; -}; - /// Interface für Klassen, in denen eine Farbe angezeigt wird class ColorControlInterface { === modified file 'src/ctrlScrollBar.cpp' --- src/ctrlScrollBar.cpp 2010-03-01 20:10:51 +0000 +++ src/ctrlScrollBar.cpp 2010-03-08 20:18:25 +0000 @@ -48,8 +48,8 @@ unsigned short button_height, TextureColor tc, unsigned short pagesize) - : Window(x, y, id, parent), - width(width), height(height), button_height(button_height), tc(tc), pagesize(pagesize), + : Window(x, y, id, parent, width, height), + button_height(button_height), tc(tc), pagesize(pagesize), move(false), scroll_range(0), scroll_pos(0), scroll_height(0), scrollbar_height(0), scrollbar_pos(0), last_y(0) { visible = false; @@ -57,8 +57,9 @@ AddImageButton(0, 0, 0, width, button_height, tc, LOADER.GetImageN("io", 33)); AddImageButton(1, 0, (height>button_height) ? height - button_height : 1, width, button_height, tc, LOADER.GetImageN("io", 34)); - if(height > 2 * button_height) - scroll_height = height - 2 * button_height; + Resize_(width, height); + + CalculateScrollBar(); } bool ctrlScrollBar::Msg_LeftUp(const MouseCoords& mc) @@ -198,11 +199,15 @@ CalculateScrollBar(); } -void ctrlScrollBar::SetHeight(unsigned short height) +void ctrlScrollBar::Resize_(unsigned short width, unsigned short height) { - ctrlButton *button = GetCtrl(1); - - this->height = height; + ctrlButton *button; + + button = GetCtrl(0); + button->Resize(width, button_height); + + button = GetCtrl(1); + button->Resize(width, button_height); if(height >= button_height) { @@ -212,7 +217,7 @@ else button->SetVisible(false); - CalculateScrollBar(); + CalculateScrollBar(height); } /////////////////////////////////////////////////////////////////////////////// @@ -243,9 +248,12 @@ * * @author FloSoft */ -void ctrlScrollBar::CalculateScrollBar() +void ctrlScrollBar::CalculateScrollBar(unsigned short height) { - scroll_height = height - 2 * button_height; + // Default parameter + if(height == 0) height = this->height; + + scroll_height = ((height>2*button_height) ? height-2*button_height : 0); if(scroll_range > pagesize) { === modified file 'src/ctrlScrollBar.h' --- src/ctrlScrollBar.h 2010-03-01 20:10:51 +0000 +++ src/ctrlScrollBar.h 2010-03-08 20:18:25 +0000 @@ -33,11 +33,6 @@ unsigned short GetPos() { return scroll_pos; } - void SetHeight(unsigned short height); - unsigned short GetHeight() const { return height; } - void SetWidth(unsigned short width) { this->width = width; } - unsigned short GetWidth() const { return width; } - virtual bool Msg_LeftUp(const MouseCoords& mc); virtual bool Msg_LeftDown(const MouseCoords& mc); virtual bool Msg_MouseMove(const MouseCoords& mc); @@ -46,13 +41,13 @@ protected: virtual bool Draw_(void); + void Resize_(unsigned short width, unsigned short height); + private: void CalculatePosition() { scroll_pos = (scrollbar_pos * scroll_range / scroll_height); } - void CalculateScrollBar(); + void CalculateScrollBar(unsigned short height = 0); private: - unsigned short width; - unsigned short height; unsigned short button_height; TextureColor tc; unsigned short pagesize; === modified file 'src/ctrlTab.cpp' --- src/ctrlTab.cpp 2010-03-01 20:10:51 +0000 +++ src/ctrlTab.cpp 2010-03-08 20:18:25 +0000 @@ -44,8 +44,8 @@ unsigned short x, unsigned short y, unsigned short width) - : Window(x, y, id, parent), - width(width), tab_count(0), tab_selection(0) + : Window(x, y, id, parent, width, 45), + tab_count(0), tab_selection(0) { memset(tabs, 0, MAX_TAB_COUNT * sizeof(unsigned int)); } === modified file 'src/ctrlTab.h' --- src/ctrlTab.h 2010-03-01 20:10:51 +0000 +++ src/ctrlTab.h 2010-03-08 20:18:25 +0000 @@ -71,7 +71,6 @@ virtual bool Draw_(void); private: - unsigned short width; unsigned short tab_count; unsigned short tab_selection; === modified file 'src/ctrlTable.cpp' --- src/ctrlTable.cpp 2010-03-01 20:10:51 +0000 +++ src/ctrlTable.cpp 2010-03-08 20:18:25 +0000 @@ -49,8 +49,8 @@ glArchivItem_Font *font, unsigned short column_count, va_list liste) - : Window(x, y, id, parent), - width(width), height(height), tc(tc), font(font), + : Window(x, y, id, parent, width, height), + tc(tc), font(font), row_l_selection(0xFFFF), row_r_selection(0xFFFF), sort_column(0xFFFF), sort_direction(true) { @@ -97,6 +97,39 @@ /////////////////////////////////////////////////////////////////////////////// /** + * Größe verändern + * + * @author Divan + */ +void ctrlTable::Resize_(unsigned short width, unsigned short height) +{ + ctrlScrollBar *scrollbar = GetCtrl(0); + + // changed height + + scrollbar->Move(width - 20, 0); + scrollbar->Resize(20, height); + + line_count = (height - header_height - 2) / font->getHeight(); + scrollbar->SetPageSize(line_count); + + // If the size was enlarged we have to check that we don't try to + // display more lines than present + if(height > this->height) + while(rows.size() - scrollbar->GetPos() < line_count + && scrollbar->GetPos() > 0) + scrollbar->SetPos(scrollbar->GetPos()-1); + + // changed width + + this->width=width; + ResetButtonWidths(); + if(scrollbar->GetVisible()) + Msg_ScrollShow(0, true); +} + +/////////////////////////////////////////////////////////////////////////////// +/** * löscht alle Items. * * @author OLiver === modified file 'src/ctrlTable.h' --- src/ctrlTable.h 2010-03-01 20:10:51 +0000 +++ src/ctrlTable.h 2010-03-08 20:18:25 +0000 @@ -67,12 +67,12 @@ virtual bool Draw_(void); + /// Größe ändern + void Resize_(unsigned short width, unsigned short height); /// Setzt die Breite und Position der Buttons ohne Scrolleiste void ResetButtonWidths(); private: - unsigned short width; - unsigned short height; TextureColor tc; glArchivItem_Font *font; === modified file 'src/ctrlText.cpp' --- src/ctrlText.cpp 2010-03-01 20:10:51 +0000 +++ src/ctrlText.cpp 2010-03-08 20:18:25 +0000 @@ -49,7 +49,7 @@ unsigned int color, unsigned int format, glArchivItem_Font *font) - : Window(x, y, id, parent), ctrlBaseText(text,color,font), format(format) + : Window(x, y, id, parent, width, height), ctrlBaseText(text,color,font), format(format) { } === modified file 'src/ctrlVarDeepening.cpp' --- src/ctrlVarDeepening.cpp 2010-03-01 20:10:51 +0000 +++ src/ctrlVarDeepening.cpp 2010-03-08 20:18:25 +0000 @@ -49,8 +49,14 @@ unsigned int count, va_list liste) : ctrlVarText(parent, id, x, y, text, color, 0, font, count, liste), - tc(tc), width(width), height(height) + tc(tc) { + // We don't want to pass these through all those constructors + // of only-text objects down to the Window class. This is a special + // situation, as we are a Deepening _and_ a VarText instead + // of owning the VarText. + this->width = width; + this->height = height; } /////////////////////////////////////////////////////////////////////////////// === modified file 'src/ctrlVarDeepening.h' --- src/ctrlVarDeepening.h 2010-03-01 20:10:51 +0000 +++ src/ctrlVarDeepening.h 2010-03-08 20:18:25 +0000 @@ -33,8 +33,6 @@ private: TextureColor tc; - unsigned short width; - unsigned short height; }; #endif // !CTRLVARDEEPENING_H_INCLUDED === modified file 'src/dskGameInterface.cpp' --- src/dskGameInterface.cpp 2010-03-01 20:10:51 +0000 +++ src/dskGameInterface.cpp 2010-03-08 20:18:25 +0000 @@ -147,14 +147,17 @@ * @author OLiver */ void dskGameInterface::SettingsChanged(void) - { +{ +} + +void dskGameInterface::Resize_(unsigned short width, unsigned short height) +{ // recreate borders - cbb.buildBorder(VideoDriverWrapper::inst().GetScreenWidth(), - VideoDriverWrapper::inst().GetScreenHeight(),&borders); + cbb.buildBorder(width, height, &borders); // move buttons - int barx = (VideoDriverWrapper::inst().GetScreenWidth() - LOADER.GetImageN("resource", 29)->getWidth()) / 2 + 44; - int bary = VideoDriverWrapper::inst().GetScreenHeight() - LOADER.GetImageN("resource", 29)->getHeight() + 4; + int barx = (width - LOADER.GetImageN("resource", 29)->getWidth()) / 2 + 44; + int bary = height - LOADER.GetImageN("resource", 29)->getHeight() + 4; ctrlImageButton *button = GetCtrl(0); button->Move(barx, bary, true); @@ -170,9 +173,8 @@ ctrlText *text = GetCtrl(4); text->Move(barx + 37 * 3 + 18, bary + 24); - // refresh view (does not change position) - this->gwv->MoveTo(0, 0); - } + this->gwv->Resize(width, height); +} /////////////////////////////////////////////////////////////////////////////// /** @@ -269,7 +271,7 @@ { GameClientPlayer *player = GAMECLIENT.GetPlayer(i); if(player->is_lagging) - LOADER.GetImageN("rttr", 0)->Draw(SETTINGS.video.width-70-i*40, 35, 30, 30, 0, 0, 0, 0, COLOR_WHITE, COLORS[player->color]); + LOADER.GetImageN("rttr", 0)->Draw(VideoDriverWrapper::inst().GetScreenWidth()-70-i*40, 35, 30, 30, 0, 0, 0, 0, COLOR_WHITE, COLORS[player->color]); } } @@ -281,8 +283,8 @@ */ bool dskGameInterface::Msg_LeftDown(const MouseCoords& mc) { - if(Coll(mc.x,mc.y,SETTINGS.video.width/2-LOADER.GetImageN("resource", 29)->getWidth()/2+44, - SETTINGS.video.height-LOADER.GetImageN("resource", 29)->getHeight()+4,37*4,32*4)) + if(Coll(mc.x,mc.y,VideoDriverWrapper::inst().GetScreenWidth()/2-LOADER.GetImageN("resource", 29)->getWidth()/2+44, + VideoDriverWrapper::inst().GetScreenHeight()-LOADER.GetImageN("resource", 29)->getHeight()+4,37*4,32*4)) return false; // Unterscheiden je nachdem Straäcnbaumodus an oder aus ist === modified file 'src/dskGameInterface.h' --- src/dskGameInterface.h 2010-03-01 20:10:51 +0000 +++ src/dskGameInterface.h 2010-03-08 20:18:25 +0000 @@ -136,6 +136,8 @@ private: + void Resize_(unsigned short width, unsigned short height); + /// Baut Weg zurück von Ende bis zu start_id void DemolishRoad(const unsigned start_id); === modified file 'src/dskHostGame.cpp' --- src/dskHostGame.cpp 2010-03-01 20:10:51 +0000 +++ src/dskHostGame.cpp 2010-03-08 20:18:25 +0000 @@ -165,6 +165,23 @@ /////////////////////////////////////////////////////////////////////////////// /** + * Größe ändern-Reaktionen die nicht vom Skaling-Mechanismus erfasst werden. + * + * @author Divan + */ +void dskHostGame::Resize_(unsigned short width, unsigned short height) +{ + // Text unter der PreviewMinimap verschieben, dessen Höhe von der Höhe der + // PreviewMinimap abhängt, welche sich gerade geändert hat. + ctrlPreviewMinimap *preview = GetCtrl(70); + ctrlText *text = GetCtrl(71); + assert(preview); + assert(text); + text->Move(text->GetX(false),preview->GetY(false)+preview->GetBottom()+10); +} + +/////////////////////////////////////////////////////////////////////////////// +/** * * * @author OLiver === modified file 'src/dskHostGame.h' --- src/dskHostGame.h 2010-03-01 20:10:51 +0000 +++ src/dskHostGame.h 2010-03-08 20:18:25 +0000 @@ -39,6 +39,8 @@ /// Map übergeben, damit die Kartenvorschau erstellt werden kann dskHostGame(); + /// Größe ändern-Reaktionen die nicht vom Skaling-Mechanismus erfasst werden. + void Resize_(unsigned short width, unsigned short height); private: void TogglePlayerReady(unsigned char player, bool ready); === modified file 'src/iwAction.cpp' --- src/iwAction.cpp 2010-03-01 20:10:51 +0000 +++ src/iwAction.cpp 2010-03-08 20:18:25 +0000 @@ -503,7 +503,7 @@ } - SetHeight(height); + SetIwHeight(height); } break; } @@ -523,7 +523,7 @@ case Tabs::BT_CASTLE: height = 186; break; case Tabs::BT_MINE: height = 186; break; } - SetHeight(height); + SetIwHeight(height); } break; } } === modified file 'src/iwHelp.cpp' --- src/iwHelp.cpp 2010-03-01 20:10:51 +0000 +++ src/iwHelp.cpp 2010-03-08 20:18:25 +0000 @@ -68,7 +68,7 @@ unsigned short text_height=show_lines*NormalFont->getHeight(); // Höhe setzen - SetHeight(text_height+40); + SetIwHeight(text_height+40); // Fenster neben die Maus schieben MoveNextToMouse(); === modified file 'src/iwMinimap.cpp' --- src/iwMinimap.cpp 2010-03-01 20:10:51 +0000 +++ src/iwMinimap.cpp 2010-03-08 20:18:25 +0000 @@ -74,9 +74,6 @@ /// Verändert die Größe des Fensters und positioniert alle Controls etc. neu void iwMinimap::ChangeWindowSize(const unsigned short width, const unsigned short height) { - SetWidth(width); - SetHeight(height); - ctrlIngameMinimap * im = GetCtrl(0); im->SetDisplaySize(width-20,height-30); @@ -89,7 +86,7 @@ // Fensterbreite anpassen SetWidth(im->GetWidth()+20); - SetHeight(im->GetHeight()+30+BUTTON_HEIGHT+BUTTON_MAP_SPACE+BUTTON_WINDOW_SPACE); + SetIwHeight(im->GetHeight()+30+BUTTON_HEIGHT+BUTTON_MAP_SPACE+BUTTON_WINDOW_SPACE); // Buttonpositionen anpassen, nach unten verschieben === modified file 'src/iwSettings.cpp' --- src/iwSettings.cpp 2010-03-01 20:10:51 +0000 +++ src/iwSettings.cpp 2010-03-08 20:18:25 +0000 @@ -115,9 +115,6 @@ { if(!VideoDriverWrapper::inst().ResizeScreen(SETTINGS.video.width,SETTINGS.video.height,SETTINGS.video.fullscreen)){ // WindowManager::inst().Show(new iwMsgbox(_("Sorry!"), _("You need to restart your game to change the screen resolution!"), this, MSB_OK, MSB_EXCLAMATIONGREEN, 1)); - } else { - // notify that settings where changed - this->gameDesktop->SettingsChanged(); } } }