Repair damage during mouse move.

This is a compromise between updating the screen every frame (which
takes ~60% CPU on my old no-GPU hardware) and repairing damage from e.g.
dragging offscreen and back on, or covering and uncovering the window
with another window.
This commit is contained in:
Simon Forman 2023-02-26 08:42:37 -08:00
parent c48f1797b4
commit e047af09b3
1 changed files with 36 additions and 5 deletions

View File

@ -10,8 +10,11 @@ size_t FRAME_HEIGHT = 800;
// RGBA pixels: 800 * 600
u32 frame_buffer[1024_000];
int wid;
void anim_callback()
void
anim_callback()
{
// Clear the screen
memset(frame_buffer, 0, sizeof(frame_buffer));
@ -25,13 +28,41 @@ void anim_callback()
*pix_ptr = (alpha << 24) | (red << 16) | (green << 8) | blue;
}
}
window_draw_frame(0, frame_buffer);
time_delay_cb(100, anim_callback);
window_draw_frame(wid, frame_buffer);
// This rate of refresh of the whole screen caused ~60% CPU use. :(
// time_delay_cb(100, anim_callback);
}
void main()
//void
//keydown(u64 window_id, u16 keycode)
//{
// window_draw_frame(window_id, frame_buffer);
//}
void
mousemove(u64 window_id, u64 new_x, u64 new_y)
{
window_create(FRAME_WIDTH, FRAME_HEIGHT, "Bouncing Ball Example", 0);
// Redrawing the window on move seems to repair damage from
// dragging portion of the window offscreen then back on as
// you drag, without using too much CPU.
// No, weird, it doesn't.
// It did, once, but maybe that was teh X server somehow doing it for me?
// In any event, moving the mouse over the screen after drag damage
// works fine, as expected.
// (I just really would like to know why it stopped damaging the window
// in the previous try? Ugh!)
window_draw_frame(window_id, frame_buffer);
}
void
main()
{
wid = window_create(FRAME_WIDTH, FRAME_HEIGHT, "Bouncing Ball Example", 0);
time_delay_cb(0, anim_callback);
//window_on_keydown(wid, keydown);
window_on_mousemove(wid, mousemove);
enable_event_loop();
}