[client] app: rename up,right,down,left rotation to 0,90,180,270

This commit is contained in:
Geoffrey McRae 2021-01-18 14:42:57 +11:00
parent ff1dc32efe
commit 733bbf5153
4 changed files with 41 additions and 64 deletions

View File

@ -59,10 +59,10 @@ LG_RendererSupport;
typedef enum LG_RendererRotate typedef enum LG_RendererRotate
{ {
LG_ROTATE_UP, LG_ROTATE_0,
LG_ROTATE_DOWN, LG_ROTATE_90,
LG_ROTATE_LEFT, LG_ROTATE_180,
LG_ROTATE_RIGHT LG_ROTATE_270
} }
LG_RendererRotate; LG_RendererRotate;

View File

@ -18,25 +18,25 @@ void main()
muv.x += mouse.x; muv.x += mouse.x;
muv.y -= mouse.y; muv.y -= mouse.y;
if (rotate == 0) // up if (rotate == 0) // 0
{ {
gl_Position.xy = muv; 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.x = -muv.x;
gl_Position.y = -muv.y; gl_Position.y = -muv.y;
} }
else if (rotate == 2) // left else if (rotate == 3) // 270
{ {
gl_Position.x = -muv.y; gl_Position.x = -muv.y;
gl_Position.y = muv.x; 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; gl_Position.w = 1.0;
uv = vertexUV; uv = vertexUV;

View File

@ -16,25 +16,25 @@ uniform int cbMode;
void main() void main()
{ {
highp vec2 ruv; highp vec2 ruv;
if (rotate == 0) // up if (rotate == 0) // 0
{ {
ruv = uv; 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.x = -uv.x + 1.0f;
ruv.y = -uv.y + 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.x = -uv.y + 1.0f;
ruv.y = uv.x; ruv.y = uv.x;
} }
else if (rotate == 3) // right
{
ruv.x = uv.y;
ruv.y = -uv.x + 1.0f;
}
if(nearest == 1) if(nearest == 1)
color = texture(sampler1, ruv); color = texture(sampler1, ruv);

View File

@ -38,9 +38,7 @@ static bool optSizeParse (struct Option * opt, const char * str);
static StringList optSizeValues (struct Option * opt); static StringList optSizeValues (struct Option * opt);
static char * optSizeToString (struct Option * opt); static char * optSizeToString (struct Option * opt);
static char * optScancodeToString(struct Option * opt); static char * optScancodeToString(struct Option * opt);
static bool optRotateParse (struct Option * opt, const char * str); static bool optRotateValidate (struct Option * opt, const char ** error);
static StringList optRotateValues (struct Option * opt);
static char * optRotateToString (struct Option * opt);
static void doLicense(); static void doLicense();
@ -241,10 +239,9 @@ static struct Option options[] =
.module = "win", .module = "win",
.name = "rotate", .name = "rotate",
.description = "Rotate the displayed image", .description = "Rotate the displayed image",
.type = OPTION_TYPE_CUSTOM, .type = OPTION_TYPE_INT,
.parser = optRotateParse, .validator = optRotateValidate,
.getValues = optRotateValues, .value.x_int = 0,
.toString = optRotateToString
}, },
// input options // input options
@ -487,6 +484,14 @@ bool config_load(int argc, char * argv[])
params.showAlerts = option_get_bool ("win", "alerts" ); params.showAlerts = option_get_bool ("win", "alerts" );
params.quickSplash = option_get_bool ("win", "quickSplash" ); 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.grabKeyboard = option_get_bool("input", "grabKeyboard" );
params.grabKeyboardOnFocus = option_get_bool("input", "grabKeyboardOnFocus"); params.grabKeyboardOnFocus = option_get_bool("input", "grabKeyboardOnFocus");
params.escapeKey = option_get_int ("input", "escapeKey" ); params.escapeKey = option_get_int ("input", "escapeKey" );
@ -677,45 +682,17 @@ static char * optScancodeToString(struct Option * opt)
return str; return str;
} }
static bool optRotateParse(struct Option * opt, const char * str) static bool optRotateValidate(struct Option * opt, const char ** error)
{ {
if (!str) switch(opt->value.x_int)
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)
{ {
case LG_ROTATE_UP : str = "UP" ; break; case 0:
case LG_ROTATE_DOWN : str = "DOWN" ; break; case 90:
case LG_ROTATE_LEFT : str = "LEFT" ; break; case 180:
case LG_ROTATE_RIGHT: str = "RIGHT"; break; case 270:
default: return true;
return NULL;
} }
return strdup(str); *error = "Rotation angle must be one of 0, 90, 180 or 270";
return false;
} }