Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add missing Widget::getGlobalFont. #137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added examples/dactylographe.ttf
Binary file not shown.
37 changes: 31 additions & 6 deletions examples/widgets_example.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,21 @@ namespace WidgetsExample
MainContainer(gcn::Gui& gui, int width, int height) :
demoListModel{{"zero", "one", "two", "three", "four"}}
{
#if USE_SDL2_TTF
TTF_Init();

trueFont = std::make_unique<gcn::SDLTrueTypeFont>("dactylographe.ttf", 12);
#endif
// Load the image font.
font = std::make_unique<gcn::ImageFont>(
imageFont = std::make_unique<gcn::ImageFont>(
"fixedfont.bmp", " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
// The global font is static and must be set.
gcn::Widget::setGlobalFont(font.get());

// The global font is static and must be set.
#if USE_SDL2_TTF
gcn::Widget::setGlobalFont(trueFont.get());
#else
gcn::Widget::setGlobalFont(imageFont.get());
#endif
top = std::make_unique<gcn::Container>();
// Set the dimension of the top container to match the screen.
top->setDimension(gcn::Rectangle(0, 0, width, height));
Expand Down Expand Up @@ -82,7 +91,8 @@ namespace WidgetsExample
checkBox1 = std::make_unique<gcn::CheckBox>("Checkbox 1");
checkBox2 = std::make_unique<gcn::CheckBox>("Checkbox 2");

toggleButton = std::make_unique<gcn::ToggleButton>("Toggle button");
toggleButton = std::make_unique<gcn::ToggleButton>("Toggle font");
toggleButton->addActionListener(this);

radioButton1 = std::make_unique<gcn::RadioButton>("Radio Button 1", "radiogroup", true);
radioButton2 = std::make_unique<gcn::RadioButton>("Radio Button 2", "radiogroup");
Expand Down Expand Up @@ -178,6 +188,19 @@ namespace WidgetsExample
label->adjustSize();
}
}
else if (actionEvent.getSource() == toggleButton.get())
{
if (gcn::Widget::getGlobalFont() == imageFont.get())
{
#if USE_SDL2_TTF
gcn::Widget::setGlobalFont(trueFont.get());
#endif
}
else
{
gcn::Widget::setGlobalFont(imageFont.get());
}
}
else if (actionEvent.getSource() == messageBox.get())
{
switch (messageBox->getClickedButton())
Expand All @@ -195,8 +218,10 @@ namespace WidgetsExample
}

private:
std::unique_ptr<gcn::ImageFont> font; // A font

std::unique_ptr<gcn::Font> imageFont; // A font
#if USE_SDL2_TTF
std::unique_ptr<gcn::Font> trueFont; // A font
#endif
/*
* All of the widgets
*/
Expand Down
9 changes: 9 additions & 0 deletions include/guisan/widget.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,15 @@ namespace gcn
*/
static void setGlobalFont(Font* font);

/**
* Gets the global font to be used by default for all widgets.
*
* @return font The global font.
* @see setGlobalFont
* @since 1.2.0
*/
static Font* getGlobalFont();

/**
* Set the base color for all widgets
*
Expand Down
5 changes: 5 additions & 0 deletions src/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,11 @@ namespace gcn
}
}

Font* Widget::getGlobalFont()
{
return mGlobalFont;
}

void Widget::setWidgetsBaseColor(Color color)
{
for (Widget* w : mWidgetInstances)
Expand Down
Loading