shoes / shoes3

a tiny graphical app kit for ruby
http://walkabout.mvmanila.com
Other
181 stars 19 forks source link

target image in image ? #248

Closed dredknight closed 8 years ago

dredknight commented 8 years ago

Alright everybody I am getting the hang out Shoes better and better every day :) Unfortunately I stumbled upon something... actually it is very stupid I just dont know how to approach it.

I got an image and when I click it I want to change that image, it is very simple here is an example.

@BUTTON=image "pics/buttons/normal.png", left: left, top: top do
            unless CONDITION then
                @BUTTON.path = "pics/buttons/pushed.png"
                timer(0.1) {@BUTTON.path = "pics/buttons/normal.png" }      
            end
        end

But I want many visually dynamic buttons so I put the code in a module. Then I do

@BUTTON=module var1, var2....

the module itself is this

def set_button var1, var2, var3
    image "pics/buttons/normal.png", left: left, top: top do
        unless CONDITION then
            path = "pics/buttons/pushed.png"
            timer(0.1) { path = "pics/buttons/normal.png" }     
        end
    end
end

My question is how to change the PATH of the image from the inside when the image is not assigned to any variable?

ccoupe commented 8 years ago

I'm not that skilled about this so I could be wrong, but I think Shoes.widget class is there for creating your own widget (image acting as /button in this case). Subclass it and add methods/vars for what ever state variables you need for your buttons that you need to call from the main Shoes app.

IanTrudel commented 8 years ago

Nooooo. Create a stack with an image inside, make sure you save the image object in a @variable also, and add a click event on the stack that will replace the image using its variable.

ccoupe commented 8 years ago

Or what @BackOrder said! Nice to hear from you.

ccoupe commented 8 years ago

You might want to explore sub-classing image. It might work if you just want to add a 'path' variable. Overriding draw() and initialize() could be a problem. Or not.

IanTrudel commented 8 years ago

Or what @BackOrder said! Nice to hear from you.

Still so busy but I'm following the issue tracker.

You might want to explore sub-classing image. It might work if you just want to add a 'path' variable. Overriding draw() and initialize() could be a problem. Or not.

It's just too complicated for absolutely no reason. In Numinoes, I preload all images, define a click event on stacks, flip through images in an array.

ccoupe commented 8 years ago

If I remember correctly, @dredknight's app draws his image buttons in a circle and he implements tool-tip like enter/leave for each of them so he's already well past the boundaries of 'simple' and into the edges of what Shoes can do. I don't go there myself.

It's just too complicated for absolutely no reason

My personal preference is to find a simple way with the least eye-candy. But, if someone want the most eye-candy (and pain) we should help them if we can.

dredknight commented 8 years ago

My personal preference is to find a simple way with the least eye-candy. But, if someone want the most eye-candy (and pain) we should help them if we can.

Thanks a lot for the support I will check the advices you all gave me and let you know where the muse hit me!

dredknight commented 8 years ago

Alright I got something like this.

def set_button_up button, klas, hero
        if hero<CLASSES[klas]["heroes"].length-1 then
            hero+=1
            @hero_box.clear { image "pics/heroes/#{CLASSES["#{klas}"]["heroes"][hero]}.png", width: 60 } 
            button.path = "pics/buttons/pushed.png"
            set_skillwheel klas, hero
            timer(0.1) { button.path = "pics/buttons/normal.png" }  
        end
    end

@right_button = image "pics/buttons/normal.png", left: 385, top: 327 
        @right_button.click do
            set_button_up @right_button, @ch_class, @ch_hero
        end

But I stumbled on a wierd issue. as you can see I pass a variable called @ch_hero that I increase with each click. Unfortunately when it is increased inside the module (hero var) it is not saved in the oringal var (@ch_hero). Is there anyway I can returnthe change from hero to @ch_hero or I better do this outside the module?

dredknight commented 8 years ago
def set_button_down button, klas, hero
        unless hero==0 then 
            hero-=1 
            @hero_box.clear { image "pics/heroes/#{CLASSES[klas]["heroes"][hero]}.png", width: 60 } 
            button.path = "pics/buttons/pushed.png"
            set_skillwheel klas, hero
            timer(0.1) { button.path = "pics/buttons/normal.png" }
        end
        return hero
    end

@left_button.click do
            @ch_hero=set_button_down @left_button, @ch_class, @ch_hero
end

Done!

P.S. Unfortunately those image changes inside does not work as button.path does not transfer the change to @left_button but I will live with that ;)