mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-03-18 21:30:38 +01:00
[code] Fixed the wait for user input after drawing using Python.
A SandboxController is now pushed on the StackViewController and sets the KDIonContext::sharedContext before drawing, sets a white background and handles user input after the Python computation to dismiss the drawing screen. Change-Id: I51b0474365a85e845227379a16d090541fa8ded7
This commit is contained in:
@@ -1,10 +1,15 @@
|
||||
extern "C" {
|
||||
#include "modkandinsky.h"
|
||||
}
|
||||
#include <escher/metric.h>
|
||||
#include <kandinsky.h>
|
||||
#include "port.h"
|
||||
|
||||
/* KDIonContext::sharedContext needs to be set to the wanted Rect before
|
||||
* calling kandinsky_get_pixel, kandinsky_set_pixel and kandinsky_draw_string.
|
||||
* We do this here with displaySandbox(), which pushes the SandboxController on
|
||||
* the stackViewController and forces the window to redraw itself.
|
||||
* KDIonContext::sharedContext is set to the frame of the last object drawn. */
|
||||
|
||||
mp_obj_t kandinsky_color(mp_obj_t red, mp_obj_t green, mp_obj_t blue) {
|
||||
return
|
||||
MP_OBJ_NEW_SMALL_INT(
|
||||
@@ -18,25 +23,26 @@ mp_obj_t kandinsky_color(mp_obj_t red, mp_obj_t green, mp_obj_t blue) {
|
||||
|
||||
mp_obj_t kandinsky_get_pixel(mp_obj_t x, mp_obj_t y) {
|
||||
KDColor c = KDIonContext::sharedContext()->getPixel(
|
||||
KDPoint(mp_obj_get_int(x), mp_obj_get_int(y) + Metric::TitleBarHeight)
|
||||
KDPoint(mp_obj_get_int(x), mp_obj_get_int(y))
|
||||
);
|
||||
return MP_OBJ_NEW_SMALL_INT(c);
|
||||
}
|
||||
|
||||
mp_obj_t kandinsky_set_pixel(mp_obj_t x, mp_obj_t y, mp_obj_t color) {
|
||||
MicroPython::ExecutionEnvironment::currentExecutionEnvironment()->displaySandbox();
|
||||
KDIonContext::sharedContext()->setPixel(
|
||||
KDPoint(mp_obj_get_int(x), mp_obj_get_int(y) + Metric::TitleBarHeight),
|
||||
KDPoint(mp_obj_get_int(x), mp_obj_get_int(y)),
|
||||
KDColor::RGB16(mp_obj_get_int(color))
|
||||
);
|
||||
MicroPython::ExecutionEnvironment::currentExecutionEnvironment()->didModifyFramebuffer();
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
mp_obj_t kandinsky_draw_string(mp_obj_t text, mp_obj_t x, mp_obj_t y) {
|
||||
MicroPython::ExecutionEnvironment::currentExecutionEnvironment()->displaySandbox();
|
||||
KDIonContext::sharedContext()->drawString(
|
||||
mp_obj_str_get_str(text),
|
||||
KDPoint(mp_obj_get_int(x), mp_obj_get_int(y) + Metric::TitleBarHeight)
|
||||
KDPoint(mp_obj_get_int(x), mp_obj_get_int(y))
|
||||
);
|
||||
MicroPython::ExecutionEnvironment::currentExecutionEnvironment()->didModifyFramebuffer();
|
||||
return mp_const_none;
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ static MicroPython::ScriptProvider * sScriptProvider = nullptr;
|
||||
static MicroPython::ExecutionEnvironment * sCurrentExecutionEnvironment = nullptr;
|
||||
|
||||
MicroPython::ExecutionEnvironment::ExecutionEnvironment() :
|
||||
m_framebufferHasBeenModified(false)
|
||||
m_sandboxIsDisplayed(false)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -34,21 +34,10 @@ MicroPython::ExecutionEnvironment * MicroPython::ExecutionEnvironment::currentEx
|
||||
return sCurrentExecutionEnvironment;
|
||||
}
|
||||
|
||||
void MicroPython::ExecutionEnvironment::didModifyFramebuffer() {
|
||||
m_framebufferHasBeenModified = true;
|
||||
}
|
||||
|
||||
void MicroPython::ExecutionEnvironment::didCleanFramebuffer() {
|
||||
m_framebufferHasBeenModified = false;
|
||||
}
|
||||
|
||||
void MicroPython::ExecutionEnvironment::runCode(const char * str) {
|
||||
assert(sCurrentExecutionEnvironment == nullptr);
|
||||
sCurrentExecutionEnvironment = this;
|
||||
|
||||
KDIonContext::sharedContext()->setOrigin(KDPointZero);
|
||||
KDIonContext::sharedContext()->setClippingRect(KDRect(0, Metric::TitleBarHeight, Ion::Display::Width, Ion::Display::Height - Metric::TitleBarHeight));
|
||||
|
||||
nlr_buf_t nlr;
|
||||
if (nlr_push(&nlr) == 0) {
|
||||
mp_lexer_t *lex = mp_lexer_new_from_str_len(0, str, strlen(str), false);
|
||||
@@ -94,18 +83,6 @@ void MicroPython::ExecutionEnvironment::runCode(const char * str) {
|
||||
/* End of mp_obj_print_exception. */
|
||||
}
|
||||
|
||||
#ifdef __EMSCRIPTEN__
|
||||
#else
|
||||
while (m_framebufferHasBeenModified) {
|
||||
int timeout = 3000;
|
||||
Ion::Events::Event event = Ion::Events::getEvent(&timeout);
|
||||
if (event == Ion::Events::OK || event == Ion::Events::Back) {
|
||||
m_framebufferHasBeenModified = false;
|
||||
redraw();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
assert(sCurrentExecutionEnvironment == this);
|
||||
sCurrentExecutionEnvironment = nullptr;
|
||||
}
|
||||
|
||||
@@ -12,16 +12,13 @@ class ExecutionEnvironment {
|
||||
public:
|
||||
ExecutionEnvironment();
|
||||
static ExecutionEnvironment * currentExecutionEnvironment();
|
||||
void didModifyFramebuffer();
|
||||
bool isFramebufferModified() const { return m_framebufferHasBeenModified; }
|
||||
void didCleanFramebuffer();
|
||||
void runCode(const char * );
|
||||
virtual void displaySandbox() {
|
||||
}
|
||||
virtual void printText(const char * text, size_t length) {
|
||||
}
|
||||
virtual void redraw() {
|
||||
}
|
||||
private:
|
||||
bool m_framebufferHasBeenModified;
|
||||
protected:
|
||||
bool m_sandboxIsDisplayed;
|
||||
};
|
||||
|
||||
void init(void * heapStart, void * heapEnd);
|
||||
|
||||
Reference in New Issue
Block a user