void RenderTarget::drawText(const ALLEGRO_FONT *font, const ISString &text, float x, float y, const ALLEGRO_COLOR &color, int flags) {
	setAsCurrent();
	convertCoords(x, y);
	if ((flags & Center) == Center) {
		al_draw_text(font, color, x, y - al_get_font_ascent(font) * 0.5f, ALLEGRO_ALIGN_CENTRE, text.getUtf8Encoded().c_str());
		return;
	}
	if ((flags & VCenter) == VCenter) {
		y -= al_get_font_ascent(font) * 0.5f;
	}
	else if ((flags & Bottom) == Bottom) {
		y -= al_get_font_ascent(font);
	}
	if ((flags & HCenter) == HCenter) {
		al_draw_text(
			font,
			color,
			x,
			y,
			ALLEGRO_ALIGN_CENTRE,
			text.getUtf8Encoded().c_str()
		);
		return;
	}
	if ((flags & Right) == Right) {
		al_draw_text(font, color, x, y, ALLEGRO_ALIGN_RIGHT, text.getUtf8Encoded().c_str());
		return;
	}
	al_draw_text(font, color, x, y, 0, text.getUtf8Encoded().c_str());
}
Beispiel #2
0
void LoadGame(Heroi *Heroi)
{
	FILE *Load;
	Load = fopen("SaveLoadGame/SaveLoadGame.bin", "r");

	al_clear_to_color(al_map_rgb(0, 0, 0));
	if (!Load)
	{
		al_draw_text(Fonte, al_map_rgb(255, 255, 255), (LARGURA_TELA / 2 - al_get_font_ascent(Fonte)), (ALTURA_TELA / 2 - al_get_font_ascent(Fonte)), ALLEGRO_ALIGN_CENTRE, "Nenhum Save Game Encontrado...");
		al_flip_display();
		al_rest(3.0);
	}
	else
	{
		al_draw_text(Fonte, al_map_rgb(255, 255, 255), (LARGURA_TELA / 2 - al_get_font_ascent(Fonte)), (ALTURA_TELA / 2 - al_get_font_ascent(Fonte)), ALLEGRO_ALIGN_CENTRE, "Carregando Jogo...");
		al_flip_display();
		al_rest(3.0);
	}

	fscanf(Load, "%d", &IDMapa);
	fscanf(Load, "%d", &Heroi->x);
	fscanf(Load, "%d", &Heroi->y);
	fscanf(Load, "%d", &Heroi->LinhaAnimacao);
	fscanf(Load, "%d", &Heroi->ColunaAnimacao);
	fscanf(Load, "%d", &Heroi->Life);
	fscanf(Load, "%d", &Heroi->MaxLife);
	fscanf(Load, "%d", &Heroi->Mana);
	fscanf(Load, "%d", &Heroi->MaxMana);
	fscanf(Load, "%d", &Heroi->QtdVida);
	fscanf(Load, "%d", &Heroi->QtdMana);

	fclose(Load);
}
void DrawingInterfaceAllegro5::draw_text(std::string text, 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;
   int flags = 0;
   if (basically_equal(align_x, 0)) flags = ALLEGRO_FLAGS_EMPTY;
   al_draw_text(font, color, x, y - al_get_font_ascent(font), flags, text.c_str());
}
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);
}
Beispiel #5
0
		int Font::get_text_line_length(void)
		{
			RAGE_CHECK_DISPOSED_RET(disposed, 0);

			if (font == nullptr)
				return 0;

			return al_get_font_ascent(font);
		}
