From 5a117c2d27f513942d7621980a79d357af122ba4 Mon Sep 17 00:00:00 2001 From: Simon Robertshaw Date: Thu, 24 May 2012 19:38:58 +0100 Subject: [PATCH] Element search interface by pressing 'e' First search is for element names, second search looks at the description, pressing enter will give you the first result the the left button selection, left click and right click can also be used to select. --- includes/interface.h | 2 + src/interface.c | 200 +++++++++++++++++++++++++++++++++++++++++++ src/main.c | 4 + 3 files changed, 206 insertions(+) diff --git a/includes/interface.h b/includes/interface.h index c1e48f1d6..478273a5d 100644 --- a/includes/interface.h +++ b/includes/interface.h @@ -287,6 +287,8 @@ void draw_svf_ui(pixel *vid_buf, int alternate); void error_ui(pixel *vid_buf, int err, char *txt); +void element_search_ui(pixel *vid_buf, int * sl, int * sr); + void info_ui(pixel *vid_buf, char *top, char *txt); void copytext_ui(pixel *vid_buf, char *top, char *txt, char *copytxt); diff --git a/src/interface.c b/src/interface.c index 0e31ffb56..b7d3d9ccd 100644 --- a/src/interface.c +++ b/src/interface.c @@ -984,6 +984,206 @@ void error_ui(pixel *vid_buf, int err, char *txt) } } +typedef struct int_pair +{ + int first, second; +} int_pair; + +int int_pair_cmp (const void * a, const void * b) +{ + int_pair *ap = a; + int_pair *bp = a; + return ( ap->first - bp->first ); +} + +void element_search_ui(pixel *vid_buf, int * slp, int * srp) +{ + int windowHeight = 300, windowWidth = 240; + int x0 = (XRES-windowWidth)/2, y0 = (YRES-windowHeight)/2, b = 1, bq, mx, my; + int toolx = 0, tooly = 0, i, xoff, yoff, c, found; + char tempCompare[512]; + char tempString[512]; + int_pair tempInts[PT_NUM]; + ui_edit ed; + int selectedl = -1; + int selectedr = -1; + int firstResult = -1, hover = -1; + + ed.x = x0+12; + ed.y = y0+30; + ed.w = windowWidth - 20; + ed.nx = 1; + ed.def = "[element name]"; + ed.focus = 1; + ed.hide = 0; + ed.cursor = 0; + ed.multiline = 0; + ed.str[0] = 0; + + + while (!sdl_poll()) + { + bq = b; + b = mouse_get_state(&mx, &my); + + clearrect(vid_buf, x0-2, y0-2, windowWidth+4, windowHeight+4); + drawrect(vid_buf, x0, y0, windowWidth, windowHeight, 192, 192, 192, 255); + + drawtext(vid_buf, x0+8, y0+8, "Element Search", 255, 255, 255, 255); + + drawrect(vid_buf, ed.x-4, ed.y-5, ed.w+4, 16, 192, 192, 192, 255); + ui_edit_draw(vid_buf, &ed); + ui_edit_process(mx, my, b, &ed); + + drawrect(vid_buf, ed.x-4, (ed.y-5)+20, ed.w+4, windowHeight-((ed.y-5)), 192, 192, 192, 255); + xoff = (ed.x-4)+6; + yoff = ((ed.y-5)+20)+4; + toolx = 0; + tooly = 0; + + drawtext(vid_buf, xoff+toolx+4, yoff+tooly+3, "Matches:", 255, 255, 255, 180); + draw_line(vid_buf, xoff+toolx+2, yoff+tooly+14, xoff+toolx+5+(ed.w-16), yoff+tooly+14, 180, 180, 180, XRES+BARSIZE); + tooly += 17; + + //Covert input to lower case + c = 0; + while (ed.str[c]) { tempString[c] = tolower(ed.str[c]); c++; } tempString[c] = 0; + + firstResult = -1; + hover = -1; + for(i = 0; i < PT_NUM; i++) + { + c = 0; + while (ptypes[i].name[c]) { tempCompare[c] = tolower(ptypes[i].name[c]); c++; } tempCompare[c] = 0; + if(strstr(tempCompare, tempString)!=0) + { + if(firstResult==-1) + firstResult = i; + toolx += draw_tool_xy(vid_buf, toolx+xoff, tooly+yoff, i, ptypes[i].pcolors)+5; + if (!bq && mx>=xoff+toolx-32 && mx=yoff+tooly && my ed.w-4) + { + tooly += 18; + toolx = 0; + } + if(tooly>windowHeight-((ed.y-5)+20)) + break;; + } + } + + if(toolx>0) + { + toolx = 0; + tooly += 18; + } + + if(tooly=xoff+toolx-32 && mx=yoff+tooly && my ed.w-4) + { + tooly += 18; + toolx = 0; + } + if(tooly>windowHeight-((ed.y-5)+18)) + break; + } + } + + if(b==1 && hover!=-1) + { + selectedl = hover; + break; + } + if(b==4 && hover!=-1) + { + selectedr = hover; + break; + } + + drawtext(vid_buf, x0+5, y0+windowHeight-12, "Dismiss", 255, 255, 255, 255); + drawrect(vid_buf, x0, y0+windowHeight-16, windowWidth, 16, 192, 192, 192, 255); +#ifdef OGLR + clearScreen(1.0f); +#endif + sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE)); + + if (b && !bq && mx>=x0 && mx=y0+windowHeight-16 && my<=y0+windowHeight) + break; + + if (sdl_key==SDLK_RETURN) + { + if(selectedl==-1) + selectedl = firstResult; + break; + } + if (sdl_key==SDLK_ESCAPE) + { + selectedl = -1; + selectedr = -1; + break; + } + } + + if(selectedl!=-1) + *slp = selectedl; + if(selectedr!=-1) + *srp = selectedr; + + while (!sdl_poll()) + { + b = mouse_get_state(&mx, &my); + if (!b) + break; + } +} char *input_ui(pixel *vid_buf, char *title, char *prompt, char *text, char *shadow) { diff --git a/src/main.c b/src/main.c index b61627321..4cbef1c1f 100644 --- a/src/main.c +++ b/src/main.c @@ -1389,6 +1389,10 @@ int main(int argc, char *argv[]) it = 50; save_mode = 1; } + if(sdl_key=='e') + { + element_search_ui(vid_buf, &sl, &sr); + } //TODO: Superseded by new display mode switching, need some keyboard shortcuts if (sdl_key=='1') {