Split tooltip definitions into separate files

This commit is contained in:
Celtic Minstrel 2017-04-28 14:57:19 -04:00
parent d4c75b6ad6
commit 06450e8bb6
2 changed files with 198 additions and 189 deletions

View file

@ -0,0 +1,198 @@
#textdomain wesnoth-lib
###
### Definition of the window used to show large tooltips.
### The placement algorithms used are described in the
### »Tooltip placement« section in the GUI2 design document.
###
### gui/dialogs/title_screen.cpp has test code, which is
### activated by defining the DEBUG_TOOLTIP macro.
###
#define __GUI_WINDOW_HEIGHT
(
if(window_height = 0
# Determine the wanted maximum height. #
# The value should be high enough to avoid an #
# unable to place exception. #
, 100000
# Determine the height to use. #
, window_height)
)#enddef
#define __GUI_WINDOW_FUNCTIONS
def placement_method(m, w, s)
(
if((w.y > s.y) or ((w.x * 2) > s.x)
, 'V'
, if(m.y >= w.y
, if(m.x >= w.x, 'I', 'III')
, if(m.x >= w.x, 'II', 'IV')
)
)
);
def set_x(m, w, s)
(
[
if(preferred_x + w.x > s.x
, s.x - w.x
, preferred_x)
where
preferred_x = switch(
placement_method(m, w, s)
, 'I' , m.x - (w.x / 2)
, 'II' , m.x - w.x
, 'III' , 5
# extra offset to avoid being obscured by the mouse. #
, 'IV' , m.x + 15
, 'V' , 5
, #default# m.x
),
#
debug_print('placement_method, mouse ', m),
debug_print('window ', w),
debug_print('screen ', s),
debug_print('y margin', s.y - (m.y + w.y)),
debug_print('result ', placement_method(m, w, s)),
#
][0]
);
def set_y(m, w, s)
(
switch(
placement_method(m, w, s)
, 'I' , m.y - (w.y + 5)
, 'II' , 5
, 'III' , m.y - w.y
, 'IV' , 5
, 'V' , 5
, #default# m.y - w.y
)
);
def get_maximum_width(w, s)
(
if(w.x = 0
# The default width upon the initial run. #
, 450
, if(w.y <= s.y
# If the window's height fits use that. #
, w.x
# Else use an increased width, which should reduce #
# the required height. #
, 2 * w.x))
);
def set_w(r, w, s)
(
switch(
r
, 'maximum', get_maximum_width(w, s)
, 'size', w.x
)
);
def reevaluate_best_size(w, s)
(
[
w.y > s.y,
#
debug_print('window ', w),
debug_print('screen ', s)
#
][0]
);
#enddef
#define __GUI_WINDOW_X
(
set_x(
loc(source_x + (source_w / 2), source_y + (source_h / 2))
, loc(window_width, window_height)
, loc(screen_width, screen_height))
)
#enddef
#define __GUI_WINDOW_Y
(
set_y(
loc(source_x, source_y)
, loc(window_width, window_height)
, loc(screen_width, screen_height))
)#enddef
#define __GUI_WINDOW_WIDTH
(
set_w(
size_request_mode
, loc(window_width, window_height)
, loc(screen_width, screen_height))
)#enddef
#define __GUI_WINDOW_REEVALUATE_BEST_SIZE
(
reevaluate_best_size(
loc(window_width, window_height)
, loc(screen_width, screen_height))
)#enddef
[window]
id = "tooltip"
description = "The tooltip popup window with large tooltips, eg in the main menu."
[resolution]
definition = "tooltip"
automatic_placement = false
functions = "{__GUI_WINDOW_FUNCTIONS}"
x = "{__GUI_WINDOW_X}"
y = "{__GUI_WINDOW_Y}"
width = "{__GUI_WINDOW_WIDTH}"
height = "{__GUI_WINDOW_HEIGHT}"
reevaluate_best_size = "{__GUI_WINDOW_REEVALUATE_BEST_SIZE}"
# TODO tooltips in this window make little sense.
# Have to think of a nice solution.
[tooltip]
id = "tooltip"
[/tooltip]
[helptip]
id = "tooltip"
[/helptip]
[grid]
[row]
[column]
[label]
id = "label"
definition = "default_small"
use_markup = true
wrap = true
[/label]
[/column]
[/row]
[/grid]
[/resolution]
[/window]
#undef __GUI_WINDOW_REEVALUATE_BEST_SIZE
#undef __GUI_WINDOW_HEIGHT
#undef __GUI_WINDOW_WIDTH
#undef __GUI_WINDOW_Y
#undef __GUI_WINDOW_X
#undef __GUI_WINDOW_FUNCTIONS

