assert(action != 0);
update();
- context.draw_surface_part(action->surfaces[frameidx], source, size,
- pos - Vector(action->x_offset, action->y_offset),
+ context.draw_surface_part(action->surfaces[frameidx],
+ Rectf(source, Sizef(size)),
+ Rectf(pos - Vector(action->x_offset, action->y_offset),
+ action->surfaces[frameidx]->get_size()),
layer + action->z_order);
}
}
void
-DrawingContext::draw_surface_part(SurfacePtr surface, const Vector& source,
- const Vector& size, const Vector& dest, int layer)
+DrawingContext::draw_surface_part(SurfacePtr surface,
+ const Rectf& srcrect, const Rectf& dstrect,
+ int layer)
{
assert(surface != 0);
request->target = target;
request->type = SURFACE_PART;
- request->pos = transform.apply(dest);
+ request->pos = transform.apply(dstrect.p1);
request->layer = layer;
request->drawing_effect = transform.drawing_effect;
request->alpha = transform.alpha;
SurfacePartRequest* surfacepartrequest = new(obst) SurfacePartRequest();
- surfacepartrequest->size = size;
- surfacepartrequest->source = source;
+ surfacepartrequest->srcrect = srcrect;
+ surfacepartrequest->dstsize = dstrect.get_size();
surfacepartrequest->surface = surface.get();
- // clip on screen borders
- if(request->pos.x < 0) {
- surfacepartrequest->size.x += request->pos.x;
- if(surfacepartrequest->size.x <= 0)
- return;
- surfacepartrequest->source.x -= request->pos.x;
- request->pos.x = 0;
- }
- if(request->pos.y < 0) {
- surfacepartrequest->size.y += request->pos.y;
- if(surfacepartrequest->size.y <= 0)
- return;
- surfacepartrequest->source.y -= request->pos.y;
- request->pos.y = 0;
- }
request->request_data = surfacepartrequest;
requests->push_back(request);
float angle, const Color& color, const Blend& blend,
int layer);
/// Adds a drawing request for part of a surface.
- void draw_surface_part(SurfacePtr surface, const Vector& source,
- const Vector& size, const Vector& dest, int layer);
+ void draw_surface_part(SurfacePtr surface,
+ const Rectf& srcrect, const Rectf& dstrect,
+ int layer);
/// Draws a text.
void draw_text(FontPtr font, const std::string& text,
const Vector& position, FontAlignment alignment, int layer, Color color = Color(1.0,1.0,1.0));
#include <stdint.h>
+#include "math/rectf.hpp"
+#include "math/sizef.hpp"
#include "math/vector.hpp"
#include "video/color.hpp"
#include "video/drawing_context.hpp"
{
SurfacePartRequest() :
surface(),
- source(),
- size()
+ srcrect(),
+ dstsize()
{}
const Surface* surface;
- Vector source;
- Vector size;
+ Rectf srcrect;
+ Sizef dstsize;
private:
SurfacePartRequest(const SurfacePartRequest&) = delete;
request.alpha = alpha;
SurfacePartRequest surfacepartrequest;
- surfacepartrequest.size = glyph.rect.p2 - glyph.rect.p1;
- surfacepartrequest.source = glyph.rect.p1;
+ surfacepartrequest.srcrect = glyph.rect;
+ surfacepartrequest.dstsize = glyph.rect.get_size();
surfacepartrequest.surface = notshadow ? glyph_surfaces[glyph.surface_idx].get() : shadow_surfaces[glyph.surface_idx].get();
request.request_data = &surfacepartrequest;
float uv_width = surface_data->get_uv_right() - surface_data->get_uv_left();
float uv_height = surface_data->get_uv_bottom() - surface_data->get_uv_top();
- float uv_left = surface_data->get_uv_left() + (uv_width * surfacepartrequest->source.x) / surface->get_width();
- float uv_top = surface_data->get_uv_top() + (uv_height * surfacepartrequest->source.y) / surface->get_height();
- float uv_right = surface_data->get_uv_left() + (uv_width * (surfacepartrequest->source.x + surfacepartrequest->size.x)) / surface->get_width();
- float uv_bottom = surface_data->get_uv_top() + (uv_height * (surfacepartrequest->source.y + surfacepartrequest->size.y)) / surface->get_height();
+ float uv_left = surface_data->get_uv_left() + (uv_width * surfacepartrequest->srcrect.p1.x) / surface->get_width();
+ float uv_top = surface_data->get_uv_top() + (uv_height * surfacepartrequest->srcrect.p1.y) / surface->get_height();
+ float uv_right = surface_data->get_uv_left() + (uv_width * surfacepartrequest->srcrect.p2.x) / surface->get_width();
+ float uv_bottom = surface_data->get_uv_top() + (uv_height * surfacepartrequest->srcrect.p2.y) / surface->get_height();
glBindTexture(GL_TEXTURE_2D, gltexture->get_handle());
intern_draw(request.pos.x, request.pos.y,
- request.pos.x + surfacepartrequest->size.x,
- request.pos.y + surfacepartrequest->size.y,
+ request.pos.x + surfacepartrequest->dstsize.width,
+ request.pos.y + surfacepartrequest->dstsize.height,
uv_left,
uv_top,
uv_right,
float uv_width = surface_data->get_uv_right() - surface_data->get_uv_left();
float uv_height = surface_data->get_uv_bottom() - surface_data->get_uv_top();
- float uv_left = surface_data->get_uv_left() + (uv_width * surfacepartrequest->source.x) / surface->get_width();
- float uv_top = surface_data->get_uv_top() + (uv_height * surfacepartrequest->source.y) / surface->get_height();
- float uv_right = surface_data->get_uv_left() + (uv_width * (surfacepartrequest->source.x + surfacepartrequest->size.x)) / surface->get_width();
- float uv_bottom = surface_data->get_uv_top() + (uv_height * (surfacepartrequest->source.y + surfacepartrequest->size.y)) / surface->get_height();
+ float uv_left = surface_data->get_uv_left() + (uv_width * surfacepartrequest->srcrect.p1.x) / surface->get_width();
+ float uv_top = surface_data->get_uv_top() + (uv_height * surfacepartrequest->srcrect.p1.y) / surface->get_height();
+ float uv_right = surface_data->get_uv_left() + (uv_width * surfacepartrequest->srcrect.p2.x) / surface->get_width();
+ float uv_bottom = surface_data->get_uv_top() + (uv_height * surfacepartrequest->srcrect.p2.y) / surface->get_height();
GLuint th = gltexture->get_handle();
if (th != last_texture) {
glBindTexture(GL_TEXTURE_2D, th);
}
intern_draw(request.pos.x, request.pos.y,
- request.pos.x + surfacepartrequest->size.x,
- request.pos.y + surfacepartrequest->size.y,
+ request.pos.x + surfacepartrequest->dstsize.width,
+ request.pos.y + surfacepartrequest->dstsize.height,
uv_left,
uv_top,
uv_right,
boost::shared_ptr<SDLTexture> sdltexture = boost::dynamic_pointer_cast<SDLTexture>(surface->surface->get_texture());
SDL_Rect src_rect;
- src_rect.x = surfacepartrequest->source.x;
- src_rect.y = surfacepartrequest->source.y;
- src_rect.w = surfacepartrequest->size.x;
- src_rect.h = surfacepartrequest->size.y;
+ src_rect.x = surfacepartrequest->srcrect.p1.x;
+ src_rect.y = surfacepartrequest->srcrect.p1.y;
+ src_rect.w = surfacepartrequest->srcrect.get_width();
+ src_rect.h = surfacepartrequest->srcrect.get_height();
SDL_Rect dst_rect;
dst_rect.x = request.pos.x;
dst_rect.y = request.pos.y;
- dst_rect.w = surfacepartrequest->size.x;
- dst_rect.h = surfacepartrequest->size.y;
+ dst_rect.w = surfacepartrequest->dstsize.width;
+ dst_rect.h = surfacepartrequest->dstsize.height;
Uint8 r = static_cast<Uint8>(request.color.red * 255);
Uint8 g = static_cast<Uint8>(request.color.green * 255);