Beispiel #6
0
InputField::InputField(std::string font_path, std::string init_string, int x, int y, int width, int height,
                       ALLEGRO_COLOR outline, ALLEGRO_COLOR textcolor, ALLEGRO_COLOR backgroundcolor)
                      : x1(x), y1(y), width(width), height(height), outline_color(outline), text_color(textcolor), bckground_color(backgroundcolor)
{
    x2 = x1 + width;
    y2 = y1 + height;

    int font_size = ((float)height / 5.0) * 4.0;

    font = al_load_ttf_font(font_path.c_str(), font_size, 0);


    if(font == nullptr)
    {
        al_show_native_message_box(NULL, "Error", "Failed to load font!", font_path.c_str(), NULL, ALLEGRO_MESSAGEBOX_ERROR);
    }

    text = init_string;
    text_width =  al_get_text_width(font, text.c_str());
    text_height = al_get_font_ascent(font);

    //al_set_new_bitmap_flags(ALLEGRO_MAG_LINEAR);  //alredy called in main
    bmp = al_create_bitmap(width, height);
    al_set_target_bitmap(bmp);
    al_clear_to_color(bckground_color);
    al_set_target_backbuffer(al_get_current_display());

    detectingbutton = new Button(x1, y1, x2, y2);

    al_text = al_ustr_new(text.c_str());

    as_bitmap = al_create_bitmap(width, height);

    x = x1;
    y = y1;

    origin_x1 = x1;
    origin_y1 = y1;
    origin_x2 = x2;
    origin_y2 = y2;
}
Beispiel #7
0
void SpritesChangeText(int num, char *text, int fontnum, int text_r, int text_g,
                       int text_b, int wrapLength)
{
    Sprite[num].text = al_ustr_new((const char *)text);
    Sprite[num].fontNum = fontnum;
    Sprite[num].textR = text_r;
    Sprite[num].textG = text_g;
    Sprite[num].textB = text_b;
    Sprite[num].wrapLength = wrapLength;

    Sprite[num].width =  al_get_text_width((const ALLEGRO_FONT *)Fonts.font[fontnum], (const char *)text);
    Sprite[num].height = al_get_font_ascent((const ALLEGRO_FONT *)Fonts.font[fontnum]);
    /* обнуляем поверхность спрайта */
    Sprite[num].texture = NULL;
    /* разбиваем спрайтшит на кадры */
    Sprite[num].clip[0].x = 0;
    Sprite[num].clip[0].y = 0;
    Sprite[num].clip[0].w = Sprite[Sprites.spritesCount - 1].width;
    Sprite[num].clip[0].h = Sprite[Sprites.spritesCount - 1].height;

    Sprite[num].clipsCount = 1;
}
Beispiel #8
0
int SpritesCreateText(char *text, int fontnum, int text_r, int text_g,
                      int text_b, int wrapLength)
{
    Sprite[Sprites.spritesCount].name = malloc(sizeof(char) * (strlen(text) + 1));
    Sprite[Sprites.spritesCount].name = strcpy(Sprite[Sprites.spritesCount].name,
                                               (const char *)text);
    LogWrite("Dummying text sprite", 0, MT_INFO,
             Sprite[Sprites.spritesCount].name);

    Sprites.spritesCount += 1; /* Увеличиваем кол-во спрайтов на 1 */

    Sprite[Sprites.spritesCount - 1].text = al_ustr_new((const char *)text);
    Sprite[Sprites.spritesCount - 1].fontNum = fontnum;
    Sprite[Sprites.spritesCount - 1].textR = text_r;
    Sprite[Sprites.spritesCount - 1].textG = text_g;
    Sprite[Sprites.spritesCount - 1].textB = text_b;
    Sprite[Sprites.spritesCount - 1].wrapLength = wrapLength;

    Sprite[Sprites.spritesCount - 1].width =  al_get_ustr_width((const ALLEGRO_FONT *)Fonts.font[fontnum], Sprite[Sprites.spritesCount - 1].text);
    Sprite[Sprites.spritesCount - 1].height = al_get_font_ascent((const ALLEGRO_FONT *)Fonts.font[fontnum]);
    /* обнуляем поверхность спрайта */
    Sprite[Sprites.spritesCount - 1].texture = NULL;

    /* устанавливаем число кадров для спрайта - для текста 1 кадр */
    Sprite[Sprites.spritesCount - 1].clip = malloc(sizeof(Rect) * 1);
    /* разбиваем спрайтшит на кадры */
    Sprite[Sprites.spritesCount - 1].clip[0].x = 0;
    Sprite[Sprites.spritesCount - 1].clip[0].y = 0;
    Sprite[Sprites.spritesCount - 1].clip[0].w = Sprite[Sprites.spritesCount - 1].width;
    Sprite[Sprites.spritesCount - 1].clip[0].h = Sprite[Sprites.spritesCount - 1].height;

    Sprite[Sprites.spritesCount - 1].clipsCount = 1;

    LogWrite("Text sprite dummied", 0, MT_INFO, NULL);

    return Sprites.spritesCount - 1;
}
Beispiel #9
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);
}
Beispiel #10
0
void PauseGame()
{
	bool pause;

	FadeOut(5, 150);
	pause = true;

	ALLEGRO_EVENT evento;
	ALLEGRO_TIMEOUT timeout;
	al_init_timeout(&timeout, 0.05);

	al_draw_text(Fonte, al_map_rgb(255, 255, 255), (cameraPosition[0] + LARGURA_TELA / 2 - al_get_font_ascent(Fonte)), (cameraPosition[1] + ALTURA_TELA / 2 - al_get_font_ascent(Fonte)), ALLEGRO_ALIGN_CENTRE, "Pause Game! Pressione Enter.");
	al_flip_display();
	while (pause)
	{
		int tem_eventos = al_wait_for_event_until(Fila_Eventos, &evento, &timeout);
		if (tem_eventos)
		{
			if (evento.keyboard.keycode == ALLEGRO_KEY_ENTER)
			{
				pause = false;
			}
		}
	}
	redraw = true;
}
Beispiel #11
0
void SaveGame(Mapas Mapa, Heroi Heroi)
{
	bool salvando;

	FadeOut(5, 150);
	salvando = true;

	ALLEGRO_EVENT evento;
	ALLEGRO_TIMEOUT timeout;
	al_init_timeout(&timeout, 0.05);

	FILE *save;
	save = fopen("SaveLoadGame/SaveLoadGame.bin", "w");

	fprintf(save, "%d\n", Mapa.ID);
	fprintf(save, "%d\n", Heroi.x);
	fprintf(save, "%d\n", Heroi.y);
	fprintf(save, "%d\n", Heroi.LinhaAnimacao);
	fprintf(save, "%d\n", Heroi.ColunaAnimacao);
	fprintf(save, "%d\n", Heroi.Life);
	fprintf(save, "%d\n", Heroi.MaxLife);
	fprintf(save, "%d\n", Heroi.Mana);
	fprintf(save, "%d\n", Heroi.MaxMana);
	fprintf(save, "%d\n", Heroi.QtdVida);
	fprintf(save, "%d\n", Heroi.QtdMana);

	fclose(save);

	al_draw_text(Fonte, al_map_rgb(255, 255, 255), (cameraPosition[0] + LARGURA_TELA / 2 - al_get_font_ascent(Fonte)), (cameraPosition[1] + ALTURA_TELA / 2 - al_get_font_ascent(Fonte)), ALLEGRO_ALIGN_CENTRE, "Jogo Salvo. Preciso Enter!");
	al_flip_display();

	while (salvando)
	{
		int tem_eventos = al_wait_for_event_until(Fila_Eventos, &evento, &timeout);
		if (tem_eventos)
		{
			if (evento.keyboard.keycode == ALLEGRO_KEY_ENTER)
			{
				salvando = 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);
}
Beispiel #13
0
 /**
     Returns the font ascent.
     @return the font ascent.
  */
 int getAscent() const {
     return al_get_font_ascent(get());
 }