// The dialog handler borrows heavily from the newmenu_handler static int ui_dialog_handler(window *wind, d_event *event, UI_DIALOG *dlg) { int rval = 0; if (event->type == EVENT_WINDOW_CLOSED || event->type == EVENT_WINDOW_ACTIVATED || event->type == EVENT_WINDOW_DEACTIVATED) return 0; if (dlg->callback) if ((*dlg->callback)(dlg, event, dlg->userdata)) return 1; // event handled if (!window_exists(wind)) return 1; switch (event->type) { case EVENT_MOUSE_BUTTON_DOWN: case EVENT_MOUSE_BUTTON_UP: case EVENT_MOUSE_MOVED: /*return*/ ui_dialog_do_gadgets(dlg, event); if (!window_exists(wind)) return 1; rval = mouse_in_window(dlg->wind); break; case EVENT_KEY_COMMAND: case EVENT_KEY_RELEASE: rval = ui_dialog_do_gadgets(dlg, event); break; case EVENT_IDLE: timer_delay2(50); rval = ui_dialog_do_gadgets(dlg, event); break; case EVENT_WINDOW_DRAW: { d_event event2 = { EVENT_UI_DIALOG_DRAW }; ui_dialog_draw(dlg); rval = ui_dialog_do_gadgets(dlg, event); window_send_event(wind, &event2); break; } case EVENT_WINDOW_CLOSE: ui_gadget_delete_all(dlg); selected_gadget = NULL; d_free( dlg ); break; default: break; } return rval; }
int click_in_window(int win_id, int x, int y, Uint32 flags) { window_info *win; int _x, _y; if(mouse_in_window(win_id, x, y) > 0) { // watch for needing to convert the globals into the flags // TODO: put this in the window manager if(!flags){ if(shift_on) flags |= ELW_SHIFT; if(ctrl_on) flags |= ELW_CTRL; if(alt_on) flags |= ELW_ALT; if(right_click) flags |= ELW_RIGHT_MOUSE; //if(mid_click) flags |= ELW_MID_MOUSE; if(left_click) flags |= ELW_LEFT_MOUSE; //if(double_click) flags |= ELW_DBL_CLICK; } win= &windows_list.window[win_id]; _x= x - win->cur_x; _y= y - win->cur_y; //check the X for close - but hide it if(win->flags&ELW_CLOSE_BOX) { if(_y>0 && _y<=20 && _x>(win->len_x-20) && _x<=win->len_x) { // the X was hit, hide this window hide_window(win_id); return 1; } } //use the handler if(win->click_handler != NULL){ glPushMatrix(); glTranslatef((float)win->cur_x, (float)win->cur_y, 0.0f); (*win->click_handler)(win, _x, _y, flags); glPopMatrix(); return 1; // no click-thru permitted } else { return 1; } } return 0; }
int mouseover_window(int win_id, int x, int y) { int _x, _y; if(mouse_in_window(win_id, x, y) > 0) { //use the handler if present if(windows_list.window[win_id].mouseover_handler){ _x= x - windows_list.window[win_id].cur_x; _y= y - windows_list.window[win_id].cur_y; glPushMatrix(); glTranslatef((float)windows_list.window[win_id].cur_x, (float)windows_list.window[win_id].cur_y, 0.0f); (*windows_list.window[win_id].mouseover_handler)(&windows_list.window[win_id], _x, _y); glPopMatrix(); } return 1; } return 0; }
// Work out if the specified point of the specified window is on top of the window stack. // Method to traverse layers copied from elwindow.c this could probably be a general window function. // bool is_window_coord_top(int window_id, int coord_x, int coord_y) { bool have_seen_window = false; int id = 0; int i; while (1) { int next_id = 9999; for (i = 0; i < windows_list.num_windows; i++) { // only look at displayed windows if (windows_list.window[i].displayed > 0) { // at this level? if (windows_list.window[i].order == id) { if (i == window_id) have_seen_window = true; else if (have_seen_window) { if (mouse_in_window(i, coord_x, coord_y)) return false; } } // try to find the next level else if (windows_list.window[i].order > id && windows_list.window[i].order < next_id) next_id = windows_list.window[i].order; } } if (next_id >= 9999) break; else id = next_id; } return true; }
int click_in_windows(int _x, int _y, Uint32 flags) { int done= 0; int id; int next_id; int first_win= 0; int i; // watch for needing to convert the globals into the flags if(!flags){ if(shift_on) flags |= ELW_SHIFT; if(ctrl_on) flags |= ELW_CTRL; if(alt_on) flags |= ELW_ALT; if(right_click) flags |= ELW_RIGHT_MOUSE; if(middle_click) flags |= ELW_MID_MOUSE; if(left_click) flags |= ELW_LEFT_MOUSE; // TODO: centralized double click handling // TODO: consider other ways of triggering double clieck, like middle click or shift click //if(double_click) flags |= ELW_DBL_CLICK; } // check each window in the proper order if(windows_list.display_level > 0) { id= 9999; while(done <= 0) { next_id= 0; for(i=1; i<windows_list.num_windows; i++){ // only look at displayed windows if(windows_list.window[i].displayed > 0){ // at this level? if(windows_list.window[i].order == id){ done= click_in_window(i, _x, _y, flags); if(done > 0){ if(windows_list.window[i].displayed > 0) select_window(i); // select this window to the front return i; } if(first_win == 0 && mouse_in_window(i, _x, _y)) first_win= i; } else if(windows_list.window[i].order < id && windows_list.window[i].order > next_id){ // try to find the next level next_id= windows_list.window[i].order; } } } if(next_id <= 0) { break; } else { id= next_id; } } } // now check the background windows in the proper order id= -9999; while(done <= 0) { next_id= 0; for(i=1; i<windows_list.num_windows; i++){ // only look at displayed windows if(windows_list.window[i].displayed > 0){ // at this level? if(windows_list.window[i].order == id){ done= click_in_window(i, _x, _y, flags); if(done > 0){ //select_window(i); // these never get selected return i; } } else if(windows_list.window[i].order > id && windows_list.window[i].order < next_id){ // try to find the next level next_id= windows_list.window[i].order; } } } if(next_id >= 0) { break; } else { id= next_id; } } // nothing to click on, do a select instead if(first_win > 0) { select_window(first_win); return 1; } return 0; // no click in a window }
int drag_windows(int _x, int _y, int dx, int dy) { int next_id; int id, i; int drag_id= 0; // check each window in the proper order for which one might be getting dragged if(windows_list.display_level > 0) { id= 9999; while(drag_id <= 0) { next_id= 0; for(i=1; i<windows_list.num_windows; i++){ // only look at displayed windows if(windows_list.window[i].displayed > 0 && (windows_list.window[i].flags&ELW_DRAGGABLE)){ // at this level? if(windows_list.window[i].order == id){ // check for being actively dragging or on the top bar if(windows_list.window[i].dragged || (mouse_in_window(i, _x, _y) && _y<windows_list.window[i].cur_y) ){ drag_id= i; break; } else if(mouse_in_window(i, _x, _y)){ // stop processing if we are inside of another window return 0; } } else if(windows_list.window[i].order < id && windows_list.window[i].order > next_id){ // try to find the next level next_id= windows_list.window[i].order; } } } if(next_id <= 0) { break; } else { id= next_id; } } } // this section probably won't be needed, included to be complete // now check the background windows in the proper order for which one might be getting dragged id= -9999; while(drag_id <= 0) { next_id= 0; for(i=1; i<windows_list.num_windows; i++){ // only look at displayed windows if(windows_list.window[i].displayed > 0 && (windows_list.window[i].flags&ELW_DRAGGABLE)){ // at this level? if(windows_list.window[i].order == id){ // check for being actively dragging or on the top bar if(windows_list.window[i].dragged || (mouse_in_window(i, _x, _y) && _y<windows_list.window[i].cur_y) ){ drag_id= i; break; } else if(mouse_in_window(i, _x, _y)){ // stop processing if we are inside of another window return 0; } } else if(windows_list.window[i].order > id && windows_list.window[i].order < next_id){ // try to find the next level next_id= windows_list.window[i].order; } } } if(next_id >= 0) { break; } else { id= next_id; } } // are we dragging a window? if(drag_id <= 0) return 0; // dragged window is always on top select_window(drag_id); // flag we are dragging windows_list.window[drag_id].dragged= 1; if(left_click>1 && (dx != 0 || dy != 0)) // TODO: avoid globals? { // move to new location move_window(drag_id, windows_list.window[drag_id].pos_id, windows_list.window[drag_id].pos_loc, windows_list.window[drag_id].pos_x+dx, windows_list.window[drag_id].pos_y+dy); } return 1; }
int display_storage_handler(window_info * win) { int i; int n=0; int pos; have_storage_list = 0; //We visited storage, so we may have changed something glColor3f(0.77f, 0.57f, 0.39f); glEnable(GL_TEXTURE_2D); for(i=pos=vscrollbar_get_pos(storage_win,STORAGE_SCROLLBAR_CATEGORIES); i<no_storage_categories && storage_categories[i].id!=-1 && i<pos+STORAGE_CATEGORIES_DISPLAY; i++,n++){ draw_string_small(20, 20+n*13, (unsigned char*)storage_categories[i].name,1); } if(storage_text[0]){ if (strcmp(storage_text, last_storage_text) != 0) { safe_strncpy(last_storage_text, storage_text, sizeof(last_storage_text)); put_small_text_in_box ((Uint8 *)storage_text, strlen(storage_text), win->len_x - 18*2, wrapped_storage_text); } draw_string_small(18, 220, (unsigned char*)wrapped_storage_text, 2); } glColor3f(1.0f,1.0f,1.0f); for(i=pos=6*vscrollbar_get_pos(storage_win, STORAGE_SCROLLBAR_ITEMS); i<pos+36 && i<no_storage;i++){ GLfloat u_start, v_start, u_end, v_end; int x_start, x_end, y_start, y_end; int cur_item; GLuint this_texture; if(!storage_items[i].quantity)continue; cur_item=storage_items[i].image_id%25; #ifdef NEW_TEXTURES get_item_uv(cur_item, &u_start, &v_start, &u_end, &v_end); #else /* NEW_TEXTURES */ u_start=0.2f*(cur_item%5); u_end=u_start+(float)50/255; v_start=(1.0f+((float)50/255)/255.0f)-((float)50/255*(cur_item/5)); v_end=v_start-(float)50/255; #endif /* NEW_TEXTURES */ this_texture=get_items_texture(storage_items[i].image_id/25); #ifdef NEW_TEXTURES if (this_texture != -1) { bind_texture(this_texture); } #else /* NEW_TEXTURES */ if(this_texture!=-1) get_and_set_texture_id(this_texture); #endif /* NEW_TEXTURES */ x_start=(i%6)*32+161; x_end=x_start+31; y_start=((i-pos)/6)*32+10; y_end=y_start+31; glBegin(GL_QUADS); draw_2d_thing(u_start,v_start,u_end,v_end,x_start,y_start,x_end,y_end); glEnd(); } if(cur_item_over!=-1 && mouse_in_window(win->window_id, mouse_x, mouse_y) == 1){ char str[20]; Uint16 item_id = storage_items[cur_item_over].id; int image_id = storage_items[cur_item_over].image_id; if (show_item_desc_text && item_info_available() && (get_item_count(item_id, image_id) == 1)) show_help(get_item_description(item_id, image_id), 0, win->len_y + 10); if (active_storage_item!=storage_items[cur_item_over].pos) { safe_snprintf(str, sizeof(str), "%d",storage_items[cur_item_over].quantity); show_help(str,mouse_x-win->pos_x-(strlen(str)/2)*8,mouse_y-win->pos_y-14); } } // Render the grid *after* the images. It seems impossible to code // it such that images are rendered exactly within the boxes on all // cards glDisable(GL_TEXTURE_2D); glColor3f(0.77f, 0.57f, 0.39f); glBegin(GL_LINE_LOOP); glVertex2i(10, 10); glVertex2i(10, 202); glVertex2i(130, 202); glVertex2i(130, 10); glEnd(); glBegin(GL_LINE_LOOP); glVertex2i(10, 212); glVertex2i(10, 262); glVertex2i(392, 262); glVertex2i(392, 212); glEnd(); if (view_only_storage) { Uint32 currentticktime = SDL_GetTicks(); if (currentticktime < drop_fail_time) drop_fail_time = 0; /* trap wrap */ if ((currentticktime - drop_fail_time) < 250) glColor3f(0.8f,0.2f,0.2f); /* flash red if tried to drop into */ else glColor3f(0.37f, 0.37f, 0.39f); /* otherwise draw greyed out */ } rendergrid(6, 6, 160, 10, 32, 32); glEnable(GL_TEXTURE_2D); glColor3f(1.0f,1.0f,1.0f); if(active_storage_item >= 0) { /* Draw the active item's quantity on top of everything else. */ for(i = pos = 6*vscrollbar_get_pos(storage_win, STORAGE_SCROLLBAR_ITEMS); i < pos+36 && i < no_storage; i++) { if(storage_items[i].pos == active_storage_item) { if (storage_items[i].quantity) { char str[20]; int x = (i%6)*32+161; safe_snprintf(str, sizeof(str), "%d", storage_items[i].quantity); if(x > 353) { x = 321; } show_help(str, x, ((i-pos)/6)*32+18); } break; } } } #ifdef OPENGL_TRACE CHECK_GL_ERRORS(); #endif //OPENGL_TRACE return 1; }