Add ruby bindings for internal structures, allow better controlled localization
This commit is contained in:
+16
-11
@@ -56,7 +56,7 @@ Window::~Window() {
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
uint64_t Window::load_image(const char *path, float alpha, bool pixel_art) {
|
||||
uint64_t Window::load_image(const char *path, bool pixel_art) {
|
||||
SDL_Texture *texture = IMG_LoadTexture(renderer, path);
|
||||
|
||||
if (pixel_art) {
|
||||
@@ -68,8 +68,6 @@ uint64_t Window::load_image(const char *path, float alpha, bool pixel_art) {
|
||||
return UINT64_MAX;
|
||||
}
|
||||
|
||||
SDL_SetTextureAlphaMod(texture, (uint8_t)(alpha * 255));
|
||||
|
||||
float w, h;
|
||||
SDL_GetTextureSize(texture, &w, &h);
|
||||
|
||||
@@ -119,7 +117,7 @@ uint64_t Window::create_text(uint64_t font_id, const char *text, uint32_t length
|
||||
return UINT64_MAX;
|
||||
}
|
||||
|
||||
SDL_Color sdl_color = {color.r, color.g, color.b, color.a};
|
||||
SDL_Color sdl_color = {color.r, color.g, color.b, 255};
|
||||
SDL_Surface *surface = TTF_RenderText_Solid(font_pool[font_id]->font, text, length, sdl_color);
|
||||
|
||||
if (surface == nullptr) {
|
||||
@@ -157,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) {
|
||||
bool Window::write(uint64_t text_id, Vec2<float> position, float z, float angle, 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;
|
||||
@@ -168,6 +166,7 @@ bool Window::write(uint64_t text_id, Vec2<float> position, float z, float angle,
|
||||
.z = z,
|
||||
.angle = angle,
|
||||
.scale = scale,
|
||||
.alpha = alpha,
|
||||
.draw_text = {
|
||||
.text_id = text_id,
|
||||
.position = position,
|
||||
@@ -177,7 +176,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) {
|
||||
bool Window::draw(uint64_t image_id, Vec2<float> position, float z, float angle, 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;
|
||||
@@ -188,6 +187,7 @@ bool Window::draw(uint64_t image_id, Vec2<float> position, float z, float angle,
|
||||
.z = z,
|
||||
.angle = angle,
|
||||
.scale = scale,
|
||||
.alpha = alpha,
|
||||
.draw_image = {
|
||||
.image_id = image_id,
|
||||
.position = position,
|
||||
@@ -197,12 +197,13 @@ 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) {
|
||||
bool Window::draw_rect(Rect rect, Color color, float z, float angle, Vec2<float> scale, float alpha) {
|
||||
render_instructions.push_back(
|
||||
{.type = RenderInstruction::DRAW_RECT,
|
||||
.z = z,
|
||||
.angle = angle,
|
||||
.scale = {1.0f, 1.0f},
|
||||
.scale = scale,
|
||||
.alpha = alpha,
|
||||
.draw_rect = {
|
||||
.rect = rect,
|
||||
.color = color,
|
||||
@@ -276,6 +277,8 @@ void Window::render() {
|
||||
dst_rect.w = scale_x * text->size.x;
|
||||
dst_rect.h = scale_y * text->size.y;
|
||||
|
||||
SDL_SetTextureAlphaModFloat(texture, instruction.alpha);
|
||||
|
||||
SDL_RenderTextureRotated(
|
||||
renderer,
|
||||
texture,
|
||||
@@ -306,6 +309,8 @@ void Window::render() {
|
||||
dst_rect.w = scale_x * image->size.x;
|
||||
dst_rect.h = scale_y * image->size.y;
|
||||
|
||||
SDL_SetTextureAlphaModFloat(image->texture, instruction.alpha);
|
||||
|
||||
SDL_RenderTextureRotated(
|
||||
renderer,
|
||||
image->texture,
|
||||
@@ -321,8 +326,8 @@ void Window::render() {
|
||||
SDL_FRect dst_rect;
|
||||
dst_rect.x = instruction.draw_rect.rect.x() * scale + offset.x;
|
||||
dst_rect.y = instruction.draw_rect.rect.y() * scale + offset.y;
|
||||
dst_rect.w = instruction.draw_rect.rect.w() * scale;
|
||||
dst_rect.h = instruction.draw_rect.rect.h() * scale;
|
||||
dst_rect.w = instruction.draw_rect.rect.w() * scale * instruction.scale.x;
|
||||
dst_rect.h = instruction.draw_rect.rect.h() * scale * instruction.scale.y;
|
||||
|
||||
SDL_SetTextureColorMod(
|
||||
white_tex,
|
||||
@@ -331,7 +336,7 @@ void Window::render() {
|
||||
instruction.draw_rect.color.b
|
||||
);
|
||||
|
||||
SDL_SetTextureAlphaMod(white_tex, instruction.draw_rect.color.a);
|
||||
SDL_SetTextureAlphaModFloat(white_tex, instruction.alpha);
|
||||
|
||||
SDL_RenderTextureRotated(
|
||||
renderer,
|
||||
|
||||
Reference in New Issue
Block a user