Code Cleanup
This commit is contained in:
@@ -8,7 +8,7 @@ int main(int argc, char **argv)
|
||||
// COMPILE WITH RAYLIB
|
||||
Nob_Cmd cmd = {0}; // SRC FILE
|
||||
|
||||
nob_cmd_append(&cmd, "gcc", "src/main.c", "-ggdb");
|
||||
nob_cmd_append(&cmd, "gcc", "src/main.c", "src/Items.c", "-ggdb");
|
||||
nob_cmd_append(&cmd, "-I", "./raylib-src/raylib-5.0_linux_amd64/include/");
|
||||
nob_cmd_append(&cmd, "-L", "./raylib-src/raylib-5.0_linux_amd64/lib/", "-L", "./raylib-src/old-raygui-src/", "-l:libraylib.a", "-l:raygui.so", "-lm");
|
||||
|
||||
|
||||
+86
@@ -0,0 +1,86 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
#include "raylib.h"
|
||||
#include "raymath.h"
|
||||
#include "config.h"
|
||||
|
||||
static float clampf(float value, float min, float max) {
|
||||
return (value < min) ? min : (value > max) ? max : value;
|
||||
}
|
||||
|
||||
static float ilerpf(float min, float max, float value) {
|
||||
return (value - min) / (max - min);
|
||||
}
|
||||
|
||||
static float lerpf(float min, float max, float value) {
|
||||
return min + value * (max - min);
|
||||
}
|
||||
|
||||
static void slider(int id, Rectangle bounds, float *value, float min, float max, const char *label, bool show, float change_value) {
|
||||
bounds.x += MARGIN;
|
||||
//bounds.y += MARGIN;
|
||||
bounds.width -= 2 * MARGIN;
|
||||
|
||||
DrawRectangle(
|
||||
bounds.x,
|
||||
bounds.y + bounds.height * 0.5f - SLIDER_THICKNESS * 0.5f,
|
||||
bounds.width,
|
||||
SLIDER_THICKNESS,
|
||||
SLIDER_COLOR
|
||||
);
|
||||
|
||||
assert(min <= max);
|
||||
float grip_value = ilerpf(min, max, *value) * bounds.width;
|
||||
|
||||
float grip_pos_x = bounds.x + grip_value - SLIDER_GRIP_SIZE;
|
||||
DrawRectangle(
|
||||
grip_pos_x,
|
||||
bounds.y + bounds.height * 0.5f - SLIDER_GRIP_SIZE,
|
||||
SLIDER_GRIP_SIZE * 2.0f,
|
||||
SLIDER_GRIP_SIZE * 2.0f,
|
||||
SLIDER_GRIP_COLOR
|
||||
);
|
||||
|
||||
DrawText(
|
||||
label,
|
||||
bounds.x - MARGIN - MeasureText(label, FONT_SIZE),
|
||||
bounds.y + bounds.height * 0.5f - FONT_SIZE * 0.5f,
|
||||
FONT_SIZE,
|
||||
DARKGRAY
|
||||
);
|
||||
|
||||
if (show) {
|
||||
DrawText(
|
||||
TextFormat("%.2f", *value - change_value),
|
||||
bounds.x + bounds.width + MARGIN,
|
||||
bounds.y + bounds.height * 0.5f - FONT_SIZE * 0.5f,
|
||||
FONT_SIZE,
|
||||
DARKGRAY
|
||||
);
|
||||
}
|
||||
|
||||
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
|
||||
Vector2 mouse_position = GetMousePosition();
|
||||
if (active_id < 0) {
|
||||
Rectangle grip_rect = {
|
||||
grip_pos_x,
|
||||
bounds.y + bounds.height * 0.5f - SLIDER_GRIP_SIZE,
|
||||
SLIDER_GRIP_SIZE * 2.0f,
|
||||
SLIDER_GRIP_SIZE * 2.0f
|
||||
};
|
||||
if (CheckCollisionPointRec(mouse_position, grip_rect)) {
|
||||
active_id = id;
|
||||
}
|
||||
} else if (active_id == id) {
|
||||
float grip_min = bounds.x;
|
||||
float grip_max = bounds.x + bounds.width;
|
||||
float xf = clampf(mouse_position.x, grip_min, grip_max);
|
||||
xf = ilerpf(grip_min, grip_max, xf);
|
||||
xf = lerpf(min, max, xf);
|
||||
*value = xf;
|
||||
}
|
||||
} else if (active_id == id) {
|
||||
active_id = -1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
#ifndef CONFIG_H_
|
||||
#define CONFIG_H_
|
||||
|
||||
#define FONT_SIZE 30
|
||||
#define SLIDER_COLOR DARKGRAY
|
||||
#define SLIDER_GRIP_COLOR LIGHTGRAY
|
||||
#define SLIDER_THICKNESS 20.0f
|
||||
#define SLIDER_GRIP_SIZE 10.0f
|
||||
|
||||
#define MARGIN (FONT_SIZE * 1.0f)
|
||||
|
||||
static int active_id = -1;
|
||||
|
||||
|
||||
|
||||
|
||||
#endif // CONFIG_H_
|
||||
+3
-93
@@ -1,6 +1,9 @@
|
||||
// DoppelspaltApp.c
|
||||
#include "raylib.h"
|
||||
#include "raymath.h"
|
||||
#include "config.h"
|
||||
|
||||
#include "Items.c"
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
@@ -15,98 +18,6 @@ typedef struct {
|
||||
|
||||
AppState state = {50, 75, 90, 1.5, 40};
|
||||
|
||||
static int active_id = -1;
|
||||
|
||||
|
||||
#define FONT_SIZE 30
|
||||
#define SLIDER_COLOR DARKGRAY
|
||||
#define SLIDER_GRIP_COLOR LIGHTGRAY
|
||||
#define SLIDER_THICKNESS 20.0f
|
||||
#define SLIDER_GRIP_SIZE 10.0f
|
||||
|
||||
#define MARGIN (FONT_SIZE * 1.0f)
|
||||
|
||||
static float clampf(float value, float min, float max) {
|
||||
return (value < min) ? min : (value > max) ? max : value;
|
||||
}
|
||||
|
||||
static float ilerpf(float min, float max, float value) {
|
||||
return (value - min) / (max - min);
|
||||
}
|
||||
|
||||
static float lerpf(float min, float max, float value) {
|
||||
return min + value * (max - min);
|
||||
}
|
||||
|
||||
static void slider(int id, Rectangle bounds, float *value, float min, float max, const char *label, bool show, float change_value) {
|
||||
bounds.x += MARGIN;
|
||||
//bounds.y += MARGIN;
|
||||
bounds.width -= 2 * MARGIN;
|
||||
|
||||
DrawRectangle(
|
||||
bounds.x,
|
||||
bounds.y + bounds.height * 0.5f - SLIDER_THICKNESS * 0.5f,
|
||||
bounds.width,
|
||||
SLIDER_THICKNESS,
|
||||
SLIDER_COLOR
|
||||
);
|
||||
|
||||
assert(min <= max);
|
||||
float grip_value = ilerpf(min, max, *value) * bounds.width;
|
||||
|
||||
float grip_pos_x = bounds.x + grip_value - SLIDER_GRIP_SIZE;
|
||||
DrawRectangle(
|
||||
grip_pos_x,
|
||||
bounds.y + bounds.height * 0.5f - SLIDER_GRIP_SIZE,
|
||||
SLIDER_GRIP_SIZE * 2.0f,
|
||||
SLIDER_GRIP_SIZE * 2.0f,
|
||||
SLIDER_GRIP_COLOR
|
||||
);
|
||||
|
||||
DrawText(
|
||||
label,
|
||||
bounds.x - MARGIN - MeasureText(label, FONT_SIZE),
|
||||
bounds.y + bounds.height * 0.5f - FONT_SIZE * 0.5f,
|
||||
FONT_SIZE,
|
||||
DARKGRAY
|
||||
);
|
||||
|
||||
if (show) {
|
||||
DrawText(
|
||||
TextFormat("%.2f", *value - change_value),
|
||||
bounds.x + bounds.width + MARGIN,
|
||||
bounds.y + bounds.height * 0.5f - FONT_SIZE * 0.5f,
|
||||
FONT_SIZE,
|
||||
DARKGRAY
|
||||
);
|
||||
}
|
||||
|
||||
if (IsMouseButtonDown(MOUSE_BUTTON_LEFT)) {
|
||||
Vector2 mouse_position = GetMousePosition();
|
||||
if (active_id < 0) {
|
||||
Rectangle grip_rect = {
|
||||
grip_pos_x,
|
||||
bounds.y + bounds.height * 0.5f - SLIDER_GRIP_SIZE,
|
||||
SLIDER_GRIP_SIZE * 2.0f,
|
||||
SLIDER_GRIP_SIZE * 2.0f
|
||||
};
|
||||
if (CheckCollisionPointRec(mouse_position, grip_rect)) {
|
||||
active_id = id;
|
||||
}
|
||||
} else if (active_id == id) {
|
||||
float grip_min = bounds.x;
|
||||
float grip_max = bounds.x + bounds.width;
|
||||
float xf = clampf(mouse_position.x, grip_min, grip_max);
|
||||
xf = ilerpf(grip_min, grip_max, xf);
|
||||
xf = lerpf(min, max, xf);
|
||||
*value = xf;
|
||||
}
|
||||
} else if (active_id == id) {
|
||||
active_id = -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void DrawKugelwelle(int x, int y, int breite, int hoehe, AppState* state, Color color) {
|
||||
int s0;
|
||||
double phi = (state->winkel - 90) * PI / 180.0;
|
||||
@@ -142,7 +53,6 @@ void DrawWavesFromSlits(int screenWidth, int screenHeight, AppState* state) {
|
||||
}
|
||||
|
||||
|
||||
|
||||
void DrawInterferencePoints(int breite, int hoehe, Color color) {
|
||||
double phi = (state.winkel - 90) * M_PI / 180.0;
|
||||
double s0 = fmod((double) state.gitterD / 2.0 * sin(phi), state.lambda);
|
||||
|
||||
Reference in New Issue
Block a user