upgrade button example
This commit is contained in:
parent
fa136d89a9
commit
e2a0e79df8
1 changed files with 22 additions and 6 deletions
|
@ -2,14 +2,30 @@
|
|||
#include <ptk.h>
|
||||
#include <ptk_log.h>
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
static const float color_step = 10.0f;
|
||||
|
||||
static PtkRect *r;
|
||||
|
||||
static void on_press(const int button, const int action, const int mods) {
|
||||
(void)button; (void)action; (void)mods;
|
||||
PTK_DEBUG("pressed!");
|
||||
r->color.r = r->color.r + (1.0f / 255.0f);
|
||||
if (r->color.r == 256.0f) {
|
||||
r->color.r = 0.0f;
|
||||
(void)button; (void)mods;
|
||||
if (action == GLFW_PRESS) {
|
||||
PTK_DEBUG("pressed!");
|
||||
r->color.b += color_step / 255.0f;
|
||||
if (r->color.b > 1.0f) {
|
||||
r->color.b = 0.0f;
|
||||
|
||||
r->color.g += color_step / 255.0f;
|
||||
if (r->color.g > 1.0f) {
|
||||
r->color.g = 0.0f;
|
||||
|
||||
r->color.r += color_step / 255.0f;
|
||||
if (r->color.r > 1.0f) {
|
||||
r->color.r = 0.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -21,7 +37,7 @@ int main(void) {
|
|||
r = (PtkRect *)ptk_rect(
|
||||
(PtkPos){ .x = 100.0f, .y = 100.0f },
|
||||
(PtkSize){ .w = 100.0f, .h = 50.0f },
|
||||
(PtkColor){ .r = 1.0f, .g = 0.0f, .b = 0.0f }
|
||||
(PtkColor){ .r = 1.0f, .g = 1.0f, .b = 1.0f }
|
||||
);
|
||||
|
||||
return ptk_run(
|
||||
|
|
Loading…
Reference in a new issue