From d806e62373eb0e8644eac5fefb027bdabd9da4a3 Mon Sep 17 00:00:00 2001 From: camh Date: Sun, 2 Jan 2022 22:00:22 -0800 Subject: [PATCH] get TEST_MODE working in coprocessorjs module --- JS/index.js | 6 +++--- mac_main.c | 47 +++++++++++++++++++++++++++++++++------------ nuklear_app.c | 1 + nuklear_quickdraw.h | 4 ++-- 4 files changed, 41 insertions(+), 17 deletions(-) diff --git a/JS/index.js b/JS/index.js index 9a48192..2bfe0a9 100644 --- a/JS/index.js +++ b/JS/index.js @@ -299,7 +299,7 @@ const parseChatsToFriendlyNameString = (chats) => { let lastMessageOutput -const TEST_MESSAGES = [ +let TEST_MESSAGES = [ {chatter: `friend 1`, text: `my super fun text message`}, {chatter: `me`, text: `some cool old thing I said earlier`}, {chatter: `friend 2`, text: `this message is not relevant to the conversation! not at all :(`}, @@ -387,7 +387,7 @@ class iMessageClient { if (TEST_MODE) { - TEST_MESSAGES = TEST_MESSAGES.concat({sender: `me`, text: message}) + TEST_MESSAGES = TEST_MESSAGES.concat({chatter: `me`, text: message}) return splitMessages(TEST_MESSAGES) } @@ -465,7 +465,7 @@ class iMessageClient { if (TEST_MODE) { - return + return `success` } try { diff --git a/mac_main.c b/mac_main.c index b25df08..c48d21d 100644 --- a/mac_main.c +++ b/mac_main.c @@ -90,6 +90,8 @@ void PROFILE_COMPLETE() { #include "SerialHelper.h" #include "Quickdraw.h" +#include "output_js.h" +#include "coprocessorjs.h" #include "nuklear_app.c" @@ -104,7 +106,6 @@ Boolean gHasWaitNextEvent; /* set up by Initialize */ /* GInBackground is maintained by our osEvent handling routines. Any part of the program can check it to find out if it is currently in the background. */ Boolean gInBackground; /* maintained by Initialize and DoEvent */ -Boolean gotMouseEvent; // #define MAC_APP_DEBUGGING /* The following globals are the state of the window. If we supported more than @@ -153,6 +154,14 @@ void main() SysBeep(1); + setupCoprocessor("nuklear", "modem"); // could also be "printer", modem is 0 in PCE settings - printer would be 1 + // we could build a nuklear window for selection + + char programResult[MAX_RECEIVE_SIZE]; + sendProgramToCoprocessor(OUTPUT_JS, programResult); + + coprocessorLoaded = 1; + EventLoop(ctx); /* call the main event loop */ } @@ -170,8 +179,6 @@ void EventLoop(struct nk_context *ctx) int lastMouseHPos = 0; int lastMouseVPos = 0; int lastUpdatedTickCount = 0; - Boolean firstOrMouseMove = true; - gotMouseEvent = false; do { @@ -181,6 +188,21 @@ void EventLoop(struct nk_context *ctx) // PROFILE_START("eventloop"); // #endif + // check for new stuff every 10 sec? + // note! this is used by some of the functionality in our nuklear_app to trigger + // new chat lookups + if (TickCount() - lastUpdatedTickCount > 600) { + + // writeSerialPortDebug(boutRefNum, "update by tick count"); + lastUpdatedTickCount = TickCount(); + + if (strcmp(activeChat, "no active chat")) { + + // writeSerialPortDebug(boutRefNum, "check chat"); + getHasNewMessagesInChat(activeChat); + } + } + Boolean beganInput = false; GetGlobalMouse(&mouse); @@ -214,6 +236,9 @@ void EventLoop(struct nk_context *ctx) firstOrMouseMove = true; beganInput = true; + mouse_x = tempPoint.h; + mouse_y = tempPoint.v; + lastUpdatedTickCount = TickCount(); lastMouseHPos = mouse.h; lastMouseVPos = mouse.v; @@ -222,6 +247,7 @@ void EventLoop(struct nk_context *ctx) } else { gotEvent = GetNextEvent(everyEvent, &event); + gotMouseEvent = false; // drain all events before rendering -- really this only applies to keyboard events and single mouse clicks now while (gotEvent) { @@ -289,14 +315,7 @@ void EventLoop(struct nk_context *ctx) PROFILE_START("nk_quickdraw_render"); #endif - GetGlobalMouse(&mouse); - - // if the mouse is moving, don't try to render. we'll likely have more rendering to do when - // the user stops moving the mouse - if (lastMouseVPos == mouse.v || lastMouseHPos == mouse.h) { - - nk_quickdraw_render(FrontWindow(), ctx); - } + nk_quickdraw_render(FrontWindow(), ctx); #ifdef PROFILING PROFILE_END("nk_quickdraw_render"); @@ -341,6 +360,8 @@ void DoEvent(EventRecord *event, struct nk_context *ctx) { case mouseUp: + gotMouseEvent = true; + #ifdef MAC_APP_DEBUGGING writeSerialPortDebug(boutRefNum, "mouseup"); #endif @@ -621,7 +642,9 @@ void DoMenuCommand(menuResult) handledByDA = SystemEdit(menuItem-1); /* since we donÕt do any Editing */ break; case mLight: - // example handling for menu item + // note this was co-opted to send new chats instead of the demo functionality. do the + // same thing for other menu items as necessary + sendNewChat = 1; break; case mHelp: diff --git a/nuklear_app.c b/nuklear_app.c index 90dcfdc..9c508a2 100644 --- a/nuklear_app.c +++ b/nuklear_app.c @@ -38,6 +38,7 @@ void aFailed(char *file, int line) { #include #include "nuklear.h" #include "nuklear_quickdraw.h" +#include "coprocessorjs.h" #define MAX_CHAT_MESSAGES 16 diff --git a/nuklear_quickdraw.h b/nuklear_quickdraw.h index f8fe431..48ca851 100644 --- a/nuklear_quickdraw.h +++ b/nuklear_quickdraw.h @@ -1019,10 +1019,10 @@ void updateBounds(int top, int bottom, int left, int right) { updateBounds(quickDrawRectangle.top, quickDrawRectangle.bottom, quickDrawRectangle.left, quickDrawRectangle.right); #endif - if (!t->allowCache) { + // if (!t->allowCache) { EraseRect(&quickDrawRectangle); - } + // } color = nk_color_to_quickdraw_bw_color(t->foreground); ForeColor(color);