Thread: [Fxruby-users] subclassing FXColor
Status: Inactive
Brought to you by:
lyle
From: meinrad r. <mei...@gm...> - 2004-01-31 12:22:47
|
dear lyle, id like to subclass FXColor to add some more functionality. like this: class Color < Fox::FXColor def initialize r, g, b end end but i don't know how to subclass Bignum (that is what FXRGB returns ...) how could i do this to integrate with fxruby? cheers - mr |
From: Lyle J. <ly...@kn...> - 2004-01-31 15:07:57
|
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Jan 30, 2004, at 5:29 PM, meinrad recheis wrote: > id like to subclass FXColor to add some more functionality. like this: > > class Color < Fox::FXColor > def initialize r, g, b > end > end > > but i don't know how to subclass Bignum (that is what FXRGB returns > ...) > how could i do this to integrate with fxruby? Fox::FXColor should really be a Ruby module and not a class; you can't create instances of it and use them in any meaningful way. And as you already noted, we already have a way to construct color values from the red, green and blue (and optionally alpha) components, e.g. color = Fox.FXRGB(r, g, b) or color_with_some_alpha = Fox.FXRGBA(r, g, b, a) It's not clear what advantage a full-blown FXColor class would offer. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (Darwin) iD8DBQFAG8S2FXV/hD6oMd0RAk8PAJ4oeFiVMEqLxK2TS/Cl5aspqMyBkQCffDQs 6LS+dXpYVkI7LzeluNxjaxU= =sL3l -----END PGP SIGNATURE----- |
From: meinrad r. <mei...@gm...> - 2004-01-31 16:07:51
|
Lyle Johnson wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > > On Jan 30, 2004, at 5:29 PM, meinrad recheis wrote: > >> id like to subclass FXColor to add some more functionality. like this: >> >> class Color < Fox::FXColor >> def initialize r, g, b >> end >> end >> >> but i don't know how to subclass Bignum (that is what FXRGB returns ...) >> how could i do this to integrate with fxruby? > > > Fox::FXColor should really be a Ruby module and not a class; you can't > create instances of it and use them in any meaningful way. And as you > already noted, we already have a way to construct color values from the > red, green and blue (and optionally alpha) components, e.g. > > color = Fox.FXRGB(r, g, b) > > or > > color_with_some_alpha = Fox.FXRGBA(r, g, b, a) > > It's not clear what advantage a full-blown FXColor class would offer. [...] it is the OO-paradigma that gives many advantages by encapsulating data (the color value) and methods that operate on that data (FXRGB, FXREDVALUE, etc ...) in an object! i now see that FXRuby expects bignum where FXColor is stated, so the question is how to subclass bignum (and that does not belong to this list). thanks anyways, meinrad |
From: Lyle J. <ly...@kn...> - 2004-02-04 04:04:32
|
On Jan 30, 2004, at 11:06 PM, meinrad recheis wrote: > #color object (united fox functions) > class Color > attr_accessor :r, :g, :b, :a > #construct by red, green, blue and (optionally) alpha value > def initialize r=0, g=0, b=0, a=nil > @r,@g,@b,@a=r,g,b,a > end <snip> I have added this as a change request on the list at SourceForge: https://sourceforge.net/tracker/index.php? func=detail&aid=890161&group_id=20243&atid=370243 I could change things so that methods that currently expect an Integer for a FOX color value will accept either an Integer *or* an FXColor instance, e.g. widget.textColor = Fox.FXRGB(255, 0, 0) and: widget.textColor = Fox::FXColor.new(255, 0, 0) are equivalent. One concern, however, is how to handle return values for methods that currently return colors as Integers. That is, I think to preserve back-compatibility those methods would need to continue to return color values as integers. Any thoughts? Lyle |
From: Martin H. <ma...@zs...> - 2004-02-04 10:42:24
|
On Wednesday 04 February 2004 04:04, Lyle Johnson wrote: > .... One concern, however, is how to handle return values > for methods that currently return colors as Integers. That is, I think > to preserve back-compatibility those methods would need to continue to > return color values as integers. Any thoughts? > Two that I can think of - one is to provide an alternative method=20 (xxx_as_color) that returns a colour object rather than an integer, or th= e=20 other is to add to_color to the Integer class which returns an instance o= f=20 itself as a colour object? I don't find either very attractive but they would offer both integer and= =20 colour retrieval. Another is maybe to allow a class/global setter -=20 Fox.returnColorsAsObject=3D(boolean) and maybe use that to determine what= to=20 return from each FXRuby function?=20 Although probably more work from a development point of view, I actually=20 prefer this approach because it does not clutter the rest of the API, nor= =20 interfere with the Integer class... Cheers, Martin |