mirror of
https://github.com/weiju/amiga-stuff
synced 2026-10-12 18:13:46 +00:00
requesters: file requester index mapping
map visible selection indexes to file list indexes
This commit is contained in:
@@ -21,6 +21,7 @@ struct FileListEntry {
|
|||||||
struct FileListEntry *next, *prev;
|
struct FileListEntry *next, *prev;
|
||||||
UWORD file_type;
|
UWORD file_type;
|
||||||
UWORD index; // index in the list
|
UWORD index; // index in the list
|
||||||
|
UWORD selected;
|
||||||
char name[MAX_FILENAME_LEN + 1];
|
char name[MAX_FILENAME_LEN + 1];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+37
-13
@@ -246,7 +246,8 @@ static void close_requester()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int file_index(int mx, int my) {
|
// for a window coordinate, return the visual index in the file list
|
||||||
|
int file_list_index(int mx, int my) {
|
||||||
int x1 = REQ_HMARGIN;
|
int x1 = REQ_HMARGIN;
|
||||||
int y1 = REQ_VMARGIN + FILE_LIST_VMARGIN + FILE_LIST_BM_MARGIN;
|
int y1 = REQ_VMARGIN + FILE_LIST_VMARGIN + FILE_LIST_BM_MARGIN;
|
||||||
int x2 = x1 + filelist_width;
|
int x2 = x1 + filelist_width;
|
||||||
@@ -254,12 +255,25 @@ int file_index(int mx, int my) {
|
|||||||
if (mx >= x1 && mx <= x2 && my >= y1 && my <= y2) {
|
if (mx >= x1 && mx <= x2 && my >= y1 && my <= y2) {
|
||||||
int rely = my - y1;
|
int rely = my - y1;
|
||||||
int index = rely / (font_height + FILE_LIST_LINE_DIST);
|
int index = rely / (font_height + FILE_LIST_LINE_DIST);
|
||||||
//printf("rely: %d, new sel index: %d\n", rely, index);
|
// printf("rely: %d, new sel index: %d\n", rely, index);
|
||||||
return index < NUM_FILE_ENTRIES ? index : -1;
|
return index < NUM_FILE_ENTRIES ? index : -1;
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// map file list index to index in the file list
|
||||||
|
struct FileListEntry *entry_at_list_index(int index)
|
||||||
|
{
|
||||||
|
if (index < 0) return NULL;
|
||||||
|
struct FileListEntry *cur = first_visible_entry;
|
||||||
|
int count = 0;
|
||||||
|
while (cur && count < index) {
|
||||||
|
cur = cur->next;
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
return cur;
|
||||||
|
}
|
||||||
|
|
||||||
int vertpot2entry(int vertpot)
|
int vertpot2entry(int vertpot)
|
||||||
{
|
{
|
||||||
int index = vertpot / slider_increment, final_index = index;
|
int index = vertpot / slider_increment, final_index = index;
|
||||||
@@ -278,11 +292,11 @@ static void render_list_backbuffer()
|
|||||||
0xc0);
|
0xc0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void draw_selection(struct RastPort *src_rp)
|
static void draw_selection(struct RastPort *src_rp, int view_index)
|
||||||
{
|
{
|
||||||
// Draw selection rectangle
|
// Draw selection rectangle
|
||||||
SetDrMd(src_rp, COMPLEMENT);
|
SetDrMd(src_rp, COMPLEMENT);
|
||||||
int y1 = FILE_LIST_VMARGIN + select_index * (font_height + FILE_LIST_LINE_DIST) - FILE_LIST_BM_MARGIN;
|
int y1 = FILE_LIST_VMARGIN + view_index * (font_height + FILE_LIST_LINE_DIST) - FILE_LIST_BM_MARGIN;
|
||||||
int y2 = y1 + font_height;
|
int y2 = y1 + font_height;
|
||||||
RectFill(src_rp, 0, y1, filelist_bm_width, y2);
|
RectFill(src_rp, 0, y1, filelist_bm_width, y2);
|
||||||
}
|
}
|
||||||
@@ -295,6 +309,15 @@ static void clear_list()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void clear_selections()
|
||||||
|
{
|
||||||
|
struct FileListEntry *cur = current_files;
|
||||||
|
while (cur) {
|
||||||
|
cur->selected = 0;
|
||||||
|
cur = cur->next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Render the currently visible portion of the current file list.
|
* Render the currently visible portion of the current file list.
|
||||||
* We can simply clear the whole thing and render the visible
|
* We can simply clear the whole thing and render the visible
|
||||||
@@ -318,12 +341,12 @@ static void draw_list()
|
|||||||
while (cur && count < NUM_FILE_ENTRIES) {
|
while (cur && count < NUM_FILE_ENTRIES) {
|
||||||
Move(src_rp, 8, ypos);
|
Move(src_rp, 8, ypos);
|
||||||
Text(src_rp, cur->name, strlen(cur->name));
|
Text(src_rp, cur->name, strlen(cur->name));
|
||||||
cur = cur->next;
|
|
||||||
ypos += font_height + FILE_LIST_LINE_DIST;
|
ypos += font_height + FILE_LIST_LINE_DIST;
|
||||||
|
if (cur->selected) draw_selection(src_rp, count);
|
||||||
|
cur = cur->next;
|
||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
draw_selection(src_rp);
|
|
||||||
|
|
||||||
// Done drawing, offscreen bitmap is rendered, copy to the requester's layer
|
// Done drawing, offscreen bitmap is rendered, copy to the requester's layer
|
||||||
render_list_backbuffer();
|
render_list_backbuffer();
|
||||||
@@ -384,13 +407,14 @@ static void handle_events()
|
|||||||
break;
|
break;
|
||||||
case IDCMP_MOUSEBUTTONS:
|
case IDCMP_MOUSEBUTTONS:
|
||||||
if (msg->Code == SELECTUP) {
|
if (msg->Code == SELECTUP) {
|
||||||
// TODO: map to virtual file list indexes
|
// map to virtual file list indexes, only select if not already selected
|
||||||
WORD mx = msg->MouseX, my = msg->MouseY, file_i = file_index(mx, my);
|
struct FileListEntry *entry = entry_at_list_index(file_list_index(msg->MouseX, msg->MouseY));
|
||||||
if (file_i >= 0 && file_i != select_index) {
|
if (entry != NULL && !entry->selected) {
|
||||||
draw_selection(&filelist_rastport);
|
clear_selections();
|
||||||
select_index = file_i;
|
//printf("select '%s', index: %d\n", entry->name, (int) entry->index);
|
||||||
draw_selection(&filelist_rastport);
|
entry->selected = 1;
|
||||||
render_list_backbuffer();
|
clear_list();
|
||||||
|
draw_list();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ReplyMsg((struct Message *) msg);
|
ReplyMsg((struct Message *) msg);
|
||||||
|
|||||||
Reference in New Issue
Block a user