Added the window update command
- some other small misc stuff
This commit is contained in:
@@ -10,6 +10,8 @@ char* CommandToStr(Command id) {
|
||||
return (char*)"CmdCreateWindow";
|
||||
case CmdDestroyWindow:
|
||||
return (char*)"CmdDestroyWindow";
|
||||
case CmdUpdateWinDims:
|
||||
return (char*)"CmdUpdateWinDims";
|
||||
default:
|
||||
return (char*)"CmdUnknown";
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@ typedef enum : uint8_t {
|
||||
CmdRequestID = 1,
|
||||
CmdAckID = 2,
|
||||
CmdCreateWindow = 3,
|
||||
CmdDestroyWindow = 4
|
||||
CmdDestroyWindow = 4,
|
||||
CmdUpdateWinDims = 5
|
||||
} Command;
|
||||
|
||||
char* CommandToStr(Command id);
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#ifndef __PACKETS__
|
||||
#define __PACKETS__
|
||||
|
||||
#include "UIDimensions.h"
|
||||
#include <stdint.h>
|
||||
|
||||
typedef uint8_t PacketType;
|
||||
|
||||
@@ -132,6 +132,11 @@ void loop(void) {
|
||||
|
||||
break;
|
||||
}
|
||||
case CmdUpdateWinDims: {
|
||||
LOG_INFO(F("Updating Win\n"));
|
||||
Window::UpdateDims(payload, &mainScreen);
|
||||
break;
|
||||
}
|
||||
case CmdDestroyWindow: {
|
||||
uint8_t destroyedWinID = Window::Destroy(payload, &mainScreen);
|
||||
if (destroyedWinID < 0) {
|
||||
|
||||
+41
-5
@@ -1,5 +1,7 @@
|
||||
#include "methods.h"
|
||||
#include "Arduino.h"
|
||||
#include "UIDrawing.h"
|
||||
#include "communication/packets.h"
|
||||
#include "logger.h"
|
||||
#include "UIComponent.h"
|
||||
#include "UIScreen.h"
|
||||
@@ -8,13 +10,17 @@
|
||||
|
||||
namespace Window {
|
||||
// Window creation
|
||||
void printUIDimsPacket(UIDimensions *dims) {
|
||||
LOG_INFO(F(" Dimensions:\n"));
|
||||
LOG_INFO(F(" X0 : %d\n"), dims->x);
|
||||
LOG_INFO(F(" Y0 : %d\n"), dims->y);
|
||||
LOG_INFO(F(" Width : %d\n"), dims->width);
|
||||
LOG_INFO(F(" Height: %d\n"), dims->height);
|
||||
}
|
||||
|
||||
void printUIWindowPacket(UICreateWindowPacket *win) {
|
||||
LOG_INFO(F("New window:\n"));
|
||||
LOG_INFO(F(" Dimensions:\n"));
|
||||
LOG_INFO(F(" X0 : %d\n"), win->dims.x);
|
||||
LOG_INFO(F(" Y0 : %d\n"), win->dims.y);
|
||||
LOG_INFO(F(" Width : %d\n"), win->dims.width);
|
||||
LOG_INFO(F(" Height: %d\n"), win->dims.height);
|
||||
printUIDimsPacket(&win->dims);
|
||||
LOG_INFO(F(" Decorations:\n"));
|
||||
LOG_INFO(F(" HasBorder : %d\n"), win->decor.hasBorder);
|
||||
LOG_INFO(F(" BGColour : %d\n"), win->decor.bgColor);
|
||||
@@ -26,6 +32,12 @@ namespace Window {
|
||||
LOG_INFO(F(" Title: %s\n"), win->title);
|
||||
}
|
||||
|
||||
void printUpdateDimsPacket(UpdateDimsPacket *pkt) {
|
||||
LOG_INFO(F("NEW DIMENSIONS:\n"));
|
||||
LOG_INFO(F(" TARGET WINDOW: %d\n"), pkt->wID);
|
||||
printUIDimsPacket(&pkt->dims);
|
||||
}
|
||||
|
||||
UICreateWindowPacket::UICreateWindowPacket() {}
|
||||
|
||||
int8_t Create(uint8_t *payload, Curses::Screen *mainScreen) {
|
||||
@@ -56,6 +68,30 @@ namespace Window {
|
||||
return childID;
|
||||
}
|
||||
|
||||
bool UpdateDims(uint8_t *payload, Curses::Screen *mainScreen) {
|
||||
UpdateDimsPacket pkt;
|
||||
memcpy((void*)&pkt, payload, sizeof(UpdateDimsPacket));
|
||||
printUpdateDimsPacket(&pkt);
|
||||
|
||||
UIElement *mainWindow = mainScreen->mainWindowHandle;
|
||||
UIElement* win = mainWindow->GetChild(pkt.wID);
|
||||
if (win == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Delete the old window
|
||||
fillRect(win->dims.x, win->dims.y, win->dims.width,
|
||||
win->dims.height, win->decor.bgColor, win->display);
|
||||
|
||||
// Update the windows dimensions
|
||||
win->dims = pkt.dims;
|
||||
|
||||
// Redraw the window
|
||||
win->drawBox();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
// Window destruction
|
||||
void printUIDestroyWindowPacket(UIDestroyWindowPacket *win) {
|
||||
LOG_INFO(F("Destroy window:\n"));
|
||||
|
||||
@@ -28,6 +28,15 @@ namespace Window {
|
||||
|
||||
void printUIDestroyWindowPacket(UIDestroyWindowPacket *win);
|
||||
int8_t Destroy(uint8_t *payload, Curses::Screen *mainScreen);
|
||||
|
||||
// Window Updates
|
||||
struct UpdateDimsPacket {
|
||||
int16_t wID;
|
||||
UIDimensions dims;
|
||||
};
|
||||
|
||||
void printUpdateDimsPacket(UpdateDimsPacket *pkt);
|
||||
bool UpdateDims(uint8_t *payload, Curses::Screen *mainScreen);
|
||||
};
|
||||
|
||||
namespace Screen {
|
||||
|
||||
Reference in New Issue
Block a user