Skip to content

Commit

Permalink
Add support for dpi based HUD scaling
Browse files Browse the repository at this point in the history
Add support for (configurable) multiline hotbar
Improved screensize handling
Add userdefined gui scale by BlockMen
  • Loading branch information
sapier authored and sapier committed Apr 27, 2014
1 parent 8d31534 commit 1838a3f
Show file tree
Hide file tree
Showing 13 changed files with 266 additions and 151 deletions.
10 changes: 9 additions & 1 deletion doc/menu_lua_api.txt
Expand Up @@ -116,6 +116,14 @@ engine.file_open_dialog(formname,caption)
^ -if dialog was canceled "_cancelled"
^ will be added to fieldname value is set to formname itself
^ returns nil or selected file/folder
engine.get_screen_info()
^ returns {
density = <screen density 0.75,1.0,2.0,3.0 ... (dpi)>,
display_width = <width of display>,
display_height = <height of display>,
window_width = <current window width>,
window_height = <current window height>
}

Games:
engine.get_game(index)
Expand Down Expand Up @@ -198,7 +206,7 @@ engine.handle_async(async_job,parameters,finished)
^ execute a function asynchronously
^ async_job is a function receiving one parameter and returning one parameter
^ parameters parameter table passed to async_job
^ finished function to be called once async_job has finished
^ finished function to be called once async_job has finished
^ the result of async_job is passed to this function

Limitations of Async operations
Expand Down
7 changes: 6 additions & 1 deletion minetest.conf.example
Expand Up @@ -140,13 +140,18 @@
#crosshair_color = (255,255,255)
# Cross alpha (opaqueness, between 0 and 255)
#crosshair_alpha = 255
# scale gui by a user specified value
#gui_scaling = 1.0
# Sensitivity multiplier
#mouse_sensitivity = 0.2
# Sound settings
#enable_sound = true
#sound_volume = 0.7
# Whether node texture animations should be desynchronized per MapBlock
#desynchronize_mapblock_texture_animation = true
# maximum percentage of current window to be used for hotbar
# (usefull if you've there's something to be displayed right or left of hotbar)
#hud_hotbar_max_width = 1.0
# Texture filtering settings
#mip_map = false
#anisotropic_filter = false
Expand All @@ -165,7 +170,7 @@
#normalmaps_strength = 0.6
# Strength of generated normalmaps
#normalmaps_smooth = 1
# Defines sampling step of texture (0 - 2)
# Defines sampling step of texture (0 - 2)
# Higher the value normal maps will be smoother
#enable_parallax_occlusion = false
# Scale of parallax occlusion effect
Expand Down
4 changes: 2 additions & 2 deletions src/camera.cpp
Expand Up @@ -249,7 +249,7 @@ void Camera::step(f32 dtime)
}

