cmd screen
This commit is contained in:
@@ -8,6 +8,7 @@
|
||||
#pragma once
|
||||
#include "console/console.h"
|
||||
#include "display/screen.h"
|
||||
#include "util/string.h"
|
||||
|
||||
void cmdScreen(const consolecmdexec_t *exec) {
|
||||
if(exec->argc < 1) {
|
||||
@@ -19,4 +20,81 @@ void cmdScreen(const consolecmdexec_t *exec) {
|
||||
SCREEN.mode = SCREEN_MODE_BACKBUFFER;
|
||||
return;
|
||||
}
|
||||
|
||||
#if DISPLAY_SIZE_DYNAMIC == 1
|
||||
if(strcmp(exec->argv[0], "fixed") == 0) {
|
||||
if(exec->argc < 3) {
|
||||
consolePrint("Expected 3 arguments: fixed <width> <height>");
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t w, h;
|
||||
if(!stringToI32(exec->argv[1], &w) || w <= 0) {
|
||||
consolePrint("Invalid width: %s", exec->argv[1]);
|
||||
return;
|
||||
}
|
||||
if(!stringToI32(exec->argv[2], &h) || h <= 0) {
|
||||
consolePrint("Invalid height: %s", exec->argv[2]);
|
||||
return;
|
||||
}
|
||||
|
||||
SCREEN.mode = SCREEN_MODE_FIXED_SIZE;
|
||||
SCREEN.fixedSize.width = w;
|
||||
SCREEN.fixedSize.height = h;
|
||||
return;
|
||||
}
|
||||
|
||||
if(strcmp(exec->argv[0], "aspect") == 0) {
|
||||
if(exec->argc < 2) {
|
||||
consolePrint("Expected 2 arguments: aspect <size>");
|
||||
return;
|
||||
}
|
||||
|
||||
float_t r;
|
||||
if(!stringToF32(exec->argv[1], &r) || r <= 0) {
|
||||
consolePrint("Invalid aspect ratio: %s", exec->argv[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
SCREEN.mode = SCREEN_MODE_ASPECT_RATIO;
|
||||
SCREEN.aspectRatio.ratio = r;
|
||||
return;
|
||||
}
|
||||
|
||||
if(strcmp(exec->argv[0], "height") == 0) {
|
||||
if(exec->argc < 2) {
|
||||
consolePrint("Expected 2 arguments: height <size>");
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t h;
|
||||
if(!stringToI32(exec->argv[1], &h) || h <= 0) {
|
||||
consolePrint("Invalid height: %s", exec->argv[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
SCREEN.mode = SCREEN_MODE_FIXED_HEIGHT;
|
||||
SCREEN.fixedHeight.height = h;
|
||||
return;
|
||||
}
|
||||
|
||||
if(strcmp(exec->argv[0], "width") == 0) {
|
||||
if(exec->argc < 2) {
|
||||
consolePrint("Expected 2 arguments: width <size>");
|
||||
return;
|
||||
}
|
||||
|
||||
int32_t w;
|
||||
if(!stringToI32(exec->argv[1], &w) || w <= 0) {
|
||||
consolePrint("Invalid width: %s", exec->argv[1]);
|
||||
return;
|
||||
}
|
||||
|
||||
SCREEN.mode = SCREEN_MODE_FIXED_WIDTH;
|
||||
SCREEN.fixedWidth.width = w;
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
|
||||
consolePrint("Unknown mode: %s", exec->argv[0]);
|
||||
}
|
@@ -133,6 +133,20 @@ bool_t stringToU16(const char_t *str, uint16_t *out) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool_t stringToF32(const char_t *str, float_t *out) {
|
||||
assertNotNull(str, "str must not be NULL");
|
||||
assertNotNull(out, "out must not be NULL");
|
||||
|
||||
char_t *endptr;
|
||||
errno = 0;
|
||||
float_t result = strtof(str, &endptr);
|
||||
if (errno != 0 || *endptr != '\0') {
|
||||
return false;
|
||||
}
|
||||
*out = result;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool_t stringEndsWith(const char_t *str, const char_t *suffix) {
|
||||
assertNotNull(str, "str must not be NULL");
|
||||
assertNotNull(suffix, "suffix must not be NULL");
|
||||
|
@@ -127,6 +127,15 @@ bool_t stringToI16(const char_t *str, int16_t *out);
|
||||
*/
|
||||
bool_t stringToU16(const char_t *str, uint16_t *out);
|
||||
|
||||
/**
|
||||
* Converts a string to a float.
|
||||
*
|
||||
* @param str The string to convert.
|
||||
* @param out The output float.
|
||||
* @return TRUE if the conversion was successful, FALSE otherwise.
|
||||
*/
|
||||
bool_t stringToF32(const char_t *str, float_t *out);
|
||||
|
||||
/**
|
||||
* Determines if a string ends with a specified suffix.
|
||||
*
|
||||
|
Reference in New Issue
Block a user