Skip to content
Snippets Groups Projects
Commit 3a223e49 authored by DarkGod's avatar DarkGod
Browse files

New option to zoom the whole screen, for use on veyr high DPI screens where...

New option to zoom the whole screen, for use on veyr high DPI screens where the game may look too tiny
parent a0f134f2
No related branches found
No related tags found
No related merge requests found
......@@ -524,14 +524,14 @@ function _M:setResolution(res, force)
-- Change the window size
print("setResolution: switching resolution to", res, r[1], r[2], r[3], r[4], force and "(forced)")
local old_w, old_h, old_f, old_b = self.w, self.h, self.fullscreen, self.borderless
core.display.setWindowSize(r[1], r[2], r[3], r[4])
local old_w, old_h, old_f, old_b, old_rw, old_rh = self.w, self.h, self.fullscreen, self.borderless
core.display.setWindowSize(r[1], r[2], r[3], r[4], config.settings.screen_zoom)
-- Don't write self.w/h/fullscreen yet
local new_w, new_h, new_f, new_b = core.display.size()
local new_w, new_h, new_f, new_b, new_rw, new_rh = core.display.size()
-- Check if a resolution change actually happened
if new_w ~= old_w or new_h ~= old_h or new_f ~= old_f or new_b ~= old_b then
if new_w ~= old_w or new_h ~= old_h or new_rw ~= old_rw or new_rh ~= old_rh or new_f ~= old_f or new_b ~= old_b then
print("setResolution: performing onResolutionChange...\n")
self:onResolutionChange()
-- onResolutionChange saves settings...
......@@ -552,11 +552,12 @@ function _M:onResolutionChange()
end
-- Get new resolution and save
self.w, self.h, self.fullscreen, self.borderless = core.display.size()
config.settings.window.size = ("%dx%d%s"):format(self.w, self.h, self.fullscreen and " Fullscreen" or (self.borderless and " Borderless" or " Windowed"))
local realw, realh
self.w, self.h, self.fullscreen, self.borderless, realw, realh = core.display.size()
config.settings.window.size = ("%dx%d%s"):format(realw, realh, self.fullscreen and " Fullscreen" or (self.borderless and " Borderless" or " Windowed"))
self:saveSettings("resolution", ("window.size = '%s'\n"):format(config.settings.window.size))
print("onResolutionChange: resolution changed to ", self.w, self.h, "from", ow, oh)
print("onResolutionChange: resolution changed to ", realw, realh, "from", ow, oh)
-- We do not even have a game yet
if not game then
......
......@@ -34,8 +34,8 @@ function _M:init()
self.c_enable = Checkbox.new{title="Enable audio", default=config.settings.audio.enable, fct=function() end, on_change=function(s) self:sfxEnable(s) end}
self.c_music_vol = NumberSlider.new{title="Music: ", size_title="Effects: ", w=300, max=100, min=0, value=config.settings.audio.music_volume, on_change = function(v) self:sfxVolume("music", v) end}
self.c_effects_vol = NumberSlider.new{title="Effects: ", w=300, max=100, min=0, value=config.settings.audio.effects_volume, on_change = function(v) self:sfxVolume("effects", v) end}
self.c_music_vol = NumberSlider.new{title="Music: ", size_title="Effects: ", w=400, max=100, min=0, value=config.settings.audio.music_volume, on_change = function(v) self:sfxVolume("music", v) end}
self.c_effects_vol = NumberSlider.new{title="Effects: ", w=400, max=100, min=0, value=config.settings.audio.effects_volume, on_change = function(v) self:sfxVolume("effects", v) end}
self:loadUI{
{left=0, top=0, ui=self.c_enable},
......
-- TE4 - T-Engine 4
-- Copyright (C) 2009 - 2016 Nicolas Casalini
--
-- This program is free software: you can redistribute it and/or modify
-- it under the terms of the GNU General Public License as published by
-- the Free Software Foundation, either version 3 of the License, or
-- (at your option) any later version.
--
-- This program is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY; without even the implied warranty of
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-- GNU General Public License for more details.
--
-- You should have received a copy of the GNU General Public License
-- along with this program. If not, see <http://www.gnu.org/licenses/>.
--
-- Nicolas Casalini "DarkGod"
-- darkgod@te4.org
require "engine.class"
local Module = require "engine.Module"
local Dialog = require "engine.ui.Dialog"
local Button = require "engine.ui.Button"
local NumberSlider = require "engine.ui.NumberSlider"
--- Generic popup for getting quantity
-- @classmod engine.dialogs.GetQuantity
module(..., package.seeall, class.inherit(Dialog))
function _M:init(title, prompt, default, min, max, step, action)
self.action = action
Dialog.init(self, title or "Quantity", 320, 110)
local c_box = NumberSlider.new{title=prompt and (prompt..": ") or "", value=default or 0, max=max, min=min, step=step, size=400, fct=function() self:okclick() end}
self.c_box = c_box
local ok = require("engine.ui.Button").new{text="Accept", fct=function() self:okclick() end}
local cancel = require("engine.ui.Button").new{text="Cancel", fct=function() self:cancelclick() end}
self:loadUI{
{left=0, top=0, padding_h=10, ui=c_box},
{left=0, bottom=0, ui=ok},
{right=0, bottom=0, ui=cancel},
}
self:setFocus(c_box)
self:setupUI(true, true)
self.key:addBinds{
EXIT = function() game:unregisterDialog(self) end,
}
end
function _M:okclick()
self.qty = self.c_box.value
if self.qty then
game:unregisterDialog(self)
self.action(self.qty)
else
Dialog:simplePopup("Error", "Enter a quantity.")
end
end
function _M:cancelclick()
self.key:triggerVirtual("EXIT")
end
......@@ -23,6 +23,7 @@ local TreeList = require "engine.ui.TreeList"
local Textzone = require "engine.ui.Textzone"
local Separator = require "engine.ui.Separator"
local GetQuantity = require "engine.dialogs.GetQuantity"
local GetQuantitySlider = require "engine.dialogs.GetQuantitySlider"
--- Video Options
-- @classmod engine.dialogs.VideoOptions
......@@ -72,24 +73,36 @@ function _M:generateList()
game:registerDialog(menu)
end,}
local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text=string.toTString"If you have a very high DPI screen you may want to raise this value. Requires a restart to take effect.#WHITE#"}
list[#list+1] = { zone=zone, name=string.toTString"#GOLD##{bold}#Screen Zoom#WHITE##{normal}#", status=function(item)
return tostring(config.settings.screen_zoom * 100)
end, fct=function(item)
game:registerDialog(GetQuantitySlider.new("Enter Zoom %", "From 50 to 400", math.floor(config.settings.screen_zoom * 100), 50, 400, 5, function(qty)
qty = util.bound(qty, 50, 400)
game:saveSettings("screen_zoom", ("screen_zoom = %f\n"):format(qty / 100))
config.settings.screen_zoom = qty / 100
self.c_list:drawItem(item)
end))
end,}
local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text=string.toTString"Request this display refresh rate.\nSet it lower to reduce CPU load, higher to increase interface responsiveness.#WHITE#"}
list[#list+1] = { zone=zone, name=string.toTString"#GOLD##{bold}#Requested FPS#WHITE##{normal}#", status=function(item)
return tostring(config.settings.display_fps)
end, fct=function(item)
game:registerDialog(GetQuantity.new("Enter density", "From 5 to 60", config.settings.display_fps, 60, function(qty)
game:registerDialog(GetQuantitySlider.new("Enter density", "From 5 to 60", config.settings.display_fps, 5, 60, 1, function(qty)
qty = util.bound(qty, 5, 60)
game:saveSettings("display_fps", ("display_fps = %d\n"):format(qty))
config.settings.display_fps = qty
core.game.setFPS(qty)
self.c_list:drawItem(item)
end), 5)
end))
end,}
local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text=string.toTString"Controls the particle effects density.\nThis option allows to change the density of the many particle effects in the game.\nIf the game is slow when displaying spell effects try to lower this setting.#WHITE#"}
list[#list+1] = { zone=zone, name=string.toTString"#GOLD##{bold}#Particle effects density#WHITE##{normal}#", status=function(item)
return tostring(config.settings.particles_density)
end, fct=function(item)
game:registerDialog(GetQuantity.new("Enter density", "From 0 to 100", config.settings.particles_density, 100, function(qty)
game:registerDialog(GetQuantitySlider.new("Enter density", "From 0 to 100", config.settings.particles_density, 0, 100, 1, function(qty)
game:saveSettings("particles_density", ("particles_density = %d\n"):format(qty))
config.settings.particles_density = qty
self.c_list:drawItem(item)
......@@ -165,13 +178,13 @@ function _M:generateList()
list[#list+1] = { zone=zone, name=string.toTString"#GOLD##{bold}#Gamma correction#WHITE##{normal}#", status=function(item)
return tostring(config.settings.gamma_correction)
end, fct=function(item)
game:registerDialog(GetQuantity.new("Gamma correction", "From 50 to 300", config.settings.gamma_correction, 300, function(qty)
game:registerDialog(GetQuantitySlider.new("Gamma correction", "From 50 to 300", config.settings.gamma_correction, 50, 300, 5, function(qty)
qty = util.bound(qty, 50, 300)
game:saveSettings("gamma_correction", ("gamma_correction = %d\n"):format(qty))
config.settings.gamma_correction = qty
game:setGamma(config.settings.gamma_correction / 100)
self.c_list:drawItem(item)
end), 50)
end))
end,}
local zone = Textzone.new{width=self.c_desc.w, height=self.c_desc.h, text=string.toTString"Enable/disable usage of tilesets.\nIn some rare cases on very slow machines with bad GPUs/drivers it can be detrimental."}
......
......@@ -58,6 +58,7 @@ shaders_active = true
shaders_kind_distort = true
shaders_kind_adv = true
shaders_kind_volumetric = false
screen_zoom = 1
particles_density = 100
background_saves = true
mouse_cursor = true
......
......@@ -32,6 +32,7 @@ function _M:init(t)
self.value = t.value or self.min
self.step = t.step or 10
self.on_change = t.on_change
self.fct = t.fct
assert(t.size or t.w, "no numberspinner size")
self.size = t.size
self.w = t.w
......@@ -53,45 +54,58 @@ function _M:generate()
title="",
chars = #tostring(self.max) + 1,
number = self.value,
fct = function(v) self:onChange() end,
fct = function(v) self:onChange() if self.fct then self.fct() end end,
}
self.h = math.max(self.nbox.h, self.middle.h)
self.w = self.w or self.size + self.title_w
self.size = self.w - self.title_w
self.key:addBind("ACCEPT", function() self:onChange() end)
self.key:addBind("ACCEPT", function() self:onChange() if self.fct then self.fct() end end)
self.key:addCommands{
_UP = function() self.nbox:updateText(1) self:onChange() end,
_DOWN = function() self.nbox:updateText(-1) self:onChange() end,
_LEFT = function(sym, ctrl, shift, alt, meta, unicode, key) self.nbox.key:receiveKey(sym, ctrl, shift, alt, meta, unicode, false, key) end,
_RIGHT = function(sym, ctrl, shift, alt, meta, unicode, key) self.nbox.key:receiveKey(sym, ctrl, shift, alt, meta, unicode, false, key) end,
_UP = function() self.nbox:updateText(self.step) self:onChange() end,
_DOWN = function() self.nbox:updateText(-self.step) self:onChange() end,
_PAGEUP = function() self.nbox:updateText(self.step) self:onChange() end,
_PAGEDOWN = function() self.nbox:updateText(-self.step) self:onChange() end,
}
self.key.atLast = function(sym, ctrl, shift, alt, meta, unicode, isup, key) self.nbox.key:receiveKey(sym, ctrl, shift, alt, meta, unicode, isup, key) print("KEY", unicode) end
self.key.atLast = function(sym, ctrl, shift, alt, meta, unicode, isup, key) self.nbox.key:receiveKey(sym, ctrl, shift, alt, meta, unicode, isup, key) end
-- precise click
local current_button = "none"
self.mouse:allowDownEvent(true)
self.mouse:registerZone(self.title_w + self.left.w, 0, self.size - self.left.w - self.right.w, self.h, function(button, x, y, xrel, yrel, bx, by, event)
if event ~= "button" or button ~= "left" then return false end
x = x - self.title_w - self.left.w
local full = self.size - self.left.w - self.right.w
local point = util.bound(x, 0, full)
local delta = self.max - self.min
if full > 0 then
local value = point / full * delta
value = math.floor((value / self.step) + 0.5) * self.step
self.nbox:updateText(value + self.min - self.value)
self:onChange()
if
((event == "button" or event == "button-down") and button == "left") or
(event == "motion" and current_button == "left")
then
x = x - self.title_w - self.left.w
local full = self.size - self.left.w - self.right.w
local point = util.bound(x, 0, full)
local delta = self.max - self.min
if full > 0 then
local value = point / full * delta
value = math.floor((value / self.step) + 0.5) * self.step
self.nbox:updateText(value + self.min - self.value)
self:onChange()
end
end
end, {button=true}, "precise")
if event == "button-down" then current_button = button
elseif event == "button" then current_button = "none" end
end, {button=true, move=true}, "precise")
-- the box
self.mouse:registerZone(self.title_w + self.left.w, 0, self.size - self.left.w - self.right.w, self.h, function(button, x, y, ...)
self.mouse:registerZone(self.title_w + self.left.w, 0, self.size - self.left.w - self.right.w, self.h, function(button, x, y, xrel, yrel, bx, by, event)
if event == "button-down" then current_button = button
elseif event == "button" then current_button = "none" end
if x < self.range[1] or x > self.range[2] then return false end
self.nbox.mouse:delegate(button, x, y, ...)
self.nbox.mouse:delegate(button, x, y, xrel, yrel, bx, by, button)
end, nil, "box")
self.nbox.mouse.delegate_offset_y = (self.h - self.nbox.h) / 2
-- wheeeeeeee
local wheelTable = {wheelup = 1, wheeldown = -1}
local wheelTable = {wheelup = 1 * self.step, wheeldown = -1 * self.step}
self.mouse:registerZone(self.title_w, 0, self.size, self.h, function(button, x, y, xrel, yrel, bx, by, event)
if event == "button-down" then return false end
if event ~= "button" or not wheelTable[button] then return false end
self.nbox:updateText(wheelTable[button])
self:onChange()
......@@ -99,11 +113,13 @@ function _M:generate()
-- clicking on arrows
local stepTable = {left = self.step, right = 1}
self.mouse:registerZone(self.title_w, 0, self.left.w, self.h, function(button, x, y, xrel, yrel, bx, by, event)
if event == "button-down" then return false end
if event ~= "button" or not stepTable[button] then return false end
self.nbox:updateText(-stepTable[button])
self:onChange()
end, {button=true}, "left")
self.mouse:registerZone(self.title_w + self.size - self.right.w, 0, self.right.w, self.h, function(button, x, y, xrel, yrel, bx, by, event)
if event == "button-down" then return false end
if event ~= "button" or not stepTable[button] then return false end
self.nbox:updateText(stepTable[button])
self:onChange()
......@@ -113,12 +129,13 @@ function _M:generate()
end
function _M:on_focus(v)
game:onTickEnd(function() self.key:unicodeInput(v) end)
self.nbox:setFocus(v)
self:onChange()
end
function _M:onChange()
self.value = self.nbox.number
self.value = util.bound(self.nbox.number, self.min, self.max)
if self.on_change then self.on_change(self.value) end
local halfw = self.nbox.w / 2
......
......@@ -329,8 +329,8 @@ static int lua_get_mouse(lua_State *L)
int x = 0, y = 0;
int buttons = SDL_GetMouseState(&x, &y);
lua_pushnumber(L, x);
lua_pushnumber(L, y);
lua_pushnumber(L, x / screen_zoom);
lua_pushnumber(L, y / screen_zoom);
lua_pushnumber(L, SDL_BUTTON(buttons));
return 3;
......@@ -339,7 +339,7 @@ static int lua_set_mouse(lua_State *L)
{
int x = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2);
SDL_WarpMouseInWindow(window, x, y);
SDL_WarpMouseInWindow(window, x * screen_zoom, y * screen_zoom);
return 0;
}
extern int current_mousehandler;
......@@ -626,11 +626,13 @@ extern bool is_fullscreen;
extern bool is_borderless;
static int sdl_screen_size(lua_State *L)
{
lua_pushnumber(L, screen->w);
lua_pushnumber(L, screen->h);
lua_pushnumber(L, screen->w / screen_zoom);
lua_pushnumber(L, screen->h / screen_zoom);
lua_pushboolean(L, is_fullscreen);
lua_pushboolean(L, is_borderless);
return 4;
lua_pushnumber(L, screen->w);
lua_pushnumber(L, screen->h);
return 6;
}
static int sdl_window_pos(lua_State *L)
......@@ -2391,9 +2393,10 @@ static int sdl_set_window_size(lua_State *L)
int h = luaL_checknumber(L, 2);
bool fullscreen = lua_toboolean(L, 3);
bool borderless = lua_toboolean(L, 4);
float zoom = luaL_checknumber(L, 5);
printf("Setting resolution to %dx%d (%s, %s)\n", w, h, fullscreen ? "fullscreen" : "windowed", borderless ? "borderless" : "with borders");
do_resize(w, h, fullscreen, borderless);
do_resize(w, h, fullscreen, borderless, zoom);
lua_pushboolean(L, TRUE);
return 1;
......
......@@ -58,6 +58,7 @@ int start_xpos = -1, start_ypos = -1;
char *override_home = NULL;
int g_argc = 0;
char **g_argv;
float screen_zoom = 1;
SDL_Window *window = NULL;
SDL_Surface *windowIconSurface = NULL;
SDL_GLContext maincontext; /* Our opengl context handle */
......@@ -425,8 +426,8 @@ bool on_event(SDL_Event *event)
lua_concat(L, 2);
break;
}
lua_pushnumber(L, event->button.x);
lua_pushnumber(L, event->button.y);
lua_pushnumber(L, event->button.x / screen_zoom);
lua_pushnumber(L, event->button.y / screen_zoom);
lua_pushboolean(L, (event->type == SDL_MOUSEBUTTONUP) ? TRUE : FALSE);
docall(L, 5, 0);
}
......@@ -450,8 +451,8 @@ bool on_event(SDL_Event *event)
else if (event->wheel.x > 0) lua_pushstring(L, "wheelleft");
else if (event->wheel.x < 0) lua_pushstring(L, "wheelright");
else lua_pushstring(L, "wheelnone");
lua_pushnumber(L, x);
lua_pushnumber(L, y);
lua_pushnumber(L, x / screen_zoom);
lua_pushnumber(L, y / screen_zoom);
lua_pushboolean(L, i);
docall(L, 5, 0);
}
......@@ -474,8 +475,8 @@ bool on_event(SDL_Event *event)
else if (event->motion.state & SDL_BUTTON(4)) lua_pushstring(L, "wheelup");
else if (event->motion.state & SDL_BUTTON(5)) lua_pushstring(L, "wheeldown");
else lua_pushstring(L, "none");
lua_pushnumber(L, event->motion.x);
lua_pushnumber(L, event->motion.y);
lua_pushnumber(L, event->motion.x / screen_zoom);
lua_pushnumber(L, event->motion.y / screen_zoom);
lua_pushnumber(L, event->motion.xrel);
lua_pushnumber(L, event->motion.yrel);
docall(L, 6, 0);
......@@ -491,8 +492,8 @@ bool on_event(SDL_Event *event)
lua_remove(L, -2);
lua_rawgeti(L, LUA_REGISTRYINDEX, current_mousehandler);
lua_pushnumber(L, event->tfinger.fingerId);
lua_pushnumber(L, event->tfinger.x);
lua_pushnumber(L, event->tfinger.y);
lua_pushnumber(L, event->tfinger.x / screen_zoom);
lua_pushnumber(L, event->tfinger.y / screen_zoom);
lua_pushnumber(L, event->tfinger.dx);
lua_pushnumber(L, event->tfinger.dy);
lua_pushnumber(L, event->tfinger.pressure);
......@@ -509,8 +510,8 @@ bool on_event(SDL_Event *event)
lua_remove(L, -2);
lua_rawgeti(L, LUA_REGISTRYINDEX, current_mousehandler);
lua_pushnumber(L, event->tfinger.fingerId);
lua_pushnumber(L, event->tfinger.x);
lua_pushnumber(L, event->tfinger.y);
lua_pushnumber(L, event->tfinger.x / screen_zoom);
lua_pushnumber(L, event->tfinger.y / screen_zoom);
lua_pushnumber(L, event->tfinger.dx);
lua_pushnumber(L, event->tfinger.dy);
lua_pushnumber(L, event->tfinger.pressure);
......@@ -526,8 +527,8 @@ bool on_event(SDL_Event *event)
lua_remove(L, -2);
lua_rawgeti(L, LUA_REGISTRYINDEX, current_mousehandler);
lua_pushnumber(L, event->mgesture.numFingers);
lua_pushnumber(L, event->mgesture.x);
lua_pushnumber(L, event->mgesture.y);
lua_pushnumber(L, event->mgesture.x / screen_zoom);
lua_pushnumber(L, event->mgesture.y / screen_zoom);
lua_pushnumber(L, event->mgesture.dTheta);
lua_pushnumber(L, event->mgesture.dDist);
docall(L, 6, 0);
......@@ -935,7 +936,7 @@ int resizeWindow(int width, int height)
/* Set our perspective */
//gluPerspective( 45.0f, ratio, 0.1f, 100.0f );
glOrtho(0, width, height, 0, -1001, 1001);
glOrtho(0, width / screen_zoom, height / screen_zoom, 0, -1001, 1001);
/* Make sure we're chaning the model view and not the projection */
glMatrixMode( GL_MODELVIEW );
......@@ -995,7 +996,7 @@ void do_move(int w, int h) {
}
/* @see main.h#do_resize */
void do_resize(int w, int h, bool fullscreen, bool borderless)
void do_resize(int w, int h, bool fullscreen, bool borderless, float zoom)
{
/* Temporary width, height (since SDL might reject our resize) */
int aw, ah;
......@@ -1003,7 +1004,9 @@ void do_resize(int w, int h, bool fullscreen, bool borderless)
int mustCreateIconSurface = 0;
SDL_Event fsEvent;
printf("[DO RESIZE] Requested: %dx%d (%d, %d)\n", w, h, fullscreen, borderless);
screen_zoom = zoom;
printf("[DO RESIZE] Requested: %dx%d (%d, %d); zoom %d%%\n", w, h, fullscreen, borderless, (int)(zoom * 100));
/* See if we need to reinitialize the window */
if (resizeNeedsNewWindow(w, h, fullscreen, borderless)) {
......@@ -1442,7 +1445,7 @@ int main(int argc, char *argv[])
boot_lua(1, FALSE, argc, argv);
do_resize(WIDTH, HEIGHT, FALSE, FALSE);
do_resize(WIDTH, HEIGHT, FALSE, FALSE, screen_zoom);
if (screen==NULL) {
printf("error opening screen: %s\n", SDL_GetError());
return 3;
......@@ -1501,7 +1504,7 @@ int main(int argc, char *argv[])
/* Note: SDL can't resize a fullscreen window, so don't bother! */
if (!is_fullscreen) {
printf("SDL_WINDOWEVENT_RESIZED: %d x %d\n", event.window.data1, event.window.data2);
do_resize(event.window.data1, event.window.data2, is_fullscreen, is_borderless);
do_resize(event.window.data1, event.window.data2, is_fullscreen, is_borderless, screen_zoom);
if (current_game != LUA_NOREF)
{
lua_rawgeti(L, LUA_REGISTRYINDEX, current_game);
......
......@@ -52,7 +52,7 @@ void do_move(int w, int h);
* and fullscreen. These three modes are mutually exclusive, with the
* fullscreen flag taking priority over the borderless flag.
*/
extern void do_resize(int w, int h, bool fullscreen, bool borderless);
extern void do_resize(int w, int h, bool fullscreen, bool borderless, float zoom);
extern void setupRealtime(float freq);
extern void setupDisplayTimer(int fps);
......@@ -68,6 +68,7 @@ extern int cur_frame_tick;
extern int g_argc;
extern char **g_argv;
extern char *override_home;
extern float screen_zoom;
/* Error handling */
struct lua_err_type_s {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment