Пример #1
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);
}
Пример #2
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);
}
Пример #3
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);
}
Пример #4
0
static int allua_Bitmap_get_clipping_rectangle(lua_State * L)
{
   int x;
   int y;
   int w;
   int h;
   al_get_clipping_rectangle(&x, &y, &w, &h);
   lua_pushinteger(L, x);
   lua_pushinteger(L, y);
   lua_pushinteger(L, w);
   lua_pushinteger(L, h);
   return 4;
}
Пример #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);
		}
	}
}
Пример #6
0
void _al_point_2d(ALLEGRO_BITMAP* texture, ALLEGRO_VERTEX* v)
{
   int shade = 1;
   int op, src_mode, dst_mode, op_alpha, src_alpha, dst_alpha;
   ALLEGRO_COLOR vc;
   int clip_min_x, clip_min_y, clip_max_x, clip_max_y;
   int x = (int)floorf(v->x);
   int y = (int)floorf(v->x);
   
   al_get_clipping_rectangle(&clip_min_x, &clip_min_y, &clip_max_x, &clip_max_y);
   clip_max_x += clip_min_x;
   clip_max_y += clip_min_y;
   
   if(x < clip_min_x || x >= clip_max_x || y < clip_min_y || y >= clip_max_y)
      return;

   vc = v->color;

   al_get_separate_blender(&op, &src_mode, &dst_mode, &op_alpha, &src_alpha, &dst_alpha);
   if (_AL_DEST_IS_ZERO && _AL_SRC_NOT_MODIFIED) {
      shade = 0;
   }
   
   if (texture) {
      float U = fix_var(v->u, al_get_bitmap_width(texture));
      float V = fix_var(v->v, al_get_bitmap_height(texture));
      ALLEGRO_COLOR color = al_get_pixel(texture, U, V);

      if(vc.r != 1 || vc.g != 1 || vc.b != 1 || vc.a != 1) {
         color.r *= vc.r;
         color.g *= vc.g;
         color.b *= vc.b;
         color.a *= vc.a;
      }

      if (shade) {
         al_put_blended_pixel(v->x, v->y, color);
      } else {
         al_put_pixel(v->x, v->y, color);
      }
   } else {
      ALLEGRO_COLOR color = al_map_rgba_f(vc.r, vc.g, vc.b, vc.a);
      if (shade) {
         al_put_blended_pixel(v->x, v->y, color);
      } else {
         al_put_pixel(v->x, v->y, color);
      }
   }
}
Пример #7
0
void
draw_bitmap_region (ALLEGRO_BITMAP *from, ALLEGRO_BITMAP *to,
                    float sx, float sy, float sw, float sh,
                    float dx, float dy, int flags)
{
  merge_drawn_rectangle (to, dx, dy, sw, sh);
  set_target_bitmap (to);

  int cx, cy, cw, ch;
  al_get_clipping_rectangle (&cx, &cy, &cw, &ch);

  if (cw <= 0 || ch <= 0) return;

  al_draw_bitmap_region (from, sx, sy, sw, sh, dx, dy, flags);
}
Пример #8
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;
}
Пример #9
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;
}
Пример #10
0
void DrawConsole(struct Game *game) {
	if (game->_priv.showconsole) {
		ALLEGRO_TRANSFORM trans;
		al_identity_transform(&trans);
		int clipX, clipY, clipWidth, clipHeight;
		al_get_clipping_rectangle(&clipX, &clipY, &clipWidth, &clipHeight);
		al_use_transform(&trans);

		al_draw_bitmap(game->_priv.console, clipX, clipY, 0);
		double game_time = al_get_time();
		if(game_time - game->_priv.fps_count.old_time >= 1.0) {
			game->_priv.fps_count.fps = game->_priv.fps_count.frames_done / (game_time - game->_priv.fps_count.old_time);
			game->_priv.fps_count.frames_done = 0;
			game->_priv.fps_count.old_time = game_time;
		}
		char sfps[6] = { };
		snprintf(sfps, 6, "%.0f", game->_priv.fps_count.fps);
		al_use_transform(&game->projection);

		DrawTextWithShadow(game->_priv.font, al_map_rgb(255,255,255), game->viewport.width*0.99, 0, ALLEGRO_ALIGN_RIGHT, sfps);

	}
	game->_priv.fps_count.frames_done++;
}
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
		);
	}
}
Пример #12
0
static void draw(void)
{
   float x, y;
   int cx, cy, cw, ch;
   int w = al_get_bitmap_width(ex.zoom);
   int h = al_get_bitmap_height(ex.zoom);
   ALLEGRO_BITMAP *screen = al_get_target_bitmap();
   ALLEGRO_BITMAP *mem;
   int rects_num = 16, i, j;
   float rects[16 * 4];
   for (j = 0; j < 4; j++) {
      for (i = 0; i < 4; i++) {
         rects[(j * 4 + i) * 4 + 0] = 2 + i * 0.25 + i * 7;
         rects[(j * 4 + i) * 4 + 1] = 2 + j * 0.25 + j * 7;
         rects[(j * 4 + i) * 4 + 2] = 2 + i * 0.25 + i * 7 + 5;
         rects[(j * 4 + i) * 4 + 3] = 2 + j * 0.25 + j * 7 + 5;
      }
   }

   al_get_clipping_rectangle(&cx, &cy, &cw, &ch);
   al_clear_to_color(ex.background);

   set_xy(8, 0);
   print("Drawing %s (press SPACE to change)", names[ex.what]);

   set_xy(8, 16);
   print("Original");

   set_xy(80, 16);
   print("Enlarged x 16");

   al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);

   if (ex.software) {
      al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
      al_set_new_bitmap_format(al_get_bitmap_format(al_get_target_bitmap()));
      mem = al_create_bitmap(w, h);
      al_set_target_bitmap(mem);
      x = 0;
      y = 0;
   }
   else {
      mem = NULL;
      x = 8;
      y = 40;
   }
   al_draw_bitmap(ex.pattern, x, y, 0);

   /* Draw the test scene. */

   al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_INVERSE_ALPHA);
   for (i = 0; i < rects_num; i++) {
      ALLEGRO_COLOR rgba = ex.foreground;
      rgba.a *= 0.5;
      primitive(
         x + rects[i * 4 + 0],
         y + rects[i * 4 + 1],
         x + rects[i * 4 + 2],
         y + rects[i * 4 + 3],
         rgba, false);
   }

   al_set_blender(ALLEGRO_ADD, ALLEGRO_ONE, ALLEGRO_ZERO);

   if (ex.software) {
      al_set_target_bitmap(screen);
      x = 8;
      y = 40;
      al_draw_bitmap(mem, x, y, 0);
      al_destroy_bitmap(mem);
   }

   /* Grab screen contents into our bitmap. */
   al_set_target_bitmap(ex.zoom);
   al_draw_bitmap_region(screen, x, y, w, h, 0, 0, 0);
   al_set_target_bitmap(screen);

   /* Draw it enlarged. */
   x = 80;
   y = 40;
   al_draw_scaled_bitmap(ex.zoom, 0, 0, w, h, x, y, w * 16, h * 16, 0);
   
   /* Draw outlines. */
   for (i = 0; i < rects_num; i++) {
      primitive(
         x + rects[i * 4 + 0] * 16,
         y + rects[i * 4 + 1] * 16,
         x + rects[i * 4 + 2] * 16,
         y + rects[i * 4 + 3] * 16,
         ex.outline, true);
   }

   set_xy(8, 640 - 48);
   print("Thickness: %d (press T to change)", ex.thickness);
   print("Drawing with: %s (press S to change)",
      ex.software ? "software" : "hardware");
   print("Supersampling: %dx (edit ex_draw.ini to change)", ex.samples);

// FIXME: doesn't work
//      al_get_display_option(ALLEGRO_SAMPLE_BUFFERS));
}
Пример #13
0
void _al_draw_soft_triangle(
   ALLEGRO_VERTEX* v1, ALLEGRO_VERTEX* v2, ALLEGRO_VERTEX* v3, uintptr_t state,
   void (*init)(uintptr_t, ALLEGRO_VERTEX*, ALLEGRO_VERTEX*, ALLEGRO_VERTEX*),
   void (*first)(uintptr_t, int, int, int, int),
   void (*step)(uintptr_t, int),
   void (*draw)(uintptr_t, int, int, int))
{
   /*
   ALLEGRO_VERTEX copy_v1, copy_v2; <- may be needed for clipping later on
   */
   ALLEGRO_VERTEX* vtx1 = v1;
   ALLEGRO_VERTEX* vtx2 = v2;
   ALLEGRO_VERTEX* vtx3 = v3;
   ALLEGRO_BITMAP *target = al_get_target_bitmap();
   int need_unlock = 0;
   ALLEGRO_LOCKED_REGION *lr;
   int min_x, max_x, min_y, max_y;
   int clip_min_x, clip_min_y, clip_max_x, clip_max_y;

   al_get_clipping_rectangle(&clip_min_x, &clip_min_y, &clip_max_x, &clip_max_y);
   clip_max_x += clip_min_x;
   clip_max_y += clip_min_y;

   /*
   TODO: Need to clip them first, make a copy of the vertices first then
   */

   /*
   Lock the region we are drawing to. We are choosing the minimum and maximum
   possible pixels touched from the formula (easily verified by following the
   above algorithm.
   */

   min_x = (int)floorf(MIN(vtx1->x, MIN(vtx2->x, vtx3->x))) - 1;
   min_y = (int)floorf(MIN(vtx1->y, MIN(vtx2->y, vtx3->y))) - 1;
   max_x = (int)ceilf(MAX(vtx1->x, MAX(vtx2->x, vtx3->x))) + 1;
   max_y = (int)ceilf(MAX(vtx1->y, MAX(vtx2->y, vtx3->y))) + 1;

   /*
   TODO: This bit is temporary, the min max's will be guaranteed to be within the bitmap
   once clipping is implemented
   */
   if (min_x >= clip_max_x || min_y >= clip_max_y)
      return;
   if (max_x >= clip_max_x)
      max_x = clip_max_x;
   if (max_y >= clip_max_y)
      max_y = clip_max_y;

   if (max_x < clip_min_x || max_y < clip_min_y)
      return;
   if (min_x < clip_min_x)
      min_x = clip_min_x;
   if (min_y < clip_min_y)
      min_y = clip_min_y;

   if (al_is_bitmap_locked(target)) {
      if (!bitmap_region_is_locked(target, min_x, min_y, max_x - min_x, max_y - min_y))
         return;
   } else {
      if (!(lr = al_lock_bitmap_region(target, min_x, min_y, max_x - min_x, max_y - min_y, ALLEGRO_PIXEL_FORMAT_ANY, 0)))
         return;
      need_unlock = 1;
   }

   triangle_stepper(state, init, first, step, draw, v1, v2, v3);

   if (need_unlock)
      al_unlock_bitmap(target);
}
Пример #14
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);
}
Пример #15
0
void m_flip_display(void)
{
	bool skip_flip = false;

	if (prompt_for_close_on_next_flip) {
		prompt_for_close_on_next_flip = false;
		prepareForScreenGrab2();
		bool hidden = is_cursor_hidden();
		show_mouse_cursor();
		int r = triple_prompt("", "Really quit game or return to menu?", "", "Menu", "Quit", "Cancel", 2, true);
		if (hidden) {
			hide_mouse_cursor();
		}
		if (r == 0) {
			break_main_loop = true;
		}
		else if (r == 1) {
			do_close_exit_game();
		}
		skip_flip = true;
	}
	else if (show_item_info_on_flip >= 0) {
		int tmp = show_item_info_on_flip;
		show_item_info_on_flip = -1;
		prepareForScreenGrab2();
		showItemInfo(tmp, true);
		skip_flip = true;
	}
	else if (show_player_info_on_flip) {
		show_player_info_on_flip = false;
		prepareForScreenGrab2();
		if (player_to_show_on_flip) {
			showPlayerInfo_ptr(player_to_show_on_flip);
			player_to_show_on_flip = NULL;
		}
		else {
			showPlayerInfo_number(player_number_to_show_on_flip);
		}
		skip_flip = true;
	}
	else if (close_pressed_for_configure) {
		close_pressed_for_configure = false;
		int _dx, _dy, _dw, _dh;
		get_screen_offset_size(&_dx, &_dy, &_dw, &_dh);
		ALLEGRO_STATE state;
		al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP | ALLEGRO_STATE_NEW_BITMAP_PARAMETERS);
		al_set_new_bitmap_format(al_get_bitmap_format(tmpbuffer->bitmap));
		al_set_new_bitmap_flags(ALLEGRO_MEMORY_BITMAP);
		ALLEGRO_BITMAP *tmp = al_create_bitmap(
			al_get_bitmap_width(tmpbuffer->bitmap),
			al_get_bitmap_height(tmpbuffer->bitmap)
		);
		al_set_target_bitmap(tmp);
		al_clear_to_color(black);
		al_draw_bitmap(tmpbuffer->bitmap, 0, 0, 0);
		al_restore_state(&state);
		config_menu();
		int __dx, __dy, __dw, __dh;
		get_screen_offset_size(&__dx, &__dy, &__dw, &__dh);
		al_store_state(&state, ALLEGRO_STATE_TARGET_BITMAP);
		al_set_target_bitmap(tmpbuffer->bitmap);
		al_clear_to_color(black);
		al_draw_scaled_bitmap(
			tmp,
			_dx, _dy, _dw, _dh,
			__dx, __dy, __dw, __dh,
			0
		);
		al_restore_state(&state);
		al_destroy_bitmap(tmp);
	}

	if (!skip_flip) {
		al_flip_display();
	}

	int xxx, yyy, www, hhh;
	al_get_clipping_rectangle(&xxx, &yyy, &www, &hhh);
	al_set_clipping_rectangle(
		0, 0,
		al_get_display_width(display),
		al_get_display_height(display)
	);
	m_clear(black);
	al_set_clipping_rectangle(xxx, yyy, www, hhh);

	fps_frames++;
	double elapsed = al_get_time() - fps_counter;
	if (fps_on && elapsed > 2) {
		fps = (int)(round((float)fps_frames/elapsed));
		fps_counter = al_get_time();
		fps_frames = 0;
	}
}