/* Function: wz_draw_single_text Draws a single line of text */ void wz_draw_single_text(float x, float y, float w, float h, int halign, int valign, ALLEGRO_COLOR color, ALLEGRO_FONT* font, ALLEGRO_USTR* text) { float xpos; float ypos; float height = al_get_font_line_height(font); if (valign == WZ_ALIGN_TOP) { ypos = y; } else if (valign == WZ_ALIGN_BOTTOM) { ypos = y + h - height; } else { ypos = y + h / 2 - height / 2; } if (halign == WZ_ALIGN_LEFT) { xpos = x; al_draw_ustr(font, color, floorf(xpos), floorf(ypos), ALLEGRO_ALIGN_LEFT, text); } else if (halign == WZ_ALIGN_RIGHT) { xpos = x + w; al_draw_ustr(font, color, floorf(xpos), floorf(ypos), ALLEGRO_ALIGN_RIGHT, text); } else { xpos = x + w / 2; al_draw_ustr(font, color, floorf(xpos), floorf(ypos), ALLEGRO_ALIGN_CENTRE, text); } }
void framerate::renderFPS() { //Renders the FPS al_draw_filled_rectangle(0,0,32,16,al_map_rgba_f(0,0,0,0.5)); al_draw_rectangle(1,1,31,15,al_map_rgba_f(1,1,1,0.7),1); al_draw_ustr(FPSRenderFont,al_map_rgb(255,255,255),6,2,0,FPSText); ALLEGRO_USTR* nS = al_ustr_newf("%i",networking::gameServer::getLatency()); al_draw_ustr(FPSRenderFont,al_map_rgb(255,255,255),6,16,0,nS); al_ustr_free(nS); }
void Inputbox_view::Render(const Widget& widget) const { const Inputbox& inputbox = dynamic_cast<const Inputbox&>(widget); Vector2 p = widget.Get_position(); Vector2 s = widget.Get_size(); ALLEGRO_COLOR text_color = al_map_rgb_f(0, 0, 0); ALLEGRO_COLOR bg_color = al_map_rgb_f(1, 1, 1); ALLEGRO_COLOR edge_color = al_map_rgb_f(0.5, 0.5, 0.5); al_draw_filled_rectangle(p.x, p.y+1, p.x+s.x-1, p.y+s.y, bg_color); al_draw_rectangle(p.x, p.y+1, p.x+s.x-1, p.y+s.y, edge_color, 0); int y = p.y + 3; int x = p.x + 3; const Ustring& text = inputbox.Get_text(); if(inputbox.Has_focus()) { int sel_s = inputbox.Get_selection_start(); int sel_e = inputbox.Get_selection_end(); int cp_s = font->Get_ustr_width(text.Substring(0, sel_s).Astring()); int cp_e = font->Get_ustr_width(text.Substring(0, sel_e).Astring()); int h = al_get_font_line_height(font->Afont()); if(sel_s != sel_e) al_draw_filled_rectangle(x+cp_s-1, y, x+cp_e, y+h, al_map_rgb_f(0.5, 0.5, 1)); else if(cursor_flash>0) al_draw_line(x+cp_e-1, y, x+cp_e, y+h, al_map_rgb_f(0, 0, 0), 0); } al_draw_ustr(font->Afont(), text_color, x, y, 0, text.Astring()); }
void TextEntry::draw() { const Theme & theme = dialog->get_theme(); SaveState state; ALLEGRO_COLOR bg = theme.bg; if (is_disabled()) { bg = al_map_rgb(64, 64, 64); } al_draw_filled_rectangle(x1, y1, x2, y2, bg); al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA); if (!focused) { al_draw_ustr(theme.font, theme.fg, x1, y1, 0, UString(text, left_pos)); } else { int x = x1; if (cursor_pos > 0) { UString sub(text, left_pos, cursor_pos); al_draw_ustr(theme.font, theme.fg, x1, y1, 0, sub); x += al_get_ustr_width(theme.font, sub); } if ((unsigned) cursor_pos == al_ustr_size(text)) { al_draw_filled_rectangle(x, y1, x + CURSOR_WIDTH, y1 + al_get_font_line_height(theme.font), theme.fg); } else { int post_cursor = cursor_pos; al_ustr_next(text, &post_cursor); UString sub(text, cursor_pos, post_cursor); int subw = al_get_ustr_width(theme.font, sub); al_draw_filled_rectangle(x, y1, x + subw, y1 + al_get_font_line_height(theme.font), theme.fg); al_draw_ustr(theme.font, theme.bg, x, y1, 0, sub); x += subw; al_draw_ustr(theme.font, theme.fg, x, y1, 0, UString(text, post_cursor)); } } }
void DrawingInterfaceAllegro5::draw_ustr_chr(int32_t ustr_char, float x, float y, float align_x, float align_y, ALLEGRO_COLOR color, std::string font_family, float font_size, ALLEGRO_FONT *font) { if (!font) return; ALLEGRO_USTR *ustr = al_ustr_new(""); al_ustr_set_chr(ustr, 0, ustr_char); al_draw_ustr(font, color, x, y - al_get_font_ascent(font), ALLEGRO_FLAGS_EMPTY, ustr); al_ustr_free(ustr); }
void MenuItem::DrawMenuItem(ALLEGRO_FONT* font) { al_draw_text(font, al_map_rgb(255, 255, 255), menuItemX_, menuItemY_, ALLEGRO_ALIGN_CENTRE, menuItemText_.c_str()); if (menuItemPropertyU_ != nullptr) { al_draw_ustr(font, al_map_rgb(255, 255, 255), menuItemPropertyX_, menuItemY_, ALLEGRO_ALIGN_LEFT, menuItemPropertyU_); } }
void TextEntry::draw() { const Theme & theme = dialog->get_theme(); SaveState state; al_draw_filled_rectangle(x1, y1, x2, y2, theme.bg); al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, theme.fg); if (!focused) { al_draw_ustr(theme.font, x1, y1, 0, UString(text, left_pos)); } else { int x = x1; if (cursor_pos > 0) { UString sub(text, left_pos, cursor_pos); al_draw_ustr(theme.font, x1, y1, 0, sub); x += al_get_ustr_width(theme.font, sub); } if (cursor_pos == text.size()) { al_draw_filled_rectangle(x, y1, x + CURSOR_WIDTH, y1 + al_get_font_line_height(theme.font), theme.fg); } else { UString sub(text, cursor_pos, 1); al_set_blender(ALLEGRO_ADD, ALLEGRO_INVERSE_ALPHA, ALLEGRO_ALPHA, theme.fg); al_draw_ustr(theme.font, x, y1, 0, sub); x += al_get_ustr_width(theme.font, sub); al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA, theme.fg); al_draw_ustr(theme.font, x, y1, 0, UString(text, cursor_pos + 1)); } } }
void shal_draw_ustr(ALLEGRO_FONT const * font, float color_r, float color_g, float color_b, float color_a, float x, float y, int flags, ALLEGRO_USTR const * ustr) { ALLEGRO_COLOR color; color.r = color_r; color.g = color_g; color.b = color_b; color.a = color_a; return al_draw_ustr(font, color, x, y, flags, ustr); }
void SpritesBlitSprite(int num, int clip, int x, int y, int width, int height, int centerX, int centerY, double angle, int a, int flip) { if (Sprite[num].text == NULL) { if (Sprite[num].texture != NULL) { al_draw_tinted_scaled_rotated_bitmap_region(Sprite[num].texture, Sprite[num].clip[clip].x, Sprite[num].clip[clip].y, Sprite[num].clip[clip].w, Sprite[num].clip[clip].h, al_map_rgba(255 * a / 255, 255 * a / 255, 255 * a / 255, 255 * a / 255), centerX, centerY, x, y, width / Sprite[num].clip[clip].w, height / Sprite[num].clip[clip].h, angle, 0); } } else { al_draw_ustr(Fonts.font[Sprite[num].fontNum], al_map_rgba(Sprite[num].textR * a / 255, Sprite[num].textG * a / 255, Sprite[num].textB * a / 255, 255 * a / 255), x, y, ALLEGRO_ALIGN_INTEGER, (const ALLEGRO_USTR *)Sprite[num].text); } }
/* Print some text with a shadow. */ static void print(int x, int y, bool vertical, char const *format, ...) { va_list list; char message[1024]; ALLEGRO_COLOR color; int h; int j; va_start(list, format); vsnprintf(message, sizeof message, format, list); va_end(list); al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA); h = al_get_font_line_height(ex.myfont); for (j = 0; j < 2; j++) { if (j == 0) color = al_map_rgb(0, 0, 0); else color = al_map_rgb(255, 255, 255); if (vertical) { int i; ALLEGRO_USTR_INFO ui; const ALLEGRO_USTR *us = al_ref_cstr(&ui, message); for (i = 0; i < (int)al_ustr_length(us); i++) { ALLEGRO_USTR_INFO letter; al_draw_ustr(ex.myfont, color, x + 1 - j, y + 1 - j + h * i, 0, al_ref_ustr(&letter, us, al_ustr_offset(us, i), al_ustr_offset(us, i + 1))); } } else { al_draw_text(ex.myfont, color, x + 1 - j, y + 1 - j, 0, message); } } }
void Dropdown_menu_view::Render(const Widget& widget) const { const Dropdown_menu& dropdown_menu = dynamic_cast<const Dropdown_menu&>(widget); Vector2 p = widget.Get_position(); Vector2 s = widget.Get_size(); ALLEGRO_COLOR text_color = al_map_rgb_f(1, 1, 1); ALLEGRO_COLOR tri_color = al_map_rgb_f(1, 1, 1); ALLEGRO_COLOR edge_color = al_map_rgb_f(0.5, 0.5, 0.5); ALLEGRO_COLOR select_color = al_map_rgb_f(0.0, 0, 0.8); //const Ustring& text = dropdown_menu.Get_text(); float h = al_get_font_line_height(font->Afont()); Menu *child = dynamic_cast<Menu*>(dropdown_menu.Get_child()); if(child) { const Ustring& text = child->Get_option(child->Get_selected_option()); float text_width = font->Get_ustr_width(text.Astring()); al_draw_ustr(font->Afont(), text_color, p.x+6+h/2, p.y+3, 0, text.Astring()); } float top = h*0.25; float middle = h*0.5; float bottom = h*0.75; if(dropdown_menu.Is_open()) { al_draw_filled_triangle(p.x+3, p.y+3+middle, p.x+3+middle, p.y+3+middle, p.x+3+top, p.y+3+bottom, tri_color); al_draw_triangle (p.x+3, p.y+3+middle, p.x+3+middle, p.y+3+middle, p.x+3+top, p.y+3+bottom, edge_color, 0); } else { al_draw_filled_triangle(p.x+3, p.y+3+top, p.x+3+top, p.y+3+middle, p.x+3, p.y+3+bottom, tri_color); al_draw_triangle (p.x+3, p.y+3+top, p.x+3+top, p.y+3+middle, p.x+3, p.y+3+bottom, edge_color, 0); } }
static void render(void) { ALLEGRO_COLOR white = al_map_rgba_f(1, 1, 1, 1); ALLEGRO_COLOR black = al_map_rgba_f(0, 0, 0, 1); ALLEGRO_COLOR red = al_map_rgba_f(1, 0, 0, 1); ALLEGRO_COLOR green = al_map_rgba_f(0, 0.5, 0, 1); ALLEGRO_COLOR blue = al_map_rgba_f(0.1, 0.2, 1, 1); ALLEGRO_COLOR purple = al_map_rgba_f(0.3, 0.1, 0.2, 1); int x, y, w, h, as, de, xpos, ypos; unsigned int index; int target_w, target_h; ALLEGRO_USTR_INFO info, sub_info; const ALLEGRO_USTR *u; ALLEGRO_USTR *tulip = al_ustr_new("Tulip"); ALLEGRO_USTR *dimension_text = al_ustr_new("Tulip"); ALLEGRO_USTR *vertical_text = al_ustr_new("Rose."); al_clear_to_color(white); al_hold_bitmap_drawing(true); al_draw_textf(ex.f1, black, 50, 20, 0, "Tulip (kerning)"); al_draw_textf(ex.f2, black, 50, 80, 0, "Tulip (no kerning)"); x = 50; y = 140; for (index = 0; index < al_ustr_length(dimension_text); index ++) { int cp = ustr_at(dimension_text, index); int bbx, bby, bbw, bbh; al_get_glyph_dimensions(ex.f2, cp, &bbx, &bby, &bbw, &bbh); al_draw_rectangle(x + bbx + 0.5, y + bby + 0.5, x + bbx + bbw - 0.5, y + bby + bbh - 0.5, blue, 1); al_draw_rectangle(x + 0.5, y + 0.5, x + bbx + bbw - 0.5, y + bby + bbh - 0.5, green, 1); al_draw_glyph(ex.f2, purple, x, y, cp); x += al_get_glyph_advance(ex.f2, cp, ALLEGRO_NO_KERNING); } al_draw_line(50.5, y+0.5, x+0.5, y+0.5, red, 1); al_draw_textf(ex.f2, black, x + 10, y, 0, "(dimensions)"); al_draw_textf(ex.f3, black, 50, 200, 0, "This font has a size of 12 pixels, " "the one above has 48 pixels."); al_hold_bitmap_drawing(false); al_hold_bitmap_drawing(true); al_draw_textf(ex.f3, red, 50, 220, 0, "The color can simply be changed.🐊← fallback glyph"); al_hold_bitmap_drawing(false); al_hold_bitmap_drawing(true); al_draw_textf(ex.f3, green, 50, 240, 0, "Some unicode symbols:"); al_draw_textf(ex.f3, green, 50, 260, 0, "%s", get_string("symbols1")); al_draw_textf(ex.f3, green, 50, 280, 0, "%s", get_string("symbols2")); al_draw_textf(ex.f3, green, 50, 300, 0, "%s", get_string("symbols3")); #define OFF(x) al_ustr_offset(u, x) #define SUB(x, y) al_ref_ustr(&sub_info, u, OFF(x), OFF(y)) u = al_ref_cstr(&info, get_string("substr1")); al_draw_ustr(ex.f3, green, 50, 320, 0, SUB(0, 6)); u = al_ref_cstr(&info, get_string("substr2")); al_draw_ustr(ex.f3, green, 50, 340, 0, SUB(7, 11)); u = al_ref_cstr(&info, get_string("substr3")); al_draw_ustr(ex.f3, green, 50, 360, 0, SUB(4, 11)); u = al_ref_cstr(&info, get_string("substr4")); al_draw_ustr(ex.f3, green, 50, 380, 0, SUB(0, 11)); al_draw_textf(ex.f5, black, 50, 395, 0, "forced monochrome"); /* Glyph rendering tests. */ al_draw_textf(ex.f3, red, 50, 410, 0, "Glyph adv Tu: %d, draw: ", al_get_glyph_advance(ex.f3, 'T', 'u')); x = 50; y = 425; for (index = 0; index < al_ustr_length(tulip); index ++) { int cp = ustr_at(tulip, index); /* Use al_get_glyph_advance for the stride, with no kerning. */ al_draw_glyph(ex.f3, red, x, y, cp); x += al_get_glyph_advance(ex.f3, cp, ALLEGRO_NO_KERNING); } x = 50; y = 440; /* First draw a red string using al_draw_text, that should be hidden * completely by the same text drawing in green per glyph * using al_draw_glyph and al_get_glyph_advance below. */ al_draw_ustr(ex.f3, red, x, y, 0, tulip); for (index = 0; index < al_ustr_length(tulip); index ++) { int cp = ustr_at(tulip, index); int ncp = (index < (al_ustr_length(tulip) - 1)) ? ustr_at(tulip, index + 1) : ALLEGRO_NO_KERNING; /* Use al_get_glyph_advance for the stride and apply kerning. */ al_draw_glyph(ex.f3, green, x, y, cp); x += al_get_glyph_advance(ex.f3, cp, ncp); } x = 50; y = 466; al_draw_ustr(ex.f3, red, x, y, 0, tulip); for (index = 0; index < al_ustr_length(tulip); index ++) { int cp = ustr_at(tulip, index); int bbx, bby, bbw, bbh; al_get_glyph_dimensions(ex.f3, cp, &bbx, &bby, &bbw, &bbh); al_draw_glyph(ex.f3, blue, x, y, cp); x += bbx + bbw; } x = 10; y = 30; for (index = 0; index < al_ustr_length(vertical_text); index ++) { int bbx, bby, bbw, bbh; int cp = ustr_at(vertical_text, index); /* Use al_get_glyph_dimensions for the height to apply. */ al_get_glyph_dimensions(ex.f3, cp, &bbx, &bby, &bbw, &bbh); al_draw_glyph(ex.f3, green, x, y, cp); y += bby; y += bbh; } x = 30; y = 30; for (index = 0; index < al_ustr_length(vertical_text); index ++) { int bbx, bby, bbw, bbh; int cp = ustr_at(vertical_text, index); /* Use al_get_glyph_dimensions for the height to apply, here bby is * omited for the wrong result. */ al_get_glyph_dimensions(ex.f3, cp, &bbx, &bby, &bbw, &bbh); al_draw_glyph(ex.f3, red, x, y, cp); y += bbh; } al_hold_bitmap_drawing(false); target_w = al_get_bitmap_width(al_get_target_bitmap()); target_h = al_get_bitmap_height(al_get_target_bitmap()); xpos = target_w - 10; ypos = target_h - 10; al_get_text_dimensions(ex.f4, "Allegro", &x, &y, &w, &h); as = al_get_font_ascent(ex.f4); de = al_get_font_descent(ex.f4); xpos -= w; ypos -= h; x += xpos; y += ypos; al_draw_rectangle(x, y, x + w - 0.5, y + h - 0.5, black, 0); al_draw_line(x+0.5, y + as + 0.5, x + w - 0.5, y + as + 0.5, black, 0); al_draw_line(x + 0.5, y + as + de + 0.5, x + w - 0.5, y + as + de + 0.5, black, 0); al_hold_bitmap_drawing(true); al_draw_textf(ex.f4, blue, xpos, ypos, 0, "Allegro"); al_hold_bitmap_drawing(false); al_hold_bitmap_drawing(true); al_draw_textf(ex.f3, black, target_w, 0, ALLEGRO_ALIGN_RIGHT, "%.1f FPS", ex.fps); al_draw_textf(ex.f3, black, 0, 0, 0, "%s: %d unicode ranges", font_file, ex.ranges_count); al_hold_bitmap_drawing(false); }
static void render(void) { ALLEGRO_COLOR white = al_map_rgba_f(1, 1, 1, 1); ALLEGRO_COLOR black = al_map_rgba_f(0, 0, 0, 1); ALLEGRO_COLOR red = al_map_rgba_f(1, 0, 0, 1); ALLEGRO_COLOR green = al_map_rgba_f(0, 0.5, 0, 1); ALLEGRO_COLOR blue = al_map_rgba_f(0.1, 0.2, 1, 1); int x, y, w, h, as, de, xpos, ypos; int target_w, target_h; ALLEGRO_USTR_INFO info, sub_info; const ALLEGRO_USTR *u; al_clear_to_color(white); al_hold_bitmap_drawing(true); al_draw_textf(ex.f1, black, 50, 50, 0, "Tulip (kerning)"); al_draw_textf(ex.f2, black, 50, 100, 0, "Tulip (no kerning)"); al_draw_textf(ex.f3, black, 50, 200, 0, "This font has a size of 12 pixels, " "the one above has 48 pixels."); al_hold_bitmap_drawing(false); al_hold_bitmap_drawing(true); al_draw_textf(ex.f3, red, 50, 220, 0, "The color can simply be changed."); al_hold_bitmap_drawing(false); al_hold_bitmap_drawing(true); al_draw_textf(ex.f3, green, 50, 240, 0, "Some unicode symbols:"); al_draw_textf(ex.f3, green, 50, 260, 0, "%s", get_string("symbols1")); al_draw_textf(ex.f3, green, 50, 280, 0, "%s", get_string("symbols2")); al_draw_textf(ex.f3, green, 50, 300, 0, "%s", get_string("symbols3")); #define OFF(x) al_ustr_offset(u, x) #define SUB(x, y) al_ref_ustr(&sub_info, u, OFF(x), OFF(y)) u = al_ref_cstr(&info, get_string("substr1")); al_draw_ustr(ex.f3, green, 50, 320, 0, SUB(0, 6)); u = al_ref_cstr(&info, get_string("substr2")); al_draw_ustr(ex.f3, green, 50, 340, 0, SUB(7, 11)); u = al_ref_cstr(&info, get_string("substr3")); al_draw_ustr(ex.f3, green, 50, 360, 0, SUB(4, 11)); u = al_ref_cstr(&info, get_string("substr4")); al_draw_ustr(ex.f3, green, 50, 380, 0, SUB(0, 11)); al_draw_textf(ex.f5, black, 50, 420, 0, "forced monochrome"); al_hold_bitmap_drawing(false); target_w = al_get_bitmap_width(al_get_target_bitmap()); target_h = al_get_bitmap_height(al_get_target_bitmap()); xpos = target_w - 10; ypos = target_h - 10; al_get_text_dimensions(ex.f4, "Allegro", &x, &y, &w, &h); as = al_get_font_ascent(ex.f4); de = al_get_font_descent(ex.f4); xpos -= w; ypos -= h; x += xpos; y += ypos; al_draw_rectangle(x, y, x + w, y + h, black, 0); al_draw_line(x, y + as, x + w, y + as, black, 0); al_draw_line(x, y + as + de, x + w, y + as + de, black, 0); al_hold_bitmap_drawing(true); al_draw_textf(ex.f4, blue, xpos, ypos, 0, "Allegro"); al_hold_bitmap_drawing(false); al_hold_bitmap_drawing(true); al_draw_textf(ex.f3, black, target_w, 0, ALLEGRO_ALIGN_RIGHT, "%.1f FPS", ex.fps); al_hold_bitmap_drawing(false); }
/** Draws text using this font. @param x target x coordinate. @param y target y coordinate. @param flags flags. @param color color. @param text string to draw. */ void draw(float x, float y, int flags, ALLEGRO_COLOR color, const String &text) const { al_draw_ustr(get(), color, x, y, flags, text.get()); }
/* {{{ Addon.Font: */ void al_draw_ustr_w(const ALLEGRO_FONT *font, ALLEGRO_COLOR *color, float x, float y, int flags, ALLEGRO_USTR const *ustr) { al_draw_ustr(font, *color, x, y, flags, ustr); }