Thread: [Fxruby-users] Newbie question about making own drawables
Status: Inactive
Brought to you by:
lyle
From: Fredrik J. <fr...@po...> - 2003-11-23 23:10:04
|
Hi, I want to make something that's pretty simple. I want to have a couple of objects drawn on a canvas. These objects should be event-aware, so I get notified if they're clicked, dragged or otherwise manipulated. But I can't even figure out which FX object to inherit from. Neither 'FXDrawable' or 'FXImage' implements the 'connect' method. And since I can't even get to know when SEL_PAINT is requested, I don't know how I can get to know if a key has been pressed from SEL_KEYPRESSED. I guess my lack of knowledge of how to program GUI is the major culprit here, but could someone please point me to some documents which could help me out? The stuff I find on FXRuby seems to assume that I already know Fox and the document on Fox assumes that I'm using C++, although I'd suppose it's pretty easy to translate into Ruby? TIA, //F |
From: Lyle J. <jl...@cf...> - 2003-11-24 15:38:43
|
Fredrik Jagenheim wrote: > I want to make something that's pretty simple. I want to have a couple > of objects drawn on a canvas. These objects should be event-aware, so > I get notified if they're clicked, dragged or otherwise manipulated. Good, I think you will get a lot of people interested in the final product (including me ;) > But I can't even figure out which FX object to inherit from. Neither > 'FXDrawable' or 'FXImage' implements the 'connect' method. Right, the only objects that implement connect() are those that have a message target, namely, subclasses of FXWindow and FXDataTarget. I suspect that in your case you'll want to start out with the FXCanvas object (which is showcased in the scribble.rb example program) and work from that. > And since I can't even get to know when SEL_PAINT is requested, I > don't know how I can get to know if a key has been pressed from > SEL_KEYPRESSED. If the question is "when are SEL_PAINT messages sent", it's whenever part (or all) of a window is exposed and needs to be repainted. > I guess my lack of knowledge of how to program GUI is the major > culprit here, but could someone please point me to some documents > which could help me out? The stuff I find on FXRuby seems to assume > that I already know Fox and the document on Fox assumes that I'm using > C++, although I'd suppose it's pretty easy to translate into Ruby? The three primary sources for FOX documentation are the two sites you mentioned (the FOX home page at http://www.fox-toolkit.org and the FXRuby home page at http://www.fxruby.org) as well as the FOX Community Wiki site, found here: http://fifthplanet.net Hope this helps, Lyle |
From: Will M. <wi...@co...> - 2003-11-24 23:26:33
|
On Sunday, November 23, 2003 6:10 PM, Fredrik Jagenheim wrote: > I want to make something that's pretty simple. I want to have > a couple of objects drawn on a canvas. These objects should > be event-aware, so I get notified if they're clicked, dragged > or otherwise manipulated. As it happens, I am using FXRuby, Fox and Ruby to prototype an app I have in mind and so far have implemented a small application that does a lot of what you ask. Right now its spread across a half dozen files so I won't include it here, but if there is (or could be) a site to post "in progress" code, I would be happy to share it. (I am hoping soon to create a website of my own for this project, but for now its on my "real soon now" list.) Actually, I would love a site where we could post some code and give and get feedback. I have no idea if what I am writing is good Ruby/Fox/FXRuby code or not. Any ideas or possibilities? May such a thing already exists? > But I can't even figure out which FX object to inherit from. > Neither 'FXDrawable' or 'FXImage' implements the 'connect' method. > > And since I can't even get to know when SEL_PAINT is requested, > I don't know how I can get to know if a key has been pressed > from SEL_KEYPRESSED. The aproach I took was to simply use an FXWindow and set up a couple of event handlers on mouse down, move and up. Each object (stored in a simple array of objects. Boy this language is fun!) handles its own drawing and has a method to determine if the mouse coordiates are inside it. So when I click on an object, the FXWindow iterates over each object until one says "That's me!" and then that one becomes the current object for all subsequent operations. Most of this is handled by a base "drawable object" class that handles most of this, and then each type of object is subclassed from it. For the last week or two I have been trying to implement a Delphi style "Object Inspector" to work with this, and it has been kicking my butt. I am trying to use the FoxTails/Observable extensions. I like the way it works when I can figure it out, but the documentation and examples are so scant that it is really hard to figure out, at least in my case. > I guess my lack of knowledge of how to program GUI is > the major culprit here, but could someone please point > me to some documents which could help me out? The stuff > I find on FXRuby seems to assume that I already know > Fox and the document on Fox assumes that I'm using > C++, although I'd suppose it's pretty easy to translate > into Ruby? You're right, the documentation is a bit thinner than I would like too, but you can work it out by studying the examples and using lots of "print" statements. I recomend launching your app from a command line so you can see the output as it happens. I also recomend the "code'a'little, test'a'little" approach. Start with something that works, make small changes, then test your changes, fixing then until they work. Repeat. Frequently. -- Will Merrell |
From: Lyle J. <ly...@kn...> - 2003-11-25 02:45:01
|
On Nov 24, 2003, at 5:26 PM, Will Merrell wrote: > Actually, I would love a site where we could post some code and give > and get > feedback. I have no idea if what I am writing is good Ruby/Fox/FXRuby > code > or not. Any ideas or possibilities? May such a thing already exists? It's not quite what you're asking for, but you could carve out a section of the FOX Community Wiki site (http://fifthplanet.net) for this purpose. |
From: Joel V. <vj...@PA...> - 2003-11-26 00:28:18
|
Will Merrell wrote: > For the last week or two I have been trying to implement a Delphi style > "Object Inspector" to work with this, and it has been kicking my butt. I am > trying to use the FoxTails/Observable extensions. I like the way it works > when I can figure it out, but the documentation and examples are so scant > that it is really hard to figure out, at least in my case. Arg, that's my fault. I will soon upload FoxTails 0.2, which is 1.8-friendly and has a tree browser widget. Maybe I'll have some time to document better... (The tree browser is like the other FoxTails widgets in that it allows multiple views and automatically syncs between model and view.) In the meantime, pls. feel free to ask questions, either here or to me directly. Joel |
From: Will M. <wi...@co...> - 2003-11-26 05:00:29
|
Joel VanderWerf wrote: > > Will Merrell wrote: > > the documentation and examples are so scant > > that it is really hard to figure out, at least in my case. > > Arg, that's my fault. Hey, don't beat yourself up, I knew your code was pretty alpha level. You made it clear that it isn't done yet. And I *DID* figure it out. I am just glad you wrote something that solves my problem and works well. Thanks! > I will soon upload FoxTails 0.2, which is 1.8-friendly > and has a tree browser widget. Maybe I'll have some > time to document better... That will be great, although, at this point its really Observable that I am most working with at the moment. Once I get the current stuff working I may use Foxtails more. BTW any idea when you will release it? > (The tree browser is like the other FoxTails widgets > in that it allows multiple views and automatically > syncs between model and view.) Sounds great > In the meantime, pls. feel free to ask questions, > either here or to me directly. If I could figure out what the questions are I'll ask them ;^) As for documentation, I have some suggestions. The part I had the most trouble with (still do for that matter) is figuring out how to work observable things in other objects like windows. For example, if a value in that window over there changes how do I find out about it and react to it over here in this window. Specfically, how do I write a when_var for a different object. None of the examples seemed to cover this case. To work it out I wrote a little test program that I will include below. Some better documentation in this area would help a lot. ===================== begin include ============================ #!/usr/bin/env ruby require 'foxtails' include Fox include FoxTails class OutputWindow < FXMainWindow observable :mydata def initialize(app, projName) createWindow(app, projName) end def createWindow(app, projName) @app = app @outputdlg = FXDialogBox.new(app, projName, DECOR_ALL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0) outputText = FTTextField.new(@outputdlg, 20, self, :mydata) outputText.dynamic = true end def create @outputdlg.create @outputdlg.position(200, 30, 150, 20) @outputdlg.show(PLACEMENT_DEFAULT) end end class TestWindow < FXMainWindow observable :outp, :locdata def initialize(*args) super inputText = FTTextField.new(self, 20, self, :locdata) inputText.dynamic = true outputText = FTTextField.new(self, 20, self, :locdata) outputText.dynamic = true end def create super position(0, 30, 150, 60) show(PLACEMENT_DEFAULT) @outp = OutputWindow.new(self, "Output") @outp.create @outp.when_mydata CHANGES do self.locdata = @outp.mydata end when_locdata CHANGES do @outp.mydata = @locdata end end end class TestApp < FTApp def initialize super("Test", "TEST") TestWindow.new(self, "Test") end end TestApp.new.run ====================== end include ============================= |
From: Joel V. <vj...@PA...> - 2003-11-29 01:40:43
|
Will Merrell wrote: >>I will soon upload FoxTails 0.2, which is 1.8-friendly >>and has a tree browser widget. Maybe I'll have some >>time to document better... > > > That will be great, although, at this point its really Observable that I am > most working with at the moment. Once I get the current stuff working I may > use Foxtails more. > > BTW any idea when you will release it? Later today, along with an update of Observable. You make a good point about having an example with action at a distance. I'll put in something like that. Also, to take that to the extreme, I've written an example which distributes the observer relationship over a DRb connection. (This is why I had to update the Observable package). It makes writing distributed GUIs a snap, at least in simple cases. |