void update_text_windows (text_message * pmsg) { if (console_root_win >= 0) update_console_win (pmsg); switch (use_windowed_chat) { case 0: rewrap_message(pmsg, chat_zoom, get_console_text_width(), NULL); lines_to_show += pmsg->wrap_lines; if (lines_to_show > 10) lines_to_show = 10; break; case 1: update_tab_bar (pmsg); break; case 2: update_chat_window (pmsg, 1); break; } }
static int notepad_load_file() { xmlDocPtr doc; xmlNodePtr cur; if (note_list == 0) { note_list = calloc (NOTE_LIST_INIT_SIZE, sizeof (note)); note_list_size = NOTE_LIST_INIT_SIZE; } notepad_loaded = 1; doc = xmlParseFile ("notes.xml"); if (doc == NULL) { LOG_ERROR_OLD (cant_parse_notes); return 0; } cur = xmlDocGetRootElement (doc); if (cur == NULL) { // Not an error, just an empty notepad //LOG_ERROR_OLD ("Empty xml notepad. It will be overwritten."); xmlFreeDoc(doc); return 0; } if (xmlStrcasecmp (cur->name, (const xmlChar *) "PAD")) { LOG_ERROR_OLD (notes_wrong); xmlFreeDoc(doc); return 0; } // Load child node cur = cur->xmlChildrenNode; // Loop while we have a node, copying ATTRIBS, etc while (cur != NULL) { if ((!xmlStrcasecmp (cur->name, (const xmlChar *)"NOTE"))) { xmlChar* xmlName = xmlGetProp (cur, BAD_CAST "NAME"); char* name = fromUTF8 (xmlName, strlen ((const char*) xmlName)); char* data = NULL; if (cur->children) data = fromUTF8 (cur->children->content, strlen ((const char*)cur->children->content)); if (nr_notes >= note_list_size) { int new_size = note_list_size * 2; note_list = realloc (note_list, new_size * sizeof (note)); note_list_size = new_size; } init_note (nr_notes, name, data); if (data) free (data); free (name); xmlFree (xmlName); rewrap_message (¬e_list[nr_notes].text, 1.0f, notepad_win_x_len - 70, NULL); nr_notes++; } else if(cur->type == XML_ELEMENT_NODE) { LOG_ERROR_OLD ("%s: [%s]", wrong_note_node, cur->name); } cur = cur->next; // Advance to the next node. } return 1; }
int find_line_nr (int nr_lines, int line, Uint8 filter, int *msg, int *offset, float zoom, int width) { int line_count = 0, lines_no = nr_lines - line; int imsg, ichar; char *data; imsg = last_message; if ( imsg<0 ) { /* No data in buffer */ *msg = *offset = 0; return 1; } do { int msgchan = display_text_buffer[imsg].chan_idx; switch (msgchan) { case CHAT_LOCAL: if (!local_chat_separate) msgchan = CHAT_ALL; break; case CHAT_PERSONAL: if (!personal_chat_separate) msgchan = CHAT_ALL; break; case CHAT_GM: if (!guild_chat_separate) msgchan = CHAT_ALL; break; case CHAT_SERVER: if (!server_chat_separate) msgchan = CHAT_ALL; break; case CHAT_MOD: if (!mod_chat_separate) msgchan = CHAT_ALL; break; case CHAT_MODPM: msgchan = CHAT_ALL; break; } if (msgchan == filter || msgchan == CHAT_ALL || filter == FILTER_ALL) { data = display_text_buffer[imsg].data; if (data == NULL) // Hmmm... we messed up. This should not be // happening. break; rewrap_message(&display_text_buffer[imsg], zoom, width, NULL); for (ichar = display_text_buffer[imsg].len - 1; ichar >= 0; ichar--) { if (data[ichar] == '\n' || data[ichar] == '\r') { line_count++; if (line_count >= lines_no) { *msg = imsg; *offset = ichar+1; return 1; } } } line_count++; if (line_count >= lines_no) { *msg = imsg; *offset = 0; return 1; } } --imsg; } while (imsg >= 0 && imsg != last_message); *msg = 0; *offset = 0; return 1; }
void draw_messages (int x, int y, text_message *msgs, int msgs_size, Uint8 filter, int msg_start, int offset_start, int cursor, int width, int height, float text_zoom, select_info* select) { float displayed_font_x_size = DEFAULT_FONT_X_LEN * text_zoom; float displayed_font_y_size = DEFAULT_FONT_Y_LEN * text_zoom; float selection_red = 255 / 255.0f; float selection_green = 162 / 255.0f; float selection_blue = 0; unsigned char cur_char; int i; int imsg, ichar; int cur_x, cur_y; int cursor_x = x-1, cursor_y = y-1; unsigned char ch; int cur_line = 0; int cur_col = 0; unsigned char last_color_char = 0; int in_select = 0; imsg = msg_start; ichar = offset_start; if (msgs[imsg].data == NULL || msgs[imsg].deleted) return; if (width < displayed_font_x_size || height < displayed_font_y_size) // no point in trying return; #ifndef MAP_EDITOR2 if (filter != FILTER_ALL) { // skip all messages of the wrong channel while (1) { if (skip_message(&msgs[imsg], filter)) { ichar = 0; if (++imsg >= msgs_size) imsg = 0; if (msgs[imsg].data == NULL || imsg == msg_start || msgs[imsg].deleted) // nothing to draw return; } else { break; } } if (msgs[imsg].data == NULL || msgs[imsg].deleted) return; } #endif //! MAP_EDITOR2 ch = msgs[imsg].data[ichar]; if (!is_color (ch)) { // search backwards for the last color for (i = ichar-1; i >= 0; i--) { ch = msgs[imsg].data[i]; if (is_color (ch)) { find_font_char (ch); last_color_char = ch; break; } } if (i < 0) { // no color character found, try the message color if (msgs[imsg].r >= 0) glColor3f (msgs[imsg].r, msgs[imsg].g, msgs[imsg].b); } } glEnable (GL_ALPHA_TEST); // enable alpha filtering, so we have some alpha key glAlphaFunc (GL_GREATER, 0.1f); #ifdef NEW_TEXTURES bind_texture(font_text); #else /* NEW_TEXTURES */ get_and_set_texture_id(font_text); #endif /* NEW_TEXTURES */ i = 0; cur_x = x; cur_y = y; glBegin (GL_QUADS); while (1) { if (i == cursor) { cursor_x = cur_x; cursor_y = cur_y; if (cursor_x - x > width - displayed_font_x_size) { cursor_x = x; cursor_y = cur_y + displayed_font_y_size; } } cur_char = msgs[imsg].data[ichar]; // watch for special characters if (cur_char == '\0') { // end of message if (++imsg >= msgs_size) { imsg = 0; } #ifndef MAP_EDITOR2 if (filter != FILTER_ALL) { // skip all messages of the wrong channel while (skip_message (&msgs[imsg], filter)) { if (++imsg >= msgs_size) imsg = 0; if (msgs[imsg].data == NULL || imsg == msg_start) break; } } #endif if (msgs[imsg].data == NULL || imsg == msg_start || msgs[imsg].deleted) break; rewrap_message (&msgs[imsg], text_zoom, width, NULL); ichar = 0; last_color_char = 0; } if (select != NULL && select->lines && select->lines[cur_line].msg == -1) { select->lines[cur_line].msg = imsg; select->lines[cur_line].chr = ichar; } if (cur_char == '\n' || cur_char == '\r' || cur_char == '\0') { // newline cur_y += displayed_font_y_size; if (cur_y - y > height - displayed_font_y_size) break; cur_x = x; if (cur_char != '\0') ichar++; i++; cur_line++; cur_col = 0; continue; } if (pos_selected(imsg, ichar, select)) { if (!in_select) { glColor3f (selection_red, selection_green, selection_blue); in_select = 1; } } else { if (in_select) { if (last_color_char) find_font_char (last_color_char); else if (msgs[imsg].r < 0) find_font_char (to_color_char (c_grey1)); else glColor3f (msgs[imsg].r, msgs[imsg].g, msgs[imsg].b); in_select = 0; } } if (is_color (cur_char)) { last_color_char = cur_char; if (in_select) { // don't draw color characters in a selection i++; ichar++; continue; } } cur_x += draw_char_scaled (cur_char, cur_x, cur_y, displayed_font_x_size, displayed_font_y_size); cur_col++; ichar++; i++; if (cur_x - x > width - displayed_font_x_size) { // ignore rest of this line, but keep track of // color characters while (1) { ch = msgs[imsg].data[ichar]; if (ch == '\0' || ch == '\n' || ch == '\r') break; if (is_color (ch)) last_color_char = ch; ichar++; i++; } } } if (cursor_x >= x && cursor_y >= y && cursor_y - y <= height - displayed_font_y_size) { draw_char_scaled ('_', cursor_x, cursor_y, displayed_font_x_size, displayed_font_y_size); } glEnd(); glDisable(GL_ALPHA_TEST); #ifdef OPENGL_TRACE CHECK_GL_ERRORS(); #endif //OPENGL_TRACE }