From 12c99a4b5bcf4b8255fd6bad40afc02ca8c53e83 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=28=C2=B4=E3=83=BB=CF=89=E3=83=BB=EF=BD=80=29?= Date: Thu, 22 Oct 2020 08:55:31 +0900 Subject: [PATCH] ADD: a new gadget - Window locked --- gui/gui_theme.h | 2 ++ gui/simwin.cc | 57 +++++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 50 insertions(+), 9 deletions(-) diff --git a/gui/gui_theme.h b/gui/gui_theme.h index 581ece3a4c..143a55a9c4 100644 --- a/gui/gui_theme.h +++ b/gui/gui_theme.h @@ -147,6 +147,8 @@ enum { SKIN_WINDOW_RESIZE, SKIN_GADGET_GOTOPOS, // SKIN_GADGET_BUTTON, + SKIN_GADGET_NOTLOCKED, + SKIN_GADGET_LOCKED, SKIN_GADGET_COUNT, // maximum number, NOT AN IMAGE // scrollbars horizontal diff --git a/gui/simwin.cc b/gui/simwin.cc index f06e439a65..e03d837e23 100644 --- a/gui/simwin.cc +++ b/gui/simwin.cc @@ -75,7 +75,7 @@ class inthashtable_tpl saved_windowsizes; class simwin_gadget_flags_t { public: - simwin_gadget_flags_t( ) : title(true), close( false ), help( false ), prev( false ), size( false ), next( false ), sticky( false ), gotopos( false ) { } + simwin_gadget_flags_t( ) : title(true), close( false ), help( false ), prev( false ), size( false ), next( false ), sticky( false ), gotopos( false ), locked(false) { } bool title:1; bool close:1; @@ -85,6 +85,7 @@ class simwin_gadget_flags_t bool next:1; bool sticky:1; bool gotopos:1; + bool locked:1; }; class simwin_t @@ -97,6 +98,7 @@ class simwin_t gui_frame_t *gui; uint16 gadget_state; // which buttons to hilite bool sticky; // true if window is sticky + bool locked; // true if window is locked bool rollup; bool dirty; @@ -175,7 +177,7 @@ static int display_gadget_box(sint8 code, if( img != NULL ) { // Max Kielland: This center the gadget image and compensates for any left/top margins within the image to be backward compatible with older PAK sets. - display_color_img(img->imageid, x-img->x + D_GET_CENTER_ALIGN_OFFSET(img->w,D_GADGET_WIDTH), y, 0, false, false); + display_color_img(img->imageid, x-img->x + D_GET_CENTER_ALIGN_OFFSET(img->w,D_GADGET_WIDTH), y, 0, false, true); } else { @@ -194,6 +196,12 @@ static int display_gadget_box(sint8 code, else if( code == SKIN_GADGET_PINNED ) { gadget_text = "S"; } + else if (code == SKIN_GADGET_NOTLOCKED) { + gadget_text = "l"; + } + else if (code == SKIN_GADGET_LOCKED) { + gadget_text = "L"; + } display_proportional_rgb( x+4, y+4, gadget_text, ALIGN_LEFT, color_idx_to_rgb(COL_BLACK), false ); } @@ -213,7 +221,8 @@ static int display_gadget_boxes( PIXVAL darker, uint16 gadget_state, bool sticky_pushed, - bool goto_pushed + bool goto_pushed, + bool locked_pushed ) { int width = 0; const int k=(REVERSE_GADGETS?1:-1); @@ -240,6 +249,9 @@ static int display_gadget_boxes( if( flags->sticky ) { width += k*display_gadget_box( sticky_pushed ? SKIN_GADGET_PINNED : SKIN_GADGET_NOTPINNED, x + width, y, lighter, darker, gadget_state & (1<locked ) { + width += k*display_gadget_box( locked_pushed ? SKIN_GADGET_LOCKED : SKIN_GADGET_NOTLOCKED, x + width, y, lighter, darker, gadget_state & (1 << SKIN_GADGET_NOTLOCKED)); + } return abs( width ); } @@ -298,6 +310,12 @@ static sint8 decode_gadget_boxes(simwin_gadget_flags_t const * const flags, int } offset += w; } + if (flags->locked) { + if (offset >= 0 && offset < D_GADGET_WIDTH) { + return SKIN_GADGET_NOTLOCKED; + } + offset += w; + } return SKIN_GADGET_COUNT; } @@ -310,14 +328,20 @@ static void win_draw_window_title(const scr_coord pos, const scr_size size, const uint16 gadget_state, const bool sticky, const bool goto_pushed, - simwin_gadget_flags_t &flags ) + const bool locked, + simwin_gadget_flags_t &flags ) { PUSH_CLIP_FIT(pos.x, pos.y, size.w, size.h); PIXVAL lighter = display_blend_colors(title_color, color_idx_to_rgb(COL_WHITE), 25); PIXVAL darker = display_blend_colors(title_color, color_idx_to_rgb(COL_BLACK), 25); - display_fillbox_wh_clip_rgb(pos.x, pos.y, size.w, D_TITLEBAR_HEIGHT, title_color, false); + if (locked) { + display_blend_wh_rgb(pos.x, pos.y, size.w, D_TITLEBAR_HEIGHT, title_color, 25); + } + else { + display_fillbox_wh_clip_rgb(pos.x, pos.y, size.w, D_TITLEBAR_HEIGHT, title_color, true); + } display_fillbox_wh_clip_rgb( pos.x + 1, pos.y, size.w - 2, 1, lighter, false ); display_fillbox_wh_clip_rgb( pos.x + 1, pos.y + D_TITLEBAR_HEIGHT - 1, size.w - 2, 1, darker, false ); @@ -327,7 +351,10 @@ static void win_draw_window_title(const scr_coord pos, const scr_size size, // Draw the gadgets and then move left and draw text. flags.gotopos = (welt_pos != koord3d::invalid); - int width = display_gadget_boxes( &flags, pos.x+(REVERSE_GADGETS?0:size.w-D_GADGET_WIDTH), pos.y, lighter, darker, gadget_state, sticky, goto_pushed ); + int width = display_gadget_boxes( &flags, pos.x+(REVERSE_GADGETS?0:size.w-D_GADGET_WIDTH), pos.y, lighter, darker, gadget_state, sticky, goto_pushed, locked ); + if (locked) { + display_proportional_clip_rgb(pos.x + (REVERSE_GADGETS?width+4:4)+1, pos.y+(D_TITLEBAR_HEIGHT-LINEASCENT)/2+1, text, ALIGN_LEFT, title_color, false); + } int titlewidth = display_proportional_clip_rgb( pos.x + (REVERSE_GADGETS?width+4:4), pos.y+(D_TITLEBAR_HEIGHT-LINEASCENT)/2, text, ALIGN_LEFT, text_color, false ); if( flags.gotopos ) { display_proportional_clip_rgb( pos.x + (REVERSE_GADGETS?width+4:4)+titlewidth+8, pos.y+(D_TITLEBAR_HEIGHT-LINEASCENT)/2, welt_pos.get_2d().get_fullstr(), ALIGN_LEFT, text_color, false ); @@ -551,6 +578,7 @@ void rdwr_all_win(loadsave_t *file) i.pos.rdwr(file); file->rdwr_byte(i.wt); file->rdwr_bool(i.sticky); + file->rdwr_bool(i.locked); file->rdwr_bool(i.rollup); i.gui->rdwr(file); } @@ -616,8 +644,9 @@ void rdwr_all_win(loadsave_t *file) uint8 win_type; file->rdwr_byte( win_type ); create_win( p.x, p.y, w, (wintype)win_type, id ); - bool sticky, rollup; + bool sticky, rollup, locked; file->rdwr_bool( sticky ); + file->rdwr_bool( locked ); file->rdwr_bool( rollup ); // now load the window uint32 count = wins.get_count(); @@ -627,6 +656,7 @@ void rdwr_all_win(loadsave_t *file) // ensure that the new status is to currently loaded window if (wins.get_count() >= count) { wins.back().sticky = sticky; + wins.back().locked = locked; wins.back().rollup = rollup; } } @@ -702,6 +732,7 @@ int create_win(int x, int y, gui_frame_t* const gui, wintype const wt, ptrdiff_t win.flags.next = gui->has_next(); win.flags.size = gui->has_min_sizer(); win.flags.sticky = gui->has_sticky(); + win.flags.locked = gui->has_sticky(); win.gui = gui; // take care of time delete windows ... @@ -711,6 +742,7 @@ int create_win(int x, int y, gui_frame_t* const gui, wintype const wt, ptrdiff_t win.gadget_state = 0; win.rollup = false; win.sticky = false; + win.locked = false; win.dirty = true; // Notify window to be shown @@ -895,6 +927,9 @@ bool destroy_win(const gui_frame_t *gui) for( uint i=0; iis_weltpos(), + wins[win].locked, wins[win].flags ); } if( wins[win].dirty ) { @@ -1484,13 +1520,16 @@ bool check_pos_win(event_t *ev) case SKIN_GADGET_NOTPINNED: wins[i].sticky = !wins[i].sticky; break; + case SKIN_GADGET_NOTLOCKED: + wins[i].locked = !wins[i].locked; + break; } } } } else { // Somewhere on the titlebar - if (IS_LEFTDRAG(ev)) { + if (IS_LEFTDRAG(ev) && !wins[i].sticky) { i = top_win(i,false); move_win(i, ev); is_moving = i;