// The mouse is over the window // int List_Window::mouseover(window_info *win, int mx, int my) { if ((my < 0) || (cm_window_shown()!=CM_INIT_VALUE)) return 0; if (Vars::lists()->valid_active_list() && mx>=0 && mx<(get_grid_size()*6) && my>=0 && my<(get_grid_size()*num_grid_rows)) { size_t item_number = get_item_number(mx, my); if (item_number < Vars::lists()->get_list().get_num_items()) { Uint16 item_id = Vars::lists()->get_list().get_item_id(item_number); int image_id = Vars::lists()->get_list().get_image_id(item_number); if (show_item_desc_text && item_info_available() && (get_item_count(item_id, image_id) == 1)) desc_str = get_item_description(item_id, image_id); help_str.push_back(item_list_pickup_help_str); help_str.push_back(item_list_use_help_str); help_str.push_back(item_list_edit_help_str); } if ((storage_item_dragged != -1) || (item_dragged != -1)) help_str.push_back(item_list_add_help_str); else help_str.push_back(item_list_drag_help_str); } // check if over the add list button if (my>add_button_y && my<(add_button_y+2*DEFAULT_FONT_Y_LEN) && mx>add_button_x && mx<win->len_x) { help_str.push_back(item_list_create_help_str); mouse_over_add_button = true; } // check if over the list names and get which name int start_names = get_grid_size()*num_grid_rows; if ((my > start_names) && (my < (start_names+get_names_size_y()))) name_under_mouse = vscrollbar_get_pos (win_id, names_scroll_id) + static_cast<int>((my - start_names - get_list_gap()/2) / (get_list_gap() + names_list_height)); // name list context help if ((my > start_names) && (my < (start_names+get_names_size_y()))) { help_str.push_back(cm_help_options_str); if (!strlen(filter)) help_str.push_back(item_list_find_help_str); } return 0; }
int mouseover_knowledge_handler(window_info *win, int mx, int my) { int i; if (mx>=progress_left_x && mx<progress_right_x && my>progress_top_y && my<progress_bot_y) mouse_over_progress_bar=1; if (cm_window_shown()!=CM_INIT_VALUE) return 0; for(i=0;i<knowledge_count;i++)knowledge_list[i].mouse_over=0; if (my>0) know_show_win_help = 1; if(mx>win->len_x-win->box_size) return 0; if(my>booklist_y_len) return 0; mx = (mx < (win->len_x-win->box_size)/2) ?0 :1; my/=booklist_y_step; knowledge_list[mx+2*(my+vscrollbar_get_pos (win->window_id, knowledge_scroll_id))].mouse_over=1; return 0; }
// Display the main window. All the players achievemnt icons and the controls. // Handle the mouse over events for the icons and the controls. // int Achievements_Window::display_handler(window_info *win) { Achievements_System *as = Achievements_System::get_instance(); int icon_per = (256 / as->get_size()); int icon_per_texture = icon_per * icon_per; bool another_page = false; glEnable(GL_TEXTURE_2D); glColor3f(1.0f,1.0f,1.0f); for (size_t i=first; i<their_achievements.size(); ++i) { size_t shown_num = i-first; if ((static_cast<int>(shown_num)/as->get_per_row()) >= physical_rows) { another_page = true; break; } int texture = -1; const Achievement * achievement = as->achievement(their_achievements[i]); if (achievement) texture = as->texture(achievement->get_id() / icon_per_texture); if (texture >= 0) { int cur_item = achievement->get_id() % icon_per_texture; float u_start = 1.0f/static_cast<float>(icon_per) * (cur_item % icon_per); float u_end = u_start + static_cast<float>(as->get_size())/256; float v_start = 1.0f/static_cast<float>(icon_per) * (cur_item / icon_per); float v_end = v_start + static_cast<float>(as->get_size()) / 256; int start_x = as->get_border() + as->get_display() * (shown_num % as->get_per_row()); int start_y = as->get_border() + as->get_display() * (shown_num / as->get_per_row()); bind_texture(texture); glEnable(GL_ALPHA_TEST); glAlphaFunc(GL_GREATER, 0.05f); glBegin(GL_QUADS); draw_2d_thing( u_start, v_start, u_end, v_end, start_x, start_y, start_x+as->get_display(), start_y+as->get_display() ); glEnd(); glDisable(GL_ALPHA_TEST); } else { int pos_x = as->get_border() + (shown_num % as->get_per_row()) * as->get_display() + (as->get_display() - win->default_font_len_x) / 2; int pos_y = as->get_border() + (shown_num / as->get_per_row()) * as->get_display() + (as->get_display() - win->default_font_len_y) / 2; draw_string_zoomed(pos_x+gx_adjust, pos_y+gy_adjust, (const unsigned char *)"?", 1, win->current_scale); } } size_t now_over = Achievement::npos; if ((cm_window_shown() == CM_INIT_VALUE) && (win_mouse_x > as->get_border()) && (win_mouse_y > as->get_border())) { int row = (win_mouse_y - as->get_border()) / as->get_display(); int col = (win_mouse_x - as->get_border()) / as->get_display(); if ((row >= 0) && (row < physical_rows) && (col >= 0) && (col < as->get_per_row())) { size_t current_index = first + row * as->get_per_row() + col; if (current_index < their_achievements.size()) now_over = their_achievements[current_index]; } } if (now_over != last_over) { if (last_over != Achievement::npos) hide_window(child_win_id); last_over = now_over; if (last_over != Achievement::npos) open_child(); } int prev_start = gx_adjust + as->get_border(); int prev_end = prev_start + as->get_font_x() * as->get_prev().size(); int next_start = prev_end + 2 * as->get_border(); int next_end = next_start + as->get_font_x() * as->get_next().size(); int close_start = gx_adjust + win->len_x - (as->get_border() + as->get_font_x() * as->get_close().size()); int close_end = gx_adjust + win->len_x - as->get_border(); bool over_controls = (win_mouse_y > (win->len_y - (as->get_font_y() + as->get_border()))); bool over_close = (over_controls && (win_mouse_x > close_start) && (win_mouse_x < close_end)); bool over_prev = (over_controls && (win_mouse_x > prev_start) && (win_mouse_x < prev_end)); bool over_next = (over_controls && (win_mouse_x > next_start) && (win_mouse_x < next_end)); float active_colour[3] = { 1.0f, 1.0f, 1.0f }; float inactive_colour[3] = { 0.5f, 0.5f, 0.5f }; float mouse_over_colour[3] = { 1.0f, 0.5f, 0.0f }; glColor3fv((first) ?((over_prev) ?mouse_over_colour :active_colour) :inactive_colour); draw_string_small_zoomed(prev_start, gy_adjust + win->len_y - (as->get_font_y() + as->get_border()), reinterpret_cast<const unsigned char *>(as->get_prev().c_str()), 1, as->get_current_scale()); glColor3fv((another_page) ?((over_next) ?mouse_over_colour :active_colour) :inactive_colour); draw_string_small_zoomed(next_start, gy_adjust + win->len_y - (as->get_font_y() + as->get_border()), reinterpret_cast<const unsigned char *>(as->get_next().c_str()), 1, as->get_current_scale()); glColor3fv((over_close) ?mouse_over_colour :active_colour); draw_string_small_zoomed(close_start, gy_adjust + win->len_y - (as->get_font_y() + as->get_border()), reinterpret_cast<const unsigned char *>(as->get_close().c_str()), 1, as->get_current_scale()); if (over_close && ctrl_clicked) as->hide_all(); if (over_close && clicked) hide_window(main_win_id); else if (over_prev && first && clicked) first -= physical_rows * as->get_per_row(); else if (over_next && another_page && clicked) first += physical_rows * as->get_per_row(); if (clicked && (over_prev || over_next)) do_click_sound(); if ((ctrl_clicked || clicked) && over_close) do_window_close_sound(); if (over_controls && show_help_text) { if (over_close) show_help(as->get_close_help(), 0, win->len_y + as->get_y_win_offset(), win->current_scale); else if (over_prev) show_help((first)?as->get_prev_help() :as->get_no_prev_help(), 0, win->len_y + as->get_y_win_offset(), win->current_scale); else if (over_next) show_help((another_page)?as->get_next_help() :as->get_no_next_help(), 0, win->len_y + as->get_y_win_offset(), win->current_scale); } win_mouse_x = win_mouse_y = -1; ctrl_clicked = clicked = false; return 1; }
/* Access the caught url list and display in a scrollable window. */ static int display_url_handler(window_info *win) { #ifdef OPENGL_TRACE CHECK_GL_ERRORS(); #endif //OPENGL_TRACE url_win_hover_url = NULL; /* save current position so K_WINDOWS_ON_TOP restores to where its been moved */ url_win_x = win->cur_x; url_win_y = win->cur_y; glEnable(GL_TEXTURE_2D); set_font(0); /* check for external state change */ if (!have_url_count && !url_win_status) url_win_status = URLW_EMPTY; /* if we have a status message, display it */ if (url_win_status) { char *message[] = { urlcmd_none_str, urlwin_clear_str, urlwin_open_str }; int y_start = (url_win_text_start_y - 0.75 * url_win_text_zoom * DEFAULT_FONT_Y_LEN)/2; glColor3f(1.0f,1.0f,1.0f); draw_string_zoomed(url_win_help_x, y_start, (unsigned char *)message[url_win_status-1], 1, 0.75 * url_win_text_zoom); url_win_status = (have_url_count) ?0 :URLW_EMPTY; } /* display a page of url */ if (have_url_count) { list_node_t *local_head = newest_url; int currenty = url_win_text_start_y; int start_url = 0; int num_url_displayed = 0; /* don't scroll if everything will fit in the window, also catch if the list has been cleared via #url */ if (((url_win_line_step * have_url_count) <= url_win_text_len_y) || (url_win_top_line > have_url_count)) url_win_top_line = 0; /* move to the first url to be displayed - set from the scroll bar */ while (start_url < url_win_top_line && local_head->next != NULL) { local_head = local_head->next; start_url++; } /* loop over the remaining URLs while there is room in the window */ while (local_head != NULL) { char *thetext = ((URLDATA *)local_head->data)->text; int dsp_string_len = 0; float string_width = 0; int highlight_url = 0; /* stop now if the url line will not fit into the window */ if (((currenty - url_win_text_start_y) + url_win_line_step) > url_win_text_len_y) break; /* highlight the active (F2) url */ if (local_head == active_url) glColor3f(0.0f,1.0f,0.0f); else glColor3f(1.0f,1.0f,1.0f); /* calculate the length of string we can display */ while((*thetext != '\0') && (string_width < url_win_max_string_width)) { float char_width = get_char_width(*thetext++) * url_win_text_zoom * DEFAULT_FONT_X_LEN / 12.0; if ((string_width+char_width) < url_win_max_string_width) { dsp_string_len++; string_width += char_width; } } /* if the string length will fit in the window, just draw it */ if (dsp_string_len == strlen(((URLDATA *)local_head->data)->text)) draw_string_zoomed(url_win_sep, currenty, (unsigned char *)((URLDATA *)local_head->data)->text, 1, url_win_text_zoom); /* otherwise, draw a truncated version with "..." at the end */ else { //float toobig_width = (get_char_width('-') + get_char_width('>')) // * url_win_text_zoom * DEFAULT_FONT_X_LEN / 12.0; float toobig_width = (3*get_char_width('.')) * url_win_text_zoom * DEFAULT_FONT_X_LEN / 12.0; draw_string_zoomed_width(url_win_sep, currenty, (unsigned char *)((URLDATA *)local_head->data)->text, url_win_sep + url_win_max_string_width - toobig_width, 1, url_win_text_zoom); draw_string_zoomed(url_win_sep + url_win_max_string_width - toobig_width, currenty, (unsigned char *)"..." , 1, url_win_text_zoom); } /* step down a line, do it now as the maths for mouse over below is easier */ currenty += url_win_line_step; /* if the mouse is over the current line, hightlight it */ if ((mouse_y >= win->cur_y + currenty - url_win_line_step) && (mouse_y < win->cur_y + currenty) && (mouse_x >= win->cur_x + (int)url_win_sep) && (mouse_x - (int)url_win_sep <= win->cur_x + url_win_max_string_width)) { /* remember which url we're over in case it's clicked */ url_win_hover_url = local_head; highlight_url = 1; } /* if a context menu is open, only hightlight the last URL hovered over before the context opened */ if (cm_window_shown() != CM_INIT_VALUE) { if (cm_url == local_head) highlight_url = 1; else highlight_url = 0; } else cm_url = NULL; /* if mouse over or context activated, highlight the current URL */ if (highlight_url) { char *help_substring = NULL; size_t help_substring_len = 0; int dsp_start = 0; int helpline = 0; Uint32 currenttime = SDL_GetTicks(); size_t full_help_len = strlen(((URLDATA *)local_head->data)->text) + 30; char *full_help_text = (char *)malloc(sizeof(char) * full_help_len); /* display the mouse over help next time round */ url_win_status = URLW_OVER; /* underline the text, just clicked links are red, otherwise blue - paler when visited */ if ((currenttime - url_win_clicktime < 500) && (url_win_clicked_url == url_win_hover_url)) glColor3f(1.0f,0.0f,0.3f); else if (((URLDATA *)local_head->data)->visited) glColor3f(0.3f,0.5f,1.0f); else glColor3f(0.1f,0.2f,1.0f); glDisable(GL_TEXTURE_2D); glBegin(GL_LINES); glVertex2i(url_win_sep, currenty-2); glVertex2i(url_win_sep+string_width, currenty-2); glEnd(); glEnable(GL_TEXTURE_2D); /* write the full url as help text at the bottom of the window */ safe_snprintf(full_help_text, full_help_len, "%s (seen %d time%s) (%s)", ((URLDATA *)local_head->data)->text, ((URLDATA *)local_head->data)->seen_count, ((URLDATA *)local_head->data)->seen_count == 1?"":"s", ((((URLDATA *)local_head->data)->visited)?"visited":"unvisited")); thetext = full_help_text; dsp_string_len = 0; string_width = 0; while(*thetext != '\0') { float char_width = get_char_width(*thetext++) * SMALL_FONT_X_LEN / 12.0; if (((string_width+char_width) > (win->len_x - 2*url_win_sep)) || (*thetext == '\0')) { if (*thetext == '\0') /* catch the last line */ dsp_string_len++; if (help_substring_len < dsp_string_len) { if (help_substring != NULL) free(help_substring); help_substring = (char *)malloc(sizeof(char)*(dsp_string_len+1)); help_substring_len = dsp_string_len; } strncpy(help_substring, &full_help_text[dsp_start], dsp_string_len); help_substring[dsp_string_len] = '\0'; show_help(help_substring, url_win_sep, (url_win_y_len - url_win_full_url_y_len) + helpline++ * SMALL_FONT_Y_LEN); dsp_start += dsp_string_len; dsp_string_len = 0; string_width = 0; } dsp_string_len++; string_width += char_width; } free(help_substring); free(full_help_text); } /* end if mouse over url */ /* count how many displayed so we can set the scroll bar properly */ num_url_displayed++; local_head = local_head->next; } /* set the number of steps for the scroll bar */ vscrollbar_set_bar_len(url_win, url_scroll_id, have_url_count - num_url_displayed); } /* end if have url */ /* draw a line below the list of url, above the current url full text */ glColor3f(0.77f,0.59f,0.39f); glDisable(GL_TEXTURE_2D); glBegin(GL_LINES); glVertex2i(0, url_win_url_y_start); glVertex2i(url_win_x_len+1, url_win_url_y_start); glEnd(); glEnable(GL_TEXTURE_2D); #ifdef OPENGL_TRACE CHECK_GL_ERRORS(); #endif //OPENGL_TRACE return 1; } /* end display_url_handler() */