-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
keira: wasting time on fun stuff (closes #82)
- Loading branch information
Showing
6 changed files
with
2,578 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#include <AnimatedGIF.h> | ||
|
||
#include "petpet.h" | ||
#include "petpet_gif.h" | ||
#include "utils/defer.h" | ||
|
||
// Idea by @imbirWIthSugar | ||
|
||
PetPetApp::PetPetApp() : App("PetPet") { | ||
} | ||
|
||
void GIFDraw(GIFDRAW* pDraw) { | ||
// Called once per line | ||
PetPetApp* app = static_cast<PetPetApp*>(pDraw->pUser); | ||
if (pDraw->y == 0) { | ||
// First line of the frame | ||
app->canvas->fillScreen(lilka::colors::Black); | ||
} | ||
int16_t x = (app->canvas->width() - petpet_gif_width) / 2; | ||
int16_t y = (app->canvas->height() - petpet_gif_height) / 2 + pDraw->y; | ||
uint16_t* pixels = reinterpret_cast<uint16_t*>(pDraw->pPixels); | ||
if (pDraw->ucHasTransparency) { | ||
app->canvas->draw16bitRGBBitmapWithTranColor( | ||
x, y, pixels, pDraw->pPalette[pDraw->ucTransparent], petpet_gif_width, 1 | ||
); | ||
} else { | ||
app->canvas->draw16bitRGBBitmap(x, y, pixels, petpet_gif_width, 1); | ||
} | ||
if (pDraw->y == petpet_gif_height - 1) { | ||
// Last line of the frame | ||
app->queueDraw(); | ||
} | ||
} | ||
|
||
void* GIFAlloc(uint32_t u32Size) { | ||
return ps_malloc(u32Size); | ||
} | ||
|
||
void GIFFree(void* p) { | ||
free(p); | ||
} | ||
|
||
void PetPetApp::run() { | ||
AnimatedGIF* gif = new AnimatedGIF(); | ||
std::unique_ptr<AnimatedGIF> gif_ptr(gif); | ||
|
||
gif->begin(); | ||
if (!gif->open(const_cast<uint8_t*>(petpet_gif), petpet_gif_size, GIFDraw)) { | ||
lilka::serial_log("Failed to open GIF"); | ||
return; | ||
} | ||
Defer closeGif([&gif] { gif->close(); }); | ||
|
||
if (gif->allocFrameBuf(GIFAlloc) != GIF_SUCCESS) { | ||
lilka::serial_log("Failed to allocate frame buffer"); | ||
return; | ||
} | ||
Defer freeFrameBuf([&gif] { gif->freeFrameBuf(GIFFree); }); | ||
|
||
gif->setDrawType(GIF_DRAW_COOKED); | ||
while (1) { | ||
gif->playFrame(true, NULL, this); | ||
lilka::State state = lilka::controller.getState(); | ||
if (state.a.justPressed) { | ||
break; | ||
} | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#pragma once | ||
|
||
#include "app.h" | ||
|
||
class PetPetApp : public App { | ||
public: | ||
PetPetApp(); | ||
|
||
private: | ||
void run() override; | ||
}; |
Oops, something went wrong.