1. Window Color Value

Hi All,

I have another unique problem. I am trying to have a window get=
 the 
color value out of a EditText, and use the information it=
 receives to 
change the color of the window. But for some reason it does not=
 work. 
The window changes to a dark brown color. Does anyone know how I=
 can 
accomplish this? Example code below:

include Win32Lib.ew
without warning
-----

constant

Win =3D create( Window, "", 0, Default, Default, 127, 140, 0 ),
ColorValue =3D create( EditText, "", Win, 4, 8, 112, 20, 0 ),
ChangeColor =3D create( PushButton, "Change Color", Win, 16, 84, 
88,24,0 )
-----

----Change Color

procedure onClick_ChangeColor()
 object Colors

Colors =3D getText(ColorValue)

 if length(Colors)=3D0
  then
 setWindowBackColor(Win, 8404992 )
   else
 setWindowBackColor(Win, getText(ColorValue) )
  end if

 end procedure

onClick[ChangeColor] =3D routine_id("onClick_ChangeColor")
-----

WinMain( Win, Normal )




Thank You,
Chris

new topic     » topic index » view message » categorize

2. Re: Window Color Value

On Monday 25 June 2001 09:21, president at insight-concepts.com wrote:

> include Win32Lib.ew
> without warning
> -----
>
> constant
>
> Win = create( Window, "", 0, Default, Default, 127, 140, 0 ),
> ColorValue = create( EditText, "", Win, 4, 8, 112, 20, 0 ),
> ChangeColor = create( PushButton, "Change Color", Win, 16, 84,
> 88,24,0 )
> -----
>
> ----Change Color
>
> procedure onClick_ChangeColor()
>  object Colors
>
> Colors = getText(ColorValue) <== 
  
Don't you think you should use getNumber here? 
Or, if you're entering the color by name "LightBlue", 
then maybe you could use getText, and then lookup the 
color value from a table.

Regards,
Irv

new topic     » goto parent     » topic index » view message » categorize

3. Re: Window Color Value

Hello Chris,

I'm assuming you want to type in a color in the form: #RRGGBB or equivalent. 
Well, "setWindowBackColor()" seems to want it in #BBGGRR format instead. I 
don't know why. Maybe it's a bug. If this is Okay with you, here is the code 
that will do the trick.


constant
Win =        create( Window,      "",      0,   99, 99, 127, 140, 0 ),
ColorValue = create( EditText,    "",      Win,  4,  8, 112,  20, 0 ),
ChangeColor = create(PushButton,  "Color", Win, 16, 84,  88,  24, 0 )

----Change Color
procedure onClick_ChangeColor()
  setWindowBackColor(Win, getNumber(ColorValue) )
end procedure
onClick[ChangeColor] = routine_id("onClick_ChangeColor")

-----Start
WinMain( Win, Normal )

If you don't like the BGR format you will have to programatically massage 
your input into that format. Or else get Derek to change it. Is it a bug 
Derek, David?

later,
Lewis Townsend

new topic     » goto parent     » topic index » view message » categorize

4. Re: Window Color Value

> ------- Start of forwarded message -------
> From: Lewis Townsend <keroltarr at HOTMAIL.COM>
> To: EUforum <EUforum at topica.com>
> Reply-To: EUforum at topica.com
> Subject: Re: Window Color Value
> Date: 26/06/2001 11:19:27 AM
> 
> 
> Hello Chris,
> 
> I'm assuming you want to type in a color in the form: #RRGGBB 
> or equivalent. 
> Well, "setWindowBackColor()" seems to want it in #BBGGRR 
> format instead. I 
> don't know why. Maybe it's a bug. If this is Okay with you, 
> here is the code 
> that will do the trick.
> 
> 
> constant
> Win =        create( Window,      "",      0,   99, 99, 127, 140, 0 ),
> ColorValue = create( EditText,    "",      Win,  4,  8, 112,  20, 0 ),
> ChangeColor = create(PushButton,  "Color", Win, 16, 84,  88,  24, 0 )
> 
> ----Change Color
> procedure onClick_ChangeColor()
>   setWindowBackColor(Win, getNumber(ColorValue) )
> end procedure
> onClick[ChangeColor] = routine_id("onClick_ChangeColor")
> 
> -----Start
> WinMain( Win, Normal )
> 
> If you don't like the BGR format you will have to 
> programatically massage 
> your input into that format. Or else get Derek to change it. 
> Is it a bug 
> Derek, David?

Hi Lewis and Chris,
this is not a true bug. It's an artifact of the Intel chip design.

The problem is this:
  Color is used as a 3-byte array of intensities; byte 1 is Red, byte 2 is
Green, and byte 3 is Blue. As these are bytes, they have a value range of 0
to 255 each.

However, the Euphoria object written as #RRGGBB is a 24-bit number, and not
a 3-byte array. The difference is that Intel machines store numbers in
reverse byte sequence. Thus in Euphoria you might write #C0F044, this is
stored in memory as (a 32-bit value) four ascending byte locations with #44,
#F0, #C0, #00. Motorola chips (68000 series in Macs) store the same number
in the opposite sequence. Anyhow, when the Windows software is passed the
color value, it treats it as a 3-byte array rather than a 24-bit number.

To get around this effect, you either have to write the Euphoria color
number as #BBGGRR or use the rgb() function to convert 3 intensities to a
single color number.

If you must convert a Euphoria 24-bit number into a 3-byte color array you
could use this...

  ----------------------
  include machine.e
  function convRGB(integer pColorNumber)
    integer r,g,b

    r = and_bits(pColorNumber, #FF0000) / 256 / 256
    g = and_bits(pColorNumber, #FF00) / 256
    b = and_bits(pColorNumber, #FF)
    return rgb(r, g, b ) 

  end function
  --------------------

setWindowBackColor(Win, convRGB(getNumber(ColorValue)) )

---------------

cheers,
Derek Parnell
Senior Design Engineer
Global Technology Australasia Ltd
dparnell at glotec.com.au


confidential information intended solely for the use of the individual or
entity to whom they are addressed. If you are not the intended recipient of
this message you are hereby notified that any use, dissemination,
distribution or reproduction of this message is prohibited. If you have
received this message in error please notify the sender immediately. Any
views expressed in this message are those of the individual sender and may
not necessarily reflect the views of Global Technology Australasia Limited.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu