allow selecting range of icons in graphics sheet

This commit is contained in:
2025-06-23 15:11:18 -05:00
parent 82824e3f06
commit 3810b6e92f
2 changed files with 40 additions and 0 deletions

View File

@@ -6,6 +6,8 @@
<text top='36' left='152' width='80' height='16'>Sheet Number:</text>
<text name='num' top='36' left='242' width='40' height='16'/>
<pict name='sheet' framed='true' scaled='true' type='full' num='0' top='54' left='12' width='280' height='360'/>
<!-- Whole-sheet operations -->
<button name='copy' type='regular' def-key='ctrl c' top='54' left='304'>Copy</button>
<button name='paste' type='regular' def-key='ctrl v' relative='pos-in pos-in' rel-anchor='prev' top='26' left='0'>Paste</button>
<button name='edit' type='regular' relative='pos-in pos-in' rel-anchor='prev' top='26' left='0'>Edit</button>
@@ -13,9 +15,17 @@
<button name='open' type='regular' def-key='ctrl o' relative='pos-in pos-in' rel-anchor='prev' top='26' left='0'>Import</button>
<button name='save' type='regular' def-key='ctrl s' relative='pos-in pos-in' rel-anchor='prev' top='26' left='0'>Export</button>
<button name='del' type='regular' def-key='ctrl x' relative='pos-in pos-in' rel-anchor='prev' top='26' left='0'>Delete</button>
<!-- Icon operations -->
<text name='icon-head' relative='pos-in pos' rel-anchor='prev' top='5' left='0'>Selected icons:</text>
<text name='icon-min' relative='pos-in pos' rel-anchor='prev' top='2' left='0' width='30' framed='true'>0</text>
<text relative='pos pos-in' rel-anchor='prev' top='0' left='0'>-</text>
<text name='icon-max' relative='pos pos-in' rel-anchor='prev' top='0' left='0' width='30' framed='true'>0</text>
<button name='left' type='left' def-key='left' top='426' left='20'/>
<button name='right' type='right' def-key='right' top='426' left='85'/>
<button name='new' type='regular' def-key='ctrl n' top='426' left='162'>New</button>
<button name='cancel' type='regular' top='426' left='239'>Cancel</button>
<button name='okay' type='regular' top='426' left='304'>OK</button>
</dialog>

View File

@@ -4022,6 +4022,36 @@ void edit_custom_sheets() {
}, {"left", "right"});
set_dlg_custom_sheet(pic_dlg, all_pics[cur]);
int icon_start = 0;
int icon_end = 0;
int icon_min = 0;
int icon_max = 0;
pic_dlg["sheet"].attachClickHandler([&all_pics, &cur, &icon_start, &icon_end, &icon_min, &icon_max](cDialog& me, std::string, eKeyMod mod) -> bool {
location where_curs = sf::Mouse::getPosition(me.getWindow());
where_curs = me.getWindow().mapPixelToCoords(where_curs);
rectangle sheet_bounds = me["sheet"].getBounds();
where_curs.x -= sheet_bounds.left;
where_curs.y -= sheet_bounds.top;
where_curs.x /= 28;
where_curs.y /= 36;
int icon_hit = 1000 + 100 * all_pics[cur] + 10 * where_curs.y + where_curs.x;
if(mod_contains(mod, mod_shift)){
icon_end = icon_hit;
}else{
icon_start = icon_end = icon_hit;
}
icon_min = min(icon_start, icon_end);
icon_max = max(icon_start, icon_end);
me["icon-min"].setTextToNum(icon_min);
me["icon-max"].setTextToNum(icon_max);
// TODO highlight the selected icons visually
return true;
});
shut_down_menus(5); // So that cmd+O, cmd+N, cmd+S can work
pic_dlg.run();