sle/src/scale.c

47 lines
1.3 KiB
C

/* SPDX-License-Identifier: GPL-3.0-or-later */
/* Copyright (C) 2021 KikooDX */
#include "scale.h"
#include "options.h"
#include <raylib.h>
float scale_editor(struct Options options)
{
const float w_ratio =
(float)GetScreenWidth() / options.editor_width;
const float h_ratio =
(float)GetScreenHeight() / options.editor_height;
return (w_ratio < h_ratio) ? w_ratio : h_ratio;
}
Vector2 offset_editor(struct Options options)
{
const float scaling = scale_editor(options);
return (Vector2){
((float)GetScreenWidth() - options.editor_width * scaling) /
2,
((float)GetScreenHeight() -
options.editor_height * scaling) /
2};
}
float scale_picker(struct Options options)
{
const float w_ratio =
(float)GetScreenWidth() / options.picker_window_width;
const float h_ratio =
(float)GetScreenHeight() / options.picker_window_height;
return (w_ratio < h_ratio) ? w_ratio : h_ratio;
}
Vector2 offset_picker(struct Options options)
{
const float scaling = scale_picker(options);
return (Vector2){((float)GetScreenWidth() -
options.picker_window_width * scaling) /
2,
((float)GetScreenHeight() -
options.picker_window_height * scaling) /
2};
}