Skip to content

Commit

Permalink
refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
julesgrc0 committed Feb 26, 2024
1 parent 6dc87ca commit 86a1502
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 22 deletions.
3 changes: 1 addition & 2 deletions src/core/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,7 @@ w_config *load_config() {
}

void save_config(w_config *config) {
// #if !defined(_DEBUG) && !defined(__ANDROID__)
#if 1
#if !defined(_DEBUG) && !defined(__ANDROID__)
char *config_path = malloc(MAX_PATH * 2);
if (config_path == NULL)
return;
Expand Down
4 changes: 2 additions & 2 deletions src/core/utils/smooth.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

#define smooth_float(current, target, speed) \
current = ((float)current < (float)target) \
? fmin((float)current + (float)speed, (float)target) \
: fmax((float)current - (float)speed, (float)target);
? fminf((float)current + (float)speed, (float)target) \
: fmaxf((float)current - (float)speed, (float)target);

void smooth_vec(Vector2 *position, Vector2 target, float move);
void smooth_rect(Rectangle *box, Rectangle target, float move);
Expand Down
17 changes: 9 additions & 8 deletions src/gui/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,15 @@ bool update_action(w_guiaction *act) {
CheckCollisionPointCircle(GetMousePosition(), act->position, act->size);
#endif

DrawCircle(act->position.x, act->position.y, act->size,
Fade(clicked ? BLACK : WHITE, 0.3f));
DrawCircle(act->position.x, act->position.y, act->size * 0.9f,
Fade(clicked ? BLACK : WHITE, 0.3f));
DrawTexturePro(act->icon, RECT(0, 0, act->icon.width, act->icon.height),
RECT(act->position.x - act->size / 2,
act->position.y - act->size / 2, act->size, act->size),
VEC_ZERO, 0, BLACK);
DrawCircleV(act->position, act->size, Fade(clicked ? BLACK : WHITE, 0.3f));
DrawCircleV(act->position, act->size * 0.9f,
Fade(clicked ? BLACK : WHITE, 0.3f));
DrawTexturePro(
act->icon,
RECT(0.f, 0.f, (float)act->icon.width, (float)act->icon.height),
RECT(act->position.x - act->size / 2, act->position.y - act->size / 2,
act->size, act->size),
VEC_ZERO, 0, BLACK);

return clicked;
}
Expand Down
5 changes: 3 additions & 2 deletions src/gui/button.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ w_guibutton *create_button(w_guicontext *ctx, Vector2 position, Color color,
button->default_color = color;
button->hover_color = Fade(color, 0.8f);
button->text = text;
button->size = VEC(MeasureText(text, ctx->font_size), ctx->font_size);
button->size =
VEC((float)MeasureText(text, (int)ctx->font_size), ctx->font_size);
move_button(button, position);
return button;
}
Expand Down Expand Up @@ -40,7 +41,7 @@ bool update_button(w_guibutton *button) {

Color color = is_hover ? button->hover_color : button->default_color;

DrawRectangleRoundedLines(button->rect, button->ctx->border_radius, 1.f,
DrawRectangleRoundedLines(button->rect, button->ctx->border_radius, 1,
button->ctx->border_size, color);
DrawText(button->text, (int)button->position.x, (int)button->position.y,
(int)button->ctx->font_size, color);
Expand Down
10 changes: 5 additions & 5 deletions src/gui/joystick.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ w_guijoystick *create_joystick(w_guicontext *ctx, Vector2 position,
}

Vector2 update_joystick(w_guijoystick *js) {
DrawCircle(js->position.x, js->position.y, js->size, Fade(WHITE, 0.3f));
DrawCircle(js->position.x, js->position.y, js->size * 0.9f,
Fade(WHITE, 0.3f));
DrawCircleV(js->position, js->size, Fade(WHITE, 0.3f));
DrawCircleV(js->position, js->size * 0.9f, Fade(WHITE, 0.3f));

#ifdef __ANDROID__
if (has_touch()) {
Vector2 mouse = get_nearest_touch(Vector2SubtractValue(js->position, js->size/2.f));
Vector2 mouse =
get_nearest_touch(Vector2SubtractValue(js->position, js->size / 2.f));
Vector2 touch = get_collision_touch(js->position, js->size);
#else
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) {
Expand All @@ -48,7 +48,7 @@ Vector2 update_joystick(w_guijoystick *js) {
} else {
js->cursor = js->position;
}
DrawCircle(js->cursor.x, js->cursor.y, js->size / 4, Fade(BLACK, 0.5f));
DrawCircleV(js->cursor, js->size / 4, Fade(BLACK, 0.5f));

Vector2 dir = Vector2Subtract(js->cursor, js->position);
dir = Vector2Normalize(dir);
Expand Down
6 changes: 3 additions & 3 deletions src/gui/text.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@ w_guitext *create_text(w_guicontext *ctx, Vector2 position, char *text,

void center_text(w_guitext *text, bool x, bool y) {
if (x) {
text->position.x -= MeasureText(text->text, text->font_size) / 2;
text->position.x -= MeasureText(text->text, (int)text->font_size) / 2;
}
if (y) {
text->position.y -= text->font_size / 2;
}
}

void update_text(w_guitext *text) {
DrawText(text->text, text->position.x, text->position.y, text->font_size,
text->color);
DrawText(text->text, (int)text->position.x, (int)text->position.y,
(int)text->font_size, text->color);
}

void destroy_text(w_guitext *text) {
Expand Down

0 comments on commit 86a1502

Please sign in to comment.