static void listview_recompute_elements ( listview *lv ) { unsigned int newne = 0; if ( lv->max_rows == 0 ) { return; } if ( lv->req_elements < lv->max_elements ) { newne = lv->req_elements; lv->cur_columns = ( lv->req_elements + ( lv->max_rows - 1 ) ) / lv->max_rows; } else { newne = lv->max_elements; lv->cur_columns = lv->menu_columns; } for ( unsigned int i = newne; i < lv->cur_elements; i++ ) { widget_free ( WIDGET ( lv->boxes[i] ) ); } lv->boxes = g_realloc ( lv->boxes, newne * sizeof ( textbox* ) ); if ( newne > 0 ) { for ( unsigned int i = lv->cur_elements; i < newne; i++ ) { TextboxFlags flags = ( lv->multi_select ) ? TB_INDICATOR : 0; char *name = g_strjoin ( ".", lv->listview_name, "element", NULL ); lv->boxes[i] = textbox_create ( name, flags, NORMAL, "" ); g_free ( name ); } } lv->rchanged = TRUE; lv->cur_elements = newne; }
void state_menu_init(void *ptr) { glClearColor(0, 0, 0, 1); textbox_t *textbox_title = textbox_create( 50, 10, 300, 100, "BLOCKS", TEXTBOX_COLOR_GREEN, TEXTBOX_FONT_ROBOTO_BOLDITALIC, TEXTBOX_FONT_SIZE_HUGE, 0); textbox_play = textbox_create( 50, 100, 120, 32, "Play!", TEXTBOX_COLOR_BLUE, TEXTBOX_FONT_ROBOTO_REGULAR, TEXTBOX_FONT_SIZE_MEDIUM, TEXTBOX_FLAG_CENTER_V); textbox_load = textbox_create( 50, 130, 120, 32, "Load", TEXTBOX_COLOR_BLUE, TEXTBOX_FONT_ROBOTO_REGULAR, TEXTBOX_FONT_SIZE_MEDIUM, TEXTBOX_FLAG_CENTER_V); textbox_quit = textbox_create( 50, 190, 120, 32, "Quit", TEXTBOX_COLOR_BLUE, TEXTBOX_FONT_ROBOTO_REGULAR, TEXTBOX_FONT_SIZE_MEDIUM, TEXTBOX_FLAG_CENTER_V); ui = interface_create(0); interface_attach_textbox(ui, textbox_title); ui_play = interface_attach_textbox(ui, textbox_play); ui_load = interface_attach_textbox(ui, textbox_load); ui_quit = interface_attach_textbox(ui, textbox_quit); }
listview *listview_create ( const char *name, listview_update_callback cb, void *udata, unsigned int eh, gboolean reverse ) { listview *lv = g_malloc0 ( sizeof ( listview ) ); gchar *box = g_strjoin ( ".", name, "box", NULL ); widget_init ( WIDGET ( lv ), box ); g_free ( box ); lv->listview_name = g_strdup ( name ); lv->widget.free = listview_free; lv->widget.resize = listview_resize; lv->widget.draw = listview_draw; lv->widget.clicked = listview_clicked; lv->widget.motion_notify = listview_motion_notify; lv->widget.get_desired_height = listview_get_desired_height; lv->widget.enabled = TRUE; lv->eh = eh; char *n = g_strjoin ( ".", lv->listview_name, "scrollbar", NULL ); lv->scrollbar = scrollbar_create ( n ); // Default position on right. lv->scrollbar->widget.index = rofi_theme_get_integer_exact ( WIDGET ( lv->scrollbar ), "index", 1 ); g_free ( n ); widget_set_clicked_handler ( WIDGET ( lv->scrollbar ), listview_scrollbar_clicked, lv ); lv->scrollbar->widget.parent = WIDGET ( lv ); // Calculate height of an element. // char *tb_name = g_strjoin ( ".", lv->listview_name, "element", NULL ); textbox *tb = textbox_create ( tb_name, 0, NORMAL, "" ); lv->element_height = textbox_get_estimated_height ( tb, lv->eh ); g_free ( tb_name ); widget_free ( WIDGET ( tb ) ); lv->callback = cb; lv->udata = udata; // Some settings. lv->spacing = rofi_theme_get_distance ( WIDGET ( lv ), "spacing", DEFAULT_SPACING ); lv->menu_columns = rofi_theme_get_integer ( WIDGET ( lv ), "columns", config.menu_columns ); lv->fixed_num_lines = rofi_theme_get_boolean ( WIDGET ( lv ), "fixed-height", config.fixed_num_lines ); lv->dynamic = rofi_theme_get_boolean ( WIDGET ( lv ), "dynamic", TRUE ); lv->reverse = rofi_theme_get_boolean ( WIDGET ( lv ), "reverse", reverse ); listview_set_show_scrollbar ( lv, rofi_theme_get_boolean ( WIDGET ( lv ), "scrollbar", !config.hide_scrollbar ) ); lv->cycle = rofi_theme_get_boolean ( WIDGET ( lv ), "cycle", config.cycle ); return lv; }
// display a text message void message_box(int delay, int x, int y, char *fgc, char *bgc, char *bc, char *txt) { workarea mon; monitor_dimensions_struts(x, y, &mon); if (fork()) return; display = XOpenDisplay(0x0); box *b = box_create(root, BOX_OVERRIDE, 0, 0, 1, 1, config_title_bg); textbox *text = textbox_create(b->window, TB_CENTER | TB_AUTOHEIGHT | TB_AUTOWIDTH, 8, 5, 1, 1, config_title_font, config_title_fg, config_title_bg, txt, NULL); box_moveresize(b, MIN(mon.x + mon.w - text->w - 26, MAX(mon.x + 26, x - text->w / 2)), MIN(mon.y + mon.h - text->h - 20, MAX(mon.y + 20, y - text->h / 2)), text->w + 16, text->h + 10); XSelectInput(display, b->window, ExposureMask); textbox_show(text); box_show(b); double stamp = timestamp(); while ((timestamp() - stamp) < (double) delay / 1000) { if (XPending(display)) { XEvent ev; XNextEvent(display, &ev); if (ev.type == Expose) textbox_draw(text); } usleep(10000); // 10ms } textbox_free(text); box_free(b); exit(EXIT_SUCCESS); }
void state_game_init(void *ptr) { if(!world_is_initalized()) { error("state_game started before world_init()"); state_queue_fail(); return; } pos = world_get_player(); state_window_get_size(&windoww, &windowh); //load shaders 'n stuff gl_program_load_file(&drawprogram, "shaders/vs", "shaders/fs"); gl_program_load_file(&ppprogram, "shaders/pvs", "shaders/pfs"); modelmatrix = glGetUniformLocation(drawprogram, "MODEL"); viewprojectionmatrix = glGetUniformLocation(drawprogram, "VP"); postprocess_uniform_tex = glGetUniformLocation(ppprogram, "tex"); postprocess_uniform_depth = glGetUniformLocation(ppprogram, "depth"); postprocess_uniform_window_szie = glGetUniformLocation(ppprogram, "window_size"); //generate the post processing framebuffer glGenFramebuffers(1, &renderbuffer.framebuffer); glBindFramebuffer(GL_FRAMEBUFFER, renderbuffer.framebuffer); glGenTextures(1, &renderbuffer.colorbuffer); glGenTextures(1, &renderbuffer.depthbuffer); glBindTexture(GL_TEXTURE_2D, renderbuffer.colorbuffer); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, windoww, windowh, 0, GL_RGB, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glBindTexture(GL_TEXTURE_2D, renderbuffer.depthbuffer); glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT24, windoww, windowh, 0, GL_DEPTH_COMPONENT, GL_FLOAT, 0); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, renderbuffer.colorbuffer, 0); glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, renderbuffer.depthbuffer, 0); //put the textures in thr right spots glUseProgram(ppprogram); GLuint tex = glGetUniformLocation(ppprogram, "tex"); GLuint depth = glGetUniformLocation(ppprogram, "depth"); glUniform1i(tex, 0); glUniform1i(depth, 1); //generate the post processing mesh GLfloat mesh[] = { -1.0f, 1.0f, -1.0f, -1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f, 1.0f, 1.0f, -1.0f }; glGenBuffers(1, &pppointbuffer); glBindBuffer(GL_ARRAY_BUFFER, pppointbuffer); glBufferData(GL_ARRAY_BUFFER, sizeof(mesh) * sizeof(GLfloat), mesh, GL_STATIC_DRAW); if(glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) fail("Bad Framebuffer"); rotx = 0; roty = 0; posptr = entity_pos_get_ptr(pos); vec3_t friction = {PLAYER_FRICTION,PLAYER_FRICTION,PLAYER_FRICTION}; entity_friction_set(pos, friction); state_mouse_center(); SDL_ShowCursor(0); ticks = SDL_GetTicks(); updatesem = SDL_CreateSemaphore(0); updatethread = SDL_CreateThread(updatethreadfunc, "updatethread", 0); textbox_fps = textbox_create(10, 10, 200, 100, "0fps", 0, TEXTBOX_FONT_ROBOTO_REGULAR, TEXTBOX_FONT_SIZE_MEDIUM, 0); }
int main ( int argc, char **argv ) { // Get DISPLAY const char *display_str = getenv ( "DISPLAY" ); if ( !( display = XOpenDisplay ( display_str ) ) ) { fprintf ( stderr, "cannot open display!\n" ); return EXIT_FAILURE; } TASSERT( display != NULL ); Screen *screen = DefaultScreenOfDisplay ( display ); Window root = RootWindow ( display, XScreenNumberOfScreen ( screen ) ); Window mw = XCreateSimpleWindow ( display, root, 0, 0, 200, 100, config.menu_bw, color_get ( display, config.menu_bc ), color_get ( display, config.menu_bg ) ); TASSERT( mw != None ); textbox_setup ( config.menu_bg, config.menu_fg, config.menu_hlbg, config.menu_hlfg ); textbox *box = textbox_create(mw , TB_EDITABLE|TB_AUTOWIDTH|TB_AUTOHEIGHT, 0,0, -1, -1, NORMAL, "test"); TASSERT( box != NULL ); textbox_cursor_end ( box ); TASSERT ( box->cursor == 4); textbox_cursor ( box, -1 ); TASSERT ( box->cursor == 0 ); textbox_cursor ( box, 8 ); TASSERT ( box->cursor == 4 ); textbox_cursor ( box, 2 ); TASSERT ( box->cursor == 2 ); textbox_insert ( box, 3, "bo"); TASSERT ( strcmp(box->text, "tesbot") == 0 ); textbox_cursor_end ( box ); TASSERT ( box->cursor == 6); TASSERT( textbox_get_width( box) > 0 ); TASSERT( textbox_get_height( box) > 0 ); TASSERT( textbox_get_width( box) >= textbox_get_font_width( box) ); TASSERT( textbox_get_height( box) >= textbox_get_font_height( box) ); TASSERT( textbox_get_estimated_char_width ( box) > 0 ); textbox_cursor_bkspc ( box ); TASSERT ( strcmp(box->text, "tesbo") == 0 ); TASSERT ( box->cursor == 5); textbox_cursor_dec ( box ); TASSERT ( box->cursor == 4); textbox_cursor_del ( box ); TASSERT ( strcmp(box->text, "tesb") == 0 ); textbox_cursor_dec ( box ); TASSERT ( box->cursor == 3); textbox_cursor_inc ( box ); TASSERT ( box->cursor == 4); textbox_cursor_inc ( box ); TASSERT ( box->cursor == 4); // Cursor after delete section. textbox_delete ( box, 0, 1 ); TASSERT ( strcmp(box->text, "esb") == 0 ); TASSERT ( box->cursor == 3); // Cursor before delete. textbox_text( box, "aap noot mies"); TASSERT ( strcmp(box->text, "aap noot mies") == 0 ); textbox_cursor( box, 3 ); TASSERT ( box->cursor == 3); textbox_delete ( box, 3, 6 ); TASSERT ( strcmp(box->text, "aapmies") == 0 ); TASSERT ( box->cursor == 3); // Cursor within delete textbox_text( box, "aap noot mies"); TASSERT ( strcmp(box->text, "aap noot mies") == 0 ); textbox_cursor( box, 5 ); TASSERT ( box->cursor == 5); textbox_delete ( box, 3, 6 ); TASSERT ( strcmp(box->text, "aapmies") == 0 ); TASSERT ( box->cursor == 3); // Cursor after delete. textbox_text( box, "aap noot mies"); TASSERT ( strcmp(box->text, "aap noot mies") == 0 ); textbox_cursor( box, 11 ); TASSERT ( box->cursor == 11); textbox_delete ( box, 3, 6 ); TASSERT ( strcmp(box->text, "aapmies") == 0 ); TASSERT ( box->cursor == 5); textbox_font ( box, HIGHLIGHT ); textbox_draw( box ); textbox_show( box ); textbox_move ( box, 12, 13); TASSERT ( box->x == 12 ); TASSERT ( box->y == 13 ); textbox_hide( box ); textbox_free(box); textbox_cleanup(); XDestroyWindow ( display, mw); XCloseDisplay ( display ); }