Skip to content

Commit

Permalink
(ADD) scale up or down tool icons with entry in themes.tab
Browse files Browse the repository at this point in the history
git-svn-id: svn://tron.homeunix.org/simutrans/simutrans/trunk@6994 8aca7d54-2c30-db11-9de9-000461428c89
  • Loading branch information
prissi committed Dec 19, 2013
1 parent 51e39e3 commit 66ab3e0
Show file tree
Hide file tree
Showing 11 changed files with 159 additions and 49 deletions.
3 changes: 3 additions & 0 deletions display/simgraph.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,9 @@ KOORD_VAL display_get_height();
void display_set_height(KOORD_VAL);
void display_set_actual_width(KOORD_VAL);

// force a certain size on a image (for rescaling tool images)
void display_fit_img_to_width( const image_id n, sint16 new_w );


int display_get_light();
void display_set_light(int new_light_level);
Expand Down
29 changes: 27 additions & 2 deletions display/simgraph16.cc
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,8 @@ signed short current_tile_raster_width = 0;
* Hajo: Zoom factor
*/
#define MAX_ZOOM_FACTOR (9)
static uint32 zoom_factor = 3;
#define ZOOM_NEUTRAL (3)
static uint32 zoom_factor = ZOOM_NEUTRAL;
static sint32 zoom_num[MAX_ZOOM_FACTOR+1] = { 2, 3, 4, 1, 3, 5, 1, 3, 1, 1 };
static sint32 zoom_den[MAX_ZOOM_FACTOR+1] = { 1, 2, 3, 1, 4, 8, 2, 8, 4, 8 };

Expand Down Expand Up @@ -1373,7 +1374,7 @@ static void rezoom_img(const image_id n)
}

