Vruby - passing arguments?


(Armin Roehrl) #1

Hi all,

suppose I have my own class MyOwnderDrawButton to draw
a red, green, blue, etc. button (see code below).

Can I pass an argument when I call addControl to specify
the color? Code below.

It sounds so simple …

Thank you,
Mr. your daily Vruby question.
P.S.: When I have finished my current Vruby project, I will
write a short online doc on the few things I have learnt :-).

···

#--------------------------------------

require 'vr/vruby’
require 'vr/vrcontrol’
require ‘vr/vrhandler’ # (only using- vr/contrib/vrctlcolor)
require 'vr/vrowndraw.rb’
require ‘Win32API’

class MyOwnerDrawButton < VROwnerDrawButton

DrawFrameControl=Win32API.new(“user32”,“DrawFrameControl”,[“L”,“P”,“I”,“I”],“I”)

def drawpushed(left,top,right,bottom,state)
rect=[left,top,right,bottom].pack(“iiii”)
DrawFrameControl.call(hdc,rect,4,0x210)
c = RGB(0xff,0,0)
setPen c
setBrush c
fillRect(4,4,12,12)
end

def drawreleased(left,top,right,bottom,state)
rect=[left,top,right,bottom].pack(“iiii”)
DrawFrameControl.call(hdc,rect,4,0x10)
c = RGB(0,0,0xff)
setPen c
setBrush c
fillRect(1,1,98,48)
end

end

class ARForm < VRForm
include VRCtlColor

def construct
addControl(VRButton, ‘lab1’, “ta”, 100,90,200,100)
addControl(MyOwnerDrawButton,“test”,“OK”,10,10,100,50)
end
end

VRLocalScreen.showForm(ARForm, 0, 0, 400, 400)
VRLocalScreen.messageloop
#----------------------------



(Armin Roehrl) #2

I got that most useful answer below from Steve Tuckner.
I want to share it with all of you, so that it will show up
in the archives of the mailinglist.

···

Armin,

I tried to post this to the list but failed (it never appeared – twice). So
here goes:

As far as I know, there is no way to do this with any VRuby object. In my
project I adopted the convention of using exinit as my initializer. So for
example, to create a yellow button, I might call with the following code:

addControl(VRColoredButton, ‘lab1’, “ta”, 100,90,200,100).exinit(YELLOW)

class VRColoredButton < VRButton
def self_created
# called that the button is created
end

def exinit(color)
    # set the color here
end

end

I need to release my VRTools kit that has some enhancements when working
with vruby.

Steve Tuckner