a1ex avatar a1ex committed 9a39c22

PicoC: added double buffering API (double_buffering_start / double_buffering_end) and bmp_printf_center

Comments (0)

Files changed (3)

picoc/library_ml.c

     bmp_printf(fnt, x, y, "%s", msg);
 }
 
+static void LibBmpPrintfCenter(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
+{
+    int fnt = Param[0]->Val->Integer;
+    int x = Param[1]->Val->Integer;
+    int y = Param[2]->Val->Integer;
+    char msg[512];
+
+    struct OutputStream StrStream;
+    
+    extern void SPutc(unsigned char Ch, union OutputStreamInfo *Stream);
+    StrStream.Putch = &SPutc;
+    StrStream.i.Str.Parser = Parser;
+    StrStream.i.Str.WritePos = msg;
+    
+    // there doesn't seem to be any bounds checking :(
+
+    GenericPrintf(Parser, ReturnValue, Param+3, NumArgs-3, &StrStream);
+    PrintCh(0, &StrStream);
+
+    bmp_printf(
+        fnt, 
+        x - fontspec_font(fnt)->width * strlen(msg) / 2, 
+        y - fontspec_font(fnt)->height/2, 
+        "%s", 
+        msg
+    );
+}
+
 static void LibClrScr(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
 {
     clrscr();
     bmp_fill(color, x, y, w, h);
 }
 
+static void LibDoubleBufferStart(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
+{
+    bmp_draw_to_idle(1);
+}
+
+static void LibDoubleBufferEnd(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
+{
+    console_show_status();
+    bmp_draw_to_idle(0);
+    bmp_idle_copy(1,0);
+}
+
 static void LibSetCanonGUI(struct ParseState *Parser, struct Value *ReturnValue, struct Value **Param, int NumArgs)
 {
     int enabled = Param[0]->Val->Integer;
     {LibFillCircle,     "void fill_circle(int x, int y, int radius, int color);"                    },
     {LibDrawRect,       "void draw_rect(int x, int y, int w, int h, int color);"                    },
     {LibFillRect,       "void fill_rect(int x, int y, int w, int h, int color);"                    },
+    
+    {LibDoubleBufferStart, "void double_buffering_start();"                                         }, // start double buffering, for flicker-free drawing
+    {LibDoubleBufferEnd,   "void double_buffering_end();"                                           }, // finish double buffering and update the screen
 
     /** Text output **/
     {LibBmpPrintf,      "void bmp_printf(int fnt, int x, int y, char* fmt, ...);"                   },
+    {LibBmpPrintfCenter,"void bmp_printf_center(int fnt, int x, int y, char* fmt, ...);"            },
     {LibNotifyBox,      "void notify_box(float duration, char* fmt, ...);"                          },
 
     /** Interaction with Canon GUI **/
 	return len;
 }
 
-static void console_show_status()
+void console_show_status()
 {
     int fnt = FONT(CONSOLE_FONT,60, COLOR_BLACK);
     bmp_printf(fnt, 0, 480 - font_med.height, console_status_text);
         console_show();
     }
     PicocCleanup();
+    
+    // restore some settings to normal, if script changed them
     script_cleanup_af();
+    canon_gui_enable_front_buffer(0);
+    bmp_draw_to_idle(0);
+    
     beep();
     script_state = SCRIPT_JUST_FINISHED;
     console_set_status_text("Script finished. ");
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.