Skip to content
Snippets Groups Projects
Unverified Commit cb8b682b authored by Ellie's avatar Ellie Committed by Oliver Smith
Browse files

Fix that for one-off renders, rendering twice might be required (MR 91)

parent 62bdafe2
No related branches found
No related tags found
No related merge requests found
/*
Copyright (C) 2017 Martijn Braam & Clayton Craft <clayton@craftyguy.net>
Copyright (C) 2017-2020
Martijn Braam, Clayton Craft <clayton@craftyguy.net>, et al.
This file is part of osk-sdl.
......@@ -175,6 +176,12 @@ void Keyboard::draw(SDL_Renderer *renderer, Config *config, int screenHeight) {
}
bool Keyboard::isInSlideAnimation() {
return (fabs(
getTargetPosition() - getPosition()
) > 0.0001);
}
void Keyboard::drawRow(SDL_Surface *surface, vector<touchArea> *keyList, int x, int y, int width, int height,
list<string> *keys, int padding, TTF_Font *font)
{
......
......@@ -140,6 +140,11 @@ public:
*/
int init(SDL_Renderer *renderer);
/**
Query whether keyboard is currently sliding up/down.
*/
bool isInSlideAnimation();
private:
argb keyboardColor = {0, 0, 0, 0};
rgb inputColor = {0, 0, 0};
......
/*
Copyright (C) 2017 Martijn Braam & Clayton Craft <clayton@craftyguy.net>
Copyright (C) 2017-2020
Martijn Braam, Clayton Craft <clayton@craftyguy.net>, et al.
This file is part of osk-sdl.
......@@ -310,12 +311,44 @@ int main(int argc, char **args) {
} // switch event.type
// Render event handler
if (event.type == EVENT_RENDER){
int topHalf;
SDL_RenderCopy(renderer, wallpaperTexture, NULL, NULL);
// Hide keyboard if unlock luks thread is running
keyboard->setTargetPosition(!luksDev->unlockRunning());
keyboard->draw(renderer, &config, HEIGHT);
/* NOTE ON DOUBLE BUFFERING / RENDERING TWICE:
We only re-schedule render events during animation, otherwise
we render once and then do nothing for a long while.
A single render may however never reach the screen, since
SDL_RenderCopy() page flips and with double buffering that
may just fill the hidden backbuffer.
Therefore, we need to render two times if not during animation
to make sure it actually shows on screen during lengthy pauses.
*/
int render_times = 0;
while (render_times < 2) { // double-flip so it reaches screen
render_times++;
SDL_RenderCopy(renderer, wallpaperTexture, NULL, NULL);
// Hide keyboard if unlock luks thread is running
keyboard->setTargetPosition(!luksDev->unlockRunning());
keyboard->draw(renderer, &config, HEIGHT);
topHalf = (HEIGHT - (keyboard->getHeight() * keyboard->getPosition()));
// Only show either error box or password input box, not both
if (showPasswordError){
int tooltipPosition = topHalf / 4;
tooltip->draw(renderer, WIDTH / 20, tooltipPosition);
} else {
inputBoxRect.y = (int)(topHalf / 3.5);
SDL_RenderCopy(renderer, inputBoxTexture, NULL, &inputBoxRect);
draw_password_box_dots(renderer, &config, inputHeight, WIDTH,
passphrase.size(), inputBoxRect.y,
luksDev->unlockRunning());
}
SDL_RenderPresent(renderer);
if (keyboard->isInSlideAnimation()) {
// No need to double-flip if we'll redraw more for animation
// in a tiny moment anyway.
break;
}
}
if(lastUnlockingState != luksDev->unlockRunning()){
if(luksDev->unlockRunning() == false && luksDev->isLocked()){
......@@ -326,24 +359,9 @@ int main(int argc, char **args) {
}
lastUnlockingState = luksDev->unlockRunning();
}
topHalf = (HEIGHT - (keyboard->getHeight() * keyboard->getPosition()));
// Only show either error box or password input box, not both
if(showPasswordError){
int tooltipPosition = topHalf / 4;
tooltip->draw(renderer, WIDTH / 20, tooltipPosition);
}else{
inputBoxRect.y = (int)(topHalf / 3.5);
SDL_RenderCopy(renderer, inputBoxTexture, NULL, &inputBoxRect);
draw_password_box_dots(renderer, &config, inputHeight, WIDTH,
passphrase.size(), inputBoxRect.y,
luksDev->unlockRunning());
}
SDL_RenderPresent(renderer);
// If any animations are running, continue to push render events to the
// event queue
bool keyboardAnimate = (int)floor(keyboard->getTargetPosition()*100) !=
(int)floor(keyboard->getPosition()*100);
if (luksDev->unlockRunning() || keyboardAnimate){
if (luksDev->unlockRunning() || keyboard->isInSlideAnimation()) {
SDL_PushEvent(&renderEvent);
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment