Example #1
0
static void dot_create_bg_object_effect(void * data)
{
	APP_INSTANCE * app = (APP_INSTANCE *)data;
	ALLEGRO_STATE old_state;
	ALLEGRO_TRANSFORM identity;
	float sx = 512.0 / (float)t3f_virtual_display_width;
	int i;
	bool held = al_is_bitmap_drawing_held();

	if(held)
	{
		al_hold_bitmap_drawing(false);
	}
	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_set_clipping_rectangle(0, 0, 512, 512);
    al_clear_to_color(al_map_rgba_f(0.0, 0.0, 0.0, 0.0));
    al_set_clipping_rectangle(0, 0, 512, DOT_GAME_PLAYFIELD_HEIGHT);
    al_hold_bitmap_drawing(true);
	for(i = 0; i < DOT_MAX_BG_OBJECTS; i++)
	{
		t3f_draw_scaled_bitmap(app->bitmap[DOT_BITMAP_BALL_RED], al_map_rgba_f(1.0, 1.0, 1.0, 1.0), app->bg_object[i].x * sx, app->bg_object[i].y, app->bg_object[i].z, DOT_GAME_BALL_SIZE * 2.0 * sx, DOT_GAME_BALL_SIZE * 2.0, 0);
	}
	al_hold_bitmap_drawing(false);
	t3f_set_clipping_rectangle(0, 0, 0, 0);
	al_restore_state(&old_state);
	al_hold_bitmap_drawing(held);
}
Example #2
0
void Vertical_paned_view::Render(const Widget& widget) const
{
	const Vertical_paned& vertical_paned = dynamic_cast<const Vertical_paned&>(widget);
	Widget* top = vertical_paned.Get_top();
	Widget* bottom = vertical_paned.Get_bottom();
	Widget_view* view;
	int clip_x, clip_y, clip_w, clip_h;
	al_get_clipping_rectangle(&clip_x, &clip_y, &clip_w, &clip_h);
	if(top)
	{
		Vector2 p = top->Get_position();
		Vector2 s = top->Get_size();
		al_set_clipping_rectangle(p.x, p.y, s.x, s.y);
		top->Render();
	}
	if(bottom)
	{
		Vector2 p = bottom->Get_position();
		Vector2 s = bottom->Get_size();
		al_set_clipping_rectangle(p.x, p.y, s.x, s.y);
		bottom->Render();
	}
	al_set_clipping_rectangle(clip_x, clip_y, clip_w, clip_h);

	Vector2 p = widget.Get_position();
	Vector2 s = widget.Get_size();
	float pane = p.y+vertical_paned.Get_pane_position()+1;
	ALLEGRO_COLOR bg_color = al_map_rgb_f(0.7, 0.7, 0.7);
	ALLEGRO_COLOR edge_color = al_map_rgb_f(0.3, 0.3, 0.3);
	al_draw_filled_rectangle(p.x, pane, p.x+s.x-1, pane+6, bg_color);
	al_draw_rectangle(p.x, pane, p.x+s.x-1, pane+6, edge_color, 0);
	al_draw_line(p.x+s.x/2-10, pane+2, p.x+s.x/2+10, pane+2, edge_color, 0);
	al_draw_line(p.x+s.x/2-10, pane+4, p.x+s.x/2+10, pane+4, edge_color, 0);
}
Example #3
0
void Horizontal_paned_view::Render(const Widget& widget) const
{
	const Horizontal_paned& horizontal_paned = dynamic_cast<const Horizontal_paned&>(widget);
	Widget* left = horizontal_paned.Get_left();
	Widget* right = horizontal_paned.Get_right();
	Widget_view* view;
	int clip_x, clip_y, clip_w, clip_h;
	al_get_clipping_rectangle(&clip_x, &clip_y, &clip_w, &clip_h);
	if(left)
	{
		Vector2 p = left->Get_position();
		Vector2 s = left->Get_size();
		al_set_clipping_rectangle(p.x, p.y, s.x, s.y);
		left->Render();
	}
	if(right)
	{
		Vector2 p = right->Get_position();
		Vector2 s = right->Get_size();
		al_set_clipping_rectangle(p.x, p.y, s.x, s.y);
		right->Render();
	}
	al_set_clipping_rectangle(clip_x, clip_y, clip_w, clip_h);

	Vector2 p = widget.Get_position();
	Vector2 s = widget.Get_size();
	float pane = p.x+horizontal_paned.Get_pane_position();
	ALLEGRO_COLOR bg_color = al_map_rgb_f(0.7, 0.7, 0.7);
	ALLEGRO_COLOR edge_color = al_map_rgb_f(0.3, 0.3, 0.3);
	al_draw_filled_rectangle(pane, p.y+1, pane+6, p.y+s.y, bg_color);
	al_draw_rectangle(pane, p.y+1, pane+6, p.y+s.y, edge_color, 0);
	al_draw_line(pane+2, p.y+s.y/2-10, pane+2, p.y+s.y/2+10, edge_color, 0);
	al_draw_line(pane+4, p.y+s.y/2-10, pane+4, p.y+s.y/2+10, edge_color, 0);
}
Example #4
0
void ImGui_ImplA5_RenderDrawLists(ImDrawData* draw_data)
{
    int op, src, dst;
    al_get_blender(&op, &src, &dst);
    al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA);

    for (int n = 0; n < draw_data->CmdListsCount; n++)
    {
        const ImDrawList* cmd_list = draw_data->CmdLists[n];

        // FIXME-OPT: Unfortunately Allegro doesn't support 32-bits packed colors so we have to convert them to 4 floats
        static ImVector<ImDrawVertAllegro> vertices;
        vertices.resize(cmd_list->VtxBuffer.Size);
        for (int i = 0; i < cmd_list->VtxBuffer.Size; ++i)
        {
            const ImDrawVert &dv = cmd_list->VtxBuffer[i];
            ImDrawVertAllegro v;
            v.pos = dv.pos;
            v.uv = dv.uv;
            unsigned char *c = (unsigned char*)&dv.col;
            v.col = al_map_rgba(c[0], c[1], c[2], c[3]);
            vertices[i] = v;
        }

        // FIXME-OPT: Unfortunately Allegro doesn't support 16-bit indices
        // You can also use '#define ImDrawIdx unsigned int' in imconfig.h and request ImGui to output 32-bit indices
        static ImVector<int> indices;
        indices.resize(cmd_list->IdxBuffer.Size);
        for (int i = 0; i < cmd_list->IdxBuffer.Size; ++i)
            indices[i] = (int)cmd_list->IdxBuffer.Data[i];

        int idx_offset = 0;
        for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
        {
            const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
            if (pcmd->UserCallback)
            {
                pcmd->UserCallback(cmd_list, pcmd);
            }
            else
            {
                ALLEGRO_BITMAP* texture = (ALLEGRO_BITMAP*)pcmd->TextureId;
                al_set_clipping_rectangle(pcmd->ClipRect.x, pcmd->ClipRect.y, pcmd->ClipRect.z-pcmd->ClipRect.x, pcmd->ClipRect.w-pcmd->ClipRect.y);
                al_draw_indexed_prim(&vertices[0], g_VertexDecl, texture, &indices[idx_offset], pcmd->ElemCount, ALLEGRO_PRIM_TRIANGLE_LIST);
            }
            idx_offset += pcmd->ElemCount;
        }
    }

    // Restore modified state
    al_set_blender(op, src, dst);
    al_set_clipping_rectangle(0, 0, al_get_display_width(g_Display), al_get_display_height(g_Display));
}
Example #5
0
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);
		}
	}
}
Example #6
0
void m_set_clip(int x1, int y1, int x2, int y2)
{
	int dx, dy, dw, dh;
	get_screen_offset_size(&dx, &dy, &dw, &dh);
	ALLEGRO_BITMAP *target = al_get_target_bitmap();
	if (al_get_bitmap_width(target) == al_get_display_width(display) && al_get_bitmap_height(target) == al_get_display_height(display)) {
		al_set_clipping_rectangle(dx+x1*screenScaleX, dy+y1*screenScaleY, (x2-x1)*screenScaleX, (y2-y1)*screenScaleY);
	}
	else {
		al_set_clipping_rectangle(
			x1, y1, x2-x1, y2-y1
		);
	}
}
Example #7
0
void
push_clipping_rectangle (ALLEGRO_BITMAP *bitmap, int x, int y, int w, int h)
{
  assert (clipping_rectangle_stack_nmemb < CLIPPING_RECTANGLE_STACK_NMEMB_MAX);

  set_target_bitmap (bitmap);

  /* save current */
  int cx, cy, cw, ch;
  al_get_clipping_rectangle (&cx, &cy, &cw, &ch);
  size_t i = clipping_rectangle_stack_nmemb;
  clipping_rectangle_stack[i].bitmap = bitmap;
  clipping_rectangle_stack[i].x = cx;
  clipping_rectangle_stack[i].y = cy;
  clipping_rectangle_stack[i].w = cw;
  clipping_rectangle_stack[i].h = ch;
  clipping_rectangle_stack_nmemb++;

  /* intersection */
  if (! ignore_clipping_rectangle_intersection)
    intersection_rectangle (x, y, w, h,
                            cx, cy, cw, ch,
                            &x, &y, &w, &h);

  /* set new */
  al_set_clipping_rectangle (x, y, w, h);
}
Example #8
0
static void dot_create_touch_start_effect(void * data)
{
	APP_INSTANCE * app = (APP_INSTANCE *)data;
	ALLEGRO_STATE old_state;
	ALLEGRO_TRANSFORM identity;
	float sx = 512.0 / (float)t3f_virtual_display_width;
	bool held = al_is_bitmap_drawing_held();

	if(held)
	{
		al_hold_bitmap_drawing(false);
	}
	al_store_state(&old_state, ALLEGRO_STATE_TARGET_BITMAP | ALLEGRO_STATE_TRANSFORM | ALLEGRO_STATE_BLENDER);
	al_set_target_bitmap(app->bitmap[DOT_BITMAP_SCRATCH]);
	al_identity_transform(&identity);
	al_use_transform(&identity);
	al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);
	al_set_clipping_rectangle(0, 0, 512, 512);
	al_clear_to_color(al_map_rgba_f(0.0, 0.0, 0.0, 1.0));
	al_set_blender(ALLEGRO_ADD, ALLEGRO_ZERO, ALLEGRO_INVERSE_ALPHA);
	al_draw_filled_rectangle(DOT_GAME_TOUCH_START_X * sx, DOT_GAME_TOUCH_START_Y, DOT_GAME_TOUCH_END_X * sx, DOT_GAME_TOUCH_END_Y, al_map_rgba_f(1.0, 1.0, 1.0, 1.0));
	al_restore_state(&old_state);
	al_hold_bitmap_drawing(held);
	t3f_set_clipping_rectangle(0, 0, 0, 0);
}
Example #9
0
void SetupViewport(struct Game *game) {
	game->viewport.width = 320;
	game->viewport.height = 180;

	int resolution = al_get_display_width(game->display) / 320;
	if (al_get_display_height(game->display) / 180 < resolution) resolution = al_get_display_height(game->display) / 180;
	if (resolution < 1) resolution = 1;

	if (atoi(GetConfigOptionDefault(game, "SuperDerpy", "letterbox", "1"))) {
		int clipWidth = 320 * resolution, clipHeight = 180 * resolution;
		int clipX = (al_get_display_width(game->display) - clipWidth) / 2, clipY = (al_get_display_height(game->display) - clipHeight) / 2;
		al_set_clipping_rectangle(clipX, clipY, clipWidth, clipHeight);

		al_build_transform(&game->projection, clipX, clipY, resolution, resolution, 0.0f);
		al_use_transform(&game->projection);

	} else if ((atoi(GetConfigOptionDefault(game, "SuperDerpy", "rotate", "1"))) && (game->viewport.height > game->viewport.width)) {
		al_identity_transform(&game->projection);
		al_rotate_transform(&game->projection, 0.5*ALLEGRO_PI);
		al_translate_transform(&game->projection, game->viewport.width, 0);
		al_scale_transform(&game->projection, resolution, resolution);
		al_use_transform(&game->projection);
		int temp = game->viewport.height;
		game->viewport.height = game->viewport.width;
		game->viewport.width = temp;
	}
	if (game->_priv.console) Console_Unload(game);
	Console_Load(game);
}
Example #10
0
static void dot_create_grab_spot_effect(void * data)
{
	APP_INSTANCE * app = (APP_INSTANCE *)data;
	ALLEGRO_STATE old_state;
	ALLEGRO_TRANSFORM identity;
	float s;
	float sx = 512.0 / (float)t3f_virtual_display_width;
	bool held = al_is_bitmap_drawing_held();

	if(held)
	{
		al_hold_bitmap_drawing(false);
	}

	al_store_state(&old_state, ALLEGRO_STATE_TARGET_BITMAP | ALLEGRO_STATE_TRANSFORM | ALLEGRO_STATE_BLENDER);
	al_set_target_bitmap(app->bitmap[DOT_BITMAP_SCRATCH]);
	al_identity_transform(&identity);
	al_use_transform(&identity);
	al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);
	al_set_clipping_rectangle(0, 0, 512, 512);
	al_clear_to_color(al_map_rgba_f(0.0, 0.0, 0.0, 1.0));
	al_set_blender(ALLEGRO_ADD, ALLEGRO_ZERO, ALLEGRO_INVERSE_ALPHA);
	s = DOT_GAME_GRAB_SPOT_SIZE;
	t3f_draw_scaled_bitmap(app->bitmap[DOT_BITMAP_COMBO], al_map_rgba_f(0.0, 0.0, 0.0, 1.0), (float)(app->game.player.ball.x - DOT_GAME_GRAB_SPOT_SIZE) * sx, app->game.player.ball.y - DOT_GAME_GRAB_SPOT_SIZE, 0.0, (s * 2.0) * sx, s * 2, 0);
	al_restore_state(&old_state);
	al_hold_bitmap_drawing(held);
	t3f_set_clipping_rectangle(0, 0, 0, 0);
}
Example #11
0
/* object_message:
 *  Sends a message to a widget.
 *  Do NOT call this from the callback function!
 */
int t3gui_object_message(T3GUI_ELEMENT *dialog, int msg, int c)
{

   int ret = 0;
   assert(dialog);

   if (msg == MSG_DRAW) {
      if (dialog->flags & D_HIDDEN)
         return D_O_K;
      al_set_clipping_rectangle(dialog->x, dialog->y, dialog->w, dialog->h);
   }

   /* Callback? */
   if (dialog->callback) {
      ret = dialog->callback(msg, dialog, c);
      if (ret & D_CALLBACK)
         return ret & ~D_CALLBACK;
   }

   ret |= dialog->proc(msg, dialog, c);

   if (ret & D_REDRAWME) {
      dialog->flags |= D_DIRTY;
      ret &= ~D_REDRAWME;
   }

   return ret;
}
void AllegroTextBox::Draw()
{
    int bbx;
    int bby;
    int bbw;
    int bbh;

    QString display = m_value;

    if (m_passwordMode)
        display.fill('*');

    al_get_text_dimensions(m_boxFont, display.toStdString().c_str(), &bbx, &bby, &bbw, &bbh);

    int x1 = GetXPos();
    int y1 = GetYPos();
    int x2 = x1 + GetWidth();
    int y2 = y1 + GetHeight();

    al_draw_filled_rectangle(x1, y1, x2, y2, m_backgroundColor);
    al_draw_rectangle(x1, y1, x2, y2, GetFocus() ? m_focusedBorder : m_defaultBorder, 1);

    bool Overflow = (bbw > GetWidth() - m_sidePadding * 2);

    al_set_clipping_rectangle((m_xPos+m_sidePadding), m_yPos, (GetWidth()-m_sidePadding*2), GetHeight());
    al_draw_text(m_boxFont, m_textColor, Overflow ? (m_xPos+GetWidth()-m_sidePadding) : (m_xPos+m_sidePadding), (m_yPos + (GetHeight() / 2) - bbh/2), Overflow ? ALLEGRO_ALIGN_RIGHT : ALLEGRO_ALIGN_LEFT, display.toStdString().c_str());
    al_reset_clipping_rectangle();
}
Example #13
0
static void dot_create_touch_dots_effect(void * data)
{
	APP_INSTANCE * app = (APP_INSTANCE *)data;
	ALLEGRO_STATE old_state;
	ALLEGRO_TRANSFORM identity;
	float sx = 512.0 / (float)t3f_virtual_display_width;
	int i;
	bool held = al_is_bitmap_drawing_held();

	if(held)
	{
		al_hold_bitmap_drawing(false);
	}
	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_set_clipping_rectangle(0, 0, 512, 512);
	al_clear_to_color(al_map_rgba_f(0.0, 0.0, 0.0, 0.0));
	al_hold_bitmap_drawing(true);
	for(i = 0; i < DOT_GAME_MAX_BALLS; i++)
	{
		if(app->game.ball[i].active)
		{
			t3f_draw_scaled_bitmap(app->bitmap[DOT_BITMAP_BALL_RED + app->game.ball[i].type], al_map_rgba_f(1.0, 1.0, 1.0, 1.0), (app->game.ball[i].x - app->game.ball[i].r) * sx, app->game.ball[i].y - app->game.ball[i].r, app->game.ball[i].z, (app->game.ball[i].r * 2.0) * sx, app->game.ball[i].r * 2.0, 0);
		}
	}
	al_hold_bitmap_drawing(false);
	al_restore_state(&old_state);
	al_hold_bitmap_drawing(held);
	t3f_set_clipping_rectangle(0.0, 0.0, 0.0, 0.0);
}
Example #14
0
static int allua_Bitmap_set_clipping_rectangle(lua_State * L)
{
   int x = luaL_checknumber(L, 1);
   int y = luaL_checknumber(L, 2);
   int w = luaL_checknumber(L, 3);
   int h = luaL_checknumber(L, 4);
   al_set_clipping_rectangle(x, y, w, h);
   return 0;
}
Example #15
0
void Dialog::draw()
{
   int cx, cy, cw, ch;
   al_get_clipping_rectangle(&cx, &cy, &cw, &ch);

   for (std::list<Widget *>::iterator it = this->all_widgets.begin();
         it != this->all_widgets.end();
         ++it)
   {
      Widget *wid = (*it);
      al_set_clipping_rectangle(wid->x1, wid->y1, wid->width(), wid->height());
      wid->draw();
   }

   al_set_clipping_rectangle(cx, cy, cw, ch);

   this->draw_requested = false;
}
Example #16
0
/* Function: al_reset_clipping_rectangle
 */
