views:

169

answers:

5

I find my self in need of a line drawing package. I need to pop a window and draw lines and points. Text would be nice but I can live without it. Most importantly, I need something that is dirt simple to get running. I don't have time to dink around with libs (if I did have time I'd be willing but I'm already way behind as it is).

I'd prefer a D language solution (Windows XP, D1.0, Phobos) but I might be able to use anything with C linkage and source.

I'd also be able to use an out of process solution as in: generate input file, call program.

Any ideas?

A: 

wxwidgets is among the more featureful and more widely ported GUI toolkits. The toolkit is natively C, but there are bindings for plenty of other languages. I don't know if D is among them.

Norman Ramsey
+2  A: 

If you want an out-of-process solution, for getting something up and running quickly it's hard to beat generating PostScript and launching a PostScript viewer. The great advantage of this trick is that you generate something, you don't like the way it looks, you can edit it by hand until it looks better. Then you go back and edit the generator. So your prototyping cycle is very quick.

Norman Ramsey
You could also generate SVG and launch a web-browser.
Breton
+2  A: 

Another alternative is to use Cairo. It has a very easy to learn API, is quite powerful, and can write PNG, PS, PDF and SVG out of the box. It also supports drawing to GDI, X and Quartz windows.

There is an old D binding for cairo (written by some talent-less hack) which might still work. If nothing else, it'll demonstrate how to link and use cairo in D.

DK
+1  A: 

You can use SDL to pop a window and SDL_gfxPrimitves.h from SDL_gfx to draw the lines (it can also render basic text and shapes). It doesn't take much time to set up and is portable.

#include <SDL/SDL.h>
#include <SDL/SDL_gfxPrimitives.h>

main() {
    SDL_Surface *screen = NULL;

    if ( SDL_Init(SDL_INIT_VIDEO) < 0 )
        exit(EXIT_FAILURE);

    atexit(SDL_Quit);

    screen = SDL_SetVideoMode(500, 500, 32, SDL_SWSURFACE|SDL_ANYFORMAT);

    if ( screen == NULL )
        exit(EXIT_FAILURE);

    lineColor(screen, 50, 50, 200, 200, 0xff0000ff);
    SDL_Flip(screen);

    sleep(5);
}
Yuriy Yashkir
+2  A: 

QD.

It was made for this.

Just import qd, link with SDL.lib (SDL_ttf if you want text), then screen(width, height) to set up, line(x1, y1, x2, y2) to draw a line, pset(x1, y1) to draw a point, print(x1, y1, Bottom|Right, "text") to print text. cls to reset, flip to update the screen. events() to handle events. Append , rgb(r, g, b) to any of the above commands to change the line color, Fill(rgb(r, g, b)) to change the fill color.

For examples, see test*.d

Good luck!

FeepingCreature
Where can I get SDL.lib?
BCS
Check here: http://www.libsdl.org/download-1.2.php
FeepingCreature