[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Making a graphical editor with Ruby. How?

jpmprb

10/29/2003 7:01:00 PM

I would like to build a simple graphical editor in Ruby. The editor
should allow a subset of the usual graphical editing operations: draw
boxes, circles, connectors, text labels, copy, paste, and some more.
What is the best way to do it in Ruby? Is there some graphic library?
Should I use another language (library) together with Ruby? Which one.
Thanks in advance for any help.

Joao
10 Answers

gabriele renzi

10/29/2003 9:30:00 PM

0

il 29 Oct 2003 11:01:17 -0800, jpmprb@sapo.pt (Joao Barros) ha
scritto::

>I would like to build a simple graphical editor in Ruby. The editor
>should allow a subset of the usual graphical editing operations: draw
>boxes, circles, connectors, text labels, copy, paste, and some more.
>What is the best way to do it in Ruby? Is there some graphic library?
>Should I use another language (library) together with Ruby? Which one.
>Thanks in advance for any help.


I think you can do it with all the GUI supported from ruby (fltk, FOX,
GTK, Tk [1])
At least I can tell that the FXRuby distribution comes with a scribble
sample application


[1] dunno if wxWindows and Qt are actually usable from ruby

Jeremy Henty

10/29/2003 10:53:00 PM

0

In article <3c5c32de.0310291101.10d9f24b@posting.google.com>, Joao
Barros wrote:

> I would like to build a simple graphical editor in Ruby. ... What
> is the best way to do it in Ruby?

I recommend Ruby-Gnome2 and the GnomeCanvas. You get lots of basic
primitives such as lines, arcs, ellipses etc. for free and a nice
interface for binding actions to GUI events. I can't say this is the
best way because I haven't used any other approach in anger, but I do
think it works very well. Kudos to the Ruby-Gnome2 team!

Jeremy Henty

elbows

10/30/2003 2:28:00 AM

0

I've actually been working on a project like this for a while now
(specifically for drawing maps, for RPGs and such). The big thing you
will need is a canvas which does collision detection -- so you can
tell when a line on the canvas or whatever is moused over, allowing
the user to click on it and move it, etc. You'll also want a fairly
rich set of canvas items.

Tk: This is what I'm using right now. It has good ruby bindings which
your users won't have to build themselves. It does collision detection
and the canvas API is pretty powerful overall.
On the downside, image support is limited, and text items can't be
rotated (which I would like to do). The look and feel is rather
archaic, and the built-in widgets are sub-par. Non-canvas things are
sometimes a pain.
I'm considering moving to another toolkit, but first I have to find
one with a sufficiently powerful canvas, or implement the needed
canvas features myself, which I lack the time an expertise for at the
moment.

Qt: Has collision detection.
Lines are only single-segment, with width 1, and no curves. Polygons
are solids with no outline. You can draw more complex stuff, but not
as full-fledged canvas items with collision detection.
It is very difficult to implement your own canvas items, as the APIs
relating to this are not very well documented. I tried and ended up
with many segfaults.
Also, the only ruby bindings are for Qt 2.x, and I don't know if they
are maintained anymore (although they work well).

FOX: No collision detection
WxWindows: No collision detection, IIRC
Gnome: Well, I am biased against gnome/GTK since I'm a KDE fan and I
think gnome is ugly (both the look and the pseudo-OO C API). OTOH, it
has ruby bindings which I imagine improve the API, and a decent set of
canvas items. The documentation doesn't seem to be very good -- for
example, I can't tell whether it does collision detection. (Does
anyone know?)

Let us know what you decide on, and feel free to drop me an email if
you want to discuss implementation details or take a peek at my code
(which should be going up on sourceforge anyway, as soon as I can come
up with a name for the project).

Nathan

jpmprb@sapo.pt (Joao Barros) wrote in message news:<3c5c32de.0310291101.10d9f24b@posting.google.com>...
> I would like to build a simple graphical editor in Ruby. The editor
> should allow a subset of the usual graphical editing operations: draw
> boxes, circles, connectors, text labels, copy, paste, and some more.
> What is the best way to do it in Ruby? Is there some graphic library?
> Should I use another language (library) together with Ruby? Which one.
> Thanks in advance for any help.
>
> Joao

Jeremy Henty

10/30/2003 8:16:00 AM

0

In article <58ef839a.0310291827.1b745064@posting.google.com>, Nathan
Weston wrote:

> Gnome: Well, I am biased against gnome/GTK since I'm a KDE fan

I am biased against both Gnome and KDE because they bring my crusty
old 233MHz 64M system to its knees. Luckily you can use Ruby and the
GnomeCanvas without installing all of Gnome (despite what the name
might suggest).

I have installed:
glib2
pango
atk
gtk2
libart
libglade
libgnomecanvas
ruby-glib2
ruby-pango
ruby-gdkpixbuf
ruby-gtk2
ruby-libart
ruby-gnomecanvas

The canvas is just a background for rendering canvas objects, so the
alleged ugliness of Gnome is not an issue. (You still get the Gtk
look and feel of course.) It does collision detection: a canvas item
can bind actions to only those events that occur on top of itself.
You can also bind actions to events that miss all items and hit the
background.

Documentation: well, there is a nice set of code samples and test
programs that exercise all the features. I didn't find it hard to
track down the ones that demonstrated the features I wanted to use and
discover which methods to call. I leave it up to you whether or not
you think that counts as documentation but it got me up and running
pretty quickly.

HTH,

Regards,

Jeremy Henty

Richard Dale

10/30/2003 1:48:00 PM

0

Nathan Weston wrote:

> Qt: Has collision detection.
> Lines are only single-segment, with width 1, and no curves. Polygons
> are solids with no outline. You can draw more complex stuff, but not
> as full-fledged canvas items with collision detection.
> It is very difficult to implement your own canvas items, as the APIs
> relating to this are not very well documented. I tried and ended up
> with many segfaults.
> Also, the only ruby bindings are for Qt 2.x, and I don't know if they
> are maintained anymore (although they work well).
The QtRuby bindings in the KDE cvs under 'kdebindings/qtruby' are based on
Qt3, and I think the QCanvas classes have been improved since Qt2. Here's a
couple of methods from the qtruby/rubylib/examples/canvastest/canvastest.rb
example:

def contentsMousePressEvent(e)
super
list = canvas.collisions(e.pos)
return if list.empty?
c = list.first
return if c.rtti != Qt::CanvasRectangle.rtti()
c.hide
@canvas.update
end


def make_rect
rect = Qt::CanvasRectangle.new(rand(@canvas.width()),
rand(@canvas.height()),
@canvas.width / 5, @canvas.width / 5,
@canvas)
z = rand(256)
color = Qt::Color.new(z,z,z)
rect.setBrush(Qt::Brush.new(color))
color = Qt::Color.new(rand(32)*8, rand(32)*8, rand(32)*8)
rect.setPen(Qt::Pen.new(color, 6))
rect.setZ(z)
rect.show
@rects << rect
end

It looks to me as though it does variable width lines (via 'setBrush()' or
'brush=' calls), handles collision detection, and does curves
(Qt::CanvasSpline?).

I haven't really announced the bindings yet as they're not quite finished
(the kde extension isn't checked in yet), but they do work well enough to
try out and use as they are.

-- Richard

jpmprb

10/30/2003 2:23:00 PM

0

Does this work in Windows XP too?

Joao

Jeremy Henty <jeremy@chaos.org.uk> wrote in message news:<slrnbq1i5j.8o.jeremy@ganglion.demon.co.uk>...
> In article <58ef839a.0310291827.1b745064@posting.google.com>, Nathan
> Weston wrote:
>
> > Gnome: Well, I am biased against gnome/GTK since I'm a KDE fan
>
> I am biased against both Gnome and KDE because they bring my crusty
> old 233MHz 64M system to its knees. Luckily you can use Ruby and the
> GnomeCanvas without installing all of Gnome (despite what the name
> might suggest).
>
> I have installed:
> glib2
> pango
> atk
> gtk2
> libart
> libglade
> libgnomecanvas
> ruby-glib2
> ruby-pango
> ruby-gdkpixbuf
> ruby-gtk2
> ruby-libart
> ruby-gnomecanvas
>
> The canvas is just a background for rendering canvas objects, so the
> alleged ugliness of Gnome is not an issue. (You still get the Gtk
> look and feel of course.) It does collision detection: a canvas item
> can bind actions to only those events that occur on top of itself.
> You can also bind actions to events that miss all items and hit the
> background.
>
> Documentation: well, there is a nice set of code samples and test
> programs that exercise all the features. I didn't find it hard to
> track down the ones that demonstrated the features I wanted to use and
> discover which methods to call. I leave it up to you whether or not
> you think that counts as documentation but it got me up and running
> pretty quickly.
>
> HTH,
>
> Regards,
>
> Jeremy Henty

elbows

10/30/2003 3:33:00 PM

0

Where can I find the sample code?
All I've found are the API docs, which aren't helpful to me without
prior knowledge of gnome programming.

But if the canvas does collision detection, I might be considering
gnome for a future version of my project.

Nathan

Jeremy Henty <jeremy@chaos.org.uk> wrote in message news:<slrnbq1i5j.8o.jeremy@ganglion.demon.co.uk>...
> In article <58ef839a.0310291827.1b745064@posting.google.com>, Nathan
> Weston wrote:
>
> > Gnome: Well, I am biased against gnome/GTK since I'm a KDE fan
>
> I am biased against both Gnome and KDE because they bring my crusty
> old 233MHz 64M system to its knees. Luckily you can use Ruby and the
> GnomeCanvas without installing all of Gnome (despite what the name
> might suggest).
>
> I have installed:
> glib2
> pango
> atk
> gtk2
> libart
> libglade
> libgnomecanvas
> ruby-glib2
> ruby-pango
> ruby-gdkpixbuf
> ruby-gtk2
> ruby-libart
> ruby-gnomecanvas
>
> The canvas is just a background for rendering canvas objects, so the
> alleged ugliness of Gnome is not an issue. (You still get the Gtk
> look and feel of course.) It does collision detection: a canvas item
> can bind actions to only those events that occur on top of itself.
> You can also bind actions to events that miss all items and hit the
> background.
>
> Documentation: well, there is a nice set of code samples and test
> programs that exercise all the features. I didn't find it hard to
> track down the ones that demonstrated the features I wanted to use and
> discover which methods to call. I leave it up to you whether or not
> you think that counts as documentation but it got me up and running
> pretty quickly.
>
> HTH,
>
> Regards,
>
> Jeremy Henty

Jeremy Henty

10/30/2003 6:25:00 PM

0

In article <3c5c32de.0310300623.7b9a9a9a@posting.google.com>, Joao
Barros wrote:

> Does this work in Windows XP too?

No idea, I'm afraid. I only have access to Unix systems.

Regards,

Jeremy Henty

Jeremy Henty

10/30/2003 6:29:00 PM

0

In article <58ef839a.0310300732.23132cf5@posting.google.com>, Nathan
Weston wrote:

> Where can I find the sample code?

In the source distribution: ruby-gnome2-all-0.7.0/*/sample .

Regards,

Jeremy Henty

elbows

10/31/2003 12:03:00 AM

0

Richard Dale <Richard_Dale@tipitina.demon.co.uk> wrote in message news:<bnr4mg$t0c$1$8302bc10@news.demon.co.uk>...
> Nathan Weston wrote:
>
> The QtRuby bindings in the KDE cvs under 'kdebindings/qtruby' are based on
> Qt3,

Excellent! I've always liked Qt and I'm glad to that someone is
working on ruby bindings again.

> It looks to me as though it does variable width lines (via 'setBrush()' or
> 'brush=' calls), handles collision detection, and does curves
> (Qt::CanvasSpline?).

The low-level drawing functions do support variable width,
multi-segment lines and curves. However, to get collision detection
you need to use the QCanvas* classes, and QCanvasLine is only a single
segment.
It does seem that the width limitation has been removed, though, which
means it might be possible to create a polyline class that just wraps
a bunch of QCanvasLines.

Nathan