Added proper hit test with rotation and pivoting
This commit is contained in:
+24
-6
@@ -155,7 +155,7 @@ Vec2<float> Window::get_text_size(uint64_t text_id) {
|
||||
return text_pool[text_id]->size;
|
||||
}
|
||||
|
||||
bool Window::write(uint64_t text_id, Vec2<float> position, float z, float angle, Vec2<float> scale, float alpha) {
|
||||
bool Window::write(uint64_t text_id, Vec2<float> position, float z, float angle, Vec2<float> pivot, Vec2<float> scale, float alpha) {
|
||||
if (!text_pool.is_valid(text_id)) {
|
||||
fprintf(stderr, "(Write) Invalid text ID: %llu\n", (unsigned long long)text_id);
|
||||
return false;
|
||||
@@ -165,6 +165,7 @@ bool Window::write(uint64_t text_id, Vec2<float> position, float z, float angle,
|
||||
{.type = RenderInstruction::DRAW_TEXT,
|
||||
.z = z,
|
||||
.angle = angle,
|
||||
.pivot = pivot,
|
||||
.scale = scale,
|
||||
.alpha = alpha,
|
||||
.draw_text = {
|
||||
@@ -176,7 +177,7 @@ bool Window::write(uint64_t text_id, Vec2<float> position, float z, float angle,
|
||||
return true;
|
||||
};
|
||||
|
||||
bool Window::draw(uint64_t image_id, Vec2<float> position, float z, float angle, Vec2<float> scale, float alpha) {
|
||||
bool Window::draw(uint64_t image_id, Vec2<float> position, float z, float angle, Vec2<float> pivot, Vec2<float> scale, float alpha) {
|
||||
if (!image_pool.is_valid(image_id)) {
|
||||
fprintf(stderr, "Invalid image ID: %llu\n", (unsigned long long)image_id);
|
||||
return false;
|
||||
@@ -186,6 +187,7 @@ bool Window::draw(uint64_t image_id, Vec2<float> position, float z, float angle,
|
||||
{.type = RenderInstruction::DRAW_IMAGE,
|
||||
.z = z,
|
||||
.angle = angle,
|
||||
.pivot = pivot,
|
||||
.scale = scale,
|
||||
.alpha = alpha,
|
||||
.draw_image = {
|
||||
@@ -197,11 +199,12 @@ bool Window::draw(uint64_t image_id, Vec2<float> position, float z, float angle,
|
||||
return true;
|
||||
};
|
||||
|
||||
bool Window::draw_rect(Rect rect, Color color, float z, float angle, Vec2<float> scale, float alpha) {
|
||||
bool Window::draw_rect(Rect rect, Color color, float z, float angle, Vec2<float> pivot, Vec2<float> scale, float alpha) {
|
||||
render_instructions.push_back(
|
||||
{.type = RenderInstruction::DRAW_RECT,
|
||||
.z = z,
|
||||
.angle = angle,
|
||||
.pivot = pivot,
|
||||
.scale = scale,
|
||||
.alpha = alpha,
|
||||
.draw_rect = {
|
||||
@@ -279,13 +282,18 @@ void Window::render() {
|
||||
|
||||
SDL_SetTextureAlphaModFloat(texture, instruction.alpha);
|
||||
|
||||
SDL_FPoint pivot_point = {
|
||||
instruction.pivot.x * scale_x,
|
||||
instruction.pivot.y * scale_y
|
||||
};
|
||||
|
||||
SDL_RenderTextureRotated(
|
||||
renderer,
|
||||
texture,
|
||||
nullptr,
|
||||
&dst_rect,
|
||||
instruction.angle,
|
||||
nullptr,
|
||||
&pivot_point,
|
||||
flip
|
||||
);
|
||||
} break;
|
||||
@@ -311,13 +319,18 @@ void Window::render() {
|
||||
|
||||
SDL_SetTextureAlphaModFloat(image->texture, instruction.alpha);
|
||||
|
||||
SDL_FPoint pivot_point = {
|
||||
instruction.pivot.x * scale_x,
|
||||
instruction.pivot.y * scale_y
|
||||
};
|
||||
|
||||
SDL_RenderTextureRotated(
|
||||
renderer,
|
||||
image->texture,
|
||||
nullptr,
|
||||
&dst_rect,
|
||||
instruction.angle,
|
||||
nullptr,
|
||||
&pivot_point,
|
||||
flip
|
||||
);
|
||||
} break;
|
||||
@@ -338,13 +351,18 @@ void Window::render() {
|
||||
|
||||
SDL_SetTextureAlphaModFloat(white_tex, instruction.alpha);
|
||||
|
||||
SDL_FPoint pivot_point = {
|
||||
instruction.pivot.x * dst_rect.w,
|
||||
instruction.pivot.y * dst_rect.h
|
||||
};
|
||||
|
||||
SDL_RenderTextureRotated(
|
||||
renderer,
|
||||
white_tex,
|
||||
nullptr,
|
||||
&dst_rect,
|
||||
instruction.angle,
|
||||
nullptr,
|
||||
&pivot_point,
|
||||
SDL_FLIP_NONE
|
||||
);
|
||||
} break;
|
||||
|
||||
Reference in New Issue
Block a user