Initial implementation of the scaling image.
We now use a 400x400 image (max size 500x500) and scale that down to a 'nice' size for the current window size. The scale factor might need some tuning. Kitty also prefers to see a 400x400 image scaled down and evaluate the quality, this might means we only need a 400x400 image but also that we still need a 300x300 and maybe a 200x200 image. It's still not possible to manipulate the new portraits from the WML but that's postponed until we know how much images will be used.
This commit is contained in:
parent
00a521f53f
commit
80b2b5255a
2 changed files with 191 additions and 15 deletions
|
@ -4,6 +4,95 @@
|
|||
### new message dialog and Kitty's portraits.
|
||||
###
|
||||
|
||||
# These might become global have to evaluate later.
|
||||
#define _GUI_WIDTH_OFFSET
|
||||
142#enddef
|
||||
|
||||
# These might become global have to evaluate later.
|
||||
#define _GUI_HEIGHT_OFFSET
|
||||
25#enddef
|
||||
|
||||
# helper convert the scale factor, since we use it in two places define it as
|
||||
# helper value. (Two the not working and working version, but want to avoid
|
||||
# surprises when the not working version is fixed).
|
||||
#define __GUI_SIZE_FACTOR
|
||||
3#enddef
|
||||
|
||||
# This is the function I want to use for the image width, but the formula system
|
||||
# has no way to create variables (outside the AI scope). So instead of this
|
||||
# macro there's a more verbose version which doesn't use variable.
|
||||
|
||||
#define __GUI_IMAGE_WIDTH
|
||||
([
|
||||
max_width = screen_width - {_GUI_WIDTH_OFFSET},
|
||||
max_height = screen_height - {_GUI_HEIGHT_OFFSET},
|
||||
best_width = max_width / {__GUI_SIZE_FACTOR},
|
||||
best_width = if(best_width > max_height, max_height, best_width),
|
||||
if(best_width < 250, 250,
|
||||
if(best_width > 500, 500, best_width))
|
||||
][4])#enddef
|
||||
|
||||
#undef __GUI_IMAGE_WIDTH
|
||||
|
||||
###
|
||||
### The verbose version
|
||||
###
|
||||
|
||||
#define __GUI_MAX_WIDTH
|
||||
(screen_width - {_GUI_WIDTH_OFFSET})
|
||||
#enddef
|
||||
|
||||
#define __GUI_MAX_HEIGHT
|
||||
(screen_height - {_GUI_HEIGHT_OFFSET})
|
||||
#enddef
|
||||
|
||||
#define BEST_WIDTH
|
||||
({__GUI_MAX_WIDTH} / {__GUI_SIZE_FACTOR})
|
||||
#enddef
|
||||
|
||||
#define __GUI_BEST_SIZE
|
||||
(if({BEST_WIDTH} > {__GUI_MAX_HEIGHT}, {__GUI_MAX_HEIGHT}, {BEST_WIDTH}))
|
||||
#enddef
|
||||
|
||||
#define ___GUI_IMAGE_WIDTH
|
||||
if({__GUI_BEST_SIZE} < 250, 250,
|
||||
if({__GUI_BEST_SIZE} > 500, 500, {__GUI_BEST_SIZE})
|
||||
)
|
||||
#enddef
|
||||
|
||||
# This is the version with debug info
|
||||
#define __GUI_IMAGE_WIDTH
|
||||
([[
|
||||
debug_print('screen_width ', screen_width),
|
||||
debug_print('screen_height ', screen_height),
|
||||
debug_print('__GUI_MAX_WIDTH ', {__GUI_MAX_WIDTH}),
|
||||
debug_print('__GUI_MAX_HEIGHT ', {__GUI_MAX_HEIGHT}),
|
||||
debug_print('BEST_WIDTH ', {BEST_WIDTH}),
|
||||
debug_print('__GUI_BEST_SIZE ', {__GUI_BEST_SIZE})
|
||||
],
|
||||
{___GUI_IMAGE_WIDTH}
|
||||
][1]
|
||||
)
|
||||
#enddef
|
||||
|
||||
#undef __GUI_IMAGE_WIDTH
|
||||
# This is the version without debug info
|
||||
#define __GUI_IMAGE_WIDTH
|
||||
({___GUI_IMAGE_WIDTH})#enddef
|
||||
|
||||
|
||||
# This is the macro for the image width which is can be used as string
|
||||
# parameter.
|
||||
#define _GUI_IMAGE_WIDTH
|
||||
"{__GUI_IMAGE_WIDTH}"#enddef
|
||||
|
||||
# the value the image needs to be scaled by, this version can be used as string
|
||||
# parameter.
|
||||
#define _GUI_IMAGE_SCALE_FACTOR
|
||||
(
|
||||
{__GUI_IMAGE_WIDTH} / 500
|
||||
)#enddef
|
||||
|
||||
[window_definition]
|
||||
id = "message_test_left"
|
||||
description = "bar"
|
||||
|
@ -25,6 +114,8 @@
|
|||
[image]
|
||||
x = 0
|
||||
y = "(height - image_height)"
|
||||
w = "((image_original_width * {__GUI_IMAGE_WIDTH}) / 500)"
|
||||
h = "((image_original_height * {__GUI_IMAGE_WIDTH}) / 500)"
|
||||
name = "(portrait_image)"
|
||||
vertical_mirror = "(portrait_mirror)"
|
||||
[/image]
|
||||
|
@ -215,13 +306,94 @@
|
|||
|
||||
[/resolution]
|
||||
#enddef
|
||||
|
||||
|
||||
|
||||
[window]
|
||||
id = "message_test_left"
|
||||
description = "Test dialog to test Jetryl's new message style and Kitty's portraits."
|
||||
|
||||
{RESOLUTION 1000 700 250}
|
||||
{RESOLUTION 0 0 500}
|
||||
[resolution]
|
||||
window_width = 0
|
||||
window_height = 0
|
||||
|
||||
definition = "message_test_left"
|
||||
|
||||
automatic_placement = "false"
|
||||
|
||||
x = 0
|
||||
y = "(screen_height - " + {_GUI_IMAGE_WIDTH} + ")"
|
||||
width = "(screen_width - 142)"
|
||||
height = {_GUI_IMAGE_WIDTH}
|
||||
|
||||
easy_close = "true"
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
vertical_alignment = "bottom"
|
||||
horizontal_grow = "true"
|
||||
|
||||
[panel]
|
||||
definition = "message_test"
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
horizontal_grow = "true"
|
||||
|
||||
[grid]
|
||||
|
||||
[row]
|
||||
|
||||
[column]
|
||||
|
||||
[spacer]
|
||||
# reserve place for the image and set a minimum height for the text
|
||||
id = "image_place_holder"
|
||||
|
||||
width = {_GUI_IMAGE_WIDTH}
|
||||
height = 75
|
||||
[/spacer]
|
||||
|
||||
[/column]
|
||||
|
||||
[column]
|
||||
grow_factor = 1
|
||||
horizontal_grow = "true"
|
||||
|
||||
border = "all"
|
||||
border_size = 5
|
||||
|
||||
[label]
|
||||
id = "message"
|
||||
definition = "default"
|
||||
[/label]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/panel]
|
||||
|
||||
[/column]
|
||||
|
||||
[/row]
|
||||
|
||||
[/grid]
|
||||
|
||||
[/resolution]
|
||||
|
||||
[/window]
|
||||
|
||||
|
@ -429,3 +601,15 @@
|
|||
[/resolution]
|
||||
|
||||
[/window]
|
||||
|
||||
#undef _GUI_IMAGE_SCALE_FACTOR
|
||||
#undef _GUI_IMAGE_WIDTH
|
||||
#undef __GUI_IMAGE_WIDTH
|
||||
#undef ___GUI_IMAGE_WIDTH
|
||||
#undef __GUI_BEST_SIZE
|
||||
#undef __GUI_MAX_HEIGHT
|
||||
#undef __GUI_MAX_WIDTH
|
||||
#undef __GUI_SIZE_FACTOR
|
||||
#undef _GUI_HEIGHT_OFFSET
|
||||
#undef _GUI_WIDTH_OFFSET
|
||||
|
||||
|
|
|
@ -2967,22 +2967,14 @@ namespace {
|
|||
// We whether we can show the new dialog.
|
||||
if(gui2::new_widgets && options.empty() && speaker != units->end()) {
|
||||
// Get the portrait and if found proceed to use the new dialog.
|
||||
gui2::twindow window = gui2::build((screen)->video(), "message_test_left");
|
||||
|
||||
// Use an ugly hack, if the spacer has the wanted best_size we use the
|
||||
// bigger image otherwise the smaller one.
|
||||
gui2::tspacer* spacer =
|
||||
dynamic_cast<gui2::tspacer*>(window.find_widget("image_place_holder", false));
|
||||
|
||||
unsigned image_size = 200;
|
||||
if(spacer && spacer->get_best_size().x == 500) {
|
||||
image_size = 400;
|
||||
}
|
||||
|
||||
const tportrait* portrait =
|
||||
speaker->second.portrait(image_size, tportrait::LEFT);
|
||||
speaker->second.portrait(400, tportrait::LEFT);
|
||||
if(portrait) {
|
||||
|
||||
gui2::twindow window =
|
||||
gui2::build((screen)->video(), "message_test_left");
|
||||
|
||||
const t_string message = cfg["message"];
|
||||
const std::string image = portrait ? portrait->image : "";
|
||||
const bool mirror = portrait ? portrait->mirror : false;
|
||||
|
|
Loading…
Add table
Reference in a new issue