View file

@ -53,192 +53,3 @@
[/window]
#define __GUI_WINDOW_HEIGHT
(
if(window_height = 0
# Determine the wanted maximum height. #
# The value should be high enough to avoid an #
# unable to place exception. #
, 100000
# Determine the height to use. #
, window_height)
)#enddef
#define __GUI_WINDOW_FUNCTIONS
def placement_method(m, w, s)
(
if((w.y > s.y) or ((w.x * 2) > s.x)
, 'V'
, if(m.y >= w.y
, if(m.x >= w.x, 'I', 'III')
, if(m.x >= w.x, 'II', 'IV')
)
)
);
def set_x(m, w, s)
(
[
if(preferred_x + w.x > s.x
, s.x - w.x
, preferred_x)
where
preferred_x = switch(
placement_method(m, w, s)
, 'I' , m.x - (w.x / 2)
, 'II' , m.x - w.x
, 'III' , 5
# extra offset to avoid being obscured by the mouse. #
, 'IV' , m.x + 15
, 'V' , 5
, #default# m.x
),
#
debug_print('placement_method, mouse ', m),
debug_print('window ', w),
debug_print('screen ', s),
debug_print('y margin', s.y - (m.y + w.y)),
debug_print('result ', placement_method(m, w, s)),
#
][0]
);
def set_y(m, w, s)
(
switch(
placement_method(m, w, s)
, 'I' , m.y - (w.y + 5)
, 'II' , 5
, 'III' , m.y - w.y
, 'IV' , 5
, 'V' , 5
, #default# m.y - w.y
)
);
def get_maximum_width(w, s)
(
if(w.x = 0
# The default width upon the initial run. #
, 450
, if(w.y <= s.y
# If the window's height fits use that. #
, w.x
# Else use an increased width, which should reduce #
# the required height. #
, 2 * w.x))
);
def set_w(r, w, s)
(
switch(
r
, 'maximum', get_maximum_width(w, s)
, 'size', w.x
)
);
def reevaluate_best_size(w, s)
(
[
w.y > s.y,
#
debug_print('window ', w),
debug_print('screen ', s)
#
][0]
);
#enddef
#define __GUI_WINDOW_X
(
set_x(
loc(source_x + (source_w / 2), source_y + (source_h / 2))
, loc(window_width, window_height)
, loc(screen_width, screen_height))
)
#enddef
#define __GUI_WINDOW_Y
(
set_y(
loc(source_x, source_y)
, loc(window_width, window_height)
, loc(screen_width, screen_height))
)#enddef
#define __GUI_WINDOW_WIDTH
(
set_w(
size_request_mode
, loc(window_width, window_height)
, loc(screen_width, screen_height))
)#enddef
#define __GUI_WINDOW_REEVALUATE_BEST_SIZE
(
reevaluate_best_size(
loc(window_width, window_height)
, loc(screen_width, screen_height))
)#enddef
[window]
id = "tooltip"
description = "The tooltip popup window with large tooltips, eg in the main menu."
[resolution]
definition = "tooltip"
automatic_placement = false
functions = "{__GUI_WINDOW_FUNCTIONS}"
x = "{__GUI_WINDOW_X}"
y = "{__GUI_WINDOW_Y}"
width = "{__GUI_WINDOW_WIDTH}"
height = "{__GUI_WINDOW_HEIGHT}"
reevaluate_best_size = "{__GUI_WINDOW_REEVALUATE_BEST_SIZE}"
# TODO tooltips in this window make little sense.
# Have to think of a nice solution.
[tooltip]
id = "tooltip"
[/tooltip]
[helptip]
id = "tooltip"
[/helptip]
[grid]
[row]
[column]
[label]
id = "label"
definition = "default_small"
use_markup = true
wrap = true
[/label]
[/column]
[/row]
[/grid]
[/resolution]
[/window]
#undef __GUI_WINDOW_REEVALUATE_BEST_SIZE
#undef __GUI_WINDOW_HEIGHT
#undef __GUI_WINDOW_WIDTH
#undef __GUI_WINDOW_Y
#undef __GUI_WINDOW_X
#undef __GUI_WINDOW_FUNCTIONS