summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/glamac_render.h11
-rw-r--r--include/glamac_view.h33
-rw-r--r--include/glamacdef.h5
3 files changed, 44 insertions, 5 deletions
diff --git a/include/glamac_render.h b/include/glamac_render.h
index f18d53f..546bafe 100644
--- a/include/glamac_render.h
+++ b/include/glamac_render.h
@@ -16,12 +16,12 @@ void draw_filled_circle(SDL_Renderer *renderer, i32 centerX, i32 centerY, i32 ra
// 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);
+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, const ViewState* view);
+void render(SDL_Renderer *renderer, TTF_Font *font, TTF_Font *titleFont, TTF_Font *labelFont, const ViewState* view, GlassCluster* clusters, i32 clusterCount);
// Font management
typedef struct {
@@ -33,8 +33,15 @@ typedef struct {
// 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);
+// Static label positioning
+void calculate_static_label_positions(GlassCluster* clusters, i32 clusterCount, const ViewState* view);
+void cleanup_static_label_positions(void);
+
#endif /* GLAMAC_RENDER_H */
diff --git a/include/glamac_view.h b/include/glamac_view.h
index 8f0b984..21f273f 100644
--- a/include/glamac_view.h
+++ b/include/glamac_view.h
@@ -8,12 +8,27 @@
#include "glamacdef.h"
// Constants for view
-#define PADDING_PERCENT 0.08f // Padding as percentage of window size
+#define MIN_PADDING 20 // Minimum padding in pixels
+#define MAX_PADDING_PERCENT 0.04f // Maximum padding as percentage of window size
#define PAN_STEP 0.05f // Step size for keyboard panning
#define ZOOM_FACTOR 1.2f // Zoom factor for zoom operations
#define MIN_ZOOM 0.5f // Minimum zoom level
#define MAX_ZOOM 10.0f // Maximum zoom level
+// Glass label positioning constants (adjustable parameters)
+#define LABEL_OFFSET_X 12 // Horizontal offset from glass point (pixels)
+#define LABEL_OFFSET_Y -8 // Vertical offset from glass point (pixels)
+#define LABEL_SIZE_SCALE 1.4f // Scale factor for glass name labels
+
+// Glass clustering for nearly identical glasses
+#define MAX_CLUSTER_SIZE 8
+typedef struct {
+ i32 glassIndices[MAX_CLUSTER_SIZE]; // Indices of glasses in this cluster
+ i32 count; // Number of glasses in cluster
+ f32 avgAbbeNumber; // Average position for rendering
+ f32 avgRefractiveIndex;
+} GlassCluster;
+
// State for zooming and panning
typedef struct {
f32 zoomLevel;
@@ -29,15 +44,22 @@ typedef struct {
b32 gKeyPressed; // Flag to track if 'g' was pressed
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)
} ViewState;
// Initialize a view state with default values
void init_view_state(ViewState* view, i32 windowWidth, i32 windowHeight);
+// Helper function to calculate adaptive padding
+static inline i32 get_adaptive_padding(const ViewState* view) {
+ i32 padding = (i32)(view->windowWidth * MAX_PADDING_PERCENT);
+ return padding > MIN_PADDING ? padding : MIN_PADDING;
+}
+
// Convert glass data to screen coordinates with zoom and offset
static inline void data_to_screen_coords(f32 abbeNumber, f32 refractiveIndex,
const ViewState* view, i32 *x, i32 *y) {
- const i32 padding = (i32)(view->windowWidth * PADDING_PERCENT);
+ const i32 padding = get_adaptive_padding(view);
// Apply zoom and offset transformation
// FLIPPED: Use 1.0f - normalized to flip the Abbe number axis
@@ -56,7 +78,7 @@ static inline void data_to_screen_coords(f32 abbeNumber, f32 refractiveIndex,
// Convert screen coordinates to data values
static inline void screen_to_data_coords(i32 x, i32 y, const ViewState* view,
f32 *abbeNumber, f32 *refractiveIndex) {
- const i32 padding = (i32)(view->windowWidth * PADDING_PERCENT);
+ const i32 padding = get_adaptive_padding(view);
// Convert to normalized coordinates
f32 normalizedX = (f32)(x - padding) / (view->windowWidth - 2 * padding);
@@ -87,4 +109,9 @@ void toggle_fullscreen(SDL_Window* window);
// Reset view to default
void reset_view(ViewState* view);
+// Glass clustering functions
+GlassCluster* create_glass_clusters(i32* clusterCount);
+void free_glass_clusters(GlassCluster* clusters);
+i32 find_cluster_at_position(GlassCluster* clusters, i32 clusterCount, i32 x, i32 y, const ViewState* view);
+
#endif /* GLAMAC_VIEW_H */
diff --git a/include/glamacdef.h b/include/glamacdef.h
index 563df70..aeba926 100644
--- a/include/glamacdef.h
+++ b/include/glamacdef.h
@@ -26,7 +26,12 @@ typedef uint64_t u64;
typedef float f32;
typedef double f64;
typedef uintptr_t uptr;
+#ifndef _WIN32
typedef char byte;
+#else
+// On Windows, use unsigned char to match Windows headers
+typedef unsigned char byte;
+#endif
typedef ptrdiff_t size;
typedef size_t usize;
/* Utility macros */
Back to https://optics-design.com