Compare commits
	
		
			3 Commits
		
	
	
		
			8275fce9c6
			...
			d73275f04c
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| d73275f04c | |||
| f56e6b1bb1 | |||
| c70f252349 | 
@@ -4,8 +4,11 @@
 | 
			
		||||
#include "aliases/aliases.h"
 | 
			
		||||
 | 
			
		||||
#define square(x) (x * x)
 | 
			
		||||
#define absolute(x) (x < 0.0 ? x * -1.0 : x)
 | 
			
		||||
 | 
			
		||||
i32 min(i32 a, i32 b);
 | 
			
		||||
i32 max(i32 a, i32 b);
 | 
			
		||||
f64 radians(f64 degrees);
 | 
			
		||||
f64 degrees(f64 radians);
 | 
			
		||||
 | 
			
		||||
#endif // !MATH_UTILS_H
 | 
			
		||||
 
 | 
			
		||||
@@ -76,11 +76,6 @@ i32 run_main_loop(void) {
 | 
			
		||||
 | 
			
		||||
  i32 toolbox_button_x = (toolbox->width - BUTTON_WIDTH) / 2;
 | 
			
		||||
 | 
			
		||||
  line ln = (line){
 | 
			
		||||
      (point){80, 100},
 | 
			
		||||
      (point){120, 300},
 | 
			
		||||
  };
 | 
			
		||||
 | 
			
		||||
  while (comp.running) {
 | 
			
		||||
    while (SDL_PollEvent(&(comp.event))) {
 | 
			
		||||
      handle_ui_events(&(comp.windows[comp.active_window - 1]), &(comp.ctx),
 | 
			
		||||
@@ -157,8 +152,6 @@ i32 run_main_loop(void) {
 | 
			
		||||
                                  comp.nodes[i].colours);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    ln = ui_noodle(main_window, &(comp.ctx), ln, op_node_colours);
 | 
			
		||||
 | 
			
		||||
    for (u64 i = 0; i < MAX_WINDOWS; ++i) {
 | 
			
		||||
      swap_buffers(&(comp.windows[i]));
 | 
			
		||||
    }
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,10 @@
 | 
			
		||||
#include "math_utils.h"
 | 
			
		||||
#include <math.h>
 | 
			
		||||
 | 
			
		||||
i32 min(i32 a, i32 b) { return a <= b ? a : b; }
 | 
			
		||||
 | 
			
		||||
i32 max(i32 a, i32 b) { return a >= b ? a : b; }
 | 
			
		||||
 | 
			
		||||
f64 radians(f64 degrees) { return degrees * M_PI / 180.0; }
 | 
			
		||||
 | 
			
		||||
f64 degrees(f64 radians) { return radians * 180.0 / M_PI; }
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										15
									
								
								src/ui.c
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								src/ui.c
									
									
									
									
									
								
							@@ -8,8 +8,10 @@
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
 | 
			
		||||
#define NOODLE_HALF_WIDTH 2
 | 
			
		||||
#define DEFAULT_NOODLE_LENGTH 60
 | 
			
		||||
 | 
			
		||||
INTERNAL bool aabb(rect rec, i32 x, i32 y);
 | 
			
		||||
INTERNAL line line_from_origin(point origin, f64 angle, i32 line_length);
 | 
			
		||||
 | 
			
		||||
void init_ui_ctx(ui_ctx *ctx) {
 | 
			
		||||
  *ctx = (ui_ctx){0};
 | 
			
		||||
@@ -239,3 +241,16 @@ INTERNAL bool aabb(rect rec, i32 x, i32 y) {
 | 
			
		||||
  return x > rec.topleft.x && x <= rec.topleft.x + rec.w && y > rec.topleft.y &&
 | 
			
		||||
         y <= rec.topleft.y + rec.h;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
INTERNAL line line_from_origin(point origin, f64 angle, i32 line_length) {
 | 
			
		||||
  f64 rad = radians(angle);
 | 
			
		||||
  f64 direction = angle / absolute(angle) * -1;
 | 
			
		||||
 | 
			
		||||
  i32 adjacent = line_length * cos(rad) * direction; // dx
 | 
			
		||||
  i32 opposite = line_length * sin(rad) * direction; // dy
 | 
			
		||||
 | 
			
		||||
  return (line){
 | 
			
		||||
      (point){origin.x + adjacent, origin.y + opposite},
 | 
			
		||||
      origin,
 | 
			
		||||
  };
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user