WIP attempt to fix resizing not working
This commit is contained in:
parent
1bc5e62502
commit
61e336786f
3 changed files with 50 additions and 36 deletions
|
@ -14,6 +14,11 @@
|
||||||
#define SHOW_HELP_WIDTH (state->get_width() / 2.0f)
|
#define SHOW_HELP_WIDTH (state->get_width() / 2.0f)
|
||||||
#define SHOW_HELP_HEIGHT (state->get_height() / 2.0f)
|
#define SHOW_HELP_HEIGHT (state->get_height() / 2.0f)
|
||||||
|
|
||||||
|
#define CHANGE_SIZE_MIN_X 800
|
||||||
|
#define CHANGE_SIZE_MAX_X 1920
|
||||||
|
#define CHANGE_SIZE_MIN_Y 600
|
||||||
|
#define CHANGE_SIZE_MAX_Y 1080
|
||||||
|
|
||||||
#ifndef NDEBUG
|
#ifndef NDEBUG
|
||||||
# include <cstdio>
|
# include <cstdio>
|
||||||
#endif
|
#endif
|
||||||
|
@ -171,16 +176,16 @@ namespace Tri {
|
||||||
{384.0f, 328.0f, 80.0f, 16.0f},
|
{384.0f, 328.0f, 80.0f, 16.0f},
|
||||||
"Width",
|
"Width",
|
||||||
state->get_input_width(),
|
state->get_input_width(),
|
||||||
800,
|
CHANGE_SIZE_MIN_X,
|
||||||
1920,
|
CHANGE_SIZE_MAX_X,
|
||||||
state->get_flags().test(State::F_TAB_TOGGLE));
|
!state->get_flags().test(State::F_TAB_TOGGLE));
|
||||||
GuiValueBox(
|
GuiValueBox(
|
||||||
{384.0f, 348.0f, 80.0f, 16.0f},
|
{384.0f, 348.0f, 80.0f, 16.0f},
|
||||||
"Height",
|
"Height",
|
||||||
state->get_input_height(),
|
state->get_input_height(),
|
||||||
600,
|
CHANGE_SIZE_MIN_Y,
|
||||||
1080,
|
CHANGE_SIZE_MAX_Y,
|
||||||
!state->get_flags().test(State::F_TAB_TOGGLE));
|
state->get_flags().test(State::F_TAB_TOGGLE));
|
||||||
const std::string &failMessage = state->failed_message();
|
const std::string &failMessage = state->failed_message();
|
||||||
if(!failMessage.empty()) {
|
if(!failMessage.empty()) {
|
||||||
GuiLabel({304.0f, 368.0f, 284.0f, 16.0f}, failMessage.c_str());
|
GuiLabel({304.0f, 368.0f, 284.0f, 16.0f}, failMessage.c_str());
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
|
|
||||||
|
@ -11,15 +12,11 @@
|
||||||
|
|
||||||
#define STARTING_HELP_FADE_RATE 0.2f
|
#define STARTING_HELP_FADE_RATE 0.2f
|
||||||
|
|
||||||
#ifndef NDEBUG
|
|
||||||
# include <cstdio>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
Tri::State::State(int argc, char **argv) :
|
Tri::State::State(int argc, char **argv) :
|
||||||
width(800),
|
width(800),
|
||||||
height(600),
|
height(600),
|
||||||
dt(1.0f/60.0f),
|
dt(1.0f/60.0f),
|
||||||
notification_alpha(1.0f),
|
notificationAlpha(1.0f),
|
||||||
trisIndex(0),
|
trisIndex(0),
|
||||||
currentTri_state(CurrentState::NONE),
|
currentTri_state(CurrentState::NONE),
|
||||||
currentTri_maxState(CurrentState::NONE),
|
currentTri_maxState(CurrentState::NONE),
|
||||||
|
@ -144,7 +141,7 @@ void Tri::State::handle_events() {
|
||||||
"to what was\n"
|
"to what was\n"
|
||||||
"clicked on");
|
"clicked on");
|
||||||
} else {
|
} else {
|
||||||
notification_alpha = 0.0f;
|
notificationAlpha = 0.0f;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case KEY_I:
|
case KEY_I:
|
||||||
|
@ -259,10 +256,10 @@ void Tri::State::handle_events() {
|
||||||
void Tri::State::update() {
|
void Tri::State::update() {
|
||||||
dt = GetFrameTime();
|
dt = GetFrameTime();
|
||||||
|
|
||||||
if(notification_alpha > 0.0f) {
|
if(notificationAlpha > 0.0f) {
|
||||||
notification_alpha -= dt * STARTING_HELP_FADE_RATE;
|
notificationAlpha -= dt * STARTING_HELP_FADE_RATE;
|
||||||
if(notification_alpha < 0.0f) {
|
if(notificationAlpha < 0.0f) {
|
||||||
notification_alpha = 0.0f;
|
notificationAlpha = 0.0f;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,19 +370,31 @@ const Tri::State::BitsetType Tri::State::get_flags() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
float Tri::State::get_notification_alpha() const {
|
float Tri::State::get_notification_alpha() const {
|
||||||
return notification_alpha;
|
return notificationAlpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* Tri::State::get_notification_text() const {
|
const char* Tri::State::get_notification_text() const {
|
||||||
return notification_text.data();
|
return notificationText.data();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Tri::State::set_notification_text(const char *text) {
|
void Tri::State::set_notification_text(const char *text) {
|
||||||
notification_text.fill(0);
|
notificationText.fill(0);
|
||||||
std::strncpy(notification_text.data(),
|
std::strncpy(notificationText.data(),
|
||||||
text,
|
text,
|
||||||
notification_text.max_size() - 1);
|
notificationText.max_size() - 1);
|
||||||
notification_alpha = 1.0f;
|
notificationAlpha = 1.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
void Tri::State::append_notification_text(const char *text) {
|
||||||
|
auto length = std::strlen(notificationText.data());
|
||||||
|
if(length + 1 >= notificationText.max_size()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
std::strncpy(
|
||||||
|
notificationText.data() + length,
|
||||||
|
text,
|
||||||
|
notificationText.max_size() - length - 1);
|
||||||
|
notificationAlpha = 1.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::array<float, 4>& Tri::State::get_color() {
|
std::array<float, 4>& Tri::State::get_color() {
|
||||||
|
@ -471,34 +480,33 @@ void Tri::State::close_bg_color_picker() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Tri::State::change_width_height() {
|
bool Tri::State::change_width_height() {
|
||||||
std::bitset<2> warnings;
|
|
||||||
if(inputWidth < 0 || inputHeight < 0) {
|
if(inputWidth < 0 || inputHeight < 0) {
|
||||||
failedMessage = "Width or Height cannot be less than 0";
|
failedMessage = "Width or Height cannot be less than 0";
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(inputWidth < 800) {
|
if(inputWidth < 800) {
|
||||||
inputWidth = 800;
|
inputWidth = 800;
|
||||||
warnings.set(0);
|
|
||||||
}
|
}
|
||||||
if(inputHeight < 600) {
|
if(inputHeight < 600) {
|
||||||
inputHeight = 600;
|
inputHeight = 600;
|
||||||
warnings.set(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(warnings.test(0) && warnings.test(1)) {
|
notificationText.fill(0);
|
||||||
set_notification_text("Width set to 800\nHeight set to 600");
|
std::array<char, 5> tempBuf = {0, 0, 0, 0, 0};
|
||||||
} else if(warnings.test(0)) {
|
|
||||||
set_notification_text("Width set to 800");
|
append_notification_text("Width set to ");
|
||||||
} else if(warnings.test(1)) {
|
snprintf(tempBuf.data(), 5, "%u", inputWidth);
|
||||||
set_notification_text("Height set to 600");
|
append_notification_text(tempBuf.data());
|
||||||
}
|
|
||||||
|
append_notification_text(", Height set to ");
|
||||||
|
snprintf(tempBuf.data(), 5, "%u", inputHeight);
|
||||||
|
append_notification_text(tempBuf.data());
|
||||||
|
|
||||||
this->width = inputWidth;
|
this->width = inputWidth;
|
||||||
this->height = inputHeight;
|
this->height = inputHeight;
|
||||||
|
|
||||||
SetWindowSize(this->width, this->height);
|
|
||||||
|
|
||||||
UnloadRenderTexture(drawCache);
|
UnloadRenderTexture(drawCache);
|
||||||
|
SetWindowSize(this->width, this->height);
|
||||||
drawCache = LoadRenderTexture(this->width, this->height);
|
drawCache = LoadRenderTexture(this->width, this->height);
|
||||||
|
|
||||||
flags.set(F_DRAW_CACHE_DIRTY);
|
flags.set(F_DRAW_CACHE_DIRTY);
|
||||||
|
|
|
@ -44,8 +44,8 @@ namespace Tri {
|
||||||
unsigned int width;
|
unsigned int width;
|
||||||
unsigned int height;
|
unsigned int height;
|
||||||
float dt;
|
float dt;
|
||||||
float notification_alpha;
|
float notificationAlpha;
|
||||||
std::array<char, 256> notification_text;
|
std::array<char, 256> notificationText;
|
||||||
|
|
||||||
std::vector<Triangle> tris;
|
std::vector<Triangle> tris;
|
||||||
unsigned int trisIndex;
|
unsigned int trisIndex;
|
||||||
|
@ -91,6 +91,7 @@ namespace Tri {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void set_notification_text(const char *text);
|
void set_notification_text(const char *text);
|
||||||
|
void append_notification_text(const char *text);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
std::array<float, 4>& get_color();
|
std::array<float, 4>& get_color();
|
||||||
|
|
Loading…
Reference in a new issue