コード例 #1
0
/* ----------------------------------------------------------------------------
 * 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);
        }
    }
}
コード例 #2
0
static int m_text_length_real(const MFONT *font, const char *text)
{
	if (font != game_font) {
		return al_get_text_width(font, text);
	}
	return al_get_text_width(font, text) / (screenScaleX < screenScaleY ? (screenScaleX / textScaleX) : (screenScaleY / textScaleY));
}
コード例 #3
0
ファイル: button.cpp プロジェクト: tsteinholz/Hangman
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
}
コード例 #4
0
ファイル: Textbox.cpp プロジェクト: AdamGaik/kinf
void Textbox::draw()
{
    al_draw_filled_rectangle(AREA, al_map_rgba(255,255,255,1));

    [=]{ // Lambda rysująca text
        int length = (text == "" ? default_text : text).size();
        float x = area.x() + font_size;
        const float y = area.y() + font_size;
        for (int i = 0; i < text.size(); ++i) {
            if (x + al_get_text_width(font(font_size), (text == "" ? default_text : text).substr(0, i+1).c_str()) >= area.x2()) {
                length = i;
                break;
            }
        }
        string text_to_draw = (text == "" ? default_text : text).substr(0, length);
        if (text == "") {
            al_draw_text(font(font_size), Color(200,200,200), x, y, ALLEGRO_ALIGN_LEFT, text_to_draw.c_str());
            return;
        }
        pair<int,int> s;
        s.first = range(selection.first, 0, length);
        s.second = range(selection.second, 0, length);
        string t = text_to_draw.substr(0, s.first);
        al_draw_text(font(font_size), Color::black(), x, y, ALLEGRO_ALIGN_LEFT, t.c_str());
        x += al_get_text_width(font(font_size), t.c_str());
        t = text_to_draw.substr(s.first, s.second - s.first);
        al_draw_filled_rectangle(x, y, x+al_get_text_width(font(font_size), t.c_str()), y+font_size, color);
        al_draw_text(font(font_size), color.ifDark() ? Color::white() : Color::black(), x, y, ALLEGRO_ALIGN_LEFT, t.c_str());
        x += al_get_text_width(font(font_size), t.c_str());
        t = text_to_draw.substr(s.second);
        al_draw_text(font(font_size), Color::black(), x, y, ALLEGRO_ALIGN_LEFT, t.c_str());
    }();

    //al_draw_rectangle(area.x1()+font_size/2, area.y1()+font_size/2, area.x2()-font_size/2, area.y2()-font_size/2, Color::white(), font_size);
    al_draw_filled_rectangle(area.x2()-font_size, area.y1(), area.x2(), area.y2(), Color::white());

    al_draw_rectangle(AREA, Color::black(), 1);

    if (cs.getInvaded() || cs.getIsPressed() || active) {

        int x = 7;
        for (float i = 0; i < x; ++i) {
            al_draw_rectangle(area.x1()+i, area.y1()+i, area.x2()-i, area.y2()-i, Color(0, 0, 0, 255-255*((i*2)/x)), 1);
        }

        if (active) {

            al_draw_rectangle(AREA, color, 3);
            if (show_cursor) {
                al_draw_line(cursor_x(), area.y() + font_size, cursor_x(), area.y() + font_size*2, Color::black(), font_size/10);
            }
        }
    }
}
コード例 #5
0
ファイル: button.cpp プロジェクト: tsteinholz/Hangman
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;
    }
}
コード例 #6
0
ファイル: button.c プロジェクト: kiddos/billiard_ball
void button_draw(button *b) {
  int bitmap_width, bitmap_height, text_width;
  double sx, sy;

  // draw the button bitmap
  if (b->is_pressed) {
    bitmap_width = al_get_bitmap_width(b->pressed_bitmap);
    bitmap_height = al_get_bitmap_height(b->pressed_bitmap);
    al_draw_scaled_bitmap(b->pressed_bitmap, 0, 0,
                          bitmap_width, bitmap_height,
                          b->sx, b->sy, b->width, b->height, 0);
  } else if (b->is_hovered) {
    bitmap_width = al_get_bitmap_width(b->hover_bitmap);
    bitmap_height = al_get_bitmap_height(b->hover_bitmap);
    al_draw_scaled_bitmap(b->hover_bitmap, 0, 0,
                          bitmap_width, bitmap_height,
                          b->sx, b->sy, b->width, b->height, 0);
  } else {
    bitmap_width = al_get_bitmap_width(b->release_bitmap);
    bitmap_height = al_get_bitmap_height(b->release_bitmap);
    al_draw_scaled_bitmap(b->release_bitmap, 0, 0,
                          bitmap_width, bitmap_height,
                          b->sx, b->sy, b->width, b->height, 0);
  }

  if (b->with_text) {
    text_width = al_get_text_width(b->text_font, b->text);
    sx = (b->width - text_width) / 2.0 + b->sx;
    sy = (b->height * (1 - TEXT_SIZE_SCALE)) / 2.0 + b->sy;
    al_draw_text(b->text_font, b->text_color, sx, sy, 0, b->text);
  }
}
コード例 #7
0
ファイル: InputField.cpp プロジェクト: kruci/Juicy-Plebs
bool InputField::SetDefaultText(std::string default_text)
{
    text = default_text;
    text_width =  al_get_text_width(font, text.c_str()) + 7;

    return true;
}
コード例 #8
0
ファイル: Textbox.cpp プロジェクト: AdamGaik/kinf
int Textbox::mouse_position()
{
    if (mouse_x() <= area.x() + font_size) return 0;
    if (mouse_x() >= area.x() + font_size + al_get_text_width(font(font_size),text.c_str())) return text.size();
    for (int i = 0; i < text.size(); i++) {
        if (mouse_x() > area.x() + font_size + al_get_text_width(font(font_size),text.substr(0, i).c_str()) &&
            mouse_x() < area.x() + font_size + al_get_text_width(font(font_size),text.substr(0, i+1).c_str())) {
            if (al_get_text_width(font(font_size),text.substr(i, 1).c_str())/2 >
                mouse_x() - (area.x() + font_size + al_get_text_width(font(font_size),text.substr(0, i).c_str()))) {
                return i;
            } else {
                return i+1;
            }
        }
    }
}
コード例 #9
0
ファイル: font.c プロジェクト: trezker/allua
static int allua_Font_get_text_width(lua_State * L)
{
   ALLUA_font font = allua_check_font(L, 1);
   const char *text = luaL_checkstring(L, 2);
   lua_pushinteger(L, al_get_text_width(font, text));
   return 1;
}
コード例 #10
0
/* move current message until the position of the end is less than 0 */
void csd_process_message_queue(CSD_MESSAGE_QUEUE * qp, ALLEGRO_FONT * fp)
{
	int w;
	
	if(qp->messages > 0)
	{
		switch(qp->message[0].type)
		{
			case CSD_MESSAGE_SCROLL:
			{
				w = al_get_text_width(fp, qp->message[0].text);
				qp->message[0].pos -= 4;
				if(qp->message[0].pos + w < 0)
				{
					csd_remove_message(qp);
				}
				break;
			}
			case CSD_MESSAGE_FLASH:
			{
				qp->message[0].pos -= 4;
				if(qp->message[0].pos <= 0)
				{
					csd_remove_message(qp);
				}
				break;
			}
		}
	}
}
コード例 #11
0
ファイル: menu.c プロジェクト: dos1/TickleMonster
void About(struct Game *game, struct MenuResources* data) {
	ALLEGRO_TRANSFORM trans;
	al_identity_transform(&trans);
	al_use_transform(&trans);

	if (!game->_priv.font_bsod) {
		game->_priv.font_bsod = al_create_builtin_font();
	}

	al_set_target_backbuffer(game->display);
	al_clear_to_color(al_map_rgb(0,0,170));

	char *header = "TICKLE MONSTER";

	al_draw_filled_rectangle(al_get_display_width(game->display)/2 - al_get_text_width(game->_priv.font_bsod, header)/2 - 4, (int)(al_get_display_height(game->display) * 0.32), 4 + al_get_display_width(game->display)/2 + al_get_text_width(game->_priv.font_bsod, header)/2, (int)(al_get_display_height(game->display) * 0.32) + al_get_font_line_height(game->_priv.font_bsod), al_map_rgb(170,170,170));

	al_draw_text(game->_priv.font_bsod, al_map_rgb(0, 0, 170), al_get_display_width(game->display)/2, (int)(al_get_display_height(game->display) * 0.32), ALLEGRO_ALIGN_CENTRE, header);

	char *header2 = "A fatal exception 0xD3RP has occured at 0028:M00F11NZ in GST SD(01) +";

	al_draw_text(game->_priv.font_bsod, al_map_rgb(255,255,255), al_get_display_width(game->display)/2, (int)(al_get_display_height(game->display) * 0.32+2*al_get_font_line_height(game->_priv.font_bsod)*1.25), ALLEGRO_ALIGN_CENTRE, header2);
	al_draw_textf(game->_priv.font_bsod, al_map_rgb(255,255,255), al_get_display_width(game->display)/2 - al_get_text_width(game->_priv.font_bsod, header2)/2, (int)(al_get_display_height(game->display) * 0.32+3*al_get_font_line_height(game->_priv.font_bsod)*1.25), ALLEGRO_ALIGN_LEFT, "%p and system just doesn't know what went wrong.", (void*)game);

	al_draw_text(game->_priv.font_bsod, al_map_rgb(255,255,255), al_get_display_width(game->display)/2, (int)(al_get_display_height(game->display) * 0.32+5*al_get_font_line_height(game->_priv.font_bsod)*1.25), ALLEGRO_ALIGN_CENTRE, 	"About screen not implemented!");
	al_draw_text(game->_priv.font_bsod, al_map_rgb(255,255,255), al_get_display_width(game->display)/2, (int)(al_get_display_height(game->display) * 0.32+6*al_get_font_line_height(game->_priv.font_bsod)*1.25), ALLEGRO_ALIGN_CENTRE, 	"See http://dosowisko.net/ticklemonster/");
	al_draw_text(game->_priv.font_bsod, al_map_rgb(255,255,255), al_get_display_width(game->display)/2, (int)(al_get_display_height(game->display) * 0.32+7*al_get_font_line_height(game->_priv.font_bsod)*1.25), ALLEGRO_ALIGN_CENTRE, 	"Made for Ludum Dare 33 by Sebastian Krzyszkowiak");

	al_draw_text(game->_priv.font_bsod, al_map_rgb(255,255,255), al_get_display_width(game->display)/2 - al_get_text_width(game->_priv.font_bsod, header2)/2, (int)(al_get_display_height(game->display) * 0.32+9*al_get_font_line_height(game->_priv.font_bsod)*1.25), ALLEGRO_ALIGN_LEFT, "* Press any key to terminate this error.");
	al_draw_text(game->_priv.font_bsod, al_map_rgb(255,255,255), al_get_display_width(game->display)/2 - al_get_text_width(game->_priv.font_bsod, header2)/2, (int)(al_get_display_height(game->display) * 0.32+10*al_get_font_line_height(game->_priv.font_bsod)*1.25), ALLEGRO_ALIGN_LEFT, "* Press any key to destroy all muffins in the world.");
	al_draw_text(game->_priv.font_bsod, al_map_rgb(255,255,255), al_get_display_width(game->display)/2 - al_get_text_width(game->_priv.font_bsod, header2)/2, (int)(al_get_display_height(game->display) * 0.32+11*al_get_font_line_height(game->_priv.font_bsod)*1.25), ALLEGRO_ALIGN_LEFT, "* Just kidding, please press any key anyway.");

	al_draw_text(game->_priv.font_bsod, al_map_rgb(255,255,255), al_get_display_width(game->display)/2, (int)(al_get_display_height(game->display) * 0.32+13*al_get_font_line_height(game->_priv.font_bsod)*1.25), ALLEGRO_ALIGN_CENTRE, "Press any key to continue _");

	al_use_transform(&game->projection);
}
コード例 #12
0
void csd_render_message_queue(CSD_MESSAGE_QUEUE * qp, ALLEGRO_FONT * fp, float x, float y, int smooth)
{
	int w;
	
	if(qp->messages > 0)
	{
		switch(qp->message[0].type)
		{
			case CSD_MESSAGE_SCROLL:
			{
				if(smooth)
				{
					al_draw_text(fp, t3f_color_white, x + (float)qp->message[0].pos, y, 0, qp->message[0].text);
				}
				else
				{
					w = al_get_text_width(fp, "A");
					al_draw_text(fp, t3f_color_white, x + (float)(qp->message[0].pos / w) * w, y, 0, qp->message[0].text);
				}
				break;
			}
			case CSD_MESSAGE_FLASH:
			{
				if(qp->message[0].pos % 60 < 30)
				{
					al_draw_text(fp, t3f_color_white, x, y, 0, qp->message[0].text);
				}
				break;
			}
		}
	}
}
コード例 #13
0
ファイル: game.c プロジェクト: NewCreature/Dot-to-Dot-Sweep
static void dot_game_create_score_effect(void * data, float x, float y, int number)
{
	APP_INSTANCE * app = (APP_INSTANCE *)data;
	ALLEGRO_STATE old_state;
	ALLEGRO_TRANSFORM identity;
	char buf[16] = {0};
	int i, j;
	ALLEGRO_COLOR c;
	unsigned char r, g, b, a;
	float ox;
	float w, h;

	al_store_state(&old_state, ALLEGRO_STATE_TARGET_BITMAP | ALLEGRO_STATE_TRANSFORM);
	al_set_target_bitmap(app->bitmap[DOT_BITMAP_SCRATCH]);
	al_identity_transform(&identity);
	al_use_transform(&identity);
	al_clear_to_color(al_map_rgba_f(0.0, 0.0, 0.0, 0.0));
	sprintf(buf, "%d", number);
	al_set_clipping_rectangle(0, 0, 512, 512);
	al_draw_text(app->font[DOT_FONT_16], t3f_color_white, 0, 0, 0, buf);
	t3f_set_clipping_rectangle(0, 0, 0, 0);
	al_restore_state(&old_state);
	al_lock_bitmap(app->bitmap[DOT_BITMAP_SCRATCH], ALLEGRO_PIXEL_FORMAT_ANY, ALLEGRO_LOCK_READONLY);
	ox = al_get_text_width(app->font[DOT_FONT_16], buf) / 2;
	w = al_get_text_width(app->font[DOT_FONT_16], buf);
	h = al_get_font_line_height(app->font[DOT_FONT_16]);
	for(i = 0; i < w; i++)
	{
		for(j = 0; j < h; j++)
		{
			c = al_get_pixel(app->bitmap[DOT_BITMAP_SCRATCH], i, j);
			al_unmap_rgba(c, &r, &g, &b, &a);
			if(a > 0)
			{
				dot_create_particle(&app->particle[app->current_particle], x + (float)i - ox, y + j, 0.0, dot_spread_effect_particle(i, w, strlen(buf) * 2.5), dot_spread_effect_particle(j, h, 4.0), -10.0, 0.0, 3.0, 45, app->bitmap[DOT_BITMAP_PARTICLE], c);
				app->current_particle++;
				if(app->current_particle >= DOT_MAX_PARTICLES)
				{
					app->current_particle = 0;
				}
			}
		}
	}
	al_unlock_bitmap(app->bitmap[DOT_BITMAP_SCRATCH]);
}
コード例 #14
0
ファイル: Allegro5Font.cpp プロジェクト: arvidsson/Agui
	int Allegro5Font::getTextWidth( const std::string &text ) const
	{
		if(font)
		{
			return al_get_text_width(font,text.c_str());
		}

		return 0;
		
	}
