LB Booster
Programming >> Liberty BASIC language >> #handle "rule "
http://lbb.conforums.com/index.cgi?board=lblang&action=display&num=1437424861

#handle "rule "
Post by Monkfish on Jul 20th, 2015, 8:41pm

I can't seem to find a sequence of rules that do what I want to do.

Imagine a box with black characters on a white background.

I want to draw a filled box on top so the background changes to another colour but the text remains black.

(This I have achieved simply by using MASKPEN with the new background colour)

I also want to be able to reverse this action; i.e. draw a filled box on top so the background changes back to white but the characters remain black, but I just can't seem to find a solution.
Re: #handle "rule "
Post by Richard Russell on Jul 20th, 2015, 9:03pm

on Jul 20th, 2015, 8:41pm, Monkfish wrote:
the background changes back to white but the characters remain black, but I just can't seem to find a solution.

It's impossible with a simple logical operation. If you want to change any background colour to white then - since black is itself a colour - that will inevitably change to white too!

If you literally want to 'reverse' the previous operation, then use flush to save the original state and redraw to restore it:

Code:
    button #w, "change background color", [change], LL, 50, 30
    button #w, "restore background color", [restore], LL, 46, 0
    open "Test" for graphics_nsb as #w
    #w "font Arial 18 bold"
    #w "\\\\\     Some text in black"
    wait

[change]
    #w "flush; backcolor yellow; down; rule "; _R2_MASKPEN
    #w "place 0 0; boxfilled ";WindowWidth;" ";WindowHeight
    wait

[restore]
    #w "redraw"
    wait 

Richard.
Re: #handle "rule "
Post by Monkfish on Jul 20th, 2015, 9:25pm

If users are changing the colour of different boxes and want to change them back out of order, can I achieve this by assigning each a segment name?
Re: #handle "rule "
Post by Richard Russell on Jul 20th, 2015, 9:57pm

on Jul 20th, 2015, 9:25pm, Monkfish wrote:
If users are changing the colour of different boxes and want to change them back out of order, can I achieve this by assigning each a segment name?

LBB doesn't support segments, so that's not relevant. But graphicboxes are independent so the flush/redraw method can be used to restore the background colour to the previously saved state for that box in any order.

If you need to save more than one state for a given graphicbox (which you shouldn't if you simply want to restore the previous condition), then use getbmp and drawbmp instead of flush and redraw.

Richard.
Re: #handle "rule "
Post by Monkfish on Jul 20th, 2015, 10:04pm

Thanks Richard, I will look into it. btw I made a donation the other day, but still seeing the ads. not sure how that works.
Re: #handle "rule "
Post by Richard Russell on Jul 20th, 2015, 10:21pm

on Jul 20th, 2015, 10:04pm, Monkfish wrote:
I made a donation the other day, but still seeing the ads. not sure how that works.

Conforums works by calendar months, so it's wasteful to use a donation only for the last twelve days or so of July. Yours will result in the forum being ad-free in August.

Can I encourage others to donate too, if they are so inclined.

Richard.