USER GETTING A COLOR TO BE SAVED
Freddy Mobile allows users to select colors for various displays. The user clicks a button and is presented with the standard color selection box. The image at right shows part of that screen. The edit text to the right is the current color.
To get the color selection panel, you create a color object without any parameters. Once the color is defined you can get the properties from that color object to see what was chosen.
If the user CANCEL's the color box, the object is not created. You have to trap an object error to detect that condition.
The example code below can be used to get a color as done in FM-88020. This uses the
GET_COLOR_DEF routine found in the standard MMCC
COLORGET.PLS include routine found in SUNDB. That routine will get the color properties from any object and format it in a variety of ways that can be used for other things.
If the color is to be saved as a configuration setting, the HEX or DECIMAL values are useful. Setting ListView colors, for example, requires that you use the HEX values. Other color objects can be set with the decicmal values.
We use the routine below to get the user's color selection. The decimal and hex color codes are saved in the XC file and can be used as needed. Decimal values are used for creating colors, the HEX values are used for list views.
...................................
. Sample of getting a color to be stored
. as done in FM-88020
.
CUSTOM_COLOR COLOR
.
COLOR_RED FORM 3
COLOR_GREEN FORM 3
COLOR_BLUE FORM 3
.
HEX_RED DIM 2
HEX_GREEN DIM 2
HEX_BLUE DIM 2
.
COLOR_24BITS FORM 12
COLOR_TYPE DIM 1
INTEGER_4 INTEGER 4
.
get_color_value
MOVE NO, OBJNIF
TRAP OBJECT_ERROR IF OBJECT
CREATE CUSTOM_COLOR
TRAPCLR OBJECT
IF (OBJNIF != NO)
RETURN
ENDIF
.
CALL GET_COLOR_DEF USING CUSTOM_COLOR:
COLOR_RED, COLOR_GREEN, COLOR_BLUE:
HEX_RED, HEX_GREEN, HEX_BLUE:
COLOR_24BITS:
COLOR_TYPE:
INTEGER_4
IF (COLOR_TYPE = "W")
SETPROP EditText_Sample, BTCOLOR=INTEGER_4
DISPLAY "Windows index color:",COLOR_24BITS
ELSE
SETPROP EditText_Sample, BGCOLOR=CUSTOM_COL
DISPLAY "Hex:",HEX_RED,":",HEX_GREEN,":",HEX_BLUE
ENDIF
.
. save the COLOR_xxx and the HEX_xxx values in the
. programs options in the XC file.
.
RETURN
.
INCLUDE Z:COLORGET ;get_color_def
Here's a way to use the designer to get colors.
ListView colors must be coded as a hex string in the form
"0xF17CF0". There's no direct way to get this string other than defining it as a literal or using a technique like the one described in the section above. It would be nice to just get a color at run-time from an object on screen and ust that. Unfortunately you can't use the color directly. It would be nice to just
GETPROP BGCOLOR and use that color.
Sorry... Won't work.
But you can get an object's color components at run-time and use them to build that hex string.
The technique is to:
Get the color components for the object in question as decimal numbers.
Convert each decimal number to a hex.
Build a STRING that the ListView will accept.
Here's our routine, which uses MMCC's standard
DECIMAL_TO_HEX utility routine:
MAKE A HEX STRING FROM AN OBJECTS COLORS:
WORK_COLOR COLOR ;color object
WORK_RED FORM 3
WORK_GREEN FORM 3
WORK_BLUE FORM 3
HEX_COLOR DIM 8
HEX_RETURN DIM 2
GETPROP ET_Sample, BGCOLOR=WORK_COLOR ;Get color from form.
GETPROP WORK_COLOR, 1, WORK_RED ;Split out the components
GETPROP WORK_COLOR, 2, WORK_GREEN
GETPROP WORK_COLOR, 3, COLOR_BLUE
PACK HEX_COLOR, "0x" ;Initialize color string
CALL DECIMAL_TO_HEX, WORK_RED, HEX_RETURN
PACK HEX_COLOR, HEX_COLOR, HEX_RETURN
CALL DECIMAL_TO_HEX, WORK_GREEN, HEX_RETURN
PACK HEX_COLOR, HEX_COLOR, HEX_RETURN
CALL DECIMAL_TO_HEX, WORK_BLUE, HEX_RETURN
PACK HEX_COLOR, HEX_COLOR, HEX_RETURN
The result is that
HEX_COLOR comes out something like
"0xF175C1"
The idea for this ccame from a Sunbelt Forum posting from John Shrimski 2/6/2004.
John's original posting was:
Ive been playing around with color objects recently (using plbwin 8.6c),
and I think I've found an error with the blue component when setting an
RGB color ...... for example
rgb integer 4
red form 3
green form 3
blue form 3
c color
create c=*white
getitem c,1,red (red=255)
getitem c,2,green (green = 255)
getitem c,3,blue (blue = 255)
getitem c,0,rgb (rgb = 0xFFFFFF00)
.... all the above works fine
SETitem c,0,rgb
getitem c,1,red (red = 255)
getitem c,2,green (green = 255)
getitem c,3,blue (blue = 0 )
getitem c,0,rgb (rgb = 0xFFFF0000)
i.e., the blue component has been lost. The work around is to always use a
CREATE on a color object
Is this a bug, or have I missed something?
John Shrimski,
Setting color properties
(And another way to use the designer to get colors)
There are a variety of ways to set colors. This example is for the Screen Background Color.
SETPROP F1_Window, BGCOLOR=COLOR_ID(6) ; Using standard color from COLOR_WIN.pls
SETPROP F1_Window, BGCOLOR=$BTNFACE ; As defined in PLBEQU.inc
SETPROP F1_Window, BGCOLOR=0x0000FF00 ; GREEN from the designer's BackColor
SETPROP F1_Window, BGCOLOR=0x8000000F ; windows gray from the designer's BackColor
Note that HEX colors starting with 0x80 tell windows to use it's standard color for various things.
Take a look at the PLBEQU.ini comments around $BTNFACE to see how that works.