/* gradient.i ========== Copyright(c) 4GL & M. FONDACCI 1998-1999-2000 m.fondacci@4gl.fr input parameters : &FRAME default = frame {&frame-name} &COLOR = BLUE,RED,YELLOW,GRAY,GREEN,ORANGE (default = BLUE) (var name or use "'BLUE'" notation) gradient control m.fondacci@4gl.fr ----------------------------------------------------------------- Permission granted to use and modify this library so long as the copyright above is maintained, modifications are documented, and credit is given for any use of the library. For more information, see: http://www.4gl.fr ----------------------------------------------------------------- The easiest way to use is: {gradient.i} but you can use {gradient.i &Color = "'PURPLE'"} or {gradient.i &Color = } or {gradient.i &FRAME = "FRAME myOwnFrame"} Place this before enable-ui or in local-initialize (V8 ADM1) or in initializeObject (V9 ADM2) */ &IF DEFINED(GRADIENT) = 0 &THEN DEF VAR I-Color AS INT NO-UNDO. DEF VAR h_BackGround AS HANDLE NO-UNDO. DEF VAR h_Group AS HANDLE NO-UNDO. DEF VAR h_Field AS HANDLE NO-UNDO. DEF VAR Height_Rectangle_Pixels AS INT NO-UNDO. DEF VAR Height_Frame AS INT NO-UNDO. DEF VAR N_Rectangles AS INT NO-UNDO. DEF VAR Red-Value AS INT NO-UNDO. DEF VAR Green-Value AS INT NO-UNDO. DEF VAR Blue-Value AS INT NO-UNDO INITIAL 10. DEF VAR AddRed AS INT NO-UNDO. DEF VAR AddGreen AS INT NO-UNDO. DEF VAR AddBlue AS INT NO-UNDO INITIAL 4. DEF VAR GapColor AS INT NO-UNDO INITIAL 4. &GLOBAL GRADIENT OK &ENDIF &IF "{&FRAME}" = "" &THEN &SCOP &FRAME {&FRAME-NAME} &ENDIF /* all is in the background container */ h_BackGround = {&FRAME}:BACKGROUND. IF COLOR-TABLE:NUM-ENTRIES <> 256 THEN COLOR-TABLE:NUM-ENTRIES = 256. &IF "{&COLOR}" = "" &THEN &SCOP COLOR "BLUE" &ENDIF CASE {&COLOR}: WHEN "BLUE" THEN ASSIGN Red-Value = 0 Green-Value = 0 Blue-Value = 0 AddRed = 0 AddGreen = 0 AddBlue = GapColor. WHEN "RED" THEN ASSIGN Red-Value = 10 Green-Value = 0 Blue-Value = 0 AddRed = GapColor AddGreen = 0 AddBlue = 0. WHEN "GRAY" THEN ASSIGN Red-Value = 0 Green-Value = 0 Blue-Value = 0 AddRed = GapColor AddGreen = GapColor AddBlue = GapColor. WHEN "GREEN" THEN ASSIGN Red-Value = 0 Green-Value = 0 Blue-Value = 0 AddRed = 0 AddGreen = GapColor AddBlue = 0. WHEN "PURPLE" THEN ASSIGN Red-Value = 0 Green-Value = 0 Blue-Value = 0 AddRed = 0 AddGreen = GapColor AddBlue = GapColor. WHEN "YELLOW" THEN ASSIGN Red-Value = 0 Green-Value = 0 Blue-Value = 0 AddRed = GapColor AddGreen = GapColor AddBlue = 0. END CASE. &SCOP LAST 164 &SCOP FIRST 100 IF COLOR-TABLE:GET-RED-VALUE({&LAST} - 1) <> Red-Value + ({&LAST} - {&FIRST} - 1) * AddRed OR COLOR-TABLE:GET-GREEN-VALUE({&LAST} - 1) <> Green-Value + ({&LAST} - {&FIRST} - 1) * AddGreen OR COLOR-TABLE:GET-BLUE-VALUE({&LAST} - 1) <> Blue-Value + ({&LAST} - {&FIRST} - 1) * AddBlue THEN DO I-Color = {&FIRST} TO {&LAST}: COLOR-TABLE:SET-DYNAMIC(I-Color, YES). COLOR-TABLE:SET-RED-VALUE(I-Color, Red-Value). COLOR-TABLE:SET-GREEN-VALUE(I-Color, Green-Value). COLOR-TABLE:SET-BLUE-VALUE(I-Color, Blue-Value). ASSIGN Red-Value = Red-Value + AddRed Green-Value = Green-Value + AddGreen Blue-Value = Blue-Value + AddBlue. END. /* calculate the width of rectangles */ Height_Rectangle_Pixels = {&FRAME}:HEIGHT-PIXELS / ({&LAST} - {&FIRST}) &IF "{&STYLE}" = "MEDIUM" &THEN * 1.5 &ELSEIF "{&STYLE}" = "LARGE" &THEN * 2.5 &ENDIF + 1. /* # of rectangles to draw */ Height_Frame = {&FRAME}:HEIGHT-pixels - {&FRAME}:BORDER-TOP-PIXELS - {&FRAME}:BORDER-BOTTOM-PIXELS. N_Rectangles = TRUNCATE( HEIGHT_FRAME / Height_Rectangle_Pixels, 0). IF HEIGHT_FRAME MOD Height_Rectangle_Pixels > 0 THEN N_Rectangles = N_Rectangles + 1. /* gradient already exists? */ ASSIGN h_Field = h_BackGround:FIRST-CHILD I-Color = 1. IF NOT valid-Handle(h_Field) OR h_Field:Type <> "RECTANGLE" OR h_Field:BGCOLOR < {&FIRST} THEN DO I-Color = 1 TO n_Rectangles: CREATE RECTANGLE h_Field ASSIGN Y = (I-Color - 1) * Height_Rectangle_Pixels X = 0 WIDTH-PIXELS = {&FRAME}:Width-pixels - {&FRAME}:BORDER-RIGHT-PIXELS - {&FRAME}:BORDER-LEFT-PIXELS HEIGHT-PIXELS = MIN(Height_Rectangle_Pixels, Height_FRAME - h_Field:Y) FILLED = TRUE BGCOLOR = I-Color + 99 EDGE-PIXELS = 0 PARENT = h_BackGround VISIBLE = TRUE. IF h_Field:MOVE-TO-BOTTOM() THEN. /* for compatibility with 8.1 */ END. /* set to 'transparent' background all litterals, radio, toggle, slider or text widgets Scanning is made on every object with an undefined (?) background color. I will find the color of the most accurate rectangle in the background, then set the background color of the object to this value. (my personal copyright!) If the foreground object color is undefined, setting of white color for the foreground too. */ h_Group = {&FRAME}:FIRST-CHILD. DO WHILE VALID-HANDLE(h_Group): h_Field = h_Group:FIRST-CHILD. DO WHILE VALID-HANDLE(h_Field): IF CAN-DO("LITERAL,RADIO-SET,TOGGLE-BOX,SLIDER,TEXT", h_Field:Type) AND h_Field:BGCOLOR = ? THEN DO: /* what's the middle of object? */ I-Color = h_Field:Y + h_Field:height-pixels / 2. /* middle of object */ /* what's the best color for this object? */ h_Field:BGCOLOR = {&FIRST} + (I-Color / Height_Rectangle_Pixels). IF h_Field:FGCOLOR = ? THEN h_Field:FGCOLOR = 15. /* set to white foreground */ END. h_Field = h_Field:NEXT-SIBLING. END. h_Group = h_Group:NEXT-SIBLING. END. /* end of include */