Allow different colorschemes with HUD devices

This commit is contained in:
Aaron Culliney 2017-11-11 16:02:38 -08:00
parent 021604471b
commit 7a99b72f20
16 changed files with 204 additions and 21 deletions

View File

@ -62,6 +62,21 @@ public class Apple2VideoSettingsMenu extends Apple2AbstractMenu {
INTERPOLATED
}
// must match interface_colorscheme_t
public enum DeviceColor {
GREEN_ON_BLACK(0),
GREEN_ON_BLUE(1), // ...
RED_ON_BLACK(2),
BLUE_ON_BLACK(3),
WHITE_ON_BLACK(4);
private int val;
DeviceColor(int val) {
this.val = val;
}
}
protected enum SETTINGS implements Apple2AbstractMenu.IMenuEnum {
LANDSCAPE_MODE {
@Override
@ -97,7 +112,7 @@ public class Apple2VideoSettingsMenu extends Apple2AbstractMenu {
cb.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
Apple2Preferences.setJSONPref((IMenuEnum)self, isChecked);
Apple2Preferences.setJSONPref((IMenuEnum) self, isChecked);
applyLandscapeMode(activity);
}
});
@ -196,6 +211,82 @@ public class Apple2VideoSettingsMenu extends Apple2AbstractMenu {
}
});
}
},
COLOR_DEVICE_CONFIGURE {
@Override
public final String getTitle(Apple2Activity activity) {
return activity.getResources().getString(R.string.touch_device_color);
}
@Override
public final String getSummary(Apple2Activity activity) {
return activity.getResources().getString(R.string.touch_device_color_summary);
}
@Override
public String getPrefDomain() {
return Apple2Preferences.PREF_DOMAIN_INTERFACE;
}
@Override
public String getPrefKey() {
return "hudColorMode";
}
@Override
public Object getPrefDefault() {
return 0;
}
@Override
public View getView(Apple2Activity activity, View convertView) {
convertView = _basicView(activity, this, convertView);
_addPopupIcon(activity, this, convertView);
return convertView;
}
@Override
public void handleSelection(final Apple2Activity activity, final Apple2AbstractMenu settingsMenu, boolean isChecked) {
final Apple2AbstractMenu.IMenuEnum self = this;
_alertDialogHandleSelection(activity, R.string.touch_device_color_configure, new String[]{
settingsMenu.mActivity.getResources().getString(R.string.color_red_on_black),
settingsMenu.mActivity.getResources().getString(R.string.color_green_on_black),
settingsMenu.mActivity.getResources().getString(R.string.color_blue_on_black),
settingsMenu.mActivity.getResources().getString(R.string.color_white_on_black),
}, new IPreferenceLoadSave() {
@Override
public int intValue() {
int colorscheme = (int) Apple2Preferences.getJSONPref(self);
if (colorscheme == DeviceColor.GREEN_ON_BLACK.ordinal()) {
return 1;
} else if (colorscheme == DeviceColor.BLUE_ON_BLACK.ordinal()) {
return 2;
} else if (colorscheme == DeviceColor.WHITE_ON_BLACK.ordinal()) {
return 3;
} else {
return 0;
}
}
@Override
public void saveInt(int value) {
switch (value) {
case 1:
Apple2Preferences.setJSONPref(self, (int) DeviceColor.GREEN_ON_BLACK.ordinal());
break;
case 2:
Apple2Preferences.setJSONPref(self, (int) DeviceColor.BLUE_ON_BLACK.ordinal());
break;
case 3:
Apple2Preferences.setJSONPref(self, (int) DeviceColor.WHITE_ON_BLACK.ordinal());
break;
default:
Apple2Preferences.setJSONPref(self, (int) DeviceColor.RED_ON_BLACK.ordinal());
break;
}
}
});
}
};
public static final int size = SETTINGS.values().length;

View File

@ -179,5 +179,14 @@
<string name="reset_preferences">Reset settings</string>
<string name="reset_self_test">Self Test</string>
<string name="reset_soft">Soft</string>
<string name="touch_device_color">Configure touch device color</string>
<string name="touch_device_color_summary">Configure color of HUD elements</string>
<string name="state_not_restored">Error restoring state…</string>
<string name="storage">/storage/</string>
<string name="touch_device_color_configure">Configure HUD color…</string>
<string name="color_red_on_black">Red on black</string>
<string name="color_green_on_black">Green on black</string>
<string name="color_blue_on_black">Blue on black</string>
<string name="color_white_on_black">White on black</string>
</resources>

View File

@ -179,5 +179,14 @@
<string name="reset_preferences">Reset settings</string>
<string name="reset_self_test">Self Test</string>
<string name="reset_soft">Soft</string>
<string name="touch_device_color">Configure touch device color</string>
<string name="touch_device_color_summary">Configure color of HUD elements</string>
<string name="state_not_restored">Error restoring state…</string>
<string name="storage">/storage/</string>
<string name="touch_device_color_configure">Configure HUD color…</string>
<string name="color_red_on_black">Red on black</string>
<string name="color_green_on_black">Green on black</string>
<string name="color_blue_on_black">Blue on black</string>
<string name="color_white_on_black">White on black</string>
</resources>

View File

@ -179,5 +179,14 @@
<string name="reset_self_test">Self Test</string>
<string name="reset_preferences">Reset settings</string>
<string name="reset_soft">Soft</string>
<string name="touch_device_color">Configure touch device color</string>
<string name="touch_device_color_summary">Configure color of HUD elements</string>
<string name="state_not_restored">Error restoring state…</string>
<string name="storage">/storage/</string>
<string name="touch_device_color_configure">Configure HUD color…</string>
<string name="color_red_on_black">Red on black</string>
<string name="color_green_on_black">Green on black</string>
<string name="color_blue_on_black">Blue on black</string>
<string name="color_white_on_black">White on black</string>
</resources>

View File

@ -181,5 +181,12 @@
<string name="touch_menu_enable_summary">Enables soft menu buttons in top screen corners</string>
<string name="video_configure">Configure video…</string>
<string name="video_configure_summary">Color landscape/portrait, color, etc</string>
<string name="touch_device_color">Configure touch device color</string>
<string name="touch_device_color_summary">Configure color of HUD elements</string>
<string name="touch_device_color_configure">Configure HUD color…</string>
<string name="color_red_on_black">Red on black</string>
<string name="color_green_on_black">Green on black</string>
<string name="color_blue_on_black">Blue on black</string>
<string name="color_white_on_black">White on black</string>
</resources>

View File

@ -35,7 +35,7 @@ static pthread_mutex_t display_scan_mutex = PTHREAD_MUTEX_INITIALIZER;
static uint8_t video__wider_font[0x8000] = { 0 };
static uint8_t video__font[0x4000] = { 0 };
static uint8_t video__int_font[3][0x4000] = { { 0 } }; // interface font
static uint8_t video__int_font[5][0x4000] = { { 0 } }; // interface font
static color_mode_t color_mode = COLOR_NONE;
@ -521,13 +521,17 @@ static void _loadfont_int(int first, int quantity, const uint8_t *data) {
while (j--) {
unsigned int y = (first << 6) + (i << 3) + j;
if (x & 128) {
video__int_font[0][y] = COLOR_LIGHT_GREEN;
video__int_font[1][y] = COLOR_LIGHT_GREEN;
video__int_font[2][y] = COLOR_LIGHT_RED;
video__int_font[GREEN_ON_BLACK][y] = COLOR_LIGHT_GREEN;
video__int_font[GREEN_ON_BLUE][y] = COLOR_LIGHT_GREEN;
video__int_font[RED_ON_BLACK][y] = COLOR_LIGHT_RED;
video__int_font[BLUE_ON_BLACK][y] = COLOR_LIGHT_BLUE;
video__int_font[WHITE_ON_BLACK][y] = COLOR_LIGHT_WHITE;
} else {
video__int_font[0][y] = COLOR_BLACK;
video__int_font[1][y] = COLOR_MEDIUM_BLUE;
video__int_font[2][y] = COLOR_BLACK;
video__int_font[GREEN_ON_BLACK][y] = COLOR_BLACK;
video__int_font[GREEN_ON_BLUE][y] = COLOR_MEDIUM_BLUE;
video__int_font[RED_ON_BLACK][y] = COLOR_BLACK;
video__int_font[BLUE_ON_BLACK][y] = COLOR_BLACK;
video__int_font[WHITE_ON_BLACK][y] = COLOR_BLACK;
}
x <<= 1;
}

View File

@ -22,9 +22,14 @@ typedef enum interface_colorscheme_t {
GREEN_ON_BLACK = 0,
GREEN_ON_BLUE,
RED_ON_BLACK,
BLUE_ON_BLACK,
WHITE_ON_BLACK,
// WARNING : changing here requires updating display.c ncvideo.c
BLACK_ON_RED,
// 16 COLORS
// 16 COLORS -- ncvideo.c
BLACK_ON_BLACK,
BLACK_ON_MAGENTA,
BLACK_ON_DARKBLUE,

View File

@ -39,6 +39,7 @@
#define PREF_DEVICE_LANDSCAPE "landscapeEnabled"
#define PREF_DISK_PATH "diskPath"
#define PREF_DISK_ANIMATIONS_ENABLED "diskAnimationsEnabled"
#define PREF_SOFTHUD_COLOR "hudColorMode"
// joystick
#define PREF_JOYSTICK_KPAD_AUTO_RECENTER "kpAutoRecenter"

View File

@ -9,17 +9,19 @@ precision highp float;
// but we must explicitly declared this in shaders version 1.40 and
// above.
uniform vec4 solidColor;
#if __VERSION__ >= 140
out vec4 fragColor;
#endif
#if __VERSION__ >= 140
#define OUTPUT_RED fragColor = vec4(1.0, 0.0, 0.0, 1.0)
#define OUTPUT_COLOR fragColor = vec4(solidColor.r, solidColor.g, solidColor.b, solidColor.a)
#else
#define OUTPUT_RED gl_FragColor = vec4(1.0, 0.0, 0.0, 1.0)
#define OUTPUT_COLOR gl_FragColor = vec4(solidColor.r, solidColor.g, solidColor.b, solidColor.a)
#endif
void main(void)
{
OUTPUT_RED;
OUTPUT_COLOR;
}

View File

@ -35,7 +35,6 @@ static void *_create_alert(GLModel *parent) {
parent->custom = glhud_createDefault();
GLModelHUDElement *hudElement = (GLModelHUDElement *)parent->custom;
if (hudElement) {
hudElement->colorScheme = RED_ON_BLACK;
hudElement->blackIsTransparent = false;
hudElement->opaquePixelHalo = false;
}
@ -390,6 +389,8 @@ static void alert_applyPrefs(void) {
long height = prefs_parseLongValue (PREF_DOMAIN_INTERFACE, PREF_DEVICE_HEIGHT, &lVal, 10) ? lVal : (long)(SCANHEIGHT*1.5);
bool isLandscape = prefs_parseBoolValue (PREF_DOMAIN_INTERFACE, PREF_DEVICE_LANDSCAPE, &bVal) ? bVal : true;
glhud_currentColorScheme = prefs_parseLongValue(PREF_DOMAIN_INTERFACE, PREF_SOFTHUD_COLOR, &lVal, 10) ? (interface_colorscheme_t)lVal : RED_ON_BLACK;
alert_reshape((int)width, (int)height, isLandscape);
}

View File

@ -38,6 +38,8 @@ typedef struct EightPatchArgs_s {
} while (0);
#endif
interface_colorscheme_t glhud_currentColorScheme = RED_ON_BLACK;
// Generates a semi-opaque halo effect around each glyph
static void _eightpatch_opaquePixelHaloFilter(const EightPatchArgs_s args) {
@ -134,7 +136,6 @@ void *glhud_createCustom(unsigned int sizeofModel) {
GLModelHUDElement *hudElement = (GLModelHUDElement *)CALLOC(sizeofModel, 1);
if (hudElement) {
hudElement->glyphMultiplier = 1;
hudElement->colorScheme = RED_ON_BLACK;
}
return hudElement;
}
@ -144,6 +145,8 @@ void glhud_setupDefault(GLModel *parent) {
GLModelHUDElement *hudElement = (GLModelHUDElement *)parent->custom;
assert(hudElement->glyphMultiplier > 0);
hudElement->colorScheme = glhud_currentColorScheme;
char *submenu = (char *)(hudElement->tpl);
const unsigned int cols = hudElement->tplWidth;
const unsigned int rows = hudElement->tplHeight;

View File

@ -63,4 +63,7 @@ void glhud_quadModelToScreen(const GLModel *model, const int screenW, const int
// helper method to sync timing of fade out
float glhud_getTimedVisibility(struct timespec timingBegin, float minAlpha, float maxAlpha);
// current color of HUD elements
extern interface_colorscheme_t glhud_currentColorScheme;
#endif

View File

@ -76,6 +76,7 @@ static struct {
GLuint vertShader; \
GLuint fragShader; \
GLuint program; \
GLint uniformSolidColorIdx; \
GLint uniformMVPIdx;);
AZIMUTH_CLASS(GLModelJoystickAzimuth);
@ -136,6 +137,7 @@ static void *_azimuth_create_model(GLModel *parent) {
azimuthJoystick->vertShader = UNINITIALIZED_GL;
azimuthJoystick->fragShader = UNINITIALIZED_GL;
azimuthJoystick->program = UNINITIALIZED_GL;
azimuthJoystick->uniformSolidColorIdx = UNINITIALIZED_GL;
azimuthJoystick->uniformMVPIdx = UNINITIALIZED_GL;
bool err = true;
@ -159,6 +161,14 @@ static void *_azimuth_create_model(GLModel *parent) {
// Build/use Program
azimuthJoystick->program = glshader_buildProgram(vtxSource, frgSource, /*withTexcoord:*/false, &azimuthJoystick->vertShader, &azimuthJoystick->fragShader);
// Get uniforms locations
azimuthJoystick->uniformSolidColorIdx = glGetUniformLocation(azimuthJoystick->program, "solidColor");
if (azimuthJoystick->uniformSolidColorIdx < 0) {
LOG("OOPS, no solidColor uniform in Azimuth shader : %d", azimuthJoystick->uniformSolidColorIdx);
break;
}
azimuthJoystick->uniformMVPIdx = glGetUniformLocation(azimuthJoystick->program, "modelViewProjectionMatrix");
if (azimuthJoystick->uniformMVPIdx < 0) {
LOG("OOPS, no modelViewProjectionMatrix in Azimuth shader : %d", azimuthJoystick->uniformMVPIdx);
@ -197,6 +207,33 @@ static void _azimuth_render(void) {
glUniformMatrix4fv(azimuthJoystick->uniformMVPIdx, 1, GL_FALSE, mvpIdentity);
// set the solid color values
{
float R = 0.f;
float G = 0.f;
float B = 0.f;
float A = 1.f;
switch (glhud_currentColorScheme) {
case GREEN_ON_BLACK:
G = 1.f;
break;
case GREEN_ON_BLUE:
G = 1.f; // TODO FIXME : background colors ...
break;
case BLUE_ON_BLACK:
B = 1.f;
break;
case WHITE_ON_BLACK:
R = 1.f; G = 1.f; B = 1.f;
break;
case RED_ON_BLACK:
default:
R = 1.f;
break;
}
glUniform4f(azimuthJoystick->uniformSolidColorIdx, R, G, B, A);
}
// NOTE : assuming we should just upload new postion data every time ...
glBindBuffer(GL_ARRAY_BUFFER, axes.azimuthModel->posBufferName);
glBufferData(GL_ARRAY_BUFFER, axes.azimuthModel->positionArraySize, axes.azimuthModel->positions, GL_DYNAMIC_DRAW);
@ -890,6 +927,8 @@ static void gltouchjoy_applyPrefs(void) {
long height = prefs_parseLongValue (PREF_DOMAIN_INTERFACE, PREF_DEVICE_HEIGHT, &lVal, 10) ? lVal : (long)(SCANHEIGHT*1.5);
bool isLandscape = prefs_parseBoolValue (PREF_DOMAIN_INTERFACE, PREF_DEVICE_LANDSCAPE, &bVal) ? bVal : true;
glhud_currentColorScheme = prefs_parseLongValue(PREF_DOMAIN_INTERFACE, PREF_SOFTHUD_COLOR, &lVal, 10) ? (interface_colorscheme_t)lVal : RED_ON_BLACK;
gltouchjoy_reshape(width, height, isLandscape);
}

View File

@ -251,7 +251,6 @@ static inline void _switch_keyboard(GLModel *parent, uint8_t *template) {
memcpy(hudKeyboard->tpl, template, sizeof(kbdTemplateUCase/* assuming all the same size */));
// setup normal color pixels
hudKeyboard->colorScheme = RED_ON_BLACK;
glhud_setupDefault(parent);
// find the CTRL visual(s) and render them engaged
@ -518,9 +517,6 @@ static void *_create_touchkbd_hud(GLModel *parent) {
memcpy(hudKeyboard->tpl, template, sizeof(kbdTemplateUCase/* assuming all the same dimensions */));
// setup normal color pixels
hudKeyboard->colorScheme = RED_ON_BLACK;
glhud_setupDefault(parent);
return hudKeyboard;
@ -917,7 +913,6 @@ static void gltouchkbd_applyPrefs(void) {
if (kbd.model) {
GLModelHUDElement *hudKeyboard = (GLModelHUDElement *)kbd.model->custom;
hudKeyboard->colorScheme = RED_ON_BLACK;
glhud_setupDefault(kbd.model);
}
@ -936,6 +931,8 @@ static void gltouchkbd_applyPrefs(void) {
long height = prefs_parseLongValue (PREF_DOMAIN_INTERFACE, PREF_DEVICE_HEIGHT, &lVal, 10) ? lVal : (long)(SCANHEIGHT*1.5);
bool isLandscape = prefs_parseBoolValue (PREF_DOMAIN_INTERFACE, PREF_DEVICE_LANDSCAPE, &bVal) ? bVal : true;
glhud_currentColorScheme = prefs_parseLongValue(PREF_DOMAIN_INTERFACE, PREF_SOFTHUD_COLOR, &lVal, 10) ? (interface_colorscheme_t)lVal : RED_ON_BLACK;
gltouchkbd_reshape(width, height, isLandscape);
}

View File

@ -85,8 +85,6 @@ static void gltouchmenu_applyPrefs(void);
static inline void _present_menu(GLModel *parent) {
GLModelHUDElement *hudMenu = (GLModelHUDElement *)parent->custom;
memcpy(hudMenu->tpl, topMenuTemplate, sizeof(topMenuTemplate));
hudMenu->colorScheme = RED_ON_BLACK;
glhud_setupDefault(parent);
}
@ -611,6 +609,8 @@ static void gltouchmenu_applyPrefs(void) {
long height = prefs_parseLongValue (PREF_DOMAIN_INTERFACE, PREF_DEVICE_HEIGHT, &lVal, 10) ? lVal : (long)(SCANHEIGHT*1.5);
bool isLandscape = prefs_parseBoolValue (PREF_DOMAIN_INTERFACE, PREF_DEVICE_LANDSCAPE, &bVal) ? bVal : true;
glhud_currentColorScheme = prefs_parseLongValue(PREF_DOMAIN_INTERFACE, PREF_SOFTHUD_COLOR, &lVal, 10) ? (interface_colorscheme_t)lVal : RED_ON_BLACK;
gltouchmenu_reshape(width, height, isLandscape);
}

View File

@ -441,6 +441,9 @@ static void _nc_initColors(void) {
init_pair(1+GREEN_ON_BLACK, COLOR_GREEN, COLOR_BLACK );
init_pair(1+GREEN_ON_BLUE, COLOR_GREEN, COLOR_BLUE );
init_pair(1+RED_ON_BLACK, COLOR_RED, COLOR_BLACK );
init_pair(1+BLUE_ON_BLACK, COLOR_BLUE, COLOR_BLACK );
init_pair(1+WHITE_ON_BLACK, COLOR_WHITE, COLOR_BLACK );
init_pair(1+BLACK_ON_RED, COLOR_BLACK, COLOR_RED );
// 16 COLORS: