From 733bbf5153ea057213f9a9ee58a412f50fbbe223 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Mon, 18 Jan 2021 14:42:57 +1100 Subject: [PATCH] [client] app: rename up,right,down,left rotation to 0,90,180,270 --- client/include/interface/renderer.h | 8 +-- client/renderers/EGL/shader/cursor.vert | 16 ++--- client/renderers/EGL/shader/desktop_rgb.frag | 16 ++--- client/src/config.c | 65 +++++++------------- 4 files changed, 41 insertions(+), 64 deletions(-) diff --git a/client/include/interface/renderer.h b/client/include/interface/renderer.h index b76bb16f..3e2bd19c 100644 --- a/client/include/interface/renderer.h +++ b/client/include/interface/renderer.h @@ -59,10 +59,10 @@ LG_RendererSupport; typedef enum LG_RendererRotate { - LG_ROTATE_UP, - LG_ROTATE_DOWN, - LG_ROTATE_LEFT, - LG_ROTATE_RIGHT + LG_ROTATE_0, + LG_ROTATE_90, + LG_ROTATE_180, + LG_ROTATE_270 } LG_RendererRotate; diff --git a/client/renderers/EGL/shader/cursor.vert b/client/renderers/EGL/shader/cursor.vert index 63866a97..c45308c0 100644 --- a/client/renderers/EGL/shader/cursor.vert +++ b/client/renderers/EGL/shader/cursor.vert @@ -18,25 +18,25 @@ void main() muv.x += mouse.x; muv.y -= mouse.y; - if (rotate == 0) // up + if (rotate == 0) // 0 { gl_Position.xy = muv; } - else if (rotate == 1) // down + else if (rotate == 1) // 90 + { + gl_Position.x = muv.y; + gl_Position.y = -muv.x; + } + else if (rotate == 2) // 180 { gl_Position.x = -muv.x; gl_Position.y = -muv.y; } - else if (rotate == 2) // left + else if (rotate == 3) // 270 { gl_Position.x = -muv.y; gl_Position.y = muv.x; } - else if (rotate == 3) // right - { - gl_Position.x = muv.y; - gl_Position.y = -muv.x; - } gl_Position.w = 1.0; uv = vertexUV; diff --git a/client/renderers/EGL/shader/desktop_rgb.frag b/client/renderers/EGL/shader/desktop_rgb.frag index 0ce47d66..59128b8b 100644 --- a/client/renderers/EGL/shader/desktop_rgb.frag +++ b/client/renderers/EGL/shader/desktop_rgb.frag @@ -16,25 +16,25 @@ uniform int cbMode; void main() { highp vec2 ruv; - if (rotate == 0) // up + if (rotate == 0) // 0 { ruv = uv; } - else if (rotate == 1) // down + else if (rotate == 1) // 90 + { + ruv.x = uv.y; + ruv.y = -uv.x + 1.0f; + } + else if (rotate == 2) // 180 { ruv.x = -uv.x + 1.0f; ruv.y = -uv.y + 1.0f; } - else if (rotate == 2) // left + else if (rotate == 3) // 270 { ruv.x = -uv.y + 1.0f; ruv.y = uv.x; } - else if (rotate == 3) // right - { - ruv.x = uv.y; - ruv.y = -uv.x + 1.0f; - } if(nearest == 1) color = texture(sampler1, ruv); diff --git a/client/src/config.c b/client/src/config.c index a080d671..5e99610c 100644 --- a/client/src/config.c +++ b/client/src/config.c @@ -38,9 +38,7 @@ static bool optSizeParse (struct Option * opt, const char * str); static StringList optSizeValues (struct Option * opt); static char * optSizeToString (struct Option * opt); static char * optScancodeToString(struct Option * opt); -static bool optRotateParse (struct Option * opt, const char * str); -static StringList optRotateValues (struct Option * opt); -static char * optRotateToString (struct Option * opt); +static bool optRotateValidate (struct Option * opt, const char ** error); static void doLicense(); @@ -241,10 +239,9 @@ static struct Option options[] = .module = "win", .name = "rotate", .description = "Rotate the displayed image", - .type = OPTION_TYPE_CUSTOM, - .parser = optRotateParse, - .getValues = optRotateValues, - .toString = optRotateToString + .type = OPTION_TYPE_INT, + .validator = optRotateValidate, + .value.x_int = 0, }, // input options @@ -487,6 +484,14 @@ bool config_load(int argc, char * argv[]) params.showAlerts = option_get_bool ("win", "alerts" ); params.quickSplash = option_get_bool ("win", "quickSplash" ); + switch(option_get_int("win", "rotate")) + { + case 0 : params.winRotate = LG_ROTATE_0 ; break; + case 90 : params.winRotate = LG_ROTATE_90 ; break; + case 180: params.winRotate = LG_ROTATE_180; break; + case 270: params.winRotate = LG_ROTATE_270; break; + } + params.grabKeyboard = option_get_bool("input", "grabKeyboard" ); params.grabKeyboardOnFocus = option_get_bool("input", "grabKeyboardOnFocus"); params.escapeKey = option_get_int ("input", "escapeKey" ); @@ -677,45 +682,17 @@ static char * optScancodeToString(struct Option * opt) return str; } -static bool optRotateParse(struct Option * opt, const char * str) +static bool optRotateValidate(struct Option * opt, const char ** error) { - if (!str) - return false; - - if (strcasecmp(str, "up" ) == 0) params.winRotate = LG_ROTATE_UP; - else if (strcasecmp(str, "down" ) == 0) params.winRotate = LG_ROTATE_DOWN; - else if (strcasecmp(str, "left" ) == 0) params.winRotate = LG_ROTATE_LEFT; - else if (strcasecmp(str, "right") == 0) params.winRotate = LG_ROTATE_RIGHT; - else - return false; - - return true; -} - -static StringList optRotateValues(struct Option * opt) -{ - StringList sl = stringlist_new(false); - - stringlist_push(sl, "UP" ); - stringlist_push(sl, "DOWN" ); - stringlist_push(sl, "LEFT" ); - stringlist_push(sl, "RIGHT"); - - return sl; -} - -static char * optRotateToString(struct Option * opt) -{ - const char * str; - switch(params.winRotate) + switch(opt->value.x_int) { - case LG_ROTATE_UP : str = "UP" ; break; - case LG_ROTATE_DOWN : str = "DOWN" ; break; - case LG_ROTATE_LEFT : str = "LEFT" ; break; - case LG_ROTATE_RIGHT: str = "RIGHT"; break; - default: - return NULL; + case 0: + case 90: + case 180: + case 270: + return true; } - return strdup(str); + *error = "Rotation angle must be one of 0, 90, 180 or 270"; + return false; }