void al_reset_clipping_rectangle(void)
{
   ALLEGRO_BITMAP *bitmap = al_get_target_bitmap();

   if (bitmap) {
      int w = al_get_bitmap_width(bitmap);
      int h = al_get_bitmap_height(bitmap);
      al_set_clipping_rectangle(0, 0, w, h);
   }
}
Example #17
0
void
draw_door_top (ALLEGRO_BITMAP *bitmap, struct pos *p,
               enum em em, enum vm vm)
{
  set_target_bitmap (bitmap);
  al_set_clipping_rectangle (PLACE_WIDTH * (p->place + 1),
                             PLACE_HEIGHT * p->floor - 12,
                             25, 15);
  draw_door_right (bitmap, p, em, vm);
  al_reset_clipping_rectangle ();
}
Example #18
0
void
pop_clipping_rectangle (void)
{
  assert (clipping_rectangle_stack_nmemb > 0);

  size_t i = clipping_rectangle_stack_nmemb - 1;
  ALLEGRO_BITMAP *bitmap = clipping_rectangle_stack[i].bitmap;
  int x = clipping_rectangle_stack[i].x;
  int y = clipping_rectangle_stack[i].y;
  int w = clipping_rectangle_stack[i].w;
  int h = clipping_rectangle_stack[i].h;
  set_target_bitmap (bitmap);
  al_set_clipping_rectangle (x, y, w, h);
  clipping_rectangle_stack_nmemb--;
}
Example #19
0
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]);
}
void t3f_3d_select_projection(T3F_3D_STATE * sp)
{
	t3f_3d_current_state = sp;
	float sx = t3f_3d_current_state->width / (float)t3f_virtual_display_width;
	float sy = t3f_3d_current_state->height / (float)t3f_virtual_display_height;
	float dsx = (float)al_get_display_width(t3f_display) / t3f_virtual_display_width;
	float dsy = (float)al_get_display_height(t3f_display) / t3f_virtual_display_height;
	float ox = t3f_3d_current_state->offset_x * dsx;
	float oy = t3f_3d_current_state->offset_y * dsy;
	
	/* apply additional transformations */
	al_copy_transform(&t3f_current_transform, &t3f_base_transform);
	al_scale_transform(&t3f_current_transform, sx, sy);
	al_translate_transform(&t3f_current_transform, t3f_3d_current_state->offset_x * dsx, t3f_3d_current_state->offset_y * dsy);
	al_use_transform(&t3f_current_transform);
	
	/* convert virtual screen coordinates to real display coordinates */
	al_set_clipping_rectangle(ox, oy, t3f_3d_current_state->width * dsx, t3f_3d_current_state->height * dsy);
}
Example #21
0
bool
merge_clipping_rectangle (ALLEGRO_BITMAP *bitmap, int x, int y, int w, int h)
{
  assert (clipping_rectangle_stack_nmemb > 0);

  int i;
  for (i = clipping_rectangle_stack_nmemb - 1;
       i >= 0 && clipping_rectangle_stack[i].bitmap != bitmap; i--);
  if (i < 0) return false;

  set_target_bitmap (clipping_rectangle_stack[i].bitmap);

  /* get current */
  int cx, cy, cw, ch;
  al_get_clipping_rectangle (&cx, &cy, &cw, &ch);

  /* union */
  int xr, yr, wr, hr;
  union_rectangle (x, y, w, h,
                   cx, cy, cw, ch,
                   &xr, &yr, &wr, &hr);

  /* intersection */
  if (! ignore_clipping_rectangle_intersection) {
    int xs = clipping_rectangle_stack[i].x;
    int ys = clipping_rectangle_stack[i].y;
    int ws = clipping_rectangle_stack[i].w;
    int hs = clipping_rectangle_stack[i].h;
    intersection_rectangle (xr, yr, wr, hr,
                            xs, ys, ws, hs,
                            &xr, &yr, &wr, &hr);
  }

  /* set new */
  al_set_clipping_rectangle (xr, yr, wr, hr);
  return true;
}
static void my_set_clip_rect(void)
{
   al_set_clipping_rectangle(100, 100, W - 200, H - 200);
}
void Whack_a_Skunk_Loop::draw(void)
{
	al_clear_to_color(al_map_rgb(0x00, 0x00, 0x00));

	al_draw_bitmap(
		bg_bitmap->bitmap,
		top_offset.x,
		top_offset.y,
		0
	);

	float scales[3] = { 0.83f, 0.9f, 1.0f };
	Wrap::Bitmap *hole_bmps[3] = {
		mask_back,
		mask_middle,
		mask_front
	};
	int hole_yoffs[3] = { 6, 8, 10 };
	Wrap::Bitmap *highlight_bmps[3] = {
		highlight_back,
		highlight_middle,
		highlight_front
	};
	int highlight_yoffs[3] = { 5, 6, 8 };
	Wrap::Bitmap *maskhighlight_bmps[3] = {
		mask_backhighlight,
		mask_middlehighlight,
		mask_fronthighlight
	};
	
	for (int i = 0; i < 9; i++) {
		int row = i / 3;

		if (i == curr_hole) {
			Wrap::Bitmap *highlight = highlight_bmps[row];
			int highlight_w = al_get_bitmap_width(highlight->bitmap);
			int highlight_h = al_get_bitmap_height(highlight->bitmap);
			al_draw_bitmap(
				highlight->bitmap,
				holes[i].x-highlight_w/2+top_offset.x,
				holes[i].y-highlight_h+highlight_yoffs[row]+top_offset.y,
				0
			);
		}
		
		Animation_Set *anim_set;
		bool done = get_skunk_info(i, &anim_set);

		int x = holes[i].x - skunk_size.w/2 + top_offset.x;
		int y = holes[i].y - skunk_size.h + top_offset.y;
		float scale = scales[row];
		int ox = (skunk_size.w * (1.0f-scale)) / 2;
		int oy = 10;
		oy += (skunk_size.h * (1.0f-scale)) / 2;
		int len = anim_set->get_length(anim_set->get_sub_animation_name());
		if (holes[i].count > len/2) {
			oy += ((float)(holes[i].count-(len/2)) / (len/2)) * 60 /* 60 = base skunk height */;
		}
		else {
			oy += (1.0 - ((float)holes[i].count / (len/2))) * 60;
		}

		if (!done) {
			int cx, cy, cw, ch;
			al_get_clipping_rectangle(&cx, &cy, &cw, &ch);
			General::set_clipping_rectangle(x, y, skunk_size.w, skunk_size.h);

			if (holes[i].status == ALIVE || holes[i].status == TAUNTING || holes[i].status == GOING_DOWN) {
				anim_set->get_current_animation()->draw_scaled(
					0, 0, skunk_size.w, skunk_size.h,
					x+ox, y+oy, skunk_size.w*scale, skunk_size.h*scale,
					0
				);
			}
			else if (holes[i].status == DYING) {
				std::string name = anim_set->get_sub_animation_name();
				int frame = anim_set->get_current_animation()->get_current_frame_num();
				anim_set->set_sub_animation("popup");
				anim_set->set_frame(holes[i].type == FAKE ? 0 : 3);
				anim_set->get_current_animation()->draw_scaled(
					0, 0, skunk_size.w, skunk_size.h,
					x+ox, y+oy, skunk_size.w*scale, skunk_size.h*scale,
					0
				);
				anim_set->set_sub_animation(name);
				anim_set->set_frame(frame);
			}

			al_set_clipping_rectangle(cx, cy, cw, ch);
		}

		Wrap::Bitmap *mask = i == curr_hole ? maskhighlight_bmps[row] : hole_bmps[row];
		int mask_w = al_get_bitmap_width(mask->bitmap);
		int mask_h = al_get_bitmap_height(mask->bitmap);
		al_draw_bitmap(
			mask->bitmap,
			holes[i].x-mask_w/2+top_offset.x,
			holes[i].y-mask_h+hole_yoffs[row]+top_offset.y,
			0
		);
		
		if (!done) {
			if (holes[i].status == DYING) {
				anim_set->get_current_animation()->draw_scaled(
					0, 0, skunk_size.w, skunk_size.h,
					x+ox, y+oy, skunk_size.w*scale, skunk_size.h*scale,
					0
				);
			}
		}
	}

	// Draw timer
	int digits;
	if (timer/1000 >= 10) {
		digits = 2;
	}
	else {
		digits = 1;
	}
	
	int font_w = font->get_current_animation()->get_current_frame()->get_width();
	float xx = (cfg.screen_w-font_w*(digits+1))/2;
	float yy = 5;
	int tmp = timer;
	for (int i = 0; i < digits; i++) {
		int p = powf(10, (digits-i)+2);
		int frame = tmp / p;
		font->set_sub_animation(General::itos(frame));
		font->get_current_animation()->draw(
			xx, yy, 0
		);
		tmp -= frame * p;
		xx += font_w;
	}
	font->set_sub_animation("s");
	font->get_current_animation()->draw(
		xx, yy, 0
	);

	// Draw score/hitx
	if (hits < 0) {
		hits = 0;
	}
	char buf[100];
	snprintf(buf, 100, "%d", hits);
	draw_centered_text(font, al_map_rgb(0x00, 0xff, 0x00), buf, cfg.screen_w/4-30, 5);

	int hitx;
	if (hits_in_a_row >= 7) {
		hitx = 3;
	}
	else if (hits_in_a_row >= 3) {
		hitx = 2;
	}
	else {
		hitx = 1;
	}
	snprintf(buf, 100, "x%d", hitx);
	draw_centered_text(font, al_map_rgb(0xff, 0xd7, 0x00), buf, cfg.screen_w*3/4+15, 5);

	std::list<Pow>::iterator pow_it;
	for (pow_it = pows.begin(); pow_it != pows.end(); pow_it++) {
		Pow &p = *pow_it;
		ALLEGRO_COLOR tint;
		float a;
		if (p.count < POW_LIFETIME/2) {
			a = 1.0;
		}
		else {
			a = ((float)p.count-POW_LIFETIME/2) / (POW_LIFETIME/2);
			if (a > 1.0) a = 1.0;
			a = 1.0 - a;
		}
		tint = al_map_rgba_f(1.0, 1.0, 1.0, a);
		int r = (cfg.screen_w / 120) * 2 + 1;
		al_draw_tinted_bitmap(
			p.kratch ? kratch_bmp->bitmap : pow_bmp->bitmap,
			tint,
			p.x-al_get_bitmap_width(pow_bmp->bitmap)/2+General::rand()%r-(r/2)+top_offset.x,
			p.y-al_get_bitmap_height(pow_bmp->bitmap)/2+General::rand()%r-(r/2)+top_offset.y,
			0
		);
	}
	std::list<Star>::iterator star_it;
	for (star_it = stars.begin(); star_it != stars.end(); star_it++) {
		Star &s = *star_it;
		ALLEGRO_COLOR tint;
		float b = (float)s.count / STAR_LIFETIME;
		if (b > 1.0) b = 1.0;
		tint = al_map_rgb_f(1.0, 1.0, b);
		al_draw_tinted_rotated_bitmap(
			star_bmp->bitmap,
			tint,
			al_get_bitmap_width(star_bmp->bitmap)/2,
			al_get_bitmap_height(star_bmp->bitmap)/2,
			s.x+top_offset.x, s.y+top_offset.y,
			s.angle,
			0
		);
	}

	if (bashing) {
		float xx = holes[curr_hole].x;
		float yy = holes[curr_hole].y - hand_size.h;
		xx += top_offset.x;
		yy += top_offset.y;

		xx += 90; // trial and error
		yy += 110;

		if  (curr_hole == 0 || curr_hole == 3 || curr_hole == 6) {
			hand->set_sub_animation("left");
		}
		else if (curr_hole == 1 || curr_hole == 4 || curr_hole == 7) {
			hand->set_sub_animation("middle");
			xx -= 68;
		}
		else {
			hand->set_sub_animation("right");
			xx -= 68*2;
		}

		hand->get_current_animation()->draw(
			xx-hand_size.w/2,
			yy,
			0
		);
	}
}
Example #24
0
void
update_cache_pos (struct pos *p, enum em em, enum vm vm)
{
  static bool recursive = false;

  int x, y;

  int room_view_bkp = room_view;

  struct pos pbl; prel (p, &pbl, +1, -1);
  struct pos pb; prel (p, &pb, +1, +0);
  struct pos pbr; prel (p, &pbr, +1, +1);

  struct pos pl; prel (p, &pl, +0, -1);
  struct pos pr; prel (p, &pr, +0, +1);

  struct pos pa; prel (p, &pa, -1, +0);
  struct pos pal; prel (p, &pal, -1, -1);
  struct pos par; prel (p, &par, -1, +1);

  for (y = mr.h - 1; y >= 0; y--)
    for (x = 0; x < mr.w; x++)
      if (p->room && mr.cell[x][y].room == p->room) {
        room_view = p->room;
        mr.dx = x;
        mr.dy = y;

        int cx, cy, cw, ch;
        switch (con (p)->fg) {
        default:
          cx = PLACE_WIDTH * p->place;
          cy = PLACE_HEIGHT * p->floor - 10;
          cw = 2 * PLACE_WIDTH;
          ch = PLACE_HEIGHT + 3 + 10;
          break;
        }

        set_target_bitmap (mr.cell[x][y].cache);
        al_set_clipping_rectangle (cx, cy, cw, ch);
        al_clear_to_color (TRANSPARENT_COLOR);

        con_caching = true;

        draw_conbg (mr.cell[x][y].cache, &pbl, em, vm);
        draw_conbg (mr.cell[x][y].cache, &pb, em, vm);
        draw_conbg (mr.cell[x][y].cache, &pbr, em, vm);

        draw_conbg (mr.cell[x][y].cache, &pl, em, vm);
        draw_conbg (mr.cell[x][y].cache, p, em, vm);
        draw_conbg (mr.cell[x][y].cache, &pr, em, vm);

        draw_conbg (mr.cell[x][y].cache, &pal, em, vm);
        draw_conbg (mr.cell[x][y].cache, &pa, em, vm);
        draw_conbg (mr.cell[x][y].cache, &par, em, vm);

        draw_confg_right (mr.cell[x][y].cache, &pbl, em, vm, true);
        draw_confg_right (mr.cell[x][y].cache, &pb, em, vm, true);
        draw_confg_right (mr.cell[x][y].cache, &pl, em, vm, false);

        draw_confg (mr.cell[x][y].cache, p, em, vm, true);

        draw_confg_right (mr.cell[x][y].cache, &pal, em, vm, true);
        draw_confg (mr.cell[x][y].cache, &pa, em, vm, true);
        draw_confg_base (mr.cell[x][y].cache, &par, em, vm);
        draw_confg_left (mr.cell[x][y].cache, &par, em, vm, false);

        al_reset_clipping_rectangle ();
        al_hold_bitmap_drawing (false);
        con_caching = false;
      }

  /* printf ("%i,%i,%i\n", p->room, p->floor, p->place); */

  if (! recursive && p->place == -1) {
    struct pos p0;
    p0.room = roomd (p->room, LEFT);
    p0.floor = p->floor;
    p0.place = PLACES - 1;
    recursive = true;
    update_cache_pos (&p0, em, vm);
    recursive = false;
  }

  if (! recursive && p->floor == -1) {
    struct pos p0;
    p0.room = roomd (p->room, ABOVE);
    p0.floor = FLOORS - 1;
    p0.place = p->place;
    recursive = true;
    update_cache_pos (&p0, em, vm);
    recursive = false;
  }

  if (! recursive && p->place == PLACES - 1) {
    struct pos p0;
    p0.room = roomd (p->room, RIGHT);
    p0.floor = p->floor;
    p0.place = -1;
    recursive = true;
    update_cache_pos (&p0, em, vm);
    recursive = false;
  }

  if (! recursive && p->floor == FLOORS - 1) {
    struct pos p0;
    p0.room = roomd (p->room, BELOW);
    p0.floor = -1;
    p0.place = p->place;
    recursive = true;
    update_cache_pos (&p0, em, vm);
    recursive = false;
  }

  if (! recursive && p->floor == -1 && p->place == -1) {
    struct pos p0;
    p0.room = roomd (p->room, ABOVE);
    p0.room = roomd (p0.room, LEFT);
    p0.floor = FLOORS - 1;
    p0.place = PLACES - 1;
    recursive = true;
    update_cache_pos (&p0, em, vm);
    recursive = false;
  }

  if (! recursive && p->floor == -1 && p->place == PLACES - 1) {
    struct pos p0;
    p0.room = roomd (p->room, ABOVE);
    p0.room = roomd (p0.room, RIGHT);
    p0.floor = FLOORS - 1;
    p0.place = -1;
    recursive = true;
    update_cache_pos (&p0, em, vm);
    recursive = false;
  }

  if (! recursive && p->floor == FLOORS - 1 && p->place == -1) {
    struct pos p0;
    p0.room = roomd (p->room, LEFT);
    p0.room = roomd (p0.room, BELOW);
    p0.floor = -1;
    p0.place = PLACES - 1;
    recursive = true;
    update_cache_pos (&p0, em, vm);
    recursive = false;
  }

  if (! recursive && p->floor == FLOORS - 1 && p->place == PLACES - 1) {
    struct pos p0;
    p0.room = roomd (p->room, BELOW);
    p0.room = roomd (p0.room, RIGHT);
    p0.floor = -1;
    p0.place = -1;
    recursive = true;
    update_cache_pos (&p0, em, vm);
    recursive = false;
  }

  /* if (! recursive) printf ("----------------------------\n"); */

  room_view = room_view_bkp;
}
Example #25
0
int main(int argc, char **argv)
{
   const int display_w = 640;
   const int display_h = 480;

   ALLEGRO_DISPLAY *dpy;
   ALLEGRO_BITMAP *buf;
   ALLEGRO_BITMAP *bmp;
   ALLEGRO_BITMAP *mem_bmp;
   ALLEGRO_BITMAP *src_bmp;
   int bmp_w;
   int bmp_h;
   ALLEGRO_EVENT_QUEUE *queue;
   ALLEGRO_EVENT event;
   double theta = 0;
   double k = 1.0;
   int mode = 0;
   bool wide_mode = false;
   bool mem_src_mode = false;
   bool trans_mode = false;
   int flags = 0;
   bool clip_mode = false;
   ALLEGRO_COLOR tint;

   (void)argc;
   (void)argv;

   if (!al_init()) {
      abort_example("Could not init Allegro.\n");
   }

   al_install_keyboard();
   al_init_image_addon();
   init_platform_specific();

   open_log();
   log_printf("Press 'w' to toggle wide mode.\n");
   log_printf("Press 's' to toggle memory source bitmap.\n");
   log_printf("Press space to toggle drawing to backbuffer or off-screen bitmap.\n");
   log_printf("Press 't' to toggle translucency.\n");
   log_printf("Press 'h' to toggle horizontal flipping.\n");
   log_printf("Press 'v' to toggle vertical flipping.\n");
   log_printf("Press 'c' to toggle clipping.\n");
   log_printf("\n");

   dpy = al_create_display(display_w, display_h);
   if (!dpy) {
      abort_example("Unable to set any graphic mode\n");
   }

   buf = al_create_bitmap(display_w, display_h);
   if (!buf) {
      abort_example("Unable to create buffer\n\n");
   }

   bmp = al_load_bitmap("data/mysha.pcx");
   if (!bmp) {
      abort_example("Unable to load image\n");
   }

   al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
   mem_bmp = al_load_bitmap("data/mysha.pcx");
   if (!mem_bmp) {
      abort_example("Unable to load image\n");
   }

   bmp_w = al_get_bitmap_width(bmp);
   bmp_h = al_get_bitmap_height(bmp);

   queue = al_create_event_queue();
   al_register_event_source(queue, al_get_keyboard_event_source());

   while (true) {
      if (al_get_next_event(queue, &event)) {
         if (event.type == ALLEGRO_EVENT_KEY_CHAR) {
            if (event.keyboard.keycode == ALLEGRO_KEY_ESCAPE)
               break;
            if (event.keyboard.unichar == ' ') {
               mode = !mode;
               if (mode == 0)
                  log_printf("Drawing to off-screen buffer\n");
               else
                  log_printf("Drawing to display backbuffer\n");
            }
            if (event.keyboard.unichar == 'w')
               wide_mode = !wide_mode;
            if (event.keyboard.unichar == 's') {
               mem_src_mode = !mem_src_mode;
               if (mem_src_mode)
                  log_printf("Source is memory bitmap\n");
               else
                  log_printf("Source is display bitmap\n");
            }
            if (event.keyboard.unichar == 't')
               trans_mode = !trans_mode;
            if (event.keyboard.unichar == 'h')
               flags ^= ALLEGRO_FLIP_HORIZONTAL;
            if (event.keyboard.unichar == 'v')
               flags ^= ALLEGRO_FLIP_VERTICAL;
            if (event.keyboard.unichar == 'c')
               clip_mode = !clip_mode;
         }
      }

      /*
       * mode 0 = draw scaled to off-screen buffer before
       *          blitting to display backbuffer
       * mode 1 = draw scaled to display backbuffer
       */

      if (mode == 0) {
         al_set_target_bitmap(buf);
      }
      else {
         al_set_target_backbuffer(dpy);
      }

      src_bmp = (mem_src_mode) ? mem_bmp : bmp;
      k = (wide_mode) ? 2.0 : 1.0;

      al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
      tint = al_map_rgba_f(1, 1, 1, 1);
      if (mode == 0)
         al_clear_to_color(al_map_rgba_f(1, 0, 0, 1));
      else
         al_clear_to_color(al_map_rgba_f(0, 0, 1, 1));

      if (trans_mode) {
         al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA);
         tint = al_map_rgba_f(1, 1, 1, 0.5);
      }

      if (clip_mode) {
         al_set_clipping_rectangle(50, 50, display_w - 100, display_h - 100);
      }
      else {
         al_set_clipping_rectangle(0, 0, display_w, display_h);
      }

      al_draw_tinted_scaled_bitmap(src_bmp, tint,
         0, 0, bmp_w, bmp_h,
         display_w/2, display_h/2,
         k * cos(theta) * display_w/2, k * sin(theta) * display_h/2,
         flags);

      if (mode == 0) {
         al_set_target_backbuffer(dpy);
         al_set_clipping_rectangle(0, 0, display_w, display_h);
         al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
         al_draw_bitmap(buf, 0, 0, 0);
      }

      al_flip_display();
      al_rest(0.01);
      theta += 0.01;
   }

   al_destroy_bitmap(bmp);
   al_destroy_bitmap(mem_bmp);
   al_destroy_bitmap(buf);

   close_log(false);
   return 0;
}
Example #26
0
    void ScrollableArea::Print()
    {
        wd_PrintBegin();

        wd_Print_Background();

        al_identity_transform(&rest);
        if((wd_bf & bf_ZOOMABLE))
        {
            al_scale_transform(&rest, zoom, zoom);
        }
        al_translate_transform(&rest, wd_theme.added_thickness/2, wd_theme.added_thickness/2);
        al_use_transform(&rest);
        al_set_clipping_rectangle(wd_theme.added_thickness/2 + wd_theme.thickness,
                                  wd_theme.added_thickness/2 + wd_theme.thickness,
                                  /*wd_theme.added_thickness/2 + */wd_width - (scb_vertical_active == true ? scb_thickness:0) /*- wd_theme.thickness*/,
                                  /*wd_theme.added_thickness/2 + */wd_height - (scb_horizontal_active == true ? scb_thickness:0) /*- wd_theme.thickness*/);

        for(int a = 0; a < (int)widgets.size();a++)
        {

            if(( (widgets[a]->orig_x1 *zoom >= scb_horizontal->change && widgets[a]->orig_x1 *zoom<= scb_horizontal->change + wd_width)
                 || (widgets[a]->orig_x2 *zoom>= scb_horizontal->change && widgets[a]->orig_x2 *zoom<= scb_horizontal->change + wd_width)
                 || (widgets[a]->orig_x1 *zoom<= scb_horizontal->change && widgets[a]->orig_x2 *zoom>= scb_horizontal->change + wd_width)
                ) && (
                (widgets[a]->orig_y1 *zoom>= scb_vertical->change && widgets[a]->orig_y1 *zoom<= scb_vertical->change + wd_height)
                 || (widgets[a]->orig_y2 *zoom>= scb_vertical->change && widgets[a]->orig_y2 *zoom<= scb_vertical->change + wd_height)
                 || (widgets[a]->orig_y1 *zoom<= scb_vertical->change && widgets[a]->orig_y2 *zoom>= scb_vertical->change + wd_height)))
            {
                if(changec_p == true)
                {
                    widgets[a]->Change_print_coords(widgets[a]->orig_x1 - scb_horizontal->change/zoom,
                    widgets[a]->orig_y1 - scb_vertical->change/zoom, widgets[a]->wd_width, widgets[a]->wd_height);



                    widgets[a]->wd_md->Change_coords(wd_x1 + widgets[a]->orig_x1*zoom - scb_horizontal->change,
                                                     wd_y1 + widgets[a]->orig_y1*zoom - scb_vertical->change,
                                                     (widgets[a]->orig_x2 - widgets[a]->orig_x1)*zoom,
                                                     (widgets[a]->orig_y2 - widgets[a]->orig_y1)*zoom);
                }
                widgets[a]->Print();
            }
        }
        changec_p = false;

        al_identity_transform(&rest);
        al_translate_transform(&rest, wd_theme.added_thickness/2, wd_theme.added_thickness/2);
        al_use_transform(&rest);

        al_set_clipping_rectangle(0,0,
                                  wd_width + wd_theme.added_thickness, wd_height + wd_theme.added_thickness);
        zoomresetb->Print();
        scb_horizontal->Print();
        scb_vertical->Print();


        al_identity_transform(&rest);
        al_use_transform(&rest);
        wd_Print_Frame();

        wd_PrintEnd();
    }
