int m_text_height(const MFONT *font) { if (font != game_font) { return al_get_font_line_height(font); } return al_get_font_line_height(font) / (screenScaleX < screenScaleY ? (screenScaleX / textScaleX) : (screenScaleY / textScaleY)); }
void hyperlink_page_centre(HYPERLINK_PAGE * pp, float oy, float my) { int i; float top = 1000.0; float bottom = 0.0; int top_i; int bottom_i; float dheight = my - oy; float height; float offset; for(i = 0; i < pp->elements; i++) { if(pp->element[i].oy < top) { top = pp->element[i].oy; top_i = i; } if(pp->element[i].oy + al_get_font_line_height((ALLEGRO_FONT *)pp->element[i].aux_data) > bottom) { bottom = pp->element[i].oy + al_get_font_line_height((ALLEGRO_FONT *)pp->element[i].aux_data); bottom_i = i; } } height = bottom - top; offset = oy + dheight / 2.0 - height / 2.0; pp->oy = offset - top; }
SettingsStage::SettingsStage() { titleFont = al_load_font( GAME_FONT, 32, 0 ); titleFontHeight = al_get_font_line_height( titleFont ); itemFont = al_load_font( GAME_FONT, 24, 0 ); itemFontHeight = al_get_font_line_height( itemFont ); selectedItem = 0; scrollPosition = 0; }
/* Run the FPS test. */ static void run(void) { ALLEGRO_EVENT event; int frames = 0; double start; target = al_create_bitmap(W, H); al_set_target_bitmap(target); al_clear_to_color(al_map_rgba_f(1, 1, 0, 1)); al_set_target_backbuffer(display); dx = 81; dy = 63; start = al_get_time(); while (true) { /* Check for ESC key or close button event and quit in either case. */ if (!al_is_event_queue_empty(queue)) { while (al_get_next_event(queue, &event)) { switch (event.type) { case ALLEGRO_EVENT_DISPLAY_CLOSE: quit = true; goto done; case ALLEGRO_EVENT_KEY_DOWN: if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE) { quit = true; goto done; } if (event.keyboard.keycode == ALLEGRO_KEY_SPACE) { goto done; } break; } } } draw(); print(0, 0, "FPS: %.1f", frames / (al_get_time() - start)); if (al_get_new_bitmap_flags() & ALLEGRO_FORCE_LOCKING) { print(0, al_get_font_line_height(myfont), "using forced bitmap locking"); } else { print(0, al_get_font_line_height(myfont), "drawing directly to bitmap"); } print(0, al_get_font_line_height(myfont) * 2, "Press SPACE to toggle drawing method."); al_flip_display(); frames++; } done: al_destroy_bitmap(target); }
static void draw(void) { int x, y, offx, offy; float c = 1; static char logo_text1[] = "Allegro"; static char logo_text2[] = ""; /* XXX commented out because the font doesn't contain the characters for * anything other than "Allegro 4.2" */ /* static char logo_text2[] = "5.0"; */ if (progress < 0.5f) { c = progress / 0.5f; al_clear_to_color(al_map_rgb_f(c, c, c)); } else { if (!already_played_midi) { play_music(DEMO_MIDI_INTRO, 0); already_played_midi = 1; } c = 1; al_clear_to_color(al_map_rgb_f(c, c, c)); x = screen_width / 2; y = screen_height / 2 - 3 * al_get_font_line_height(demo_font_logo) / 2; offx = 0; if (progress < 1.0f) { offx = (int)(al_get_text_width(demo_font_logo, logo_text1) * (1.0f - 2.0f * (progress - 0.5f))); } demo_textprintf_centre(demo_font_logo, x + 6 - offx, y + 5, al_map_rgba_f(0.125, 0.125, 0.125, 0.25), logo_text1); demo_textprintf_centre(demo_font_logo, x - offx, y, al_map_rgba_f(1, 1, 1, 1), logo_text1); if (progress >= 1.5f) { y += 3 * al_get_font_line_height(demo_font_logo) / 2; offy = 0; if (progress < 2.0f) { offy = (int)((screen_height - y) * (1.0f - 2.0f * (progress - 1.5f))); } demo_textprintf_centre(demo_font_logo, x + 6, y + 5 + offy, al_map_rgba_f(0.125, 0.125, 0.125, 0.25), logo_text2); demo_textprintf_centre(demo_font_logo, x, y + offy, al_map_rgba_f(1, 1, 1, 1), logo_text2); } } }
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 Allegro5Font::reload( const std::string &fileName, int height , FontFlags fontFlags, float borderWidth, agui::Color borderColor ) { if (font) free(); font = al_load_font(fileName.c_str(),height,ALLEGRO_TTF_NO_KERNING | fontFlags); if(!font && fileName != "") { throw Exception("Allegro5 Failed to load font"); } if(font) { #ifdef AGUI_TTF_BORDER_SUPPORT if (allegroFontFlags & ALLEGRO_TTF_RENDER_BORDER) { al_set_ttf_border(this->font, borderWidth, al_map_rgb(borderColor.getR()*255, borderColor.getG()*255, borderColor.getB()*255)); } #endif this->height = height; lineHeight = al_get_font_line_height(font); autoFree = true; } else { this->height = 0; lineHeight = 0; autoFree = false; } }
/* ---------------------------------------------------------------------------- * Draws the textbox. It's basically a rectangle with a border. * The border is drawn line by line. Finally, it draws the * text within. */ void textbox::draw_self() { al_draw_filled_rectangle(x1, y1, x2, y2, get_bg_color()); draw_line(this, DRAW_LINE_TOP, 0, 1, 0, get_darker_bg_color()); // Top line. draw_line(this, DRAW_LINE_LEFT, 0, 1, 0, get_darker_bg_color()); // Left line. draw_line(this, DRAW_LINE_BOTTOM, 1, 0, 0, get_lighter_bg_color()); // Bottom line. draw_line(this, DRAW_LINE_RIGHT, 1, 0, 0, get_lighter_bg_color()); // Right line. if(style->text_font) { int text_start = x1 + 2 - scroll_x; if(parent->focused_widget == this) { al_draw_filled_rectangle( text_start + al_get_text_width(style->text_font, text.substr(0, min(sel_start, sel_end)).c_str()), y1 + 2, text_start + al_get_text_width(style->text_font, text.substr(0, max(sel_start, sel_end)).c_str()), y2 - 2, get_alt_color() ); } al_draw_text(style->text_font, get_fg_color(), text_start, (y2 + y1) / 2 - al_get_font_line_height(style->text_font) / 2, 0, text.c_str()); unsigned int cursor_x = al_get_text_width(style->text_font, text.substr(0, cursor).c_str()); if(parent->focused_widget == this) { al_draw_line( x1 + cursor_x + 1.5 - scroll_x, y1 + 2, x1 + cursor_x + 1.5 - scroll_x, y2 - 2, get_alt_color(), 1); } } }
/* 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); } }
static void redraw(void) { ALLEGRO_COLOR color; int w = al_get_display_width(display); int h = al_get_display_height(display); int pw = al_get_bitmap_width(picture); int ph = al_get_bitmap_height(picture); int th = al_get_font_line_height(font); float cx = (w - pw) * 0.5; float cy = (h - ph) * 0.5; ALLEGRO_COLOR white = al_map_rgb_f(1, 1, 1); color = al_map_rgb_f(0.8, 0.7, 0.9); al_clear_to_color(color); color = al_map_rgb(255, 0, 0); al_draw_line(0, 0, w, h, color, 0); al_draw_line(0, h, w, 0, color, 0); al_draw_bitmap(picture, cx, cy, 0); al_draw_textf(font, white, w / 2, cy + ph, ALLEGRO_ALIGN_CENTRE, "Press Space to toggle fullscreen"); al_draw_textf(font, white, w / 2, cy + ph + th, ALLEGRO_ALIGN_CENTRE, "Press Enter to toggle window size"); al_draw_textf(font, white, w / 2, cy + ph + th * 2, ALLEGRO_ALIGN_CENTRE, "Window: %dx%d (%s)", al_get_display_width(display), al_get_display_height(display), (al_get_display_flags(display) & ALLEGRO_FULLSCREEN_WINDOW) ? "fullscreen" : "not fullscreen"); al_flip_display(); }
void Button::draw() { const Theme & theme = this->dialog->get_theme(); ALLEGRO_COLOR fg; ALLEGRO_COLOR bg; SaveState state; double y; if (this->pushed) { fg = theme.bg; bg = theme.fg; } else { fg = theme.fg; bg = theme.bg; } if (is_disabled()) { bg = al_map_rgb(64, 64, 64); } al_draw_filled_rectangle(this->x1, this->y1, this->x2, this->y2, bg); al_draw_rectangle(this->x1 + 0.5, this->y1 + 0.5, this->x2 - 0.5, this->y2 - 0.5, fg, 0); al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA); /* Center the text vertically in the button, taking the font size * into consideration. */ y = (this->y1 + this->y2 - al_get_font_line_height(theme.font) - 1) / 2; al_draw_text(theme.font, fg, (this->x1 + this->x2 + 1)/2, y, ALLEGRO_ALIGN_CENTRE, this->text.c_str()); }
Menu * inicializa_menu(ALLEGRO_FONT * fonte, int largura_jogo, int altura_jogo, int n_botoes, const char* titulo) { Menu * menu = (Menu * ) malloc(sizeof(Menu)); menu->largura = largura_jogo; menu->altura = altura_jogo; menu->buffer = al_create_bitmap(largura_jogo, altura_jogo); menu->numero_botoes = n_botoes; menu->botoes = (Botao * * ) malloc(sizeof(Botao * ) * n_botoes); menu->botao_selecionado = 0; menu->fonte = fonte; menu->x_botoes = largura_jogo / 2; int botoes_y_offset = al_get_font_line_height(fonte) + altura_jogo / 24; menu->y_botoes = (int * ) malloc(sizeof(int) * n_botoes); if (titulo) { inicializa_titulo(menu, largura_jogo, titulo); for (int i = 0; i < menu->numero_botoes; i++) menu->y_botoes[i] = menu->titulo_pos_y + al_get_bitmap_height(menu->titulo) + BORDA + botoes_y_offset * i; } else { for (int i = 0; i < menu->numero_botoes; i++) menu->y_botoes[i] = BORDA + botoes_y_offset * i; menu->titulo = NULL; } return menu; }
void dot_credits_render(void * data, float ox) { APP_INSTANCE * app = (APP_INSTANCE *)data; int i; float pos_y; float pos_ox; al_hold_bitmap_drawing(true); dot_bg_objects_render(data); for(i = 0; i < 540 / 32; i++) { al_draw_bitmap(app->bitmap[DOT_BITMAP_BALL_RED + i % 6], i * 32 + 18 + ox, sin((float)(i * 4 + app->tick) / 10.0) * 32 + 32 + 12, 0); al_draw_bitmap(app->bitmap[DOT_BITMAP_BALL_RED + (i + 3) % 6], i * 32 + 18 + ox, cos((float)(i * 4 + app->tick) / 10.0) * 32 + DOT_GAME_PLAYFIELD_HEIGHT - 32 - 32 - 12 - 1, 0); } al_hold_bitmap_drawing(false); if(app->credits.state != DOT_CREDITS_STATE_WAIT) { if(app->credits.current_credit < app->credits.credits) { pos_y = DOT_GAME_PLAYFIELD_HEIGHT / 2.0 - ((app->credits.credit[app->credits.current_credit].names + 1) * al_get_font_line_height(app->font[DOT_FONT_32])) / 2.0; dot_shadow_text(app->font[DOT_FONT_32], al_map_rgba_f(1.0, 1.0, 0.0, 1.0), al_map_rgba_f(0.0, 0.0, 0.0, 0.5), t3f_virtual_display_width / 2 + app->credits.ox + ox, pos_y, DOT_SHADOW_OX * 2, DOT_SHADOW_OY * 2, ALLEGRO_ALIGN_CENTRE, app->credits.credit[app->credits.current_credit].header); for(i = 0; i < app->credits.credit[app->credits.current_credit].names; i++) { pos_y += al_get_font_line_height(app->font[DOT_FONT_32]); pos_ox = i % 2 ? app->credits.ox : -app->credits.ox; dot_shadow_text(app->font[DOT_FONT_32], t3f_color_white, al_map_rgba_f(0.0, 0.0, 0.0, 0.5), t3f_virtual_display_width / 2 + pos_ox + ox, pos_y, DOT_SHADOW_OX * 2, DOT_SHADOW_OY * 2, ALLEGRO_ALIGN_CENTRE, app->credits.credit[app->credits.current_credit].name[i]); } } } }
void List::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 + 1, y1 + 1, x2 - 1, y2 - 1, bg); al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA); const int font_height = al_get_font_line_height(theme.font); for (unsigned i = 0; i < items.size(); i++) { int yi = y1 + i * font_height; if (i == selected_item) { al_draw_filled_rectangle(x1 + 1, yi, x2 - 1, yi + font_height - 1, theme.highlight); } al_draw_text(theme.font, theme.fg, x1, yi, 0, items.at(i).c_str()); } }
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 draw_button(BUTTONPTR currentptr) { const int c = 2, d = 2, x = 0, y = 0; nscale(); static ALLEGRO_BITMAP *newbitm = NULL; if(newbitm == NULL) newbitm = al_create_bitmap(currentptr->bimage->width, currentptr->bimage->height); al_set_target_bitmap(newbitm); al_clear_to_color(al_map_rgba(0, 0, 0, 0)); if((currentptr->bdata.bflags & BDRAW) && !(currentptr->bdata.bflags & BLPRESSED)) { al_draw_tinted_bitmap(currentptr->bimage->button_image, currentptr->bdata.b_color, x, y, 0); al_draw_text(currentptr->btext.text_f, currentptr->btext.text_c, currentptr->bimage->width/d, currentptr->bimage->height/d-al_get_font_line_height(currentptr->btext.text_f)/d, ALLEGRO_ALIGN_CENTRE, currentptr->btext.text ); } else if((currentptr->bdata.bflags & BDRAW) && (currentptr->bdata.bflags & BLPRESSED)) { al_draw_tinted_bitmap(currentptr->bimage->button_image, currentptr->bdata.b_color, x, y, ALLEGRO_FLIP_VERTICAL); al_draw_text(currentptr->btext.text_f, currentptr->btext.text_c, currentptr->bimage->width/d+c, currentptr->bimage->height/d-al_get_font_line_height(currentptr->btext.text_f)/d+c, ALLEGRO_ALIGN_CENTRE, currentptr->btext.text ); } else { al_draw_tinted_bitmap(currentptr->bimage->button_image, currentptr->bdata.b_color, x, y, 0); al_draw_text(currentptr->btext.text_f, currentptr->btext.text_c, currentptr->bimage->width/d, currentptr->bimage->height/d-al_get_font_line_height(currentptr->btext.text_f)/d, ALLEGRO_ALIGN_CENTRE, currentptr->btext.text ); } scale(800.0, 600.0); al_set_target_backbuffer(get_game_data()->display); al_draw_bitmap(newbitm, currentptr->bdata.x, currentptr->bdata.y, 0); }
House::House( City* Owner, bool HasDevice ) { owner = Owner; hasdevice = HasDevice; itemFont = al_load_font( "resources/names.ttf", 22, 0 ); itemFontHeight = al_get_font_line_height( itemFont ); }
float Dropdown_menu_view::Get_value(int id, const Widget& widget) const { if(id == Dropdown_menu::SELF_HEIGHT) { return al_get_font_line_height(font->Afont()) + 6; } return 0; }
void Button::Render() { al_draw_text(_Font, Hover ? HOVER_COLOR : Pressed ? CLICKED_COLOR : Enabled ? ENABLED_COLOR : DISABLED_COLOR, _X,_Y, ALLEGRO_ALIGN_CENTER, _Text.c_str()); #ifdef DEBUG al_draw_rectangle(_X + (al_get_text_width(_Font, _Text.c_str()) / 2) + 2.5f, _Y + 7, _X - (al_get_text_width(_Font, _Text.c_str()) / 2), _Y + (al_get_font_line_height(_Font) - 9), DEBUG_COLOR, 2); #endif }
// width_factor is the preferred width (portion of the screen width), but if text won't fit // it will increase width until it fits void draw_center_text_box(ALLEGRO_FONT *font, ALLEGRO_COLOR text_color, ALLEGRO_COLOR bg_color, ALLEGRO_COLOR bd_color, float width_factor, const char *text){ int dw = al_get_bitmap_width(al_get_target_bitmap()); int dh = al_get_bitmap_height(al_get_target_bitmap()); float factor=width_factor; int w,h; if(!font) return; do{ w=dw*factor; h = get_multiline_text_lines(font, w-40, text) * al_get_font_line_height(font) + 30; factor += 0.05; }while( (h > dh*0.9) && (factor < 1) ); al_draw_filled_rectangle((dw-w)/2, (dh-h)/2, (dw+w)/2, (dh+h)/2, bg_color); al_draw_rectangle((dw-w)/2, (dh-h)/2, (dw+w)/2, (dh+h)/2, bd_color, 3); al_draw_multiline_text(font, text_color, (dw-w+40)/2, (dh-h+30)/2, w-30, al_get_font_line_height(font), ALLEGRO_ALIGN_LEFT, text); }
Vector2 Inputbox_view::Request_size(const Widget& widget) const { const Inputbox& inputbox = dynamic_cast<const Inputbox&>(widget); const Ustring& text = inputbox.Get_text(); Vector2 size; size.x = font->Get_ustr_width(text.Astring()) + 6; size.y = al_get_font_line_height(font->Afont()) + 6; return size; }
void SpeakingAgent::draw() { // store state placement2d::start_transform(); // background al_draw_filled_rectangle(0, 0, size.x, size.y, color::hex("319cff")); // mouth ALLEGRO_BITMAP *mouth_shape = _get_phoneme_image(Speaker::get_current_phoneme()); if (mouth_shape) al_draw_bitmap(mouth_shape, 0, 10, NULL); // eyes float eye_y = size.y/4; float eye_r = 2.3; float eye_1x = size.x/4; float eye_2x = size.x/4 * 3; if (blink_counter < 0.1) { al_draw_line(eye_1x-eye_r*2, eye_y, eye_1x+eye_r*2, eye_y, color::black, eye_r); al_draw_line(eye_2x-eye_r*2, eye_y, eye_2x+eye_r*2, eye_y, color::black, eye_r); if (blink_counter < 0.0) blink_counter = random_double(2.0, 6.0); } else { al_draw_filled_circle(eye_1x, eye_y, eye_r, color::black); al_draw_filled_circle(eye_2x, eye_y, eye_r, color::black); } blink_counter -= 1.0/60; // words float bx = size.x+size.x/4; float by = -size.y/3; float bw = size.x*2.5; float bh = size.y*0.8; float border_radius = 7; al_draw_filled_rounded_rectangle(bx, by, bx+bw, by+bh, border_radius, border_radius, color::white); float tx = bx+border_radius*4; float ty = by+bh-1; float ts = 20; al_draw_filled_triangle(tx, ty, tx+ts, ty, tx, ty+ts, color::white); std::string word = Speaker::get_current_word(); ALLEGRO_FONT *font = fonts["lacuna.ttf 26"]; if (is_paused()) word = "[PAUSED]"; if (font) al_draw_text(font, color::black, bx+bw/2, by+bh/2-al_get_font_line_height(font)/2, ALLEGRO_ALIGN_CENTRE, word.c_str()); // show stream # //al_draw_text(font, color::white, 0, 0, NULL, tostring(voice->get_current_stream()).c_str()); // restore state placement2d::restore_transform(); //draw_crosshair(x, y, color::white); }
static void print(char const *format, ...) { va_list list; char message[1024]; int th = al_get_font_line_height(ex.font); va_start(list, format); vsnprintf(message, sizeof message, format, list); va_end(list); al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA); al_draw_textf(ex.font, ex.text, ex.text_x, ex.text_y, 0, "%s", message); ex.text_y += th; }
static void redraw(void) { int w = al_get_display_width(example.display); int h = al_get_display_height(example.display); int i; int f1, f2; int fh = al_get_font_line_height(example.font); char const *info[] = {"textures", "memory buffers"}; char const *binfo[] = {"alpha", "additive", "tinted", "solid"}; ALLEGRO_COLOR tint = example.white; if (example.blending == 0) { al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA); tint = example.half_white; } else if (example.blending == 1) { al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ONE); tint = example.dark; } else if (example.blending == 2) { al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO); tint = example.red; } else if (example.blending == 3) al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO); for (i = 0; i < example.sprite_count; i++) { Sprite *s = example.sprites + i; al_draw_tinted_bitmap(example.bitmap, tint, s->x, s->y, 0); } al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA); if (example.show_help) { for (i = 0; i < 5; i++) al_draw_text(example.font, example.white, 0, h - 10 * fh + i * fh * 2 + fh * 0.5, 0, text[i]); } al_draw_textf(example.font, example.white, 0, 0, 0, "count: %d", example.sprite_count); al_draw_textf(example.font, example.white, 0, fh, 0, "size: %d", example.bitmap_size); al_draw_textf(example.font, example.white, 0, fh * 2, 0, "%s", info[example.use_memory_bitmaps]); al_draw_textf(example.font, example.white, 0, fh * 3, 0, "%s", binfo[example.blending]); get_fps(&f1, &f2); al_draw_textf(example.font, example.white, w, 0, ALLEGRO_ALIGN_RIGHT, "FPS: %4d +- %-4d", f1, f2); al_draw_textf(example.font, example.white, w, fh, ALLEGRO_ALIGN_RIGHT, "%4d / sec", (int)(1.0 / example.direct_speed_measure)); }
void List::on_click(int mx, int my) { const Theme & theme = dialog->get_theme(); unsigned int i = (my - this->y1) / al_get_font_line_height(theme.font); if (i < this->items.size()) { this->selected_item = i; dialog->request_draw(); } (void)mx; (void)my; }
void show_info_text(Board *b, ALLEGRO_USTR *msg){ ALLEGRO_BITMAP *dispbuf = al_get_target_bitmap(); al_set_target_bitmap(NULL); ndestroy_bitmap(b->info_text_bmp); b->info_text_bmp = al_create_bitmap(b->info_panel.w, b->info_panel.h); al_set_target_bitmap(b->info_text_bmp); al_clear_to_color(b->info_panel.bg_color); al_draw_multiline_ustr(b->text_font, INFO_TEXT_COLOR, 10, 3, b->info_panel.w-2*al_get_font_line_height(b->text_font), al_get_font_line_height(b->text_font), ALLEGRO_ALIGN_LEFT, msg); b->info_panel.bmp = &b->info_text_bmp; // make it show in the info_panel al_set_target_bitmap(dispbuf); al_ustr_free(msg); }
void wz_def_draw_editbox(struct WZ_THEME* theme, float x, float y, float w, float h, int cursor_pos, ALLEGRO_USTR* text, int style) { WZ_DEF_THEME* thm = (WZ_DEF_THEME*)theme; int len = wz_get_text_pos(thm->font, text, w - 4); int cx,cy,cw,ch; int len2 = al_ustr_length(text); int offset; ALLEGRO_USTR_INFO info; ALLEGRO_USTR* token; ALLEGRO_COLOR border_col; ALLEGRO_COLOR text_col; len = len + 1 > len2 ? len2 : len + 1; offset = al_ustr_offset(text, len); token = al_ref_ustr(&info, text, 0, offset); border_col = thm->color1; text_col = thm->color2; if (style & WZ_STYLE_FOCUSED) { border_col = wz_scale_color(thm->color1, 1.5); } if (style & WZ_STYLE_DISABLED) { border_col = wz_scale_color(thm->color1, 0.5); text_col = wz_scale_color(thm->color2, 0.5); } wz_draw_3d_rectangle(x, y, x + w, y + h, 1, border_col, true); al_get_clipping_rectangle(&cx, &cy, &cw, &ch); al_set_clipping_rectangle(x + 2, y + 2, w - 4, h - 4); wz_draw_single_text(x + 2, y + 2, w - 4, h - 4, WZ_ALIGN_LEFT, WZ_ALIGN_CENTRE, text_col, thm->font, token); al_set_clipping_rectangle(cx, cy, cw, ch); if (style & WZ_STYLE_FOCUSED) { if (((int)(al_get_time() / 0.5f)) % 2 == 0) { float len; float halfheight; offset = al_ustr_offset(text, cursor_pos); token = al_ref_ustr(&info, text, 0, offset); len = al_get_ustr_width(thm->font, token); halfheight = al_get_font_line_height(thm->font) / 2.0f; al_draw_line(x + 2 + len, y + 2 + h / 2 - halfheight, x + 2 + len, y + 2 + h / 2 + halfheight, text_col, 1); } } }
void init_fonts() { int font_ranges[] = { 0x0020, 0x007E, // ASCII 0x00A0, 0x00A1, // Non-breaking space and inverted ! 0x00BF, 0x00FF, // Inverted ? and European vowels and such }; int counter_font_ranges[] = { 0x002D, 0x002D, // Dash 0x002F, 0x0039, // Slash and numbers 0x0078, 0x0078, // x }; int value_font_ranges[] = { 0x0024, 0x0024, // Dollar sign 0x002D, 0x002D, // Dash 0x0030, 0x0039, // Numbers }; // We can't load the font directly because we want to set the ranges. // So we load into a bitmap first. ALLEGRO_BITMAP* temp_font_bitmap = load_bmp("Font.png"); if(temp_font_bitmap) font = al_grab_font_from_bitmap(temp_font_bitmap, 3, font_ranges); al_destroy_bitmap(temp_font_bitmap); temp_font_bitmap = load_bmp("Area_name_font.png"); if(temp_font_bitmap) font_area_name = al_grab_font_from_bitmap(temp_font_bitmap, 3, font_ranges); al_destroy_bitmap(temp_font_bitmap); temp_font_bitmap = load_bmp("Counter_font.png"); if(temp_font_bitmap) font_counter = al_grab_font_from_bitmap(temp_font_bitmap, 3, counter_font_ranges); al_destroy_bitmap(temp_font_bitmap); temp_font_bitmap = load_bmp("Value_font.png"); if(temp_font_bitmap) font_value = al_grab_font_from_bitmap(temp_font_bitmap, 3, value_font_ranges); al_destroy_bitmap(temp_font_bitmap); if(font) font_h = al_get_font_line_height(font); if(font_counter) font_counter_h = al_get_font_line_height(font_counter); }
World::World() { std::string filename; int tilew; int tileh; textFont = al_load_font( "resources/names.ttf", 18, 0 ); textFontHeight = al_get_font_line_height( textFont ); mapData = new ConfigFile( "resources/easy.cfg" ); filename.clear(); filename.append( mapData->GetQuickStringValue( "Overworld.Tileset.File", "resources/easy_world_tiles.png" )->c_str() ); tilew = mapData->GetQuickIntegerValue( "Overworld.Tileset.TileSize", 0, 16 ); tileh = mapData->GetQuickIntegerValue( "Overworld.Tileset.TileSize", 1, 16 ); visualMapTiles = new SpriteSheet( filename, tilew, tileh ); visualMap = new TileMap( visualMapTiles, mapData->GetQuickIntegerValue( "Overworld.MapData.MapSize", 0, 16 ), mapData->GetQuickIntegerValue( "Overworld.MapData.MapSize", 1, 16 ) ); for( int y = 0; y < visualMap->GetHeight(); y++ ) { for( int x = 0; x < visualMap->GetWidth(); x++ ) { int tilev = mapData->GetQuickIntegerValue( "Overworld.MapData.TileMap", (y * visualMap->GetWidth()) + x, 0 ); visualMap->SetTile( x, y, tilev ); } } visualMapScale = new Vector2( FRAMEWORK->Display_GetWidth() / (float)(visualMap->GetWidth() * tilew), (FRAMEWORK->Display_GetHeight() - (textFontHeight * 3)) / (float)(visualMap->GetHeight() * tileh) ); filename.clear(); filename.append( mapData->GetQuickStringValue( "Overworld.SpriteSheet", "resources/easy_world_weather.png" )->c_str() ); tilew = mapData->GetQuickIntegerValue( "Overworld.SpriteSize", 0, 72 ); tileh = mapData->GetQuickIntegerValue( "Overworld.SpriteSize", 1, 72 ); visualSprites = new SpriteSheet( filename, tilew, tileh ); GenerateWeatherAnimations(); for( int c = 0; c < mapData->GetQuickIntegerValue( "Cities.Count", 0 ) ; c++ ) { Cities.push_back( new City( this, mapData, c ) ); } AgentWillis = new Willis( this, mapData ); ProfessorFrost = new Frost( this, mapData ); IsBetweenTurns = false; BetweenTurnFrame = 0; visualNavigationLineIndex = 0; visualNavigationDelay = 0; }
void Button::Update(ALLEGRO_EVENT *event) { if (Enabled) { if (event->type == ALLEGRO_EVENT_MOUSE_AXES) { Hover = ((event->mouse.x >= _X - (al_get_text_width(_Font, _Text.c_str()) / 2)) && (event->mouse.x <= _X + (al_get_text_width(_Font, _Text.c_str()) / 2) + 2.5f)) && ((event->mouse.y >= _Y + 7) && (event->mouse.y <= _Y + (al_get_font_line_height(_Font) - 9))); } if (event->type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN && Hover) _HandleFunction(); } else if (Pressed || Hover) { Pressed = false; Hover = false; } }