Update:
This small update brings a proper shadow implementation with blurring, two new functions (textPath and textAlongPath) and a few bug fixes. textAlongPath is still somewhat buggy with multi-segment paths but otherwise works great (see the TextWave demo). I fixed a few problems with arcTo that wasn’t working as specified and made a few changes here and there. More importantly, I fixed a nasty crash bug that was sometimes happening on exit.
There is also two new utility functions available from script allowing you to suspend the canvas drawing updates. This allows you to do all the drawing necessary for a frame of animation and refresh the canvas at the end, instead of having it refresh at 30fps while your script is doing all the drawing operations.
With this new API, it was possible to fix all the flickering in the included examples! I’ve also added a few new example scripts. Check out the Polygon example, as well as all the text-related ones.
Download
Every major browser has support for it, Yahoo! Widgets has support for it, how come there isn't something for DesktopX?
Enter DXCanvas, a DesktopX drawing plugin that implements the Canvas spec (plus some DesktopX-specific additions).
How does it work
DXCanvas is a DesktopX drawing plugin, which means it takes over drawing for the object it is associated to.
In the configuration, you can set the initial size for the canvas. By default, the drawing surface size will be 300x150. You can also specify whether you want the surface to be transparent and show the other objects or windows under it, or opaque.
A canvas object is made available to scripting. To be able to draw on the canvas, you need to request a context. This is done by calling getContext(type) on the canvas object. The only supported type right now is "2d".
See the list of functions in the implementation section. Note that some are slightly different from the Canvas specification, or are completely new. This is to adjust to differences in what is possible in a browser and in DesktopX.
Canvas Controller Widget
I've made a little widget to make testing easier. It loads a list of scripts from a user-defined folder and allows you to switch between them. It support scripts written in both JScript and VBScript.
It basically associate the script to an object having the DXCanvas plugin as a capability.
Two functions are required for the scripts to work: Object_OnScriptEnter() and Object_OnScriptExit().
The canvas size is reset its default size of 300x150 when switching between scripts, so make sure to set it to the required size if needed by your script.
To add a new script to the list, create a new .js or .vbs file in a folder and select this folder in the widget preferences. A few test scripts are included in the Script folder.
It also support subfolders (only 1 folder deep), so you can organize your scripts in subfolders.
How to help
Download the Canvas Controller widget and start creating scripts!
What to look for
What is broken/not working properly
Links
Changelog
1.1 Build 287:
1.1 Build 269:
1.0 Build 225:
1.0 Build 217
1.0 Build 214
1.0 Build 211
1.0 Build 201
1.0 Build 191
1.0 Build 180
1.0 Build 168
1.0 Build 159
1.0 Build 149
You can download a test version here. It only includes the Canvas Controller widget for now. Please do not use the DXCanvas plugin in your own objects and widgets yet. This version of the plugin will expire on the 10/01/2008.
Implementation
Under the hood, it's using Cairo, a 2D vector graphics library that also powers the Mozilla and Yahoo Widgets implementations. Right now, the Cairo library is dynamically loaded at runtime, but I hope to have it statically linked into the plugin for the final version.
Here is a list classes with their attributes and functions and the state of their implementation
Canvas
CanvasRenderingContext2D
Gradient
ImageData
PixelArray
TextMetrics
Also, I'm not sure if this is possible or desireable , but if the script crashes for some reason, I'm thinking the context should be killed. When my script died last night because of an undefined variable, the CPU pegged and the context flickered until I killed the process. If the context was killed when the syntax error was found, the whole thing would exit gracefully.
Just an idea.
This should be fixed with build 225.
Confirmed - this is fixed on my XP Pro machine. I'll test on Vista shortly.
Confirmed - this is fixed on my Vista Home Premium machine. I also introduced some syntax errors in my script and it crashed without any crazy stuff happening.
Littleboy,
I messed around with the plug-in all weekend and everything seems to be working well. Here is an observation that might help someone else:
Since shadows are not yet implemented, I wanted to see what would happen if I tried to set the shadow properties of a DX object using the Canvas plug-in (and my script). Well, no shadow, and an immediate crash of DXBuilder.exe
Littleboy - is there some way to make your plug-in grey out (deactivate) state properties that can't be set thru the DX UI?
- Looking forward to the release!!!
Boy am I behind. I see the plug-in was released on Saturday.
Played around with the standard DX shadows awhile back and they didn't work but, no crash on XP SP2.
When you think about it I don't think standard shadows are available for any of the plugins unless it is part of the plugin.
I'll check to see if I can do something about that. Drawing plugins should result in most properties being disabled (and in DXCanvas case, object width and height should be disabled too), but it seems that there are some bugs here and there. I've identified a few but I still have to report them.
Canvas shadows are quite different from what you get with DX though. They apply to every drawing operation, so you get a shadow for rectangles, text, lines, etc... At least, that's what I understand of the spec.
New 1.1 test build with shadows support
Since I added quite a few things and refactored the whole state management code, I would rather put out a test build before uploading it to Wincustomize. So if you have a few canvas based objects, please test the new build and report any problems and regressions. Thanks!
Final 1.1 build with a way to avoid flickering! Examples have been updated using the new API. Make sure to check the new polygon example
There are many great features available to you once you register, including:
Sign in or Create Account