/* callback for options window to change the number of recipe entries */ void change_num_recipe_entries(int * var, int value) { if ((value >= 0) && (value < max_num_recipe_entries)) *var = value; else return; if (!recipes_loaded) return; /* never reduce the allocated memory so we can reduce and increase while keeping recipes */ if (wanted_num_recipe_entries > max_prev_num_recipe_entries) { recipes_store = (recipe_entry *)realloc(recipes_store, wanted_num_recipe_entries * sizeof(recipe_entry)); memset(&recipes_store[max_prev_num_recipe_entries], 0, sizeof(recipe_entry)*(wanted_num_recipe_entries-max_prev_num_recipe_entries)); max_prev_num_recipe_entries = wanted_num_recipe_entries; } num_recipe_entries = wanted_num_recipe_entries; /* keep current recipe in range */ if (cur_recipe >= num_recipe_entries) cur_recipe = num_recipe_entries - 1; /* resize the window if its now too big for the number of recipes */ if (num_displayed_recipes > num_recipe_entries) { num_displayed_recipes = num_recipe_entries; resize_window(recipe_win, recipe_win_width, num_displayed_recipes*SLOT_SIZE); } /* reset the scroll length and position to show the new slot */ vscrollbar_set_bar_len(recipe_win, recipe_win_scroll_id, num_recipe_entries - num_displayed_recipes); vscrollbar_set_pos(recipe_win, recipe_win_scroll_id, num_recipe_entries - num_displayed_recipes); }
int click_help_handler(window_info *win, int mx, int my, Uint32 flags) { _Text *t=Page[helppage].T.Next; if(flags&ELW_WHEEL_UP) { vscrollbar_scroll_up(help_win, help_menu_scroll_id); } else if(flags&ELW_WHEEL_DOWN) { vscrollbar_scroll_down(help_win, help_menu_scroll_id); } else { int j = vscrollbar_get_pos(help_win, help_menu_scroll_id); while(t) { int xlen=strlen(t->text)*((t->size)?11:8),ylen=(t->size)?18:15; if(t->ref && mx>(t->x) && mx<(t->x+xlen) && my>(t->y-j) && my<(t->y+ylen-j)) { //changing page int i; for(i=0; i<numpage+1; i++) { if(!xmlStrcasecmp((xmlChar*)Page[i].Name,(xmlChar*)t->ref)) { helppage=i; vscrollbar_set_pos(help_win, help_menu_scroll_id, 0); vscrollbar_set_bar_len(help_win, help_menu_scroll_id, Page[helppage].max_y); break; } } break; } t=t->Next; } } return 1; }
/* called each resize, recalculate the number of recipes that can be displayed and update the scrollbar */ static int resize_recipe_handler(window_info *win, int width, int height) { widget_resize(win->window_id, recipe_win_scroll_id, win->box_size, win->len_y - win->box_size); widget_move(win->window_id, recipe_win_scroll_id, win->len_x - win->box_size, 0); num_displayed_recipes = (int)(win->len_y / SLOT_SIZE); vscrollbar_set_bar_len(win->window_id, recipe_win_scroll_id, num_recipe_entries - num_displayed_recipes); return 1; }
static void update_note_button_scrollbar(int nr) { int max_nr_rows = note_button_scroll_height / (note_button_height + note_button_y_space); int nr_rows = (nr_notes+1) / 2; if (nr_rows <= max_nr_rows) { widget_set_flags (main_note_tab_id, note_button_scroll_id, WIDGET_INVISIBLE|WIDGET_DISABLED); vscrollbar_set_bar_len (main_note_tab_id, note_button_scroll_id, 0); scroll_to_note_button (0); } else { widget_unset_flags (main_note_tab_id, note_button_scroll_id, WIDGET_INVISIBLE|WIDGET_DISABLED); vscrollbar_set_bar_len (main_note_tab_id, note_button_scroll_id, nr_rows - max_nr_rows); scroll_to_note_button (nr); } }
static void set_scrollbar_len(void) { int i; int num_buddies = 0; for (i = 0; i < MAX_BUDDY; i++) if (buddy_list[i].type != 0xff) num_buddies++; vscrollbar_set_bar_len(buddy_win, buddy_scroll_id, ((num_buddies - num_displayed_buddies < 0) ?0: num_buddies - num_displayed_buddies)); }
/* Handle options selected from the main context menu */ static int cm_encycl_handler(window_info *win, int widget_id, int mx, int my, int option) { switch (option) { case CM_ENCYCL_INDEX: currentpage = page_index[ENCYCLT_ENCYC]; vscrollbar_set_pos(encyclopedia_win, encyclopedia_scroll_id, 0); vscrollbar_set_bar_len(encyclopedia_win, encyclopedia_scroll_id, Page[currentpage].max_y); break; case CM_ENCYCL_SEARCH: close_ipu(&ipu_encycl); init_ipu(&ipu_encycl, encyclopedia_win, DEFAULT_FONT_X_LEN * 20, -1, 40, 1, NULL, find_page_callback); ipu_encycl.x = mx; ipu_encycl.y = my; display_popup_win(&ipu_encycl, encycl_search_propmt); if (ipu_encycl.popup_win >=0 && ipu_encycl.popup_win<windows_list.num_windows) windows_list.window[ipu_encycl.popup_win].opaque = 1; break; case CM_ENCYCL_REPSEARCH: if (last_search != NULL) repeat_search = 1; break; case CM_ENCYCL_BOOKMARK: if (num_bookmarks < MAX_BOOKMARKS) { size_t i; for (i=0; i<num_page_links; i++) if(!xmlStrcasecmp((xmlChar*)Page[currentpage].Name,(xmlChar*)page_links[i].link)) { book_marks[num_bookmarks++] = i; rebuild_cm_encycl(); break; } } break; case CM_ENCYCL_UNBOOKMARK: { size_t i; size_t index = get_page_bookmark_index(); if (index < MAX_BOOKMARKS) { for (i=index+1; i<num_bookmarks; i++) book_marks[i-1] = book_marks[i]; num_bookmarks--; rebuild_cm_encycl(); } break; } case CM_ENCYCL_CLEARBOOKMARKS: num_bookmarks = 0; rebuild_cm_encycl(); break; default: open_page(book_marks[option-CM_ENCYCL_THEBOOKMARKS]); } return 1; }
/* Find the specified page then open it. */ static void open_page(size_t index) { size_t i; if (index>=num_page_links) return; for (i=0; i<numpage; ++i) if(!xmlStrcasecmp((xmlChar*)Page[i].Name,(xmlChar*)page_links[index].link)) { currentpage = i; vscrollbar_set_pos(encyclopedia_win, encyclopedia_scroll_id, 0); vscrollbar_set_bar_len(encyclopedia_win, encyclopedia_scroll_id, Page[currentpage].max_y); return; } fprintf(stderr, "Weird, open_page(%lu) not found. [%s]\n", (unsigned long)index, page_links[index].title); }
void get_storage_categories (const char *in_data, int len) { int i; int idx, idxp; idx = 1; for (i = 0; i < in_data[0] && i < STORAGE_CATEGORIES_SIZE && idx < len; i++) { storage_categories[i].id = (Uint8)in_data[idx++]; storage_categories[i].name[0] = to_color_char (c_orange1); idxp = 1; while (idx < len && idxp < sizeof (storage_categories[i].name) - 1 && in_data[idx] != '\0') { storage_categories[i].name[idxp++] = in_data[idx++]; } // always make sure the string is terminated storage_categories[i].name[idxp] = '\0'; // was the string too long? if (idxp >= sizeof (storage_categories[i].name) - 1) { // skip rest of string while (idx < len && in_data[idx] != '\0') idx++; } idx++; } if (sort_storage_categories) qsort(storage_categories, i, sizeof(*storage_categories), category_cmp); for (i = in_data[0]; i < STORAGE_CATEGORIES_SIZE; i++) { storage_categories[i].id = -1; storage_categories[i].name[0] = 0; } no_storage_categories = in_data[0]; if (storage_win > 0) vscrollbar_set_bar_len(storage_win, STORAGE_SCROLLBAR_CATEGORIES, ( no_storage_categories - STORAGE_CATEGORIES_DISPLAY ) > 1 ? (no_storage_categories - STORAGE_CATEGORIES_DISPLAY) : 1); selected_category=-1; active_storage_item=-1; display_storage_menu(); if (!view_only_storage) display_items_menu(); }
int click_encyclopedia_handler(window_info *win, int mx, int my, Uint32 flags) { _Text *t=Page[currentpage].T.Next; if(flags&ELW_WHEEL_UP) { vscrollbar_scroll_up(encyclopedia_win, encyclopedia_scroll_id); } else if(flags&ELW_WHEEL_DOWN) { vscrollbar_scroll_down(encyclopedia_win, encyclopedia_scroll_id); } else { int j = vscrollbar_get_pos(encyclopedia_win, encyclopedia_scroll_id); while(t){ int xlen=strlen(t->text)*((t->size)?11:8),ylen=(t->size)?18:15; if(t->ref && mx>(t->x) && mx<(t->x+xlen) && my>(t->y-j) && my<(t->y+ylen-j)){ // check if its a webpage if (!strncasecmp(t->ref, "http://", 7)) { open_web_link(t->ref); } else { //changing page int i; for(i=0;i<numpage+1;i++){ if(!xmlStrcasecmp((xmlChar*)Page[i].Name,(xmlChar*)t->ref)){ currentpage=i; vscrollbar_set_pos(encyclopedia_win, encyclopedia_scroll_id, 0); vscrollbar_set_bar_len(encyclopedia_win, encyclopedia_scroll_id, Page[currentpage].max_y); break; } } } break; } t=t->Next; } } 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() */
// Recalculate the scroll bar length // void List_Window::update_scroll_len(void) { if (win_id>=0) vscrollbar_set_bar_len(win_id, names_scroll_id, Vars::lists()->size()-num_show_names_list); }