void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime,
v2u32 screensize, f32 tool_reload_ratio,
f32 tool_reload_ratio,
int current_camera_mode, ClientEnvironment &c_env)
{
// Get player position
Expand Down Expand Up @@ -422,7 +422,7 @@ void Camera::update(LocalPlayer* player, f32 frametime, f32 busytime,
fov_degrees = MYMIN(fov_degrees, 170.0);

// FOV and aspect ratio
m_aspect = (f32)screensize.X / (f32) screensize.Y;
m_aspect = (f32) porting::getWindowSize().X / (f32) porting::getWindowSize().Y;
m_fov_y = fov_degrees * M_PI / 180.0;
// Increase vertical FOV on lower aspect ratios (<16:10)
m_fov_y *= MYMAX(1.0, MYMIN(1.4, sqrt(16./10. / m_aspect)));
Expand Down
2 changes: 1 addition & 1 deletion src/camera.h
Expand Up @@ -117,7 +117,7 @@ class Camera
// Update the camera from the local player's position.
// busytime is used to adjust the viewing range.
void update(LocalPlayer* player, f32 frametime, f32 busytime,
v2u32 screensize, f32 tool_reload_ratio,
f32 tool_reload_ratio,
int current_camera_mode, ClientEnvironment &c_env);

// Render distance feedback loop
Expand Down
2 changes: 2 additions & 0 deletions src/defaultsettings.cpp
Expand Up @@ -119,10 +119,12 @@ void set_default_settings(Settings *settings)
settings->setDefault("selectionbox_color", "(0,0,0)");
settings->setDefault("crosshair_color", "(255,255,255)");
settings->setDefault("crosshair_alpha", "255");
settings->setDefault("gui_scaling", "1.0");
settings->setDefault("mouse_sensitivity", "0.2");
settings->setDefault("enable_sound", "true");
settings->setDefault("sound_volume", "0.8");
settings->setDefault("desynchronize_mapblock_texture_animation", "true");
settings->setDefault("hud_hotbar_max_width","1.0");

settings->setDefault("mip_map", "false");
settings->setDefault("anisotropic_filter", "false");
Expand Down
26 changes: 9 additions & 17 deletions src/game.cpp
Expand Up @@ -1099,7 +1099,6 @@ void the_game(bool &kill, bool random_input, InputHandler *input,
// Calculate text height using the font
u32 text_height = font->getDimension(L"Random test string").Height;

v2u32 last_screensize(0,0);
v2u32 screensize = driver->getScreenSize();

/*
Expand Down Expand Up @@ -1842,15 +1841,6 @@ void the_game(bool &kill, bool random_input, InputHandler *input,
/*
Random calculations
*/
last_screensize = screensize;
screensize = driver->getScreenSize();
v2s32 displaycenter(screensize.X/2,screensize.Y/2);
//bool screensize_changed = screensize != last_screensize;


// Update HUD values
hud.screensize = screensize;
hud.displaycenter = displaycenter;
hud.resizeHotbar();

// Hilight boxes collected during the loop and displayed
Expand Down Expand Up @@ -2267,10 +2257,11 @@ void the_game(bool &kill, bool random_input, InputHandler *input,
first_loop_after_window_activation = false;
}
else{
s32 dx = input->getMousePos().X - displaycenter.X;
s32 dy = input->getMousePos().Y - displaycenter.Y;
if(invert_mouse || player->camera_mode == CAMERA_MODE_THIRD_FRONT)
s32 dx = input->getMousePos().X - (driver->getScreenSize().Width/2);
s32 dy = input->getMousePos().Y - (driver->getScreenSize().Height/2);
if(invert_mouse || player->camera_mode == CAMERA_MODE_THIRD_FRONT) {
dy = -dy;
}
//infostream<<"window active, pos difference "<<dx<<","<<dy<<std::endl;

/*const float keyspeed = 500;
Expand All @@ -2292,7 +2283,8 @@ void the_game(bool &kill, bool random_input, InputHandler *input,

turn_amount = v2f(dx, dy).getLength() * d;
}
input->setMousePos(displaycenter.X, displaycenter.Y);
input->setMousePos((driver->getScreenSize().Width/2),
(driver->getScreenSize().Height/2));
}
else{
// Mac OSX gets upset if this is set every frame
Expand Down Expand Up @@ -2657,7 +2649,7 @@ void the_game(bool &kill, bool random_input, InputHandler *input,
}
player->camera_mode = current_camera_mode;
tool_reload_ratio = MYMIN(tool_reload_ratio, 1.0);
camera.update(player, dtime, busytime, screensize, tool_reload_ratio,
camera.update(player, dtime, busytime, tool_reload_ratio,
current_camera_mode, client.getEnv());
camera.step(dtime);

Expand Down Expand Up @@ -3538,8 +3530,8 @@ void the_game(bool &kill, bool random_input, InputHandler *input,
*/
if (show_hud)
{
hud.drawHotbar(v2s32(displaycenter.X, screensize.Y),
client.getHP(), client.getPlayerItem(), client.getBreath());
hud.drawHotbar(client.getHP(), client.getPlayerItem(),
client.getBreath());
}

/*
Expand Down

0 comments on commit 1838a3f

Please sign in to comment.