Re: [Fxruby-users] FXSegment question
Status: Inactive
Brought to you by:
lyle
From: Joel V. <vj...@PA...> - 2003-08-29 14:02:22
|
Fredrik Jagenheim wrote: > Hi, > > I'm going to draw an object which consists of three separate lines. > > I thought of doing it like this: > > (In initialize:) > @segments = [] > @segments << FXSegment.new(x11, y11, x21, y21) > @segments << FXSegment.new(x12, y12, x22, y22) > @segments << FXSegment.new(x13, y13, x23, y23) > (In draw:) > gc.drawLineSegments(@segments) > > I'm saving the segments list so I don't have to setup all the lines > all the time (let's say they're hard to calculate). > > This doesn't work, as FXSegments.new doesn't take arguments, so I'd > probably have to do it like this: > > segment = FXSegment.new > segment.x1 = x11 > [...] > @segments << segment > segment = FXSegment.new > [...] > > But then I'd probably rewrite the earlier segment, so I have to: > > segment1 = FXSegment.new > segment1.x1 = x11 > [...] > segments << segment1 > segment2 = FXSegment.new > [...] > > Which ends up quite verbose... > > Does anyone have a better solution to this? > > I thought of downloading the FXRuby source and patch FXSegment.new > myself, but figured there probably was a better solution I couldn't > see... No need to patch, with ruby :) You could redefine FXSegment.new, or do something like: class FXSegment # or put this in your own class or module def make_segment(x1,y1,x2,y2) seg = FXSegment.new seg.x1 = x11 # etc. return seg end end |