size_t editor_window_jumplist_prev(Win *win) { size_t cur = view_cursor_get(win->view); while (win->jumplist) { Mark mark = ringbuf_prev(win->jumplist); if (!mark) return cur; size_t pos = text_mark_get(win->file->text, mark); if (pos != EPOS && pos != cur) return pos; } return cur; }
int ringbuf_test() { char buffer[256]; RINGBUFFER *rb; int i, s, k, m; int count; int testcount = 0; void *item; int before; for(k = 100; k < sizeof(buffer); k++) { if((k%10) == 0) dbg_msg("ringbuf", "testing at %d", k); rb = ringbuf_init(buffer, k, 0); count = 0; for(s = 1; s < sizeof(buffer); s++) { for(i = 0; i < k*8; i++, testcount++) { for(m = 0, item = ringbuf_first(rb); item; item = ringbuf_next(rb, item), m++); before = m; if(ringbuf_allocate(rb, s)) { count++; for(m = 0, item = ringbuf_first(rb); item; item = ringbuf_next(rb, item), m++); if(before+1 != m) ringbuf_debugdump(rb, "alloc error"); if(count != m) ringbuf_debugdump(rb, "count error"); } else { if(ringbuf_popfirst(rb)) { count--; for(m = 0, item = ringbuf_first(rb); item; item = ringbuf_next(rb, item), m++); if(before-1 != m) dbg_msg("", "popping error %d %d", before, m); if(count != m) ringbuf_debugdump(rb, "count error"); } } /* remove an item every 10 */ if((i%10) == 0) { for(m = 0, item = ringbuf_first(rb); item; item = ringbuf_next(rb, item), m++); before = m; if(ringbuf_popfirst(rb)) { count--; for(m = 0, item = ringbuf_first(rb); item; item = ringbuf_next(rb, item), m++); if(before-1 != m) dbg_msg("", "popping error %d %d", before, m); dbg_assert(count == m, "count error"); } } /* count items */ for(m = 0, item = ringbuf_first(rb); item; item = ringbuf_next(rb, item), m++); if(m != count) ringbuf_debugdump(rb, "wrong number of items during forward count"); for(m = 0, item = ringbuf_last(rb); item; item = ringbuf_prev(rb, item), m++); if(m != count) ringbuf_debugdump(rb, "wrong number of items during backward count"); ringbuf_validate(rb); } /* empty the ring buffer */ while(ringbuf_first(rb)) ringbuf_popfirst(rb); ringbuf_validate(rb); count = 0; } } return 0; }
void *ringbuf_last(RINGBUFFER *rb) { if(!rb->produce->free) return rb->produce+1; return ringbuf_prev(rb, rb->produce+1); }
void CONSOLE::INSTANCE::on_input(INPUT_EVENT e) { bool handled = false; if(e.flags&INPFLAG_PRESS) { if(e.key == KEY_RETURN || e.key == KEY_KP_ENTER) { if(input.get_string()[0]) { char *entry = (char *)ringbuf_allocate(history, input.get_length()+1); mem_copy(entry, input.get_string(), input.get_length()+1); execute_line(input.get_string()); input.clear(); history_entry = 0x0; } handled = true; } else if (e.key == KEY_UP) { if (history_entry) { char *test = (char *)ringbuf_prev(history, history_entry); if (test) history_entry = test; } else history_entry = (char *)ringbuf_last(history); if (history_entry) { unsigned int len = strlen(history_entry); if (len < sizeof(input) - 1) input.set(history_entry); } handled = true; } else if (e.key == KEY_DOWN) { if (history_entry) history_entry = (char *)ringbuf_next(history, history_entry); if (history_entry) { unsigned int len = strlen(history_entry); if (len < sizeof(input) - 1) input.set(history_entry); } else input.clear(); handled = true; } else if(e.key == KEY_TAB) { completion_chosen++; completion_enumeration_count = 0; console_possible_commands(completion_buffer, completion_flagmask, possible_commands_complete_callback, this); // handle wrapping if(completion_enumeration_count && completion_chosen >= completion_enumeration_count) { completion_chosen %= completion_enumeration_count; completion_enumeration_count = 0; console_possible_commands(completion_buffer, completion_flagmask, possible_commands_complete_callback, this); } } if(e.key != KEY_TAB) { completion_chosen = -1; str_copy(completion_buffer, input.get_string(), sizeof(completion_buffer)); } // find the current command { char buf[64] = {0}; const char *src = get_string(); int i = 0; for(; i < (int)sizeof(buf) && *src && *src != ' ' && *src != ' '; i++, src++) buf[i] = *src; buf[i] = 0; command = console_get_command(buf); } } if(!handled) input.process_input(e); }
void CONSOLE::on_render() { RECT screen = *ui_screen(); float console_max_height = screen.h*3/5.0f; float console_height; float progress = (time_now()-(state_change_end-state_change_duration))/float(state_change_duration); if (progress >= 1.0f) { if (console_state == CONSOLE_CLOSING) console_state = CONSOLE_CLOSED; else if (console_state == CONSOLE_OPENING) console_state = CONSOLE_OPEN; progress = 1.0f; } if (console_state == CONSOLE_CLOSED) return; if (console_state == CONSOLE_OPEN) inp_mouse_mode_absolute(); float console_height_scale; if (console_state == CONSOLE_OPENING) console_height_scale = console_scale_func(progress); else if (console_state == CONSOLE_CLOSING) console_height_scale = console_scale_func(1.0f-progress); else //if (console_state == CONSOLE_OPEN) console_height_scale = console_scale_func(1.0f); console_height = console_height_scale*console_max_height; gfx_mapscreen(screen.x, screen.y, screen.w, screen.h); // do console shadow gfx_texture_set(-1); gfx_quads_begin(); gfx_setcolorvertex(0, 0,0,0, 0.5f); gfx_setcolorvertex(1, 0,0,0, 0.5f); gfx_setcolorvertex(2, 0,0,0, 0.0f); gfx_setcolorvertex(3, 0,0,0, 0.0f); gfx_quads_drawTL(0,console_height,screen.w,10.0f); gfx_quads_end(); // do background gfx_texture_set(data->images[IMAGE_CONSOLE_BG].id); gfx_quads_begin(); gfx_setcolor(0.2f, 0.2f, 0.2f,0.9f); if(console_type != 0) gfx_setcolor(0.4f, 0.2f, 0.2f,0.9f); gfx_quads_setsubset(0,-console_height*0.075f,screen.w*0.075f*0.5f,0); gfx_quads_drawTL(0,0,screen.w,console_height); gfx_quads_end(); // do small bar shadow gfx_texture_set(-1); gfx_quads_begin(); gfx_setcolorvertex(0, 0,0,0, 0.0f); gfx_setcolorvertex(1, 0,0,0, 0.0f); gfx_setcolorvertex(2, 0,0,0, 0.25f); gfx_setcolorvertex(3, 0,0,0, 0.25f); gfx_quads_drawTL(0,console_height-20,screen.w,10); gfx_quads_end(); // do the lower bar gfx_texture_set(data->images[IMAGE_CONSOLE_BAR].id); gfx_quads_begin(); gfx_setcolor(1.0f, 1.0f, 1.0f, 0.9f); gfx_quads_setsubset(0,0.1f,screen.w*0.015f,1-0.1f); gfx_quads_drawTL(0,console_height-10.0f,screen.w,10.0f); gfx_quads_end(); console_height -= 22.0f; INSTANCE *console = current_console(); { float font_size = 10.0f; float row_height = font_size*1.25f; float x = 3; float y = console_height - row_height - 2; // render prompt TEXT_CURSOR cursor; gfx_text_set_cursor(&cursor, x, y, font_size, TEXTFLAG_RENDER); RENDERINFO info; info.wanted_completion = console->completion_chosen; info.enum_count = 0; info.current_cmd = console->completion_buffer; gfx_text_set_cursor(&info.cursor, x, y+12.0f, font_size, TEXTFLAG_RENDER); const char *prompt = "> "; if(console_type) { if(client_state() == CLIENTSTATE_ONLINE) { if(client_rcon_authed()) prompt = "rcon> "; else prompt = "ENTER PASSWORD> "; } else prompt = "NOT CONNECTED> "; } gfx_text_ex(&cursor, prompt, -1); // render console input gfx_text_ex(&cursor, console->input.get_string(), console->input.cursor_offset()); TEXT_CURSOR marker = cursor; gfx_text_ex(&marker, "|", -1); gfx_text_ex(&cursor, console->input.get_string()+console->input.cursor_offset(), -1); // render version char buf[128]; str_format(buf, sizeof(buf), "v%s", GAME_VERSION); float version_width = gfx_text_width(0, font_size, buf, -1); gfx_text(0, screen.w-version_width-5, y, font_size, buf, -1); // render possible commands if(console->input.get_string()[0] != 0) { console_possible_commands(console->completion_buffer, console->completion_flagmask, possible_commands_render_callback, &info); if(info.enum_count <= 0) { if(console->command) { char buf[512]; str_format(buf, sizeof(buf), "Help: %s ", console->command->help); gfx_text_ex(&info.cursor, buf, -1); gfx_text_color(0.75f, 0.75f, 0.75f, 1); str_format(buf, sizeof(buf), "Syntax: %s %s", console->command->name, console->command->params); gfx_text_ex(&info.cursor, buf, -1); } } } gfx_text_color(1,1,1,1); // render log y -= row_height; char *entry = (char *)ringbuf_last(console->backlog); while (y > 0.0f && entry) { gfx_text(0, x, y, font_size, entry, -1); y -= row_height; entry = (char *)ringbuf_prev(console->backlog, entry); } } }