42#include <guichan/exception.hpp>
43#include <guichan/image.hpp>
62 : mAvailableThemes(
Theme::getAvailableThemes())
63 , mCustomCursorScale(
Client::getVideo().settings().scale())
69 return theme.getPath() == themePath;
88 guiTop->setFocusable(
true);
90 guiTop->setOpaque(
false);
107 catch (gcn::Exception e)
109 Log::critical(std::string(
"Unable to load '") + fontFile +
110 "': " + e.getMessage());
120 catch (gcn::Exception e)
122 Log::critical(std::string(
"Unable to load '") + fontFile +
123 "': " + e.getMessage());
133 catch (gcn::Exception e)
135 Log::critical(std::string(
"Unable to load '") + fontFile +
136 "': " + e.getMessage());
142 gcn::Widget::setGlobalFont(
mGuiFont);
153 SDL_FreeCursor(cursor);
156 SDL_FreeCursor(cursor);
171 SDL_ShowCursor(SDL_DISABLE);
198 const float graphicsScale =
static_cast<Graphics*
>(mGraphics)->getScale();
212 int oldWidth = top->getWidth();
213 int oldHeight = top->getHeight();
214 if (oldWidth == width && oldHeight == height)
217 top->setSize(width, height);
242 mTheme = std::make_unique<Theme>(theme);
255 gcn::Gui::handleMouseMoved(mouseInput);
259 SDL_ShowCursor(SDL_ENABLE);
264 if (
auto focused = mFocusHandler->getFocused())
266 if (
auto textField =
dynamic_cast<TextField*
>(focused))
268 textField->textInput(textInput);
273static SDL_Surface *loadSurface(
const std::string &path)
276 return IMG_Load_RW(file, 1);
283 SDL_FreeCursor(cursor);
287 const std::string cursorPath =
mTheme->resolvePath(
"mouse.png");
288 SDL_Surface *mouseSurface = loadSurface(cursorPath);
291 Log::warn(
"Unable to load mouse cursor file (%s): %s",
292 cursorPath.c_str(), SDL_GetError());
296 SDL_SetSurfaceBlendMode(mouseSurface, SDL_BLENDMODE_NONE);
298 constexpr int cursorSize = 40;
300 const int columns = mouseSurface->w / cursorSize;
302 SDL_Surface *cursorSurface = SDL_CreateRGBSurfaceWithFormat(
303 0, targetCursorSize, targetCursorSize, 32,
304 SDL_PIXELFORMAT_RGBA32);
308 int x = i % columns * cursorSize;
309 int y = i / columns * cursorSize;
311 SDL_Rect srcrect = { x, y, cursorSize, cursorSize };
312 SDL_Rect dstrect = { 0, 0, targetCursorSize, targetCursorSize };
313 SDL_BlitScaled(mouseSurface, &srcrect, cursorSurface, &dstrect);
315 SDL_Cursor *cursor = SDL_CreateColorCursor(cursorSurface,
320 Log::warn(
"Unable to create cursor: %s", SDL_GetError());
326 SDL_FreeSurface(cursorSurface);
327 SDL_FreeSurface(mouseSurface);
334 SDL_SystemCursor systemCursor;
353 for (
auto cursor : cursors)
The core part of the client.
static Video & getVideo()
std::string getValue(const std::string &key, const std::string &deflt) const
Gets a value as string.
void listen(Event::Channel channel)
A central point of control for graphics.
float getScale() const
Returns the graphics scale.
int getHeight() const
Returns the logical height of the screen.
int getWidth() const
Returns the logical width of the screen.
Timer mMouseActivityTimer
void handleTextInput(const TextInput &textInput)
bool mCustomCursor
Show custom cursor.
Gui(Graphics *screen, const std::string &themePath)
void handleMouseMoved(const gcn::MouseInput &mouseInput) override
gcn::Font * mInfoParticleFont
Font for Info Particles.
std::vector< ThemeInfo > mAvailableThemes
bool videoResized(int width, int height)
Called when the application window has been resized.
std::unique_ptr< Theme > mTheme
The global GUI theme.
std::vector< SDL_Cursor * > mCustomMouseCursors
gcn::Font * mGuiFont
The global GUI font.
void setUseCustomCursor(bool customCursor)
Sets whether a custom cursor should be rendered.
std::vector< SDL_Cursor * > mSystemMouseCursors
void event(Event::Channel channel, const Event &event) override
void setTheme(const ThemeInfo &theme)
Sets the global GUI theme.
void setCursorType(Cursor cursor)
Sets which cursor should be used.
void logic() override
Performs logic of the GUI.
static void advanceGradients()
Updates all colors, that are non-static.
static std::string getPath(const std::string &file)
Returns the real path to a file.
bool passed() const
Returns whether the timer has passed.
void set(uint32_t ms=0)
Sets the timer with an optional duration in milliseconds.
A wrapper around SDL_ttf for allowing the use of TrueType fonts.
static void updateFontScale(float scale)
const VideoSettings & settings() const
void adjustAfterResize(int oldScreenWidth, int oldScreenHeight)
Ensures that all visible windows are on the screen after the screen has been resized.
static void setWindowContainer(WindowContainer *windowContainer)
Sets the window container to be used by new windows.
Config config
Global settings (config.xml)
Configuration branding
XML branding information reader.
SDLInput * guiInput
GUI input.
gcn::Font * monoFont
Monospaced text font.
gcn::Font * boldFont
Bolded text font.
SDLInput * guiInput
GUI input.
gcn::Font * monoFont
Monospaced text font.
Cursor
Cursors are in graphic order from left to right.
gcn::Font * boldFont
Bolded text font.
SDL_RWops * openRWops(const std::string &path)
void warn(const char *log_text,...) LOG_PRINTF_ATTR
void info(const char *log_text,...) LOG_PRINTF_ATTR