// just restore original size?
if( tile_raster_width == base_tile_raster_width || (images[n].recode_flags&FLAG_ZOOMABLE) == 0 ) {
if( zoom_factor == ZOOM_NEUTRAL || (images[n].recode_flags&FLAG_ZOOMABLE) == 0 ) {
// this we can do be a simple copy ...
images[n].x = images[n].base_x;
images[n].w = images[n].base_w;
Expand Down Expand Up @@ -1801,6 +1802,30 @@ static void rezoom_img(const image_id n)
}


// force a certain size on a image (for rescaling tool images)
void display_fit_img_to_width( const image_id n, sint16 new_w )
{
if( n < anz_images && images[n].base_h > 0 && images[n].w != new_w ) {
int old_zoom_factor = zoom_factor;
sint16 start_w = 32767;
for( int i=0; i<=MAX_ZOOM_FACTOR; i++ ) {
int zoom_w = (images[n].base_w * zoom_num[i]) / zoom_den[i];
if( start_w > new_w && zoom_w <= new_w ) {
uint8 old_zoom_flag = images[n].recode_flags & FLAG_ZOOMABLE;
images[n].recode_flags &= ~FLAG_ZOOMABLE;
images[n].recode_flags |= FLAG_REZOOM | FLAG_ZOOMABLE;
zoom_factor = i;
rezoom_img(n);
images[n].recode_flags |= old_zoom_flag;
zoom_factor = old_zoom_factor;
return;
}
}
}
}



/**
* Retrieve brightness setting
* @author Hj. Malthaner
Expand Down
5 changes: 5 additions & 0 deletions gui/gui_theme.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "gui_theme.h"
#include "../simskin.h"
#include "../simmenu.h"
#include "../simsys.h"
#include "../dataobj/environment.h"
#include "../dataobj/tabfile.h"
Expand Down Expand Up @@ -371,6 +372,8 @@ bool gui_theme_t::themes_init(const char *file_name)
koord dummy = contents.get_koord("gui_button_text_offset", koord(gui_theme_t::gui_button_text_offset.x, gui_theme_t::gui_button_text_offset.y) );
gui_theme_t::gui_button_text_offset = scr_coord(dummy.x, dummy.y);

// default iconsize (square for now)
env_t::iconsize.h = env_t::iconsize.w = contents.get_int("icon_width",env_t::iconsize.w );

// maybe not the best place, rather use simwin for the static defines?
gui_theme_t::gui_color_text = (COLOR_VAL)contents.get_color("gui_text_color", SYSCOL_TEXT);
Expand Down Expand Up @@ -411,6 +414,8 @@ bool gui_theme_t::themes_init(const char *file_name)
env_t::toolbar_max_height = contents.get_int("toolbar_max_height", env_t::toolbar_max_height );
env_t::cursor_overlay_color = contents.get_color("cursor_overlay_color", env_t::cursor_overlay_color );

werkzeug_t::update_toolbars();

// parsing buttons still needs to be done after agreement what to load
return false; //hence we return false for now ...
}
14 changes: 7 additions & 7 deletions gui/simwin.cc
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ int create_win(int x, int y, gui_frame_t* const gui, wintype const wt, ptrdiff_t
}
else {
x = min(get_maus_x() - size.w/2, display_get_width()-size.w);
y = min(get_maus_y() - size.h-32, display_get_height()-size.h);
y = min(get_maus_y() - size.h-env_t::iconsize.h, display_get_height()-size.h);
}
}
if(x<0) {
Expand Down Expand Up @@ -991,7 +991,7 @@ void snap_check_win( const int win, scr_coord *r, const scr_coord from_pos, cons
if( i==wins_count ) {
// Allow snap to screen edge
other_pos.x = 0;
other_pos.y = werkzeug_t::toolbar_tool[0]->iconsize.h;
other_pos.y = env_t::iconsize.h;
other_size.x = display_get_width();
other_size.y = display_get_height()-16-other_pos.y; // 16 = bottom ticker height?
if( show_ticker ) {
Expand Down Expand Up @@ -1094,7 +1094,7 @@ void move_win(int win, event_t *ev)

// CLIP(wert,min,max)
to_pos.x = CLIP( to_pos.x, 8-to_size.x, display_get_width()-16 );
to_pos.y = CLIP( to_pos.y, werkzeug_t::toolbar_tool[0]->iconsize.h, display_get_height()-24 );
to_pos.y = CLIP( to_pos.y, env_t::iconsize.h, display_get_height()-24 );

// delta is actual window movement.
const scr_coord delta = to_pos - from_pos;
Expand Down Expand Up @@ -1227,9 +1227,9 @@ bool check_pos_win(event_t *ev)
}

// click in main menu?
if (!werkzeug_t::toolbar_tool.empty() &&
werkzeug_t::toolbar_tool[0]->get_werkzeug_waehler() &&
werkzeug_t::toolbar_tool[0]->iconsize.h > y &&
if (!werkzeug_t::toolbar_tool.empty() &&
werkzeug_t::toolbar_tool[0]->get_werkzeug_waehler() &&
env_t::iconsize.h > y &&
ev->ev_class != EVENT_KEYBOARD) {
event_t wev = *ev;
inside_event_handling = werkzeug_t::toolbar_tool[0];
Expand Down Expand Up @@ -1468,7 +1468,7 @@ void win_display_flush(double konto)
{
const sint16 disp_width = display_get_width();
const sint16 disp_height = display_get_height();
const sint16 menu_height = werkzeug_t::toolbar_tool[0]->iconsize.h;
const sint16 menu_height = env_t::iconsize.h;

// display main menu
werkzeug_waehler_t *main_menu = werkzeug_t::toolbar_tool[0]->get_werkzeug_waehler();
Expand Down
47 changes: 24 additions & 23 deletions gui/werkzeug_waehler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,17 @@
#define MIN_WIDTH (80)


werkzeug_waehler_t::werkzeug_waehler_t(const char* titel, const char *helpfile, uint32 toolbar_id, scr_size icon, bool allow_break) :
werkzeug_waehler_t::werkzeug_waehler_t(const char* titel, const char *helpfile, uint32 toolbar_id, bool allow_break) :
gui_frame_t( translator::translate(titel) ), tools(0)
{
this->toolbar_id = toolbar_id;
this->allow_break = allow_break;
this->hilfe_datei = helpfile;
this->icon = icon;
this->tool_icon_disp_start = 0;
this->tool_icon_disp_end = 0;
this->titel = titel;
has_prev_next= false;
set_windowsize( scr_size(max(icon.w,MIN_WIDTH), D_TITLEBAR_HEIGHT) );
set_windowsize( scr_size(max(env_t::iconsize.w,MIN_WIDTH), D_TITLEBAR_HEIGHT) );
dirty = true;
}

Expand All @@ -45,14 +44,15 @@ werkzeug_waehler_t::werkzeug_waehler_t(const char* titel, const char *helpfile,
*/
void werkzeug_waehler_t::add_werkzeug(werkzeug_t *w)
{
if(w->get_icon(welt->get_active_player())==IMG_LEER && w!=werkzeug_t::dummy) {
image_id tool_img = w->get_icon(welt->get_active_player());
if( tool_img == IMG_LEER && w!=werkzeug_t::dummy ) {
return;
}

// only for non-empty icons ...
tools.append(w);

int ww = max(2,(display_get_width()/icon.w)-2); // to avoid zero or negative ww on posix (no graphic) backends
int ww = max(2,(display_get_width()/env_t::iconsize.w)-2); // to avoid zero or negative ww on posix (no graphic) backends
tool_icon_width = tools.get_count();
DBG_DEBUG4("werkzeug_waehler_t::add_tool()","ww=%i, tool_icon_width=%i",ww,tool_icon_width);
if(allow_break && (ww<tool_icon_width || (env_t::toolbar_max_width>0 && env_t::toolbar_max_width<tool_icon_width))) {
Expand All @@ -66,12 +66,12 @@ DBG_DEBUG4("werkzeug_waehler_t::add_tool()","ww=%i, rows=%i",ww,rows);
tool_icon_width = min( tool_icon_width, max(env_t::toolbar_max_width, 3) );
}
}
tool_icon_height = max( (display_get_height()/icon.h)-3, 1 );
tool_icon_height = max( (display_get_height()/env_t::iconsize.h)-3, 1 );
if( env_t::toolbar_max_height > 0 ) {
tool_icon_height = min(tool_icon_height, env_t::toolbar_max_height);
}
dirty = true;
set_windowsize( scr_size( tool_icon_width*icon.w, min(tool_icon_height, ((tools.get_count()-1)/tool_icon_width)+1)*icon.h+D_TITLEBAR_HEIGHT ) );
set_windowsize( scr_size( tool_icon_width*env_t::iconsize.w, min(tool_icon_height, ((tools.get_count()-1)/tool_icon_width)+1)*env_t::iconsize.h+D_TITLEBAR_HEIGHT ) );
tool_icon_disp_start = 0;
tool_icon_disp_end = min( tool_icon_disp_start+tool_icon_width*tool_icon_height, tools.get_count() );
has_prev_next = ((uint32)tool_icon_width*tool_icon_height < tools.get_count());
Expand All @@ -84,7 +84,7 @@ DBG_DEBUG4("werkzeug_waehler_t::add_tool()", "at position %i (width %i)", tools.
void werkzeug_waehler_t::reset_tools()
{
tools.clear();
gui_frame_t::set_windowsize( scr_size(max(icon.w,MIN_WIDTH), D_TITLEBAR_HEIGHT) );
gui_frame_t::set_windowsize( scr_size(max(env_t::iconsize.w,MIN_WIDTH), D_TITLEBAR_HEIGHT) );
tool_icon_width = 0;
tool_icon_disp_start = 0;
tool_icon_disp_end = 0;
Expand All @@ -93,8 +93,8 @@ void werkzeug_waehler_t::reset_tools()

bool werkzeug_waehler_t::getroffen(int x, int y)
{
int dx = x/icon.w;
int dy = (y-D_TITLEBAR_HEIGHT)/icon.h;
int dx = x/env_t::iconsize.w;
int dy = (y-D_TITLEBAR_HEIGHT)/env_t::iconsize.h;

// either click in titlebar or on an icon
if( x>=0 && y>=0 && ( (y<D_TITLEBAR_HEIGHT && x<get_windowsize().w) || (dx<tool_icon_width && dy<tool_icon_height) ) ) {
Expand All @@ -108,8 +108,8 @@ bool werkzeug_waehler_t::infowin_event(const event_t *ev)
{
if(IS_LEFTRELEASE(ev) || IS_RIGHTRELEASE(ev)) {
// tooltips?
const int x = (ev->mx) / icon.w;
const int y = (ev->my-D_TITLEBAR_HEIGHT) / icon.h;
const int x = (ev->mx) / env_t::iconsize.w;
const int y = (ev->my-D_TITLEBAR_HEIGHT) / env_t::iconsize.h;

if(x>=0 && x<tool_icon_width && y>=0) {
const int wz_idx = x+(tool_icon_width*y)+tool_icon_disp_start;
Expand Down Expand Up @@ -158,7 +158,7 @@ bool werkzeug_waehler_t::infowin_event(const event_t *ev)
int xy = tool_icon_width*tool_icon_height;
tool_icon_disp_end = min(tool_icon_disp_start+xy, tools.get_count());

set_windowsize( scr_size( tool_icon_width*icon.w, min(tool_icon_height, ((tools.get_count()-1)/tool_icon_width)+1)*icon.h+D_TITLEBAR_HEIGHT ) );
set_windowsize( scr_size( tool_icon_width*env_t::iconsize.w, min(tool_icon_height, ((tools.get_count()-1)/tool_icon_width)+1)*env_t::iconsize.h+D_TITLEBAR_HEIGHT ) );
dirty = true;
}
return false;
Expand All @@ -171,24 +171,25 @@ void werkzeug_waehler_t::draw(scr_coord pos, scr_size)
for( uint i = tool_icon_disp_start; i < tool_icon_disp_end; i++ ) {
const image_id icon_img = tools[i].tool->get_icon(sp);

const scr_coord draw_pos=pos+scr_coord(((i-tool_icon_disp_start)%tool_icon_width)*icon.w,D_TITLEBAR_HEIGHT+((i-tool_icon_disp_start)/tool_icon_width)*icon.h);
const scr_coord draw_pos=pos+scr_coord(((i-tool_icon_disp_start)%tool_icon_width)*env_t::iconsize.w,D_TITLEBAR_HEIGHT+((i-tool_icon_disp_start)/tool_icon_width)*env_t::iconsize.h);
if(icon_img == IMG_LEER) {
// Hajo: no icon image available, draw a blank
// DDD box as replacement

// top
display_fillbox_wh(draw_pos.x, draw_pos.y, icon.w, 1, MN_GREY4, dirty);
display_fillbox_wh(draw_pos.x, draw_pos.y, env_t::iconsize.w, 1, MN_GREY4, dirty);
// body
display_fillbox_wh(draw_pos.x+1, draw_pos.y+1, icon.w-2, icon.h-2, MN_GREY2, dirty);
display_fillbox_wh(draw_pos.x+1, draw_pos.y+1, env_t::iconsize.w-2, env_t::iconsize.h-2, MN_GREY2, dirty);
// bottom
display_fillbox_wh(draw_pos.x, draw_pos.y+icon.h-1, icon.w, 1, MN_GREY0, dirty);
display_fillbox_wh(draw_pos.x, draw_pos.y+env_t::iconsize.h-1, env_t::iconsize.w, 1, MN_GREY0, dirty);
// Left
display_fillbox_wh(draw_pos.x, draw_pos.y, 1, icon.h, MN_GREY4, dirty);
display_fillbox_wh(draw_pos.x, draw_pos.y, 1, env_t::iconsize.h, MN_GREY4, dirty);
// Right
display_fillbox_wh(draw_pos.x+icon.w-1, draw_pos.y, 1, icon.h, MN_GREY0, dirty);
display_fillbox_wh(draw_pos.x+env_t::iconsize.w-1, draw_pos.y, 1, env_t::iconsize.h, MN_GREY0, dirty);
}
else {
bool tool_dirty = dirty || tools[i].tool->is_selected() ^ tools[i].selected;
display_fit_img_to_width( icon_img, env_t::iconsize.w );
display_color_img(icon_img, draw_pos.x, draw_pos.y, 0, false, tool_dirty);
tools[i].tool->draw_after( draw_pos, tool_dirty);
// store whether tool was selected
Expand All @@ -197,18 +198,18 @@ void werkzeug_waehler_t::draw(scr_coord pos, scr_size)
}
if (dirty && (tool_icon_disp_end-tool_icon_disp_start < tool_icon_width*tool_icon_height) ) {
// mark empty space empty
mark_rect_dirty_wc(pos.x, pos.y, pos.x + tool_icon_width*icon.w, pos.y + tool_icon_height*icon.h);
mark_rect_dirty_wc(pos.x, pos.y, pos.x + tool_icon_width*env_t::iconsize.w, pos.y + tool_icon_height*env_t::iconsize.h);
}

// tooltips?
const sint16 mx = get_maus_x();
const sint16 my = get_maus_y();
const sint16 xdiff = (mx - pos.x) / icon.w;
const sint16 ydiff = (my - pos.y - D_TITLEBAR_HEIGHT) / icon.h;
const sint16 xdiff = (mx - pos.x) / env_t::iconsize.w;
const sint16 ydiff = (my - pos.y - D_TITLEBAR_HEIGHT) / env_t::iconsize.h;
if(xdiff>=0 && xdiff<tool_icon_width && ydiff>=0 && mx>=pos.x && my>=pos.y+D_TITLEBAR_HEIGHT) {
const int tipnr = xdiff+(tool_icon_width*ydiff)+tool_icon_disp_start;
if (tipnr < (int)tool_icon_disp_end) {
win_set_tooltip(get_maus_x() + TOOLTIP_MOUSE_OFFSET_X, pos.y + TOOLTIP_MOUSE_OFFSET_Y + ((ydiff+1)*icon.h) + 12, tools[tipnr].tool->get_tooltip(welt->get_active_player()), tools[tipnr].tool, this);
win_set_tooltip(get_maus_x() + TOOLTIP_MOUSE_OFFSET_X, pos.y + TOOLTIP_MOUSE_OFFSET_Y + ((ydiff+1)*env_t::iconsize.h) + 12, tools[tipnr].tool->get_tooltip(welt->get_active_player()), tools[tipnr].tool, this);
}
}

Expand Down
5 changes: 1 addition & 4 deletions gui/werkzeug_waehler.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ class werkzeug_t;
class werkzeug_waehler_t : public gui_frame_t
{
private:
scr_size icon; // size of symbols here


struct tool_data_t {
tool_data_t(werkzeug_t* t=NULL) : tool(t), selected(false) {}
werkzeug_t* tool; ///< pointer to associated tool
Expand Down Expand Up @@ -65,7 +62,7 @@ class werkzeug_waehler_t : public gui_frame_t
bool allow_break;

public:
werkzeug_waehler_t(const char *titel, const char *helpfile, uint32 toolbar_id, scr_size size, bool allow_break=true );
werkzeug_waehler_t(const char *titel, const char *helpfile, uint32 toolbar_id, bool allow_break=true );

/**
* Add a new tool with values and tooltip text.
Expand Down
8 changes: 4 additions & 4 deletions simmain.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,11 +224,11 @@ void modal_dialogue( gui_frame_t *gui, ptrdiff_t magic, karte_t *welt, bool (*qu
DBG_DEBUG4("zeige_banner", "calling win_poll_event");
win_poll_event(&ev);
// no toolbar events
if( ev.my < werkzeug_t::toolbar_tool[0]->iconsize.h ) {
ev.my = werkzeug_t::toolbar_tool[0]->iconsize.h;
if( ev.my < env_t::iconsize.h ) {
ev.my = env_t::iconsize.h;
}
if( ev.cy < werkzeug_t::toolbar_tool[0]->iconsize.h ) {
ev.cy = werkzeug_t::toolbar_tool[0]->iconsize.h;
if( ev.cy < env_t::iconsize.h ) {
ev.cy = env_t::iconsize.h;
}
if( ev.ev_class == EVENT_KEYBOARD && ev.ev_code == SIM_KEY_F1 ) {
if( gui_frame_t *win = win_get_top() ) {
Expand Down
8 changes: 4 additions & 4 deletions simmenu.cc
Original file line number Diff line number Diff line change
Expand Up @@ -432,10 +432,10 @@ void werkzeug_t::read_menu(const std::string &objfilename)
// now the toolbar tools
DBG_MESSAGE( "werkzeug_t::read_menu()", "Reading toolbars" );
// default size
env_t::iconsize = scr_size( contents.get_int("icon_width",32), contents.get_int("icon_height",32) );
// env_t::iconsize = scr_size( contents.get_int("icon_width",env_t::iconsize.w), contents.get_int("icon_height",env_t::iconsize.h) );
// first: add main menu
toolbar_tool.resize( skinverwaltung_t::werkzeuge_toolbars->get_bild_anzahl() );
toolbar_tool.append(new toolbar_t(TOOLBAR_TOOL, "", "", env_t::iconsize));
toolbar_tool.append(new toolbar_t(TOOLBAR_TOOL, "", ""));
// now for the rest
for( uint16 i=0; i<toolbar_tool.get_count(); i++ ) {
char id[256];
Expand Down Expand Up @@ -592,7 +592,7 @@ void werkzeug_t::read_menu(const std::string &objfilename)
const char *title = c;
c += strcspn(c, ",");
if (*c != '\0') *c++ = '\0';
toolbar_t* const tb = new toolbar_t(toolbar_tool.get_count() | TOOLBAR_TOOL, title, c, env_t::iconsize);
toolbar_t* const tb = new toolbar_t(toolbar_tool.get_count() | TOOLBAR_TOOL, title, c);
toolbar_tool.append(tb);
addtool = tb;
}
Expand Down Expand Up @@ -732,7 +732,7 @@ void toolbar_t::update(spieler_t *sp)
const bool create = (wzw == NULL);
if(create) {
DBG_MESSAGE("toolbar_t::update()","create toolbar %s",default_param);
wzw = new werkzeug_waehler_t( default_param, helpfile, toolbar_tool.index_of(this), iconsize, this!=werkzeug_t::toolbar_tool[0] );
wzw = new werkzeug_waehler_t( default_param, helpfile, toolbar_tool.index_of(this), this!=werkzeug_t::toolbar_tool[0] );
}
else {
DBG_MESSAGE("toolbar_t::update()","update toolbar %s",default_param);
Expand Down
6 changes: 1 addition & 5 deletions simmenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -387,20 +387,16 @@ class two_click_werkzeug_t : public werkzeug_t {

/* toolbar are a new overclass */
class toolbar_t : public werkzeug_t {
public:
// size of icons
scr_size iconsize;
private:
const char *helpfile;
werkzeug_waehler_t *wzw;
slist_tpl<werkzeug_t *>tools;
public:
toolbar_t(uint16 const id, char const* const t, char const* const h, scr_size const size) : werkzeug_t(id)
toolbar_t(uint16 const id, char const* const t, char const* const h) : werkzeug_t(id)
{
default_param = t;
helpfile = h;
wzw = NULL;
iconsize = size;
}
char const* get_tooltip(spieler_t const*) const OVERRIDE { return translator::translate(default_param); }
werkzeug_waehler_t *get_werkzeug_waehler() const { return wzw; }
Expand Down
Loading

0 comments on commit 66ab3e0

Please sign in to comment.