static void reset_clip_rect(void)
{
   al_set_clipping_rectangle(0, 0, W, H);
}
Example #28
0
void display_sysmenu(void)
{
#ifdef USING_SYSMENU
// al_set_target_bitmap(sysmstate.bmp);
// al_set_target_bitmap(al_get_backbuffer(display));
 al_set_clipping_rectangle(editor.panel_x, editor.panel_y, editor.panel_w, editor.panel_h);

 al_clear_to_color(colours.base [COL_BLUE] [SHADE_MIN]);

 reset_i_buttons();

 al_draw_textf(font[FONT_SQUARE_BOLD].fnt, colours.base [COL_GREY] [SHADE_MAX], 5, 2, ALLEGRO_ALIGN_LEFT, "System Menu");

 int i;

#define BUTTON_TEXT_LENGTH 30
 char button_text [BUTTON_TEXT_LENGTH] = "";
 int button_colour;
 int button_base_shade; // is increased by 1 if button highlighted, so don't set this to SHADE_MAX
 int button_selectable; // note that setting this to 0 just means the button doesn't look selectable
 int hide_button; // button completely hidden

// sysmenu buttons are a bit complicated because their appearance depends on various game state things
 for (i = 0; i < SYSMENU_BUTTONS; i ++)
 {
  button_colour = COL_BLUE;
  button_base_shade = SHADE_LOW;
  button_selectable = 1;
  hide_button = 0;

  switch(i)
  {
/*   case SYSMENU_NEXT_TURN:
    switch(game.phase)
    {
     case GAME_PHASE_TURN:
      if (game.current_turn == 0)
       strcpy(button_text, "Start execution!");
        else
         strcpy(button_text, "Next turn");
      button_colour = COL_GREEN;
      break;
     case GAME_PHASE_OVER:
      strcpy(button_text, "Game over");
//      button_colour = COL_GREEN;
      button_base_shade = SHADE_MIN;
      button_selectable = 0;
      break;
     default:
      strcpy(button_text, "Executing...");
      if (game.pause_soft)
       strcpy(button_text, "Partial execution");
      if (game.pause_hard)
       strcpy(button_text, "Halted");
      button_base_shade = SHADE_MIN;
      button_selectable = 0;
      break;
    }
    break;*/
   case SYSMENU_PAUSE:
    if (game.pause_soft == 0)
     strcpy(button_text, "Pause");
      else
      {
       strcpy(button_text, "Unpause");
       button_colour = COL_GREEN;
      }
    break;
   case SYSMENU_HALT:
    if (game.pause_hard == 0)
     strcpy(button_text, "Halt execution");
      else
      {
       strcpy(button_text, "Restart execution");
       button_colour = COL_GREEN;
      }
    break;
/*   case SYSMENU_FF:
    if (game.fast_forward == FAST_FORWARD_OFF)
     strcpy(button_text, "Fast forward");
      else
      {
       strcpy(button_text, "Stop fast forward");
       button_colour = COL_GREEN;
      }
    break;*/
   case SYSMENU_SAVE:
    strcpy(button_text, "Save game");
    break;
//   case SYSMENU_LOAD:
//    strcpy(button_text, "Load game");
//    break;
   case SYSMENU_QUIT:
    if (game.phase == GAME_PHASE_OVER)
    {
     strcpy(button_text, "Return to main menu");
     button_colour = COL_GREEN;
    }
     else
      strcpy(button_text, "Quit game");
    break;
   case SYSMENU_QUIT_CONFIRM:
    if (sysmstate.quit_confirm == 1)
    {
     strcpy(button_text, "Really quit?");
     button_colour = COL_RED;
    }
     else
     {
      button_selectable = 0;
      hide_button = 1;
     }
    break;
  }

 if (hide_button == 1)
  continue;

  if (sysmstate.button_highlight == i
   && button_selectable == 1)
//   al_draw_filled_rectangle(editor.panel_x + sysmenu_button[i].x1, editor.panel_y + sysmenu_button[i].y1, editor.panel_x + sysmenu_button[i].x2, editor.panel_y + sysmenu_button[i].y2, colours.base [button_colour] [button_base_shade + 1]);
   add_menu_button(editor.panel_x + sysmenu_button[i].x1, editor.panel_y + sysmenu_button[i].y1, editor.panel_x + sysmenu_button[i].x2, editor.panel_y + sysmenu_button[i].y2, colours.base [button_colour] [button_base_shade + 1], MBUTTON_TYPE_MENU);
    else
     add_menu_button(editor.panel_x + sysmenu_button[i].x1, editor.panel_y + sysmenu_button[i].y1, editor.panel_x + sysmenu_button[i].x2, editor.panel_y + sysmenu_button[i].y2, colours.base [button_colour] [button_base_shade], MBUTTON_TYPE_MENU);
//     al_draw_filled_rectangle(editor.panel_x + sysmenu_button[i].x1, editor.panel_y + sysmenu_button[i].y1, editor.panel_x + sysmenu_button[i].x2, editor.panel_y + sysmenu_button[i].y2, colours.base [button_colour] [button_base_shade]);

   add_menu_string(editor.panel_x + sysmenu_button[i].x1 + 15, editor.panel_y + sysmenu_button[i].y1 + 20, &colours.base [COL_GREY] [SHADE_HIGH], 0, FONT_SQUARE_BOLD, button_text);
//   al_draw_textf(font[FONT_SQUARE_BOLD].fnt, colours.base [COL_GREY] [SHADE_HIGH], editor.panel_x + sysmenu_button[i].x1 + 15, editor.panel_y + sysmenu_button[i].y1 + 20, 0, "%s", button_text);

 }

 draw_menu_buttons();
// mode buttons should be drawn in i_display.c

 display_log(editor.panel_x + EDIT_WINDOW_X, editor.panel_y + editor.mlog_window_y);
// al_set_target_bitmap(sysmstate.bmp);
 al_set_clipping_rectangle(editor.panel_x, editor.panel_y, editor.panel_w, editor.panel_h);

 draw_scrollbar(&mlog.scrollbar_v, 0, 0);

 if (ex_control.panel_drag_ready == 1
		|| ex_control.mouse_dragging_panel == 1)
		draw_panel_drag_ready_line();

// al_set_target_bitmap(al_get_backbuffer(display));
// al_draw_bitmap(sysmstate.bmp, sysmstate.panel_x, sysmstate.panel_y, 0); // TO DO!!!!: need to treat the sysmenu bitmap as a subbitmap of the display backbuffer, which would let us save this drawing operation

#endif


}
Example #29
0
// Render function.
// (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop)
void ImGui_ImplAllegro5_RenderDrawData(ImDrawData* draw_data)
{
    // Backup Allegro state that will be modified
    ALLEGRO_TRANSFORM last_transform = *al_get_current_transform();
    ALLEGRO_TRANSFORM last_projection_transform = *al_get_current_projection_transform();
    int last_clip_x, last_clip_y, last_clip_w, last_clip_h;
    al_get_clipping_rectangle(&last_clip_x, &last_clip_y, &last_clip_w, &last_clip_h);
    int last_blender_op, last_blender_src, last_blender_dst;
    al_get_blender(&last_blender_op, &last_blender_src, &last_blender_dst);

    // Setup render state
    al_set_blender(ALLEGRO_ADD, ALLEGRO_ALPHA, ALLEGRO_INVERSE_ALPHA);

    // Setup orthographic projection matrix
    // Our visible imgui space lies from draw_data->DisplayPos (top left) to draw_data->DisplayPos+data_data->DisplaySize (bottom right).
    {
        float L = draw_data->DisplayPos.x;
        float R = draw_data->DisplayPos.x + draw_data->DisplaySize.x;
        float T = draw_data->DisplayPos.y;
        float B = draw_data->DisplayPos.y + draw_data->DisplaySize.y;
        ALLEGRO_TRANSFORM transform;
        al_identity_transform(&transform);
        al_use_transform(&transform);
        al_orthographic_transform(&transform, L, T, 1.0f, R, B, -1.0f);
        al_use_projection_transform(&transform);
    }

    for (int n = 0; n < draw_data->CmdListsCount; n++)
    {
        const ImDrawList* cmd_list = draw_data->CmdLists[n];

        // Allegro's implementation of al_draw_indexed_prim() for DX9 is completely broken. Unindex our buffers ourselves.
        // FIXME-OPT: Unfortunately Allegro doesn't support 32-bits packed colors so we have to convert them to 4 float as well..
        static ImVector<ImDrawVertAllegro> vertices;
        vertices.resize(cmd_list->IdxBuffer.Size);
        for (int i = 0; i < cmd_list->IdxBuffer.Size; i++)
        {
            const ImDrawVert* src_v = &cmd_list->VtxBuffer[cmd_list->IdxBuffer[i]];
            ImDrawVertAllegro* dst_v = &vertices[i];
            dst_v->pos = src_v->pos;
            dst_v->uv = src_v->uv;
            unsigned char* c = (unsigned char*)&src_v->col;
            dst_v->col = al_map_rgba(c[0], c[1], c[2], c[3]);
        }

        const int* indices = NULL;
        if (sizeof(ImDrawIdx) == 2)
        {
            // FIXME-OPT: Unfortunately Allegro doesn't support 16-bit indices.. You can '#define ImDrawIdx int' in imconfig.h to request Dear ImGui to output 32-bit indices.
            // Otherwise, we convert them from 16-bit to 32-bit at runtime here, which works perfectly but is a little wasteful.
            static ImVector<int> indices_converted;
            indices_converted.resize(cmd_list->IdxBuffer.Size);
            for (int i = 0; i < cmd_list->IdxBuffer.Size; ++i)
                indices_converted[i] = (int)cmd_list->IdxBuffer.Data[i];
            indices = indices_converted.Data;
        }
        else if (sizeof(ImDrawIdx) == 4)
        {
            indices = (const int*)cmd_list->IdxBuffer.Data;
        }

        // Render command lists
        int idx_offset = 0;
        ImVec2 clip_off = draw_data->DisplayPos;
        for (int cmd_i = 0; cmd_i < cmd_list->CmdBuffer.Size; cmd_i++)
        {
            const ImDrawCmd* pcmd = &cmd_list->CmdBuffer[cmd_i];
            if (pcmd->UserCallback)
            {
                pcmd->UserCallback(cmd_list, pcmd);
            }
            else
            {
                ALLEGRO_BITMAP* texture = (ALLEGRO_BITMAP*)pcmd->TextureId;
                al_set_clipping_rectangle(pcmd->ClipRect.x - clip_off.x, pcmd->ClipRect.y - clip_off.y, pcmd->ClipRect.z - pcmd->ClipRect.x, pcmd->ClipRect.w - pcmd->ClipRect.y);
                al_draw_prim(&vertices[0], g_VertexDecl, texture, idx_offset, idx_offset + pcmd->ElemCount, ALLEGRO_PRIM_TRIANGLE_LIST);
            }
            idx_offset += pcmd->ElemCount;
        }
    }

    // Restore modified Allegro state
    al_set_blender(last_blender_op, last_blender_src, last_blender_dst);
    al_set_clipping_rectangle(last_clip_x, last_clip_y, last_clip_w, last_clip_h);
    al_use_transform(&last_transform);
    al_use_projection_transform(&last_projection_transform);
}
Example #30
0
int main(void)
{
   ALLEGRO_DISPLAY *display;
   ALLEGRO_BITMAP* bkg;
   ALLEGRO_COLOR black;
   ALLEGRO_EVENT_QUEUE *queue;

   // Initialize Allegro 5 and addons
   if (!al_init()) {
      abort_example("Could not init Allegro.\n");
   }
   al_init_image_addon();
   al_init_font_addon();
   al_init_primitives_addon();
   
   // Create a window to display things on: 640x480 pixels
   display = al_create_display(ScreenW, ScreenH);
   if (!display) {
      abort_example("Error creating display.\n");
      return 1;
   }
   
   // Install the keyboard handler
   if (!al_install_keyboard()) {
      abort_example("Error installing keyboard.\n");
      return 1;
   }

   if (!al_install_mouse()) {
      abort_example("Error installing mouse.\n");
      return 1;
   }
   
   // Load a font
   Font = al_load_font("data/fixed_font.tga", 0, 0);
   if (!Font) {
      abort_example("Error loading \"data/fixed_font.tga\".\n");
      return 1;
   }
   
   solid_white = al_map_rgba_f(1, 1, 1, 1);
   
   bkg = al_load_bitmap("data/bkg.png");

   Texture = al_load_bitmap("data/texture.tga");
   
   // Make and set some color to draw with
   black = al_map_rgba_f(0.0, 0.0, 0.0, 1.0);
   
   // Start the event queue to handle keyboard input and our timer
   queue = al_create_event_queue();
   al_register_event_source(queue, al_get_keyboard_event_source());
   al_register_event_source(queue, al_get_display_event_source(display));
   al_register_event_source(queue, al_get_mouse_event_source());
   
   al_set_window_title(display, "Primitives Example");
   
   {
   int refresh_rate = 60;
   int frames_done = 0;
   double time_diff = al_get_time();
   double fixed_timestep = 1.0f / refresh_rate;
   double real_time = al_get_time();
   double game_time = al_get_time();
   int ii;
   int cur_screen = 0;
   bool done = false;
   int clip = 0;
   ALLEGRO_TIMER *timer;
   ALLEGRO_EVENT_QUEUE *timer_queue;
   int old;

   timer = al_create_timer(ALLEGRO_BPS_TO_SECS(refresh_rate));
   al_start_timer(timer);
   timer_queue = al_create_event_queue();
   al_register_event_source(timer_queue, al_get_timer_event_source(timer));
   
   old = al_get_new_bitmap_flags();
   al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
   Buffer = al_create_bitmap(ScreenW, ScreenH);
   al_set_new_bitmap_flags(old);
   
   al_identity_transform(&Identity);
   
   Screens[0] = LowPrimitives;
   Screens[1] = IndexedPrimitives;
   Screens[2] = HighPrimitives;
   Screens[3] = TransformationsPrimitives;
   Screens[4] = FilledPrimitives;
   Screens[5] = IndexedFilledPrimitives;
   Screens[6] = HighFilledPrimitives;
   Screens[7] = TexturePrimitives;
   Screens[8] = FilledTexturePrimitives;
   Screens[9] = CustomVertexFormatPrimitives;

   ScreenName[0] = "Low Level Primitives";
   ScreenName[1] = "Indexed Primitives";
   ScreenName[2] = "High Level Primitives";
   ScreenName[3] = "Transformations";
   ScreenName[4] = "Low Level Filled Primitives";
   ScreenName[5] = "Indexed Filled Primitives";
   ScreenName[6] = "High Level Filled Primitives";
   ScreenName[7] = "Textured Primitives";
   ScreenName[8] = "Filled Textured Primitives";
   ScreenName[9] = "Custom Vertex Format";

   for (ii = 0; ii < NUM_SCREENS; ii++)
      Screens[ii](INIT);
      
   while (!done) {
      double frame_duration = al_get_time() - real_time;
      al_rest(fixed_timestep - frame_duration); //rest at least fixed_dt
      frame_duration = al_get_time() - real_time;
      real_time = al_get_time();
      
      if (real_time - game_time > frame_duration) { //eliminate excess overflow
         game_time += fixed_timestep * floor((real_time - game_time) / fixed_timestep);
      }
      
      while (real_time - game_time >= 0) {
         ALLEGRO_EVENT key_event;
         double start_time = al_get_time();
         game_time += fixed_timestep;
         
         Screens[cur_screen](LOGIC);
         
         while (al_get_next_event(queue, &key_event)) {
            switch (key_event.type) {
               case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN: {
                  cur_screen++;
                  if (cur_screen >= NUM_SCREENS) {
                     cur_screen = 0;
                  }
                  break;
               }

               case ALLEGRO_EVENT_DISPLAY_CLOSE: {
                  done = true;
                  break;
               }
               case ALLEGRO_EVENT_KEY_CHAR: {
                  switch (key_event.keyboard.keycode) {
                     case ALLEGRO_KEY_ESCAPE: {
                        done = true;
                        break;
                     }
                     case ALLEGRO_KEY_S: {
                        Soft = !Soft;
                        time_diff = al_get_time();
                        frames_done = 0;
                        break;
                     }
                     case ALLEGRO_KEY_C: {
                        clip = !clip;
                        time_diff = al_get_time();
                        frames_done = 0;
                        break;
                     }
                     case ALLEGRO_KEY_L: {
                        Blend = !Blend;
                        time_diff = al_get_time();
                        frames_done = 0;
                        break;
                     }
                     case ALLEGRO_KEY_B: {
                        Background = !Background;
                        time_diff = al_get_time();
                        frames_done = 0;
                        break;
                     }
                     case ALLEGRO_KEY_LEFT: {
                        Speed -= ROTATE_SPEED;
                        break;
                     }
                     case ALLEGRO_KEY_RIGHT: {
                        Speed += ROTATE_SPEED;
                        break;
                     }
                     case ALLEGRO_KEY_PGUP: {
                        Thickness += 0.5f;
                        if (Thickness < 1.0f)
                           Thickness = 1.0f;
                        break;
                     }
                     case ALLEGRO_KEY_PGDN: {
                        Thickness -= 0.5f;
                        if (Thickness < 1.0f)
                           Thickness = 0.0f;
                        break;
                     }
                     case ALLEGRO_KEY_UP: {
                        cur_screen++;
                        if (cur_screen >= NUM_SCREENS) {
                           cur_screen = 0;
                        }
                        break;
                     }
                     case ALLEGRO_KEY_SPACE: {
                        Speed = 0;
                        break;
                     }
                     case ALLEGRO_KEY_DOWN: {
                        cur_screen--;
                        if (cur_screen < 0) {
                           cur_screen = NUM_SCREENS - 1;
                        }
                        break;
                     }
                  }
               }
            }
         }
         
         if (al_get_time() - start_time >= fixed_timestep) { //break if we start taking too long
            break;
         }
      }

      al_clear_to_color(black);            

      if (Soft == 1) {
         al_set_target_bitmap(Buffer);
         al_clear_to_color(black);
      }
      
      if (Background && bkg) {
         al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
         al_draw_scaled_bitmap(bkg, 0, 0, al_get_bitmap_width(bkg), al_get_bitmap_height(bkg), 0, 0, ScreenW, ScreenH, 0);
      }
      
      if (clip == 1) {
         al_set_clipping_rectangle(ScreenW / 2, ScreenH / 2, ScreenW / 2, ScreenH / 2);
      }
      
      Screens[cur_screen](DRAW);
      
      al_set_clipping_rectangle(0, 0, ScreenW, ScreenH);

      if (Soft == 1) {
         al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);
         al_set_target_backbuffer(display);
         al_draw_bitmap(Buffer, 0, 0, 0);
      }

      al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);
      al_draw_textf(Font, solid_white, ScreenW / 2, ScreenH - 20, ALLEGRO_ALIGN_CENTRE, "%s", ScreenName[cur_screen]);
      al_draw_textf(Font, solid_white, 0, 0, 0, "FPS: %f", (float)frames_done / (al_get_time() - time_diff));
      al_draw_textf(Font, solid_white, 0, 20, 0, "Change Screen (Up/Down). Esc to Quit.");
      al_draw_textf(Font, solid_white, 0, 40, 0, "Rotation (Left/Right/Space): %f", Speed);
      al_draw_textf(Font, solid_white, 0, 60, 0, "Thickness (PgUp/PgDown): %f", Thickness);
      al_draw_textf(Font, solid_white, 0, 80, 0, "Software (S): %d", Soft);
      al_draw_textf(Font, solid_white, 0, 100, 0, "Blending (L): %d", Blend);
      al_draw_textf(Font, solid_white, 0, 120, 0, "Background (B): %d", Background);
      al_draw_textf(Font, solid_white, 0, 140, 0, "Clip (C): %d", clip);

      al_flip_display();
      frames_done++;
   }
   }
   
   return 0;
}