Colour Change 
Author Message
 Colour Change

--- I had posted this on comp.lang.pop
--- I don't think it got through to pop-forum
--- Hopefully someone can help...

Hi,

I have a sim_movable_agent which I would like to change the colour and
label (the string in rc_pic_strings) of at runtime.  The slots
rc_pic_lines and rc_pic_strings contain this information, I have written
a procedure which changes these variables to change the colour and the
label. The problem is when I change the colour or label it leaves the a
'residue' of the old colour/label on the background. I've been looking
for a standard procedure which updates these variables but can't find
one. I don't want to redraw the whole background is there another way of
preventing the residue?

The following code is a simple example of my problem, If you try and drag
the testpic with the mouse it leaves a red square at the original
location. (or it leaves a red square where the colour was changed).

;;;----------------Code starts here ------------------
uses rclib;
uses simlib;
uses sim_picagent;

;;; The class is taken from the example in sim_picagent
define :class testpic;
    is sim_movable;
    slot rc_mouse_limit = 10;
enddefine;

define newpic(x, y, label, color, w,windows) -> pic;
    instance testpic;
        sim_x = x;
        sim_y = y;
        rc_pic_lines =[COLOUR ^color WIDTH ^w SQUARE {0 0 1}];
        rc_pic_strings = [{-4 0 ^label}];
    endinstance -> pic;
    rc_add_containers(pic, windows);
enddefine;

;;;Create the window
vars
    win1 = rc_new_window_object(20, 5, 250, 250, true,'win1',newsim_picagent_window),
    windows = [^win1],
;

;;; Create the testpic instance
vars
    p1 = newpic(50, 50, 'p1', 'blue' , 50, windows),
;

;;; Change the colour of the instance p1
[COLOUR 'green' WIDTH 50 SQUARE {0 0 1}]->rc_pic_lines(p1);

;;; Change the label
 [{-4 0 'P2'}]->rc_pic_strings(p1);

;;;---------Code ends here------------------

Is it possible to change the colour/label without changing the background?

Thanks

Mike



Sat, 10 Jul 2004 00:36:42 GMT  
 Colour Change

Quote:
> --- I had posted this on comp.lang.pop
> --- I don't think it got through to pop-forum

I saw it but have been rushing around doing too many things. Otherwise
I'd have responded sooner. Sorry.

Actually having your code makes it clearer what you want to do:

Quote:
> I have a sim_movable_agent which I would like to change the colour and
> label (the string in rc_pic_strings) of at runtime.  The slots
> rc_pic_lines and rc_pic_strings contain this information, I have written
> a procedure which changes these variables to change the colour and the
> label. The problem is when I change the colour or label it leaves the a
> 'residue' of the old colour/label on the background.

You have to undraw the old one before changing the label and drawing
the new one.

If you look at HELP rclib and search for

        rc_change_picture(pic:rc_linepic_movable, newx, newy, newlines, newstrings);

you will find a method which, I think, does what you want.

You may wish to copy the definition and edit it to make a specific one
for instances of sim_movable, though you don't need to if that does what
you want.

Another option is to use the fact that the RCLIB package allows the
filler of the slot rc_pic_lines or rc_pic_strings to be a procedure (or
a word which is the name of a procedure or method, to help with run-time
debugging).

Then you can make your rc_pic_strings drawing method look at some other
slot in the instance to see what string or what colour to use, and just
draw it. But it will have to undraw first if anything has changed
since the last time it was drawn.

Then any procedure or method can change the latter slot at any time, and
the next time the instance is moved or rotated the new string and or
colour will be used.

But it may be simpler, though possibly less elegant, to use a method
like rc_change_picture, which does what you want.

To see its definition, if you wish to copy and edit it, do
        showlib rc_change_picture

( It should be in $poplocal/local/rclib/auto/rc_change_picture.p )

I hope that helps.

It's important that the sim_movable stuff in LIB sim_picagent, inherits
lots of stuff from the RCLIB package.

(Thanks to objectclass and its multiple-inheritance facilities.)

Aaron



Sat, 10 Jul 2004 00:56:50 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Scrollbar Color or Colour Change in Clarion

2. font colour change in tcl shell

3. :Tk3.6 text colour change

4. VW2 Changing Background Colour

5. AbtHtmlTableColumn: change colour of heading?

6. Changing colour of fields on reports.

7. How to Change Title Bar colour?

8. get indicator to change colour

9. Changing TextGadgets colour

10. changing background colour of an rc_graphic window

11. changing colour

12. NEWBIE: changing the colour of points

 

 
Powered by phpBB® Forum Software