summaryrefslogtreecommitdiff
path: root/include/glamac_render.h
blob: a07e055cbef25cc8ee09fc406301c6a1c0ad224c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/**
 * glamac_render.h - header file from glamac_render.c.
 */
#ifndef GLAMAC_RENDER_H
#define GLAMAC_RENDER_H

#include <SDL3/SDL.h>
#include <SDL3_ttf/SDL_ttf.h>
#include "glamacdef.h"
#include "glamac_view.h"

// Drawing primitives
void draw_text(SDL_Renderer *renderer, TTF_Font *font, const char *text, i32 x, i32 y, SDL_Color color);
void draw_filled_circle(SDL_Renderer *renderer, i32 centerX, i32 centerY, i32 radius);

// UI element rendering
void draw_axes(SDL_Renderer *renderer, TTF_Font *font, TTF_Font *titleFont, const ViewState* view);
void draw_grid(SDL_Renderer *renderer, const ViewState* view);
void draw_glass_points(SDL_Renderer *renderer, TTF_Font *labelFont, const ViewState* view, GlassCluster* clusters, i32 clusterCount);
void draw_glass_properties(SDL_Renderer *renderer, TTF_Font *font, TTF_Font *titleFont, const ViewState* view);
void draw_help_window(SDL_Renderer *renderer, TTF_Font *font, TTF_Font *titleFont, const ViewState* view);

// Main render function
void render(SDL_Renderer *renderer, TTF_Font *font, TTF_Font *titleFont, TTF_Font *labelFont, ViewState* view, GlassCluster* clusters, i32 clusterCount);

// Font management
typedef struct {
    TTF_Font *regular;
    TTF_Font *title;
    TTF_Font *label;
} FontSet;

// Load all required fonts
b32 load_fonts(FontSet *fonts);

// Load fonts with DPI-aware sizing
b32 load_adaptive_fonts(FontSet *fonts, i32 windowWidth, i32 windowHeight, f32 dpi);

// Free all fonts
void free_fonts(FontSet *fonts);
void clear_text_cache(void);

// Simple collision detection structures
typedef struct {
    i32 x, y;         // Screen position
    i32 width, height; // Label dimensions
} LabelRect;

// Pre-calculated label positions (updated only on catalog changes)
typedef struct {
    i32 glassIndex;    // Which glass this label belongs to
    i32 screenX, screenY; // Fixed screen position
    b32 visible;       // Whether to show this label
    char text[64];     // Label text
} PreCalculatedLabel;

// Global label positioning system
void recalculate_label_positions(const ViewState* view, GlassCluster* clusters, i32 clusterCount);
void draw_precalculated_labels(SDL_Renderer *renderer, TTF_Font *labelFont, const ViewState* view);
b32 needs_label_recalculation(ViewState* view);

// Collision detection functions for debug mode
b32 rects_overlap(const LabelRect* a, const LabelRect* b);
b32 label_collides_with_point(const LabelRect* label, i32 pointX, i32 pointY, i32 pointRadius);

// Advanced label visibility functions for testing
void calculate_smart_window_position(i32 glassX, i32 glassY, i32 windowWidth, i32 windowHeight, 
                                    const ViewState* view, i32* windowX, i32* windowY);
f32 calculate_label_priority(i32 glassIndex, const ViewState* view, GlassCluster* clusters, i32 clusterCount);
b32 should_show_label_advanced(i32 glassIndex, const ViewState* view, GlassCluster* clusters, i32 clusterCount);

#endif /* GLAMAC_RENDER_H */
Back to https://optics-design.com