Screen drawing routine goes to Plugin.

This commit is contained in:
Balazs Kelemen 2022-01-13 08:08:16 +01:00
parent 0f1c424731
commit f7c8cabdfe
3 changed files with 44 additions and 27 deletions

View File

@ -286,28 +286,6 @@ static void drawTextMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state
display->drawStringMaxWidth(4 + x, 10 + y, SCREEN_WIDTH - (6 + x), tempBuf);
}
static void drawCannedMessageFrame(OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
{
displayedNodeNum = 0; // Not currently showing a node pane
if (cannedMessagePlugin->getSendingState() == SENDING_STATE_NONE)
{
display->setTextAlignment(TEXT_ALIGN_LEFT);
display->setFont(FONT_SMALL);
display->drawString(0 + x, 0 + y, cannedMessagePlugin->getPrevMessage());
display->setFont(FONT_MEDIUM);
display->drawString(0 + x, 0 + y + 8, cannedMessagePlugin->getCurrentMessage());
display->setFont(FONT_SMALL);
display->drawString(0 + x, 0 + y + 24, cannedMessagePlugin->getNextMessage());
}
else
{
display->setTextAlignment(TEXT_ALIGN_CENTER);
display->setFont(FONT_MEDIUM);
display->drawString(display->getWidth()/2 + x, 0 + y + 12, "Sending...");
}
}
/// Draw a series of fields in a column, wrapping to multiple colums if needed
static void drawColumns(OLEDDisplay *display, int16_t x, int16_t y, const char **fields)
{
@ -843,6 +821,7 @@ void Screen::setup()
nodeStatusObserver.observe(&nodeStatus->onNewStatus);
if (textMessagePlugin)
textMessageObserver.observe(textMessagePlugin);
// TODO: find a nicer way to notify screen about refresh
if (cannedMessagePlugin)
cannedMessageObserver.observe(cannedMessagePlugin);
}
@ -1021,9 +1000,6 @@ void Screen::setFrames()
if (devicestate.has_rx_text_message && shouldDrawMessage(&devicestate.rx_text_message)) {
normalFrames[numframes++] = drawTextMessageFrame;
}
if (cannedMessagePlugin->shouldDraw()) {
normalFrames[numframes++] = drawCannedMessageFrame;
}
// then all the nodes
// We only show a few nodes in our scrolling list - because meshes with many nodes would have too many screens
@ -1490,7 +1466,9 @@ int Screen::handleCannedMessage(const meshtastic::Status *packet)
if (showingNormalScreen) {
setFrames(); // Regen the list of screens (will show new text message)
}
ui.switchToFrame(1);
// TODO: We might also want switch to corresponding frame,
// but we don't know the exact frame number.
//ui.switchToFrame(0);
return 0;
}

View File

@ -4,6 +4,12 @@
#include <assert.h>
// TODO: reuse defined from Screen.cpp
#define FONT_SMALL ArialMT_Plain_10
#define FONT_MEDIUM ArialMT_Plain_16
#define FONT_LARGE ArialMT_Plain_24
CannedMessagePlugin *cannedMessagePlugin;
CannedMessagePlugin::CannedMessagePlugin()
@ -160,6 +166,7 @@ int32_t CannedMessagePlugin::runOnce()
true);
this->sendingState = SENDING_STATE_ACTIVE;
this->currentMessageIndex = -1;
this->notifyObservers(NULL);
return 2000;
}
else if (this->action == CANNED_MESSAGE_ACTION_UP)
@ -195,6 +202,10 @@ String CannedMessagePlugin::getNextMessage()
}
bool CannedMessagePlugin::shouldDraw()
{
if (!radioConfig.preferences.canned_message_plugin_enabled)
{
return false;
}
return (currentMessageIndex != -1) || (this->sendingState != SENDING_STATE_NONE);
}
cannedMessagePluginSendigState CannedMessagePlugin::getSendingState()
@ -224,4 +235,28 @@ int CannedMessagePlugin::getPrevIndex()
{
return this->currentMessageIndex - 1;
}
}
}
void CannedMessagePlugin::drawFrame(
OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y)
{
displayedNodeNum = 0; // Not currently showing a node pane
if (cannedMessagePlugin->getSendingState() == SENDING_STATE_NONE)
{
display->setTextAlignment(TEXT_ALIGN_LEFT);
display->setFont(FONT_SMALL);
display->drawString(0 + x, 0 + y, cannedMessagePlugin->getPrevMessage());
display->setFont(FONT_MEDIUM);
display->drawString(0 + x, 0 + y + 8, cannedMessagePlugin->getCurrentMessage());
display->setFont(FONT_SMALL);
display->drawString(0 + x, 0 + y + 24, cannedMessagePlugin->getNextMessage());
}
else
{
display->setTextAlignment(TEXT_ALIGN_CENTER);
display->setFont(FONT_MEDIUM);
display->drawString(display->getWidth()/2 + x, 0 + y + 12, "Sending...");
}
}

View File

@ -1,4 +1,5 @@
#pragma once
#include <OLEDDisplay.h>
#include "SinglePortPlugin.h"
#include "input/InputBroker.h"
@ -51,6 +52,9 @@ class CannedMessagePlugin :
int getPrevIndex();
int handleInputEvent(const InputEvent *event);
virtual bool wantUIFrame() { return this->shouldDraw(); }
virtual void drawFrame(
OLEDDisplay *display, OLEDDisplayUiState *state, int16_t x, int16_t y);
volatile cannedMessagePluginActionType action = CANNED_MESSAGE_ACTION_NONE;
int currentMessageIndex = -1;