void menu_draw(Entity *ent) { MenuEntityData *data = entity_data(ent); if (data->logo) { draw_sprite(data->logo, -0.4, 0.35, 6, 0); } draw_textf(game.default_font, al_map_rgb(255, 255, 255), 0, 0, MENU_FONT_SIZE, TEXT_HALIGN_RIGHT, "IP: "); textbox_draw(&data->server, 0, 0); draw_textf(game.default_font, al_map_rgb(255, 255, 255), 0, -1, MENU_FONT_SIZE, TEXT_HALIGN_RIGHT, "PORT: "); textbox_draw(&data->port, 0, -1); draw_textf( game.default_font, al_map_rgb(255, 255, 255), 0, -3, MENU_FONT_SIZE, TEXT_HALIGN_CENTER, "Aperte ENTER para conectar" ); draw_textf( game.default_font, al_map_rgb(255, 255, 255), 0, -4.5, MENU_FONT_SIZE / 2, TEXT_HALIGN_CENTER, "Código e sprites por Leonardo Giovanni Scur" ); }
static int mud_drawMain( lua_State* L ) { PRETEND_TO_USE( L ); textbox_draw( UI.textMain ); return 0; }
static int mud_drawChat( lua_State* L ) { PRETEND_TO_USE( L ); textbox_draw( UI.textChat ); return 0; }
void spot_update_bar(int spot, int mon) { int i, n = 0, len = 0; client *o, *c = NULL; char title[SPOT_BUFF]; *title = 0; monitor *m = &monitors[mon]; if (spot == SPOT1) { // Show X root window name in spot1 bar // Use xsetroot -name for a custom status char *tmp = NULL; if (XFetchName(display, root, &tmp)) len += snprintf(title+len, MAX(0, SPOT_BUFF-len), " %s ", tmp); if (tmp) XFree(tmp); } for_windows(i, o) if (o->manage && o->spot == spot && o->monitor == mon) { if (!c) c = o; char *name = NULL, *tmp = NULL; if (!(name = window_get_text_prop(o->window, atoms[_NET_WM_NAME]))) if (XFetchName(display, o->window, &tmp)) name = strdup(tmp); if (name) { if (TITLE_ELLIPSIS > 0 && strlen(name) > TITLE_ELLIPSIS) { name = realloc(name, strlen(name)+4); strcpy(name+TITLE_ELLIPSIS, "..."); } len += snprintf(title+len, MAX(0, SPOT_BUFF-len), " [%d] %s ", n++, name); free(name); } if (tmp) XFree(tmp); } if (TITLE) { if (c && !c->full && *title && m->bars[spot]) { int focus = c->window == current || (spot == current_spot && mon == current_mon); char *color = focus && c->window == current ? TITLE_FOCUS : TITLE_BLUR; char *border = focus && c->window == current ? BORDER_FOCUS: BORDER_BLUR; textbox_font(m->bars[spot], TITLE, color, border); textbox_text(m->bars[spot], title); textbox_draw(m->bars[spot]); textbox_show(m->bars[spot]); } else if (m->bars[spot]) textbox_hide(m->bars[spot]); } }
// 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); }
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 ); }