コード例 #15
0
void cache_all_glyphs()
{
	std::string characters;

	for (int i = 0; translation_languages[i][0] != ""; i++) {
		characters += get_entire_translation(translation_languages[i][0].c_str());
	}

	al_get_text_width(game_font, characters.c_str());
}
コード例 #16
0
ファイル: guiWidgets.cpp プロジェクト: Glorf/SwordFallPonK
void GUI::showNotification(std::string notification)
{
    Menu *notificationMenu = addMenu(38,6.5,(double)al_get_text_width(czcionka,notification.c_str())/(double)dispx*100+10,13,Y_LAYOUT,"notification");

    notificationMenu->fillWithLayouts(2, 5, X_LAYOUT);
    notificationMenu->findLayoutByVector({1})->addLabel(notification);
    movingBlocked=true;

    notificationMenu->findLayoutByVector({2})->addButton("OK", &GUI::removeNotification, "");
}
コード例 #17
0
/* ----------------------------------------------------------------------------
 * Returns the number of the position the caret should go at,
 * when the mouse is clicked on the given X coordinate.
 * Takes into account text scroll, widget position, etc.
 */
unsigned int textbox::mouse_to_char(int mouse_x) {
    // Get the relative X, from the start of the text.
    int rel_x = mouse_x - x1 + scroll_x;
    for(size_t c = 0; c < text.size(); c++) {
        int width = al_get_text_width(style->text_font, text.substr(0, c + 1).c_str());
        if(rel_x < width) {
            return c;
        }
    }
    return text.size();
}
コード例 #18
0
ファイル: game.cpp プロジェクト: pmprog/SkySupreme
void GameStage::RenderSurvival()
{
	ALLEGRO_FONT* survivalFont = Framework::SystemFramework->GetFontManager()->GetFont( "resource/falsepos.ttf", Framework::SystemFramework->GetDisplayHeight() / 18, 0 );
	ALLEGRO_COLOR survivalBorder = al_map_rgb( 0, 0, 0 );
	ALLEGRO_COLOR survivalNormal = al_map_rgb( 255, 255, 255 );
	int Lsiz = al_get_font_line_height( survivalFont );
	int curScore = 0;

	for( std::vector<GameObject*>::const_iterator o = Objects.begin(); o != Objects.end(); o++ )
	{
		Plane* p = dynamic_cast<Plane*>( (*o) );
		if( p != 0 )
		{
			if( p->Controller_Keyboard || p->Controller_Joystick != 0 )
			{
				curScore = p->Score;
				break;
			}
		}
	}

	char cdTime[10];
	memset( (void*)&cdTime, 0, 10 );
	sprintf( (char*)&cdTime, "%d", SurvivalArrivals[SurvivalIndex] - SurvivalTimer );
	int Xpos = Framework::SystemFramework->GetDisplayWidth() - al_get_text_width( survivalFont, "Next Plane:" ) - 6;
	int XposCD = Xpos + ((Framework::SystemFramework->GetDisplayWidth() - Xpos) / 2) - (al_get_text_width( survivalFont, cdTime ) / 2);

	for( int yBrd = -1; yBrd < 2; yBrd++ )
	{
		for( int xBrd = -1; xBrd < 2; xBrd++ )
		{
			al_draw_textf( survivalFont, survivalBorder, 6 + xBrd, Framework::SystemFramework->GetDisplayHeight() - Lsiz - 4 + yBrd, 0, "Score: %d", curScore );
			al_draw_text( survivalFont, survivalBorder, Xpos + xBrd, Framework::SystemFramework->GetDisplayHeight() - Lsiz - Lsiz - 4 + yBrd, 0, "Next Plane:" );
			al_draw_text( survivalFont, survivalBorder, XposCD + xBrd, Framework::SystemFramework->GetDisplayHeight() - Lsiz - 4 + yBrd, 0, (char*)&cdTime );
		}
	}

	al_draw_textf( survivalFont, survivalNormal, 4, Framework::SystemFramework->GetDisplayHeight() - Lsiz - 4, 0, "Score: %d", curScore );
	al_draw_text( survivalFont, survivalNormal, Xpos, Framework::SystemFramework->GetDisplayHeight() - Lsiz - Lsiz - 4, 0, "Next Plane:" );
	al_draw_text( survivalFont, survivalNormal, XposCD, Framework::SystemFramework->GetDisplayHeight() - Lsiz - 4, 0, (char*)&cdTime );
}
コード例 #19
0
ファイル: guiWidgets.cpp プロジェクト: Glorf/SwordFallPonK
void GUI::quantityQuestionPrompt(std::string question, double min, double max, double step, void (GUI::*caller)(std::string))
{
    Menu *quantityMenu = addMenu(38,6.5,(double)al_get_text_width(czcionka,question.c_str())/(double)dispx*100+10,13,Y_LAYOUT,"quantityQuestion");

    quantityMenu->fillWithLayouts(3, 5, X_LAYOUT);
    quantityMenu->findLayoutByVector({1})->addLabel(question);

    movingBlocked=true;

    quantityMenu->findLayoutByVector({2})->addSlider(min, max, step);
    quantityMenu->findLayoutByVector({3})->addButton("OK", caller, "something");
}
コード例 #20
0
ファイル: intro.c プロジェクト: BorisCarvajal/allegro5
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);
      }
   }
}
コード例 #21
0
ファイル: ScreenPlay.cpp プロジェクト: kruci/Juicy-Plebs
void ScreenPlay::Print()
{
    al_clear_to_color(al_map_rgb(0,0,0));

    for(int a = 0;a < number_of_zemaky*4;a+=4)
    {

        zemaky[a] += zemaky[a+2];
        zemaky[a+1] += zemaky[a+3];

        if(zemaky[a] <= 0)
        {
            zemaky[a+2] = - zemaky[a+2];
        }
        else if(zemaky[a] + ZEMIAK_SIZE >= global::dWidth)
        {
            zemaky[a+2] = - zemaky[a+2];
        }

        if(zemaky[a+1] <= 0)
        {
            zemaky[a+3] = - zemaky[a+3];
        }
        else if(zemaky[a+1] + ZEMIAK_SIZE >= global::dHeight)
        {
            zemaky[a+3] = - zemaky[a+3];
        }

        al_draw_scaled_bitmap(zemak_bitmpa, 0, 0, al_get_bitmap_height(zemak_bitmpa), al_get_bitmap_width(zemak_bitmpa),
                                zemaky[a], zemaky[a+1], ZEMIAK_SIZE, ZEMIAK_SIZE, 0);

    }

    scba->Print();

    for(int a = 0;a < (int)buttons.size();a++)
    {
            buttons[a]->Print();
    }

    if(couldnot_load_savefile == true)
    {
        al_draw_filled_rectangle(0,0,global::dWidth, global::dHeight, al_map_rgba(0,0,0,150));
        al_draw_filled_rectangle(400, global::dHeight/2 - 100, global::dWidth - 400, global::dHeight/2 + 100, al_map_rgba(100, 100, 100, 230));
        al_draw_rectangle(400, global::dHeight/2 - 100, global::dWidth - 400, global::dHeight/2 + 100, al_map_rgb(0,0,150), 2);

        al_draw_text(n_font, al_map_rgb(255,255,255), 400 + (global::dWidth- 800 - al_get_text_width(n_font, "Could not load safe file"))/2 ,
                     global::dHeight/2 - 80, 0, "Could not load safe file");
        buttons[OK]->Print();
    }

    return;
}
コード例 #22
0
ファイル: widgetbase.cpp プロジェクト: kruci/rGUI
    bool _multilinecb(int _line_num, const char *_line, int _sizes, void *_extra)
    {
        ((ml_data*)_extra)->lines = _line_num + 1;

        std::string currentlinestr = ((std::string)_line).substr(0,_sizes);
        int currnetlinesize = al_get_text_width(((ml_data*)_extra)->font, currentlinestr.c_str());

        if(((ml_data*)_extra)->maxlinesize < currnetlinesize)
        {
            ((ml_data*)_extra)->maxlinesize = currnetlinesize;
            ((ml_data*)_extra)->longesttext = currentlinestr;
        }
        return true;
    }
コード例 #23
0
ファイル: guiWidgets.cpp プロジェクト: Glorf/SwordFallPonK
void GUI::questionPrompt(std::string question, std::vector<std::string> options, void (GUI::*caller)(std::string))
{
    Menu *questionPrompt = addMenu(38,6.5,(double)al_get_text_width(czcionka,question.c_str())/(double)dispx*100+10,
            (options.size()+1)*6.5,Y_LAYOUT,"questionPrompt");

    questionPrompt->fillWithLayouts(options.size()+1, 5, X_LAYOUT);
    questionPrompt->findLayoutByVector({1})->addLabel(question);
    movingBlocked=true;

    for(int i=0; i<options.size(); i++)
    {
        questionPrompt->findLayoutByVector({i+2})->addButton(options.at(i), caller, options.at(i));
    }
}
コード例 #24
0
ファイル: InputField.cpp プロジェクト: kruci/Juicy-Plebs
bool InputField::Input(ALLEGRO_EVENT &ev, float &scalex, float &scaley)
{
    int unichar = 0;

    detectingbutton->Input(ev, scalex, scaley);

    if(detectingbutton->is_button_clicked() == true && detectingbutton->is_mouse_in_it() == false &&
       ev.type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN && ev.mouse.button == 1)
    {
        detectingbutton->unclick();
    }
    else if(detectingbutton->is_button_clicked() == true)
    {
        if(ev.type == ALLEGRO_EVENT_KEY_CHAR && (ev.keyboard.keycode == ALLEGRO_KEY_BACKSPACE || ev.keyboard.keycode == ALLEGRO_KEY_ENTER))
        {
            switch(ev.keyboard.keycode)
            {
                case ALLEGRO_KEY_BACKSPACE :
                    if(al_ustr_length(al_text) > 0)
                    {
                        al_ustr_remove_chr(al_text, al_ustr_length(al_text)-1);
                    }
                    break;
                case ALLEGRO_KEY_ENTER :
                    detectingbutton->unclick();
                    break;
            }
        }
        else if(ev.type == ALLEGRO_EVENT_KEY_CHAR)
        {
            if(lenght_limit == true && (int)text.size() >= max_lenght)
            {
                return true;
            }
            unichar = ev.keyboard.unichar;

            if(unichar >= 32)
            {
                al_ustr_append_chr(al_text, unichar);
            }
        }
    }

    text = al_cstr_dup(al_text);
    text_width = al_get_text_width(font, text.c_str()) + 7;


    return true;
}
コード例 #25
0
ファイル: gui.c プロジェクト: NewCreature/Dot-to-Dot-Sweep
static float allegro_get_element_width(T3F_GUI_ELEMENT * ep)
{
	switch(ep->type)
	{
		case T3F_GUI_ELEMENT_TEXT:
		{
			return al_get_text_width((ALLEGRO_FONT *)ep->aux_data, ep->data);
		}
		case T3F_GUI_ELEMENT_IMAGE:
		{
			return al_get_bitmap_width(((ALLEGRO_BITMAP *)(ep->data)));
		}
	}
	return 0.0;
}
コード例 #26
0
void RoundOver::Begin()
{
#ifdef WRITE_LOG
	fprintf( FRAMEWORK->LogFile, "Stage: RoundOver::Begin()\n" );
#endif
	currentArena = (Arena*)FRAMEWORK->ProgramStages->Previous();

	fntTitle = al_load_ttf_font( "resources/titlefont.ttf", 48, 0 );
	fntTitleHeight = al_get_font_line_height( fntTitle );

	leaving = false;
	overbanner[0] = -50.0f;
	overbanner[1] = (DISPLAY->GetHeight() / 2) - 50.0f;
	overbanner[2] = -100.0f;
	overbanner[3] = overbanner[1] + 100.0f;
	overbanner[4] = -50.0f;
	overbanner[5] = overbanner[3];
	overbanner[6] = 0.0f;
	overbanner[7] = overbanner[1];

	switch( winner )
	{
		case 0:
			// Draw
			textDisplay = "Draw!";
			break;
		case 1:
			// Player 1
			textDisplay = "Player 1 Wins";
			break;
		case 2:
			// Player 2
			textDisplay = "Player 2 Wins";
			break;
	}

	textWidth = al_get_text_width( fntTitle, textDisplay.c_str() );
	textXposition = DISPLAY->GetWidth();


	overbannerXv = (DISPLAY->GetWidth() + 100) / ROUNDOVER_STEPSINOUT;
	textXv = ( textXposition - ((DISPLAY->GetWidth() - textWidth) / 2) ) / ROUNDOVER_STEPSINOUT;

	textXposition -= textXv;
	stagetime = 0;

}
コード例 #27
0
    std::unique_ptr<dick::GUI::Widget> m_make_score_container()
    {
        const double text_height = al_get_font_line_height(m_context->m_const.menu_font);
        double max_width = 0;

        std::vector<HighScoreEntry> entries =
            m_high_score.get_entries_for_balls(m_ball_counts[m_ball_index]);
        std::reverse(begin(entries), end(entries));

        auto name_rail = m_context->m_gui.make_container_rail(
                dick::GUI::Direction::DOWN,
                text_height * 1.125);

        auto score_rail = m_context->m_gui.make_container_rail(
                dick::GUI::Direction::DOWN,
                text_height * 1.125);

        for (const auto& entry: entries) {
            double name_width = al_get_text_width(
                    m_context->m_const.menu_font,
                    entry.name.c_str());
            if (name_width > max_width) {
                max_width = name_width;
            }
            name_rail->insert(
                m_context->m_gui.make_label_ex(
                    entry.name,
                    m_context->m_const.menu_font));
            score_rail->insert(
                m_context->m_gui.make_label_ex(
                    std::to_string(entry.score),
                    m_context->m_const.menu_font));
        }

        score_rail->set_offset({ 2 * max_width, 0.0 });

        auto container = m_context->m_gui.make_container_free();
        container->insert(std::move(name_rail));
        container->insert(std::move(score_rail));

        auto panel = m_context->m_gui.make_container_panel();
        panel->insert(std::unique_ptr<dick::GUI::Widget> { container.release() });

        std::unique_ptr<dick::GUI::Widget> result = std::move(panel);

        return result;
    }
コード例 #28
0
ファイル: GroupOfButtons.cpp プロジェクト: AdamGaik/kinf
void GroupOfButtons::addTextbox(string* pText, string _text)
{
    button_w = max(button_w, al_get_text_width(font(font_size), _text.c_str()) + space()*5);

    objectsSequence.push_back(0);
    textboxes.push_back(MyTextbox(Textbox(font_size, Area(), _text, default_color, false), pText));

    for (int i = 0, b = buttons.size(), t = textboxes.size(); i < objectsSequence.size(); ++i) {
        if (objectsSequence[objectsSequence.size()-i-1]) {
            buttons[--b].reInit(Area::CXYWH, cx, cy + getH()/2 - (button_h+space())*(i+1) + button_h/2, button_w, button_h);
            buttons[b].reInit(Area::CXYWH, cx, cy + getH()/2 - (button_h+space())*(i+1) + button_h/2, button_w, button_h);
        } else {
            textboxes[--t].box.reInit(Area::CXYWH, cx, cy + getH()/2 - (button_h+space())*(i+1) + button_h/2, button_w, button_h);
            textboxes[t].box.reInit(Area::CXYWH, cx, cy + getH()/2 - (button_h+space())*(i+1) + button_h/2, button_w, button_h);
        }
    }
}
コード例 #29
0
ファイル: GroupOfButtons.cpp プロジェクト: AdamGaik/kinf
void GroupOfButtons::addButton(string _text, void(*_fn)(), Color _color)
{
    button_w = max(button_w, al_get_text_width(font(font_size), _text.c_str()) + space()*5);

    objectsSequence.push_back(1);
    buttons.push_back(Button(_text, _fn, Area(), [=]()->Color{return _color == Color::null() ? default_color : _color;}()));

    for (int i = 0, b = buttons.size(), t = textboxes.size(); i < objectsSequence.size(); ++i) {
        if (objectsSequence[objectsSequence.size()-i-1]) {
            buttons[--b].reInit(Area::CXYWH, cx, cy + getH()/2 - (button_h+space())*(i+1) + button_h/2, button_w, button_h);
            buttons[b].reInit(Area::CXYWH, cx, cy + getH()/2 - (button_h+space())*(i+1) + button_h/2, button_w, button_h);
        } else {
            textboxes[--t].box.reInit(Area::CXYWH, cx, cy + getH()/2 - (button_h+space())*(i+1) + button_h/2, button_w, button_h);
            textboxes[t].box.reInit(Area::CXYWH, cx, cy + getH()/2 - (button_h+space())*(i+1) + button_h/2, button_w, button_h);
        }
    }
}
コード例 #30
0
void MultipleControllerSelectStage::Render()
{
	GameStage* g = (GameStage*)Framework::SystemFramework->ProgramStages->Previous( this );
	g->Render();
	al_draw_filled_rectangle( 0, 0, Framework::SystemFramework->GetDisplayWidth(), Framework::SystemFramework->GetDisplayHeight(), al_map_rgba( 0, 0, 0, 128 ) );

	int boxW = Framework::SystemFramework->GetDisplayWidth() / 5;
	int boxH = Framework::SystemFramework->GetDisplayHeight() / 4;
	std::list<Plane*>* players = g->GetPlaneObjects();
	ALLEGRO_BITMAP* tileset = g->GetGameScaledImage();

	int i = 0;
	for( std::list<Plane*>::const_iterator p = players->begin(); p != players->end(); p++ )
	{
		al_draw_filled_rounded_rectangle( (boxW * (i % 5)) + 2, (boxH * (i / 5)) + 2, (boxW * (i % 5)) + boxW - 2, (boxH * ((i + 5) / 5)) - 2, 6, 6, al_map_rgba( 255, 255, 255, 128 ) );

		Plane* ply = (Plane*)*p;
		int tileX = 144 * g->graphicsMultiplier;
		int tileY = (ply->Team * 48) * g->graphicsMultiplier;
		ALLEGRO_BITMAP* tmp = al_create_sub_bitmap( tileset, tileX, tileY, 48 * g->graphicsMultiplier, 48 * g->graphicsMultiplier );
		al_draw_scaled_bitmap( tmp, 0, 0, 48 * g->graphicsMultiplier, 48 * g->graphicsMultiplier, (boxW * (i % 5)) + 4, (boxH * (i / 5)) + 4, boxW - 4, boxH - 4, 0 );
		al_destroy_bitmap( tmp );
		i++;
	}


	ALLEGRO_FONT* survivalFont = Framework::SystemFramework->GetFontManager()->GetFont( "resource/falsepos.ttf", Framework::SystemFramework->GetDisplayHeight() / 18, 0 );
	ALLEGRO_COLOR survivalBorder = al_map_rgb( 0, 0, 0 );
	ALLEGRO_COLOR survivalNormal = al_map_rgb( 255, 255, 255 );

	int Xpos = (Framework::SystemFramework->GetDisplayWidth() / 2) - (al_get_text_width( survivalFont, "Press Enter To Start" ) / 2);
	int Lsiz = al_get_font_line_height( survivalFont );

	for( int yBrd = -1; yBrd < 2; yBrd++ )
	{
		for( int xBrd = -1; xBrd < 2; xBrd++ )
		{
			al_draw_text( survivalFont, survivalBorder, Xpos + xBrd, Framework::SystemFramework->GetDisplayHeight() - Lsiz - 6 + yBrd, 0, "Press Enter To Start" );
		}
	}

	al_draw_text( survivalFont, survivalNormal, Xpos, Framework::SystemFramework->GetDisplayHeight() - Lsiz - 6, 0, "Press Enter To Start" );


}