Thanks mucho.
On Thu, Feb 20, 2014 at 12:40 PM, Chad Austin <[email protected]> wrote: > On Thu, Feb 20, 2014 at 7:38 AM, Mark Hahn <[email protected]> wrote: > >> Ah, that explains a lot. I'm happy to see that it is so easy to use from >> C. With Alon's help I was able to make libraries work and they are easy to >> use. >> > > Great! > > >> > And implement _FillRect in your JavaScript. >> >> Yes, I'm planning on coding a sizable part of the GDI API in JS. My >> co-workers aren't sure my head is screwed on straight. I wore google out >> trying to find an existing solution to interface C/C++ GDI calls to canvas >> in the browser. If anyone knows any existing solution I missed I would be >> eternally grateful. >> > > For what it's worth, my coworkers also thought I was insane. But after > some work and a lot of help from Alon, they are thrilled that Emscripten > has worked out so smoothly. > >> >> > // In a C++ module <...snip...> val canvas = getCanvasFromDC(hDC); >> >> I want to verify that you also mean I would implement the C++ call >> getCanvasFromDC >> in Javascript. You aren't referring to an existing implementation, are you? >> > > Correct, I should have clarified. That function is either implemented in > JavaScript, or you could implement it in embind, with something like this: > > val getCanvasFromDC(HDC dc) { > return ((DCImplementation*)dc)->context; > } > > And the code where you create a canvas would look something like this: > > struct DCImplementation { > val canvas; > val context; > }; > > HDC createCanvas() { > // corresponds to > // var canvas = document.createElement("canvas"); > // var context = canvas.getContext("2d"); > > HDC dc = new DCImplementation; > dc->canvas = val::global("document").call<val>("createElement", > "canvas"); > dc->context = dc->canvas.call<val>("getContext", "2d"); > return dc; > } > > Anything* you can write in JavaScript can be expressed in embind. Note, I > didn't compile any of the above, but that's the idea. > > * Well, I'm sure there are some limitations, but anything I've wanted to > do can be written. :) > > >> >> Thanks for the info. It helps a lot. >> >> >> >> On Thu, Feb 20, 2014 at 12:28 AM, Chad Austin <[email protected]> wrote: >> >>> Hi Mark, >>> >>> embind is a C++11 API. It cannot be used from C, though you could write >>> a program that is written in C and links with a C++ module that talks to >>> JavaScript as C. >>> >>> However, if you're just talking to JavaScript through C, embind wouldn't >>> get you much. It would be easier in your C to simply write: >>> >>> extern int FillRect(HDC hDC, CONST RECT* lprc, HBRUSH hbr); >>> >>> And implement _FillRect in your JavaScript. >>> >>> The embind alternative would work too. For your edification, here is >>> how it might look: >>> >>> // In your C >>> extern int FillRect(HDC hDC, CONST RECT* lprc, HBRUSH hbr); >>> >>> // In a C++ module >>> using namespace emscripten; >>> int FillRect(HDC hDC, CONST RECT* lprc, HBRUSH hbr) { >>> val canvas = getCanvasFromDC(hDC); >>> setCanvasFillStyle(canvas, hbr); >>> canvas.call<void>("fillRect", lprc->left, lprc->top, lprc->right - >>> lprc->left, lprc->bottom - lprc->top); >>> } >>> >>> embind is plenty fast for real-time chatter between JavaScript and C: we >>> go through embind for every OpenGL call in our codebase. :) >>> >>> >>> >>> >>> On Mon, Feb 17, 2014 at 2:25 PM, Mark Hahn <[email protected]> wrote: >>> >>>> I'm a newbie planning on implementing a subset of GDI in javascript >>>> that is called from emscripten-converted C (not C++) to draw text on a >>>> canvas. I'm looking into using embind because I don't think I can avoid >>>> double-quotes in my javascript (I always code in coffeescript). >>>> >>>> Some embind questions ... >>>> >>>> 1) Will I have trouble interfacing with embind from C? I see most of >>>> the embind docs in the wiki relate to C++ classes. >>>> >>>> 2) The wiki page mentions that embind is "not as lightweight as JS >>>> libraries". How large is embind (bytes added to page load)? >>>> >>>> 3) I'm going to be calling several javascript functions from C for >>>> every keystroke in an editor. There can't be more than 50 ms or so delay in >>>> the browser including the canvas drawing time. Is embind to slow for this? >>>> Anyone have an idea what the call overhead is in milliseconds? >>>> >>>> Can anyone suggest a better way to have C calls draw on a canvas than >>>> coding the calls myself in javascript? I've looked at SDL and OpenGL and >>>> both seem like overkill. I was disappointed to find there wasn't already a >>>> GDI emulation in emscripten. >>>> >>>> -- >>>> You received this message because you are subscribed to the Google >>>> Groups "emscripten-discuss" group. >>>> To unsubscribe from this group and stop receiving emails from it, send >>>> an email to [email protected]. >>>> For more options, visit https://groups.google.com/groups/opt_out. >>>> >>> >>> >>> >>> -- >>> Chad Austin >>> Technical Director, IMVU >>> http://engineering.imvu.com <http://www.imvu.com/members/Chad/> >>> http://chadaustin.me >>> >>> >>> -- >>> You received this message because you are subscribed to the Google >>> Groups "emscripten-discuss" group. >>> To unsubscribe from this group and stop receiving emails from it, send >>> an email to [email protected]. >>> For more options, visit https://groups.google.com/groups/opt_out. >>> >> >> -- >> You received this message because you are subscribed to the Google Groups >> "emscripten-discuss" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected]. >> For more options, visit https://groups.google.com/groups/opt_out. >> > > > > -- > Chad Austin > Technical Director, IMVU > http://engineering.imvu.com <http://www.imvu.com/members/Chad/> > http://chadaustin.me > > > -- > You received this message because you are subscribed to the Google Groups > "emscripten-discuss" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > For more options, visit https://groups.google.com/groups/opt_out. > -- You received this message because you are subscribed to the Google Groups "emscripten-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
