mirror of
https://github.com/mauiaaron/apple2.git
synced 2025-01-14 03:30:53 +00:00
Coalesce duplicate fade-out codepaths
This commit is contained in:
parent
8b3f288018
commit
691dbd5ac2
@ -308,3 +308,24 @@ void glhud_quadModelToScreen(const GLModel *model, const int screenW, const int
|
|||||||
screenCoords[3] = yFlip1;
|
screenCoords[3] = yFlip1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
float glhud_getTimedVisibility(struct timespec timingBegin, float minAlpha, float maxAlpha) {
|
||||||
|
|
||||||
|
struct timespec now = { 0 };
|
||||||
|
struct timespec deltat = { 0 };
|
||||||
|
|
||||||
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||||
|
float alpha = minAlpha;
|
||||||
|
deltat = timespec_diff(timingBegin, now, NULL);
|
||||||
|
if (deltat.tv_sec == 0) {
|
||||||
|
alpha = maxAlpha;
|
||||||
|
if (deltat.tv_nsec >= NANOSECONDS_PER_SECOND/2) {
|
||||||
|
alpha -= ((float)deltat.tv_nsec-(NANOSECONDS_PER_SECOND/2)) / (float)(NANOSECONDS_PER_SECOND/2);
|
||||||
|
if (alpha < 0) {
|
||||||
|
alpha = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return alpha;
|
||||||
|
}
|
||||||
|
|
||||||
|
@ -32,6 +32,8 @@
|
|||||||
bool blackIsTransparent; \
|
bool blackIsTransparent; \
|
||||||
bool opaquePixelHalo; \
|
bool opaquePixelHalo; \
|
||||||
\
|
\
|
||||||
|
struct timespec timingBegin; \
|
||||||
|
\
|
||||||
__VA_ARGS__ \
|
__VA_ARGS__ \
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -58,4 +60,7 @@ void glhud_screenToModel(const float x, const float y, const int screenW, const
|
|||||||
// orthographic translation of model coordinates to screen coordinates
|
// orthographic translation of model coordinates to screen coordinates
|
||||||
void glhud_quadModelToScreen(const GLModel *model, const int screenW, const int screenH, float screenCoords[4]);
|
void glhud_quadModelToScreen(const GLModel *model, const int screenW, const int screenH, float screenCoords[4]);
|
||||||
|
|
||||||
|
// helper method to sync timing of fade out
|
||||||
|
float glhud_getTimedVisibility(struct timespec timingBegin, float minAlpha, float maxAlpha);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -74,27 +74,6 @@ static struct {
|
|||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
#warning FIXME TODO ... this can become a common helper function ...
|
|
||||||
static inline float _get_component_visibility(struct timespec timingBegin) {
|
|
||||||
struct timespec now = { 0 };
|
|
||||||
struct timespec deltat = { 0 };
|
|
||||||
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
|
||||||
float alpha = joyglobals.minAlpha;
|
|
||||||
deltat = timespec_diff(timingBegin, now, NULL);
|
|
||||||
if (deltat.tv_sec == 0) {
|
|
||||||
alpha = 1.0;
|
|
||||||
if (deltat.tv_nsec >= NANOSECONDS_PER_SECOND/2) {
|
|
||||||
alpha -= ((float)deltat.tv_nsec-(NANOSECONDS_PER_SECOND/2)) / (float)(NANOSECONDS_PER_SECOND/2);
|
|
||||||
if (alpha < joyglobals.minAlpha) {
|
|
||||||
alpha = joyglobals.minAlpha;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return alpha;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void _setup_axis_object(GLModel *parent) {
|
static void _setup_axis_object(GLModel *parent) {
|
||||||
if (UNLIKELY(!parent)) {
|
if (UNLIKELY(!parent)) {
|
||||||
LOG("gltouchjoy WARN : cannot setup axis object without parent");
|
LOG("gltouchjoy WARN : cannot setup axis object without parent");
|
||||||
@ -308,7 +287,10 @@ static void gltouchjoy_render(void) {
|
|||||||
|
|
||||||
// draw axis
|
// draw axis
|
||||||
|
|
||||||
float alpha = _get_component_visibility(axes.timingBegin);
|
float alpha = glhud_getTimedVisibility(axes.timingBegin, joyglobals.minAlpha, 1.0);
|
||||||
|
if (alpha < joyglobals.minAlpha) {
|
||||||
|
alpha = joyglobals.minAlpha;
|
||||||
|
}
|
||||||
if (alpha > 0.0) {
|
if (alpha > 0.0) {
|
||||||
glUniform1f(alphaValue, alpha);
|
glUniform1f(alphaValue, alpha);
|
||||||
|
|
||||||
@ -330,7 +312,10 @@ static void gltouchjoy_render(void) {
|
|||||||
|
|
||||||
// draw button(s)
|
// draw button(s)
|
||||||
|
|
||||||
alpha = _get_component_visibility(buttons.timingBegin);
|
alpha = glhud_getTimedVisibility(buttons.timingBegin, joyglobals.minAlpha, 1.0);
|
||||||
|
if (alpha < joyglobals.minAlpha) {
|
||||||
|
alpha = joyglobals.minAlpha;
|
||||||
|
}
|
||||||
if (alpha > 0.0) {
|
if (alpha > 0.0) {
|
||||||
glUniform1f(alphaValue, alpha);
|
glUniform1f(alphaValue, alpha);
|
||||||
|
|
||||||
|
@ -237,30 +237,6 @@ static inline void _switch_keyboard(GLModel *parent, uint8_t *template) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#warning FIXME TODO ... this can become a common helper function ...
|
|
||||||
static inline float _get_keyboard_visibility(void) {
|
|
||||||
struct timespec now = { 0 };
|
|
||||||
struct timespec deltat = { 0 };
|
|
||||||
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
|
||||||
float alpha = minAlpha;
|
|
||||||
deltat = timespec_diff(kbd.timingBegin, now, NULL);
|
|
||||||
if (deltat.tv_sec == 0) {
|
|
||||||
alpha = maxAlpha;
|
|
||||||
if (deltat.tv_nsec >= NANOSECONDS_PER_SECOND/2) {
|
|
||||||
alpha -= ((float)deltat.tv_nsec-(NANOSECONDS_PER_SECOND/2)) / (float)(NANOSECONDS_PER_SECOND/2);
|
|
||||||
if (alpha < minAlpha) {
|
|
||||||
alpha = minAlpha;
|
|
||||||
_rerender_selected(kbd.selectedCol, kbd.selectedRow);
|
|
||||||
kbd.selectedCol = -1;
|
|
||||||
kbd.selectedRow = -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return alpha;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline bool _is_point_on_keyboard(float x, float y) {
|
static inline bool _is_point_on_keyboard(float x, float y) {
|
||||||
return (x >= touchport.kbdX && x <= touchport.kbdXMax && y >= touchport.kbdY && y <= touchport.kbdYMax);
|
return (x >= touchport.kbdX && x <= touchport.kbdXMax && y >= touchport.kbdY && y <= touchport.kbdYMax);
|
||||||
}
|
}
|
||||||
@ -560,7 +536,13 @@ static void gltouchkbd_render(void) {
|
|||||||
gltouchkbd_setup();
|
gltouchkbd_setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
float alpha = _get_keyboard_visibility();
|
float alpha = glhud_getTimedVisibility(kbd.timingBegin, minAlpha, maxAlpha);
|
||||||
|
if (alpha < minAlpha) {
|
||||||
|
alpha = minAlpha;
|
||||||
|
_rerender_selected(kbd.selectedCol, kbd.selectedRow);
|
||||||
|
kbd.selectedCol = -1;
|
||||||
|
kbd.selectedRow = -1;
|
||||||
|
}
|
||||||
|
|
||||||
if (alpha > 0.0) {
|
if (alpha > 0.0) {
|
||||||
// draw touch keyboard
|
// draw touch keyboard
|
||||||
|
@ -35,8 +35,6 @@ HUD_CLASS(GLModelHUDMenu,
|
|||||||
|
|
||||||
static bool isAvailable = false; // Were there any OpenGL/memory errors on initialization?
|
static bool isAvailable = false; // Were there any OpenGL/memory errors on initialization?
|
||||||
static bool isEnabled = true; // Does player want this enabled?
|
static bool isEnabled = true; // Does player want this enabled?
|
||||||
static float minAlpha = 1/4.f; // Minimum alpha value of components (at zero, will not render)
|
|
||||||
static float maxAlpha = 1.f;
|
|
||||||
|
|
||||||
// NOTE : intent is to match touch keyboard width
|
// NOTE : intent is to match touch keyboard width
|
||||||
static uint8_t topMenuTemplate[MENU_TEMPLATE_ROWS][MENU_TEMPLATE_COLS+1] = {
|
static uint8_t topMenuTemplate[MENU_TEMPLATE_ROWS][MENU_TEMPLATE_COLS+1] = {
|
||||||
@ -76,12 +74,14 @@ static struct {
|
|||||||
bool topLeftShowing;
|
bool topLeftShowing;
|
||||||
bool topRightShowing;
|
bool topRightShowing;
|
||||||
|
|
||||||
|
struct timespec timingBegin;
|
||||||
|
float minAlpha; // Minimum alpha value of components (at zero, will not render)
|
||||||
|
float maxAlpha;
|
||||||
|
|
||||||
// pending changes requiring reinitialization
|
// pending changes requiring reinitialization
|
||||||
unsigned int nextGlyphMultiplier;
|
unsigned int nextGlyphMultiplier;
|
||||||
} menu = { 0 };
|
} menu = { 0 };
|
||||||
|
|
||||||
static struct timespec timingBegin = { 0 };
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
|
|
||||||
static inline void _present_menu(GLModel *parent) {
|
static inline void _present_menu(GLModel *parent) {
|
||||||
@ -145,26 +145,6 @@ static inline void _hide_top_right(void) {
|
|||||||
_present_menu(menu.model);
|
_present_menu(menu.model);
|
||||||
}
|
}
|
||||||
|
|
||||||
static float _get_menu_visibility(void) {
|
|
||||||
struct timespec now = { 0 };
|
|
||||||
struct timespec deltat = { 0 };
|
|
||||||
float alpha = minAlpha;
|
|
||||||
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
|
||||||
deltat = timespec_diff(timingBegin, now, NULL);
|
|
||||||
if (deltat.tv_sec == 0) {
|
|
||||||
alpha = maxAlpha;
|
|
||||||
if (deltat.tv_nsec >= NANOSECONDS_PER_SECOND/2) {
|
|
||||||
alpha -= ((float)deltat.tv_nsec-(NANOSECONDS_PER_SECOND/2)) / (float)(NANOSECONDS_PER_SECOND/2);
|
|
||||||
if (alpha < minAlpha) {
|
|
||||||
alpha = minAlpha;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return alpha;
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline bool _is_point_on_left_menu(float x, float y) {
|
static inline bool _is_point_on_left_menu(float x, float y) {
|
||||||
if (menu.topLeftShowing) {
|
if (menu.topLeftShowing) {
|
||||||
return (x >= touchport.topLeftX && x <= touchport.topLeftXMax && y >= touchport.topLeftY && y <= touchport.topLeftYMax);
|
return (x >= touchport.topLeftX && x <= touchport.topLeftXMax && y >= touchport.topLeftY && y <= touchport.topLeftYMax);
|
||||||
@ -422,7 +402,7 @@ static void gltouchmenu_setup(void) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
clock_gettime(CLOCK_MONOTONIC, &timingBegin);
|
clock_gettime(CLOCK_MONOTONIC, &menu.timingBegin);
|
||||||
|
|
||||||
isAvailable = true;
|
isAvailable = true;
|
||||||
|
|
||||||
@ -443,7 +423,10 @@ static void gltouchmenu_render(void) {
|
|||||||
gltouchmenu_setup();
|
gltouchmenu_setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
float alpha = _get_menu_visibility();
|
float alpha = glhud_getTimedVisibility(menu.timingBegin, menu.minAlpha, menu.maxAlpha);
|
||||||
|
if (alpha < menu.minAlpha) {
|
||||||
|
alpha = menu.minAlpha;
|
||||||
|
}
|
||||||
if (alpha <= 0.0) {
|
if (alpha <= 0.0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -533,7 +516,7 @@ static int64_t gltouchmenu_onTouchEvent(interface_touch_event_t action, int poin
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (handled) {
|
if (handled) {
|
||||||
clock_gettime(CLOCK_MONOTONIC, &timingBegin);
|
clock_gettime(CLOCK_MONOTONIC, &menu.timingBegin);
|
||||||
flags |= TOUCH_FLAGS_HANDLED;
|
flags |= TOUCH_FLAGS_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -552,18 +535,18 @@ static void gltouchmenu_setTouchMenuEnabled(bool enabled) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void _animation_showTouchMenu(void) {
|
static void _animation_showTouchMenu(void) {
|
||||||
clock_gettime(CLOCK_MONOTONIC, &timingBegin);
|
clock_gettime(CLOCK_MONOTONIC, &menu.timingBegin);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void _animation_hideTouchMenu(void) {
|
static void _animation_hideTouchMenu(void) {
|
||||||
_hide_top_left();
|
_hide_top_left();
|
||||||
_hide_top_right();
|
_hide_top_right();
|
||||||
timingBegin = (struct timespec){ 0 };
|
menu.timingBegin = (struct timespec){ 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gltouchmenu_setTouchMenuVisibility(float inactiveAlpha, float activeAlpha) {
|
static void gltouchmenu_setTouchMenuVisibility(float inactiveAlpha, float activeAlpha) {
|
||||||
minAlpha = inactiveAlpha;
|
menu.minAlpha = inactiveAlpha;
|
||||||
maxAlpha = activeAlpha;
|
menu.maxAlpha = activeAlpha;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gltouchmenu_setGlyphScale(int glyphScale) {
|
static void gltouchmenu_setGlyphScale(int glyphScale) {
|
||||||
@ -589,6 +572,8 @@ static void _init_gltouchmenu(void) {
|
|||||||
interface_setGlyphScale = &gltouchmenu_setGlyphScale;
|
interface_setGlyphScale = &gltouchmenu_setGlyphScale;
|
||||||
|
|
||||||
menu.glyphMultiplier = 1;
|
menu.glyphMultiplier = 1;
|
||||||
|
menu.minAlpha = 1/4.f; // Minimum alpha value of components (at zero, will not render)
|
||||||
|
menu.maxAlpha = 1.f;
|
||||||
|
|
||||||
glnode_registerNode(RENDER_TOP, (GLNode){
|
glnode_registerNode(RENDER_TOP, (GLNode){
|
||||||
.setup = &gltouchmenu_setup,
|
.setup = &gltouchmenu_setup,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user