On 2011-04-10 23:39, KennyTM~ wrote:
On Apr 9, 11 04:26, Adam D. Ruppe wrote:
We discussed this first in the GUI library thread, but since it
meandered so much, I decided to split off into a new subject. Much
of what I say here will be old to anyone who saw the previous thread.
There's some new stuff nearer to the bottom though.
I, with input from others, have started writing a little module
for simple uses of a display. You can write to a bitmap, display it
to a window, and handle events all in an easy way. The basics are
cross platform, but you can use native function calls too.
http://arsdnet.net/dcode/simpledisplay.d
It's still very much in progress, but I think it's now at the point
where the direction I'm taking it is clear.
[snip]
Thanks for the great work!
Taking the version on that link, I have ported it to use the native
Cocoa/Core Graphics in OS X, instead of X11. You can check out the diff
in https://github.com/kennytm/simpledisplay.d/commit/a790.
When using objc_msgSend and friends you need to cast the function to the
right signature, to the same signature as the method you're calling via
objc_msgSend, before calling it. See
http://www.dsource.org/projects/dstep/browser/dstep/objc/message.d#L74
If you start passing floats to objc_msgSend you'll soon notice that you
get some weird behaviors if you don't cast it to the right signature.
You also need to use different versions of objc_msgSend depending on
what the return type is and on that platform you're on. If you're
returning a struct or an floating point number of some kind you need to
use a different version of objc_msgSend. You can have a look at:
http://www.dsource.org/projects/dstep/browser/dstep/objc/bridge/Bridge.d#L779
. Also look the function being called:
http://www.dsource.org/projects/dstep/browser/dstep/objc/message.d
Only Snow Leopard (10.6) is supported.
I have only tested that it works on the pendulum example and the HSL
picker, so things like drawText and drawPixel may not work properly yet.
The implementation part is quite messy right now due to Objective-C.
Since dmd does not have "pragma(framework)", you'll need to supply the
"-L-framework -LAppKit" options to dmd to link it.
And a few things:
1. *Please use spaces instead of tabs.*
2. Color's constructor's arguments should better be "red" "green" "blue"
"alpha" rather than "a" "b" "c" "d".
3. The unit of "pulseTimeout" should be documented (milliseconds).
4. In the function "fromHsl", there is a (h is real.nan). However, 'is'
on primitives is reduced to '==' and (nan == nan) is false, so (h is
real.nan) will always be false. You should use std.math.isNaN().
5. Why use the ANSI version (LoadIconA, etc.), not the Unicode version
(LoadIconW, etc.) of API on Windows? I think the latter is preferred.
--
/Jacob Carlborg