Skip to content
Permalink
Browse files

Support for scalable font and gui elements

Fix positioning of tabheader in order to be usable for scaling GUIs
WARNING: this changes position of current tabheaders, mods have to adjust!
  • Loading branch information...
sapier sapier
sapier authored and sapier committed Jun 14, 2014
1 parent a0097c6 commit d4245e6cac58a57ad2498eee2c17e851f3292296
Showing with 143 additions and 57 deletions.
  1. +6 −6 builtin/mainmenu/init.lua
  2. +3 −3 builtin/mainmenu/store.lua
  3. +9 −0 src/constants.h
  4. +20 −4 src/defaultsettings.cpp
  5. +16 −0 src/defaultsettings.h
  6. +84 −43 src/guiFormSpecMenu.cpp
  7. +2 −1 src/guiFormSpecMenu.h
  8. +2 −0 src/hud.cpp
  9. +1 −0 src/main.cpp
@@ -83,11 +83,11 @@ local function init_globals()

menudata.worldlist:add_sort_mechanism("alphabetic",sort_worlds_alphabetic)
menudata.worldlist:set_sortmode("alphabetic")

mm_texture.init()

--create main tabview
local tv_main = tabview_create("maintab",{x=12,y=5.2},{x=-0.3,y=-0.99})
local tv_main = tabview_create("maintab",{x=12,y=5.2},{x=0,y=0})
tv_main:set_autosave_tab(true)
tv_main:add(tab_singleplayer)
tv_main:add(tab_multiplayer)
@@ -96,9 +96,9 @@ local function init_globals()
tv_main:add(tab_texturepacks)
tv_main:add(tab_mods)
tv_main:add(tab_credits)

tv_main:set_global_event_handler(main_event_handler)

tv_main:set_tab(core.setting_get("maintab_LAST"))
ui.set_default("maintab")
tv_main:show()
@@ -107,7 +107,7 @@ local function init_globals()
modstore.init({x=12,y=8},4,3)

ui.update()

core.sound_play("main_menu", true)
end

@@ -78,8 +78,8 @@ function modstore.init(size, unsortedmods, searchmods)

modstore.current_list = nil

modstore.tv_store = tabview_create("modstore",size,{x=-0.3,y=-0.99})
modstore.tv_store = tabview_create("modstore",size,{x=0,y=0})

modstore.tv_store:set_global_event_handler(modstore.handle_events)

modstore.tv_store:add(
@@ -307,7 +307,7 @@ function modstore.handle_buttons(parent, fields, name, data)
return true
end
end

return false
end

@@ -89,5 +89,14 @@ with this program; if not, write to the Free Software Foundation, Inc.,
// Maximum hit points of a player
#define PLAYER_MAX_HP 20

/*
* GUI related things
*/
#define LEGACY_SCALING (2./3.)
#define DEFAULT_FONT_SIZE (13.0 / LEGACY_SCALING)
#define DEFAULT_IMGSIZE (48.0)
#define DEFAULT_XSPACING ((15.0 + (1.0 / 3.0)))
#define DEFAULT_YSPACING (9.0)

#endif

@@ -21,6 +21,8 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "porting.h"
#include "filesys.h"
#include "config.h"
#include "constants.h"
#include "porting.h"

void set_default_settings(Settings *settings)
{
@@ -164,13 +166,11 @@ void set_default_settings(Settings *settings)
#if USE_FREETYPE
settings->setDefault("freetype", "true");
settings->setDefault("font_path", porting::getDataPath("fonts" DIR_DELIM "liberationsans.ttf"));
settings->setDefault("font_size", "13");
settings->setDefault("font_shadow", "1");
settings->setDefault("font_shadow_alpha", "128");
settings->setDefault("mono_font_path", porting::getDataPath("fonts" DIR_DELIM "liberationmono.ttf"));
settings->setDefault("mono_font_size", "13");
settings->setDefault("fallback_font_path", porting::getDataPath("fonts" DIR_DELIM "DroidSansFallbackFull.ttf"));
settings->setDefault("fallback_font_size", "13");

settings->setDefault("fallback_font_shadow", "1");
settings->setDefault("fallback_font_shadow_alpha", "128");
#else
@@ -234,7 +234,7 @@ void set_default_settings(Settings *settings)
settings->setDefault("emergequeue_limit_diskonly", "32");
settings->setDefault("emergequeue_limit_generate", "32");
settings->setDefault("num_emerge_threads", "1");

// physics stuff
settings->setDefault("movement_acceleration_default", "3");
settings->setDefault("movement_acceleration_air", "2");
@@ -278,6 +278,22 @@ void set_default_settings(Settings *settings)
settings->setDefault("language", "");
}

void late_init_default_settings(Settings* settings)
{
#ifndef SERVER
std::stringstream fontsize;
fontsize << floor(
DEFAULT_FONT_SIZE *
porting::getDisplayDensity() *
settings->getFloat("gui_scaling")
);

settings->setDefault("font_size", fontsize.str());
settings->setDefault("mono_font_size", fontsize.str());
settings->setDefault("fallback_font_size", fontsize.str());
#endif
}

void override_default_settings(Settings *settings, Settings *from)
{
std::vector<std::string> names = from->getNames();
@@ -22,7 +22,23 @@ with this program; if not, write to the Free Software Foundation, Inc.,

class Settings;

/**
* initialize basic default settings
* @param settings pointer to settings
*/
void set_default_settings(Settings *settings);

/**
* initialize default values which require knowledge about gui
* @param settings pointer to settings
*/
void late_init_default_settings(Settings* settings);

/**
* override a default settings by settings from another settings element
* @param settings target settings pointer
* @param from source settings pointer
*/
void override_default_settings(Settings *settings, Settings *from);

#endif

0 comments on commit d4245e6

Please sign in to comment.
You can’t perform that action at this time.