Aggregate SDL_Surfaces and their scale in RenSurface (#1429)
This commit is contained in:
+15
-16
@@ -257,7 +257,7 @@ RenFont* ren_font_load(RenWindow *window_renderer, const char* path, float size,
|
||||
|
||||
#endif
|
||||
|
||||
const int surface_scale = renwin_surface_scale(window_renderer);
|
||||
const int surface_scale = renwin_get_surface(window_renderer).scale;
|
||||
if (FT_Set_Pixel_Sizes(face, 0, (int)(size*surface_scale)))
|
||||
goto failure;
|
||||
int len = strlen(path);
|
||||
@@ -342,7 +342,7 @@ float ren_font_group_get_size(RenFont **fonts) {
|
||||
}
|
||||
|
||||
void ren_font_group_set_size(RenWindow *window_renderer, RenFont **fonts, float size) {
|
||||
const int surface_scale = renwin_surface_scale(window_renderer);
|
||||
const int surface_scale = renwin_get_surface(window_renderer).scale;
|
||||
for (int i = 0; i < FONT_FALLBACK_MAX && fonts[i]; ++i) {
|
||||
font_clear_glyph_cache(fonts[i]);
|
||||
FT_Face face = fonts[i]->face;
|
||||
@@ -372,16 +372,16 @@ double ren_font_group_get_width(RenWindow *window_renderer, RenFont **fonts, con
|
||||
break;
|
||||
width += (!font || metric->xadvance) ? metric->xadvance : fonts[0]->space_advance;
|
||||
}
|
||||
const int surface_scale = renwin_surface_scale(window_renderer);
|
||||
const int surface_scale = renwin_get_surface(window_renderer).scale;
|
||||
return width / surface_scale;
|
||||
}
|
||||
|
||||
double ren_draw_text(RenWindow *window_renderer, RenFont **fonts, const char *text, size_t len, float x, int y, RenColor color) {
|
||||
SDL_Surface *surface = renwin_get_surface(window_renderer);
|
||||
double ren_draw_text(RenSurface *rs, RenFont **fonts, const char *text, size_t len, float x, int y, RenColor color) {
|
||||
SDL_Surface *surface = rs->surface;
|
||||
SDL_Rect clip;
|
||||
SDL_GetClipRect(surface, &clip);
|
||||
|
||||
const int surface_scale = renwin_surface_scale(window_renderer);
|
||||
const int surface_scale = rs->scale;
|
||||
double pen_x = x * surface_scale;
|
||||
y *= surface_scale;
|
||||
int bytes_per_pixel = surface->format->BytesPerPixel;
|
||||
@@ -405,7 +405,7 @@ double ren_draw_text(RenWindow *window_renderer, RenFont **fonts, const char *te
|
||||
int end_x = (metric->x1 - metric->x0) + start_x;
|
||||
int glyph_end = metric->x1, glyph_start = metric->x0;
|
||||
if (!metric->loaded && codepoint > 0xFF)
|
||||
ren_draw_rect(window_renderer, (RenRect){ start_x + 1, y, font->space_advance - 1, ren_font_group_get_height(fonts) }, color);
|
||||
ren_draw_rect(rs, (RenRect){ start_x + 1, y, font->space_advance - 1, ren_font_group_get_height(fonts) }, color);
|
||||
if (set->surface && color.a > 0 && end_x >= clip.x && start_x < clip_end_x) {
|
||||
uint8_t* source_pixels = set->surface->pixels;
|
||||
for (int line = metric->y0; line < metric->y1; ++line) {
|
||||
@@ -456,9 +456,9 @@ double ren_draw_text(RenWindow *window_renderer, RenFont **fonts, const char *te
|
||||
else if(font != last || text == end) {
|
||||
double local_pen_x = text == end ? pen_x + adv : pen_x;
|
||||
if (underline)
|
||||
ren_draw_rect(window_renderer, (RenRect){last_pen_x, y / surface_scale + last->height - 1, (local_pen_x - last_pen_x) / surface_scale, last->underline_thickness * surface_scale}, color);
|
||||
ren_draw_rect(rs, (RenRect){last_pen_x, y / surface_scale + last->height - 1, (local_pen_x - last_pen_x) / surface_scale, last->underline_thickness * surface_scale}, color);
|
||||
if (strikethrough)
|
||||
ren_draw_rect(window_renderer, (RenRect){last_pen_x, y / surface_scale + last->height / 2, (local_pen_x - last_pen_x) / surface_scale, last->underline_thickness * surface_scale}, color);
|
||||
ren_draw_rect(rs, (RenRect){last_pen_x, y / surface_scale + last->height / 2, (local_pen_x - last_pen_x) / surface_scale, last->underline_thickness * surface_scale}, color);
|
||||
last = font;
|
||||
last_pen_x = pen_x;
|
||||
}
|
||||
@@ -477,11 +477,11 @@ static inline RenColor blend_pixel(RenColor dst, RenColor src) {
|
||||
return dst;
|
||||
}
|
||||
|
||||
void ren_draw_rect(RenWindow *window_renderer, RenRect rect, RenColor color) {
|
||||
void ren_draw_rect(RenSurface *rs, RenRect rect, RenColor color) {
|
||||
if (color.a == 0) { return; }
|
||||
|
||||
SDL_Surface *surface = renwin_get_surface(window_renderer);
|
||||
const int surface_scale = renwin_surface_scale(window_renderer);
|
||||
SDL_Surface *surface = rs->surface;
|
||||
const int surface_scale = rs->scale;
|
||||
|
||||
SDL_Rect dest_rect = { rect.x * surface_scale,
|
||||
rect.y * surface_scale,
|
||||
@@ -552,8 +552,7 @@ void ren_set_clip_rect(RenWindow *window_renderer, RenRect rect) {
|
||||
|
||||
|
||||
void ren_get_size(RenWindow *window_renderer, int *x, int *y) {
|
||||
const int scale = renwin_surface_scale(window_renderer);
|
||||
SDL_Surface *surface = renwin_get_surface(window_renderer);
|
||||
*x = surface->w / scale;
|
||||
*y = surface->h / scale;
|
||||
RenSurface rs = renwin_get_surface(window_renderer);
|
||||
*x = rs.surface->w / rs.scale;
|
||||
*y = rs.surface->h / rs.scale;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user