MMCC MASTHEAD
Mid-Michigan Computer Consultants - Bay City, Michigan
 


CONTENTS       (old style)
Mid-Michigan Computer Consultants
509 Center
Bay City, Michigan

Sales (989) 892-9242
Support (989) 686-8860

Plb-0220.cfm v1.0


plb-t010.cfm
 

ANSI Standard PL/B Language and Visual PL/B

PL/B GUI Colors

NOTE TO OUR READERS
This web resource is written for our own use. But we feel strongly that the PL/B language should be shared with the software community. So feel free to use this at will! BUT PLEASE... if you find errors or omissions or have a better way to do something. TELL US! Dialog helps us all. Send e-mail to: support@mmcctech.com



INTRODUCTION

Gotta flesh this topic out at some time! In the meantime:

The basic instructions are:
MY_COLOR    COLOR
YOUR_COLOR  COLOR
WORK_COLOR  COLOR

            CREATE  MY_COLOR={*colordef}           ;basic colors are in language
            CREATE  MY_COLOR={red}:{green}:{blue}  ;use decimal numbers
            CREATE  MY_COLOR={another color object}

            CREATE  MY_COLOR=*BLUE
            CREATE  MY_COLOR=255:244:197
            CREATE  YOUR_COLOR=MY_COLOR

            GETPROP Any_EditText,      BGCOLOR=WORK_COLOR      ;transfer color
            SETPROP Another_EditText,  BGCOLOR=WORK_COLOR      ;from one obj to another
			
.    To set list view row colors you need to use the hex value string
.    which can be a string variable or a literal:
HEX_COLOR   DIM    8
            PACK  HEX_COLOR, "0x", HEX_RED,  HEX_GREEN,  HEX_BLUE
            ListView001.SetItemText USING {row index}, HEX_COLOR,  {color column}
                 ---- or as a literal ----
            ListView001.SetItemText USING {row index}, "0xCFA5F1", {color column}


HEX CONVERSION

If you have HEX RGB color codes (FFC4F5) you need to split that and convert it to decimal before use. MMCC has a hex conversion routine in the MMCCSERV include routine. This does one number hex 00 to FF or decimal 0 to 255.
      CALL  HEX_TO_DECIMAL USING "F5", DECIMAL_RETURN     (form 3)
.... inverse:
      CALL  DECIMAL_TO_HEX USING "254",HEX_RETURN         (dim 2)
MMCC Staff: See ZZCOLORS test program in UTIL-PLB.
See COLORGET.PLS in SUNDB and FR-88020 in Freddy Mobile.


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.





v2.10 6/8/2016

Write to MMCC Technical Support at:               Send
e-mail to MMCC.
MMCC - Technical Support
600 W. Midland
Bay City, MI 48708
(989) 686-8860
© 1997 - 2024 MMCC - All Rights Reserved