You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
45 lines
1.2 KiB
45 lines
1.2 KiB
5 years ago
|
#include "scenes.h"
|
||
|
#include "liquid.h"
|
||
|
#include <malloc.h>
|
||
5 years ago
|
#include "graphics/nokia.h"
|
||
|
#include "graphics/drawing.h"
|
||
5 years ago
|
|
||
5 years ago
|
struct CarScene {
|
||
|
struct Scene base;
|
||
5 years ago
|
int32_t pos;
|
||
|
};
|
||
|
|
||
5 years ago
|
static struct SceneEvent Car_onInput(struct CarScene *self, struct InputEvent event) {
|
||
5 years ago
|
switch (event.kind) {
|
||
|
case InputEventKind_Wheel:
|
||
5 years ago
|
self->pos += event.wheel.delta;
|
||
|
if (self->pos < 0) self->pos = 0;
|
||
|
if (self->pos > LCD_WIDTH-21) self->pos = LCD_WIDTH-21;
|
||
5 years ago
|
return SceneEvent_Repaint();
|
||
|
|
||
|
case InputEventKind_Button:
|
||
|
if (event.button.state) {
|
||
|
return SceneEvent_Close(0, NULL);
|
||
|
}
|
||
|
// fall through
|
||
|
default:
|
||
|
return SceneEvent_None();
|
||
|
}
|
||
|
}
|
||
|
|
||
5 years ago
|
static void Car_paint(struct CarScene *self)
|
||
5 years ago
|
{
|
||
|
LCD_clearDisplay(0);
|
||
5 years ago
|
LCD_setRect(self->pos, LCD_HEIGHT/2-10, self->pos+20,LCD_HEIGHT/2+10,0,1);
|
||
5 years ago
|
LCD_updateDisplay();
|
||
|
}
|
||
|
|
||
|
struct Scene *NewScene_Car(void) {
|
||
5 years ago
|
struct CarScene *scene = calloc(1, sizeof(struct CarScene));
|
||
|
if (!scene) return NULL;
|
||
5 years ago
|
|
||
5 years ago
|
scene->base.onInput = (Scene_onInput_t) Car_onInput;
|
||
|
scene->base.paint = (Scene_paint_t) Car_paint;
|
||
|
return (struct Scene *) scene;
|
||
5 years ago
|
}
|