aiie/apple/appleui.cpp

132 lines
3.0 KiB
C++
Raw Normal View History

2018-01-07 19:43:17 +00:00
#include "appleui.h"
2022-01-26 18:49:28 +00:00
#include "vm.h"
#include "images.h" // for the image abstraction constants
2018-01-07 19:43:17 +00:00
#include "globals.h"
AppleUI::AppleUI()
{
redrawFrame = true;
redrawDriveLatches = true;
redrawDriveActivity = true;
driveInserted[0] = driveInserted[1] = 0;
driveActivity[0] = driveActivity[1] = 0;
2018-01-07 19:43:17 +00:00
}
AppleUI::~AppleUI()
{
}
void AppleUI::drawStaticUIElement(uint8_t element)
{
// Only one static UI element right now...
if (element != UIeOverlay)
return;
redrawFrame = true;
2018-01-07 19:43:17 +00:00
}
void AppleUI::drawOnOffUIElement(uint8_t element, bool state)
{
if (element == UIeDisk1_state ||
element == UIeDisk2_state) {
driveInserted[element-UIeDisk1_state] = state;
redrawDriveLatches = true;
}
else if (element == UIeDisk1_activity ||
element == UIeDisk2_activity) {
driveActivity[element-UIeDisk1_activity] = state;
redrawDriveActivity = true;
2018-01-07 19:43:17 +00:00
}
}
void AppleUI::drawPercentageUIElement(uint8_t element, uint8_t percent)
{
// only 1 element of this type
if (element != UIePowerPercentage) {
return;
}
2022-01-26 18:49:28 +00:00
drawBatteryStatus(percent);
2018-01-07 19:43:17 +00:00
}
void AppleUI::drawBatteryStatus(uint8_t percent)
{
return; // *** FIXME: image and positioning not updated for new aspect ratio
2020-12-29 00:28:35 +00:00
uint16_t xoff = 301;
2018-01-07 19:43:17 +00:00
uint16_t yoff = 222;
2020-12-29 00:28:35 +00:00
2018-01-07 19:43:17 +00:00
// the area around the apple is 12 wide; it's exactly 11 high the
// color is 210/202/159
2022-01-26 18:49:28 +00:00
static uint8_t *img = NULL;
2022-01-24 02:39:45 +00:00
static uint16_t h,w;
if (!img) {
if (!getImageInfoAndData(IMG_APPLEBATTERY, &w, &h, &img)) {
return;
}
}
float watermark = ((float)percent / 100.0) * h;
2018-01-07 19:43:17 +00:00
2022-01-24 02:39:45 +00:00
for (int y=0; y<h; y++) {
2018-01-07 19:43:17 +00:00
uint8_t bgr = 210;
uint8_t bgg = 202;
uint8_t bgb = 159;
2022-01-24 02:39:45 +00:00
if ((h-y) > watermark) {
2018-01-07 19:43:17 +00:00
// black...
bgr = bgg = bgb = 0;
}
2022-01-24 02:39:45 +00:00
uint16_t w = w;
for (int x=0; x<w; x++) {
2018-01-07 19:43:17 +00:00
#ifdef TEENSYDUINO
2022-01-24 02:39:45 +00:00
uint8_t r = pgm_read_byte(&img[(y * w + x)*4 + 0]);
uint8_t g = pgm_read_byte(&img[(y * w + x)*4 + 1]);
uint8_t b = pgm_read_byte(&img[(y * w + x)*4 + 2]);
uint8_t a = pgm_read_byte(&img[(y * w + x)*4 + 3]);
2018-01-07 19:43:17 +00:00
#else
2022-01-24 02:39:45 +00:00
const uint8_t *p = &img[(y * w + (x-1))*4];
2018-01-07 19:43:17 +00:00
uint8_t r, g, b, a;
r = p[0];
g = p[1];
b = p[2];
a = p[3];
#endif
// It's RGBA; blend w/ background color
float alpha = (float)a / 255.0;
r = (float)r * alpha + (bgr * (1.0 - alpha));
g = (float)g * alpha + (bgg * (1.0 - alpha));
b = (float)b * alpha + (bgb * (1.0 - alpha));
2020-12-29 00:28:35 +00:00
uint16_t color16 = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | ((b & 0xF8) >> 3);
2022-01-31 01:26:12 +00:00
g_display->drawPixel(x+xoff, y+yoff, color16);
2018-01-07 19:43:17 +00:00
}
}
}
void AppleUI::blit()
{
if (redrawFrame) {
redrawFrame = false;
2022-01-26 18:49:28 +00:00
g_display->drawUIImage(IMG_SHELL);
}
if (redrawDriveLatches) {
redrawDriveLatches = false;
2022-01-26 18:49:28 +00:00
g_display->drawUIImage(driveInserted[0] ? IMG_D1CLOSED : IMG_D1OPEN);
g_display->drawUIImage(driveInserted[1] ? IMG_D2CLOSED : IMG_D2OPEN);
2022-02-02 13:57:06 +00:00
redrawDriveActivity = true; // these overlap
}
if (redrawDriveActivity) {
redrawDriveActivity = false;
2022-02-02 13:14:58 +00:00
g_display->drawDriveActivity(driveActivity[0], driveActivity[1]);
}
}
2018-01-07 19:43:17 +00:00