From b59995f9732720e8c82e22f44c0c8cb3efe2c708 Mon Sep 17 00:00:00 2001 From: admin Date: Mon, 4 Aug 2025 18:10:36 +0200 Subject: changes to label visibility --- include/glamac_render.h | 33 +++++++++++++++++++++++++++++---- include/glamac_view.h | 10 ++++++++++ include/glass_data.h | 7 +++++++ 3 files changed, 46 insertions(+), 4 deletions(-) (limited to 'include') diff --git a/include/glamac_render.h b/include/glamac_render.h index 546bafe..a07e055 100644 --- a/include/glamac_render.h +++ b/include/glamac_render.h @@ -21,7 +21,7 @@ void draw_glass_properties(SDL_Renderer *renderer, TTF_Font *font, TTF_Font *tit 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, const ViewState* view, GlassCluster* clusters, i32 clusterCount); +void render(SDL_Renderer *renderer, TTF_Font *font, TTF_Font *titleFont, TTF_Font *labelFont, ViewState* view, GlassCluster* clusters, i32 clusterCount); // Font management typedef struct { @@ -40,8 +40,33 @@ b32 load_adaptive_fonts(FontSet *fonts, i32 windowWidth, i32 windowHeight, f32 d void free_fonts(FontSet *fonts); void clear_text_cache(void); -// Static label positioning -void calculate_static_label_positions(GlassCluster* clusters, i32 clusterCount, const ViewState* view); -void cleanup_static_label_positions(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 */ diff --git a/include/glamac_view.h b/include/glamac_view.h index 21f273f..9eec63a 100644 --- a/include/glamac_view.h +++ b/include/glamac_view.h @@ -45,11 +45,21 @@ typedef struct { u32 gKeyTime; // Time when 'g' was pressed for sequence timing i32 selectedGlass; // Index of selected glass (-1 if none) i32 selectedCluster; // Index of selected cluster (-1 if none) + + // Label recalculation tracking + f32 lastZoomLevel; // Last zoom level for which labels were calculated + i32 lastWindowWidth; // Last window width for labels + i32 lastWindowHeight; // Last window height for labels + f32 lastOffsetX; // Last X offset for labels + f32 lastOffsetY; // Last Y offset for labels } ViewState; // Initialize a view state with default values void init_view_state(ViewState* view, i32 windowWidth, i32 windowHeight); +// Refresh view state data range when catalog changes +void refresh_view_data_range(ViewState* view); + // Helper function to calculate adaptive padding static inline i32 get_adaptive_padding(const ViewState* view) { i32 padding = (i32)(view->windowWidth * MAX_PADDING_PERCENT); diff --git a/include/glass_data.h b/include/glass_data.h index 75aedde..56c2c7f 100644 --- a/include/glass_data.h +++ b/include/glass_data.h @@ -46,4 +46,11 @@ b32 load_glasses_from_json(const byte* json_path, const byte* manufacturer_filte // Cleanup glass data resources void cleanup_glass_data(void); +// Catalog management +u32 get_catalog_count(void); +const char* get_catalog_name(u32 catalog_index); +const char* get_current_catalog_name(void); +void set_current_catalog(u32 catalog_index); +void cycle_catalog(i32 direction); // +1 for next, -1 for previous + #endif /* GLASS_DATA_H */ -- cgit v1.2.3