dflplot/Plot2Kill, Most Mature *nix GUI For D2

"Jérôme M. Berger" jeberger at free.fr
Sat Jul 17 02:23:00 PDT 2010


Johannes Pfau wrote:
> On 17.07.2010 07:57, "Jérôme M. Berger" wrote:
>> dsimcha wrote:
>>> == Quote from dsimcha (dsimcha at yahoo.com)'s article
>>>> 1.  Doesn't Window mean that the plot would have to exist in its own window?  I'd
>>>> like to be able to make a plot go to one section of a larger window.
>>>> 2.  When I do:
>>>> drawable = (new DrawingArea(800, 600)).getWindow();
>>>> drawable somehow ends up null.
>>> Never mind, I figured this stuff out, though the documentation is rather obtuse
>>> and in serious need of examples of how to accomplish simple things.  However, I
>>> can't get the DrawingArea to actually show up on the screen.  I just get a blank
>>> window.  Here's a reduced test case.  Can someone tell me what's wrong w/ it
>>> and/or provide minimal example code to get stuff drawn via DrawingArea to show up
>>> on screen?
>>>
>>> import gtk.DrawingArea, gtk.Main, gtk.MainWindow, gdk.GC, gdk.Drawable,
>>>     gdk.Color;
>>>
>>> void main(string[] args) {
>>>     Main.init(args);
>>>
>>>     auto win = new MainWindow("Hello, world");
>>>     win.setDefaultSize(800, 600);
>>>     auto drawingArea = new DrawingArea(800, 600);
>>>     win.add(drawingArea);
>>>     drawingArea.realize();
>>>
>>>     auto drawable = drawingArea.getWindow();
>>>     auto gc = new GC(drawable);
>>>     gc.setForeground(new Color(255, 0, 0));
>>>     gc.setBackground(new Color(255, 255, 255));
>>>     drawable.drawLine(gc, 0, 0, 100, 100);
>>>
>>>     drawingArea.showAll();
>>>     drawingArea.queueDraw();
>>>     win.showAll();
>>>
>>>     Main.run();
>>> }
>> 	The problem is that gtk.DrawingArea is stateless. This means that
>> it won't remember what you draw on it. There are two solutions to this:
>> - Use a Canvas widget. There isn't one in gtk, but there are some
>> options out there. I don't know if any of them have a D wrapper;
>> - Define a callback for the "expose_event" signal on your
>> drawingArea and put your drawing code in there.
>>
>> 	Try the following (untested) code:
>> ========================================8<----------------------------------------
>> import gtk.DrawingArea, gtk.Main, gtk.MainWindow, gdk.GC,
>>     gdk.Drawable, gdk.Color;
>>
>> bool onExposeEvent (GdkEventExpose*, Widget drawingArea) {
>>     auto drawable = drawingArea.getWindow();
>>     auto gc = new GC(drawable);
>>     gc.setForeground(new Color(255, 0, 0));
>>     gc.setBackground(new Color(255, 255, 255));
>>     drawable.drawLine(gc, 0, 0, 100, 100);
>> }
>>
>> void main(string[] args) {
>>     Main.init(args);
>>
>>     auto win = new MainWindow("Hello, world");
>>     win.setDefaultSize(800, 600);
>>     auto drawingArea = new DrawingArea(800, 600);
>>     win.add(drawingArea);
>>     drawingArea.realize();
>>
>>     drawingArea.addOnExpose ((GdkEventExpose* event,
>>                               Widget drawingArea) {
>>         auto drawable = drawingArea.getWindow();
>>         auto gc = new GC(drawable);
>>         gc.setForeground(new Color(255, 0, 0));
>>         gc.setBackground(new Color(255, 255, 255));
>>         drawable.drawLine(gc, 0, 0, 100, 100);
>> 	return true;
>>     });
>>
>>     drawingArea.showAll();
>>     drawingArea.queueDraw();
>>     win.showAll();
>>
>>     Main.run();
>> }
>> ---------------------------------------->8========================================
>>
>> 		Jerome
> It's missing the gtk.Widget import and onExposeEvent is missing a
> return. ("TRUE to stop other handlers from being invoked for the event.
> FALSE to propagate the event further.")
> But with these small fixes, it's working.
> 
	Well, I didn't check the imports from the original message :) As
for onExposeEvent, I forgot to remove it when I put the code
directly in an anonymous delegate.

		Jerome
-- 
mailto:jeberger at free.fr
http://jeberger.free.fr
Jabber: jeberger at jabber.fr

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 198 bytes
Desc: OpenPGP digital signature
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20100717/855aa514/attachment.pgp>


More information about the Digitalmars-d mailing list