Dear All,
How can I make group similar to this:
Inside of group border has brush or color.
Any Idea?
Kind regards,
Frances
...
...
DEFINE DIALOG oDlg from 0,0 to 620, 900 pixel TITLE "Group-test" TRANSPARENT
oGroup:=TGroup():New( 3, 3, 15, 50, "Label1", oDlg, NIL, NIL,.F. , .F. , NIL )
ACTIVATE DIALOG oDlg CENTERED ;
ON INIT ( GROUP_BRUSH(oGroup), ;
GradBrush( oDlg, { { 0.50, 14853684, 16314573 }, ;
{ 0.50, 16314573, 14853684 } }, .T. ) )
RETURN NIL
//----------------------------------------------------------------------------//
STATIC FUNCTION GROUP_BRUSH(oGroup)
local oBrush
DEFINE BRUSH oBrush FILE cGrp_Brush
SET BRUSH OF oGroup TO oBrush
oBrush:End()
RETURN .T.
// -------------------------------
FUNCTION GradBrush( oDlg, aColors, lPos )
local hDC, hBmp, hBmpOld, oBrush
if Empty( oDlg:oBrush:hBitmap )
hDC = CreateCompatibleDC( oDlg:GetDC() )
hBmp = CreateCompatibleBitMap( oDlg:hDC, oDlg:nWidth, oDlg:nHeight )
hBmpOld = SelectObject( hDC, hBmp )
GradientFill( hDC, 0, 0, oDlg:nHeight, oDlg:nWidth, aColors, lPos )
DeleteObject( oDlg:oBrush:hBrush )
oDlg:oBrush:hBitmap = hBmp
oDlg:oBrush:hBrush = CreatePatternBrush( hBmp )
SelectObject( hDC, hBmpOld )
oDlg:ReleaseDC()
endif
RETURN NIL
/*
Copyright 1999 Jos‚ Lal¡n y Ferreiro <dezac@corevia.com>
-[History]-----------------------------------------------------------
Date Author Changes
---------------------------------------------------------------------
Oct 26, 1999 Jos‚ Lal¡n + Initial release
Oct 27, 1999 Jos‚ Lal¡n ! Minor changes
Apr 17, 2000 Jos‚ Lal¡n + Added New() method
Apr 17, 2000 Jos‚ Lal¡n + Added ::aCtrls var
Feb 03, 2000 Jos‚ Lal¡n ! Changed Paint() method to draw
the caption using ::oDlg:oFont or
::oFont as requested by Andi Jahja
Feb 04, 2000 Jos‚ Lal¡n ! Improved caption drawing
*/
#include "FiveWin.ch"
#include "Constant.ch"
#include "rgroup.ch"
#define TRANSPARENT 1
#define OPAQUE 2
#ifdef __XPP__
#define Super ::TGroup
#define New _New
#endif
//--------------------------------------------------------------------------//
function main()
LOCAL oDlg
LOCAL oFnt
LOCAL g
DEFINE FONT oFnt NAME "MS Sans Serif" SIZE 0, -12
DEFINE DIALOG oDlg FROM 0, 0 TO 25, 60 TITLE "Test" FONT oFnt
TRndGroup():New( 1, 1, 4, 8, "First", oDlg, CLR_GREEN, CLR_BLACK )
TRndGroup():New( 1, 10, 4, 18, "Second", oDlg, CLR_WHITE, CLR_BLUE,,,,,,,,,,.T., 10 )
@ 1, 20 ROUNDGROUP 4, 28 PROMPT "TEST" OF oDlg COLOR CLR_GREEN, CLR_GREEN, CLR_WHITE ROUNDLABEL
@ 6,5 ROUNDGROUP 10, 10 PROMPT "TEST" OF oDlg color CLR_GREEN, CLR_GREEN, CLR_BLUE GRADIENT CLR_BLUE, CLR_RED
@ 6,12 ROUNDGROUP g TO 10, 20 PROMPT "TEST" OF oDlg color CLR_BLUE, CLR_BLUE, CLR_WHITE GRADIENT CLR_BLUE, CLR_RED ROUNDLABEL 5
@ 6,22 ROUNDGROUP 10, 30 PROMPT "TEST" OF oDlg color CLR_GRAY, CLR_GRAY, CLR_BLUE GRADIENT CLR_GRAY, CLR_WHITE
ACTIVATE DIALOG oDlg CENTERED
oFnt:End()
return nil
//-----------------------------------------------------------------
CLASS TRndGroup FROM TGroup
DATA nClrTitle
DATA nElliWidth
DATA nElliHeight
DATA nClrGrad1
DATA nClrGrad2
DATA lRoundLabel
DATA nRoundLabel
DATA aCtrls AS ARRAY INIT {}
METHOD New( nTop, nLeft, nBottom, nRight, cLabel, oWnd, nClrText, ;
nClrPane, lPixel, lDesign, nWidth, nHeight, nClrTitle, ;
aCtrls, oFont, nClrGrad1, nClrGrad2, lRoundLabel, nRoundLabel ) CONSTRUCTOR
METHOD ReDefine( nId, cLabel, oWnd, nClrText, nClrPane, nWidth, ;
nHeight, nClrTitle, aCtrls, oFont, nClrGrad1, nClrGrad2, lRoundLabel, nRoundLabel ) CONSTRUCTOR
METHOD Initiate( hDlg ) INLINE Super:Initiate( hDlg )
METHOD Display() INLINE ::BeginPaint(), ::Paint(), ::EndPaint()
METHOD Paint()
METHOD DrawCtrls()
ENDCLASS
//--------------------------------------------------------------------------//
METHOD New( nTop, nLeft, nBottom, nRight, cLabel, oWnd, ;
nClrText, nClrPane, lPixel, lDesign, nWidth, ;
nHeight, nClrTitle, aCtrls, oFont, nClrGrad1, nClrGrad2, lRoundLabel, nRoundLabel ) CLASS TRndGroup
DEFAULT nWidth := 18, ;
nHeight := 18, ;
nClrText := RGB( 128, 128, 128 ), ;
nClrPane := RGB( 160, 160, 128 ), ;
nClrTitle := nClrText, ;
aCtrls := {},;
lRoundLabel := .F. ,;
nRoundLabel := 2
/* NOTE:
We don't pass the nClrText nor nClrPane value to the super class
because it will disable the round corners effect. [jlalin]
*/
Super:New( nTop, nLeft, nBottom, nRight, cLabel, oWnd, , , ;
lPixel, lDesign,,.T. )
::nClrText := nClrText
::nClrPane := nClrPane
::nClrTitle := nClrTitle
::nElliWidth := nWidth
::nElliHeight := nHeight
::aCtrls := aCtrls
::oFont := oFont
::nClrGrad1 := nClrGrad1
::nClrGrad2 := nClrGrad2
::lRoundLabel := lRoundLabel
::nRoundLabel := nRoundLabel
return Self
//--------------------------------------------------------------------------//
METHOD ReDefine( nId, cLabel, oWnd, nClrText, nClrPane, ;
nWidth, nHeight, nClrTitle, aCtrls, oFont, nClrGrad1, nClrGrad2, lRoundLabel, nRoundLabel ) CLASS TRndGroup
DEFAULT nWidth := 18, ;
nHeight := 18, ;
nClrText := RGB( 128, 128, 128 ), ;
nClrPane := RGB( 150, 157, 132 ), ;
nClrTitle := nClrText, ;
aCtrls := {} ,;
lRoundLabel := .F.,;
nRoundLabel := 2
/* NOTE:
We don't pass the nClrText nor nClrPane value to the super class
because it will disable the round corners effect. [jlalin]
*/
Super:ReDefine( nId, cLabel, oWnd,,,,.T. )
::nClrText := nClrText
::nClrPane := nClrPane
::nClrTitle := nClrTitle
::nElliWidth := nWidth
::nElliHeight := nHeight
::aCtrls := aCtrls
::oFont := oFont
::nClrGrad1 := nClrGrad1
::nClrGrad2 := nClrGrad2
::lRoundLabel := lRoundLabel
::nRoundLabel := nRoundLabel
return Self
//--------------------------------------------------------------------------//
METHOD Paint() CLASS TRndGroup
LOCAL hDC := ::GetDC()
LOCAL hBrush, hPen
LOCAL hOldBrush, hOldPen
LOCAL nOldMode, nOldClr, nOldBk
LOCAL hOldFont
LOCAL nHeight
hBrush := CreateSolidBrush( ::nClrPane )
hPen := CreatePen( 0, 1, ::nClrText )
hOldBrush := SelectObject( hDC, hBrush )
hOldPen := SelectObject( hDC, hPen)
IF ::nClrGrad1 != NIL .AND. ::nClrGrad2 != NIL
GradientFill( hDC, 4 + 3, 0, ::nHeight, ::nWidth, { { 0.5, ::nClrGrad1, ::nClrGrad2 } }, .T. )
ELSE
RoundRect( hDC, 4 + 3, 0, ::nHeight, ::nWidth, ::nElliHeight, ::nElliWidth )
ENDIF
if !Empty( ::cCaption )
hOldFont := SelectObject( hDC, ;
if( ::oFont == nil, ::oWnd:oFont:hFont, ::oFont:hFont ) )
nOldMode := SetBkMode( hDC, TRANSPARENT )
nOldClr := SetTextColor( hDC, ::nClrTitle )
nOldBk := SetBkColor( hDC, ::nClrPane )
nHeight := if( ::oFont == nil, 12, ::oFont:nHeight )
IF ::lRoundLabel
RoundRect( hDC, 2 + ( ::nElliWidth / 2 ), 3 - nHeight + 7, 8 + ( ::nElliWidth / 2 ) + GetTextWidth( hDC, ::cCaption ), 5 + 9, ::nRoundLabel, ::nRoundLabel )
ELSE
Rectangle( hDC, 3 - nHeight + 7, 2 + ( ::nElliWidth / 2 ), 5 + 9, 8 + ( ::nElliWidth / 2 ) + GetTextWidth( hDC, ::cCaption ) )
ENDIF
TextOut( hDC, 3 - nHeight + 8, 5 + ( ::nElliWidth / 2 ), ::cCaption )
SelectObject( hDC, hOldFont )
SetTextColor( hDC, nOldClr )
SetBkColor( hDC, nOldBk )
SetBkMode( hDC, nOldMode )
endif
SelectObject( hDC, hOldPen )
DeleteObject( hPen )
SelectObject( hDC, hOldBrush )
DeleteObject( hBrush )
::DrawCtrls()
::ReleaseDC()
return nil
//--------------------------------------------------------------------------//
METHOD DrawCtrls() CLASS TRndGroup
if !Empty( ::aCtrls )
aEval( ::aCtrls, {|oCtrl| ;
if( oCtrl != NIL, ;
( oCtrl:SetColor( ::nClrTitle, ::nClrPane ), ;
oCtrl:Refresh() ), ;
) } )
endif
return nil
//--------------------------------------------------------------------------//
/*
Copyright 1999 Jos‚ Lal¡n y Ferreiro <dezac@corevia.com>
-[History]-----------------------------------------------------------
Date Author Changes
---------------------------------------------------------------------
Oct 27, 1999 Jos‚ Lal¡n + Initial release
Apr 17, 2000 Jos‚ Lal¡n + Added @ ... syntax
*/
#ifndef _ROUNDGROUP_CH
#define _ROUNDGROUP_CH
/*----------------------------------------------------------------------------//
!short: ROUNDGROUP */
#xcommand @ <nTop>, <nLeft> ROUNDGROUP [<oGroup> TO] <nBottom>, <nRight > ;
[ <label:LABEL,PROMPT> <cLabel> ] ;
[ OF <oWnd> ] ;
[ COLOR <nClrFore>, <nClrBack>, <nClrTitle> ] ;
[ <lPixel: PIXEL> ] ;
[ <lDesign: DESIGN> ] ;
[ ROUND WIDTH <nElliWidth> ] ;
[ ROUND HEIGHT <nElliHeight> ] ;
[ CONTROLS <aCtrls> ] ;
[ FONT <oFont> ] ;
[ GRADIENT <nClrGrad1>,<nClrGrad2> ];
[ <lRoundLabel: ROUNDLABEL> [<nRoundLabel>] ] ;
=> ;
[ <oGroup> := ] TRndGroup():New( <nTop>, <nLeft>, <nBottom>, <nRight>,;
<cLabel>, <oWnd>, <nClrFore>, <nClrBack>, <.lPixel.>,;
[<.lDesign.>], [<nElliWidth>], [<nElliHeight>], [<nClrTitle>], ;
[<aCtrls>], [<oFont>], [<nClrGrad1>], [<nClrGrad2>], <.lRoundLabel.>,[<nRoundLabel>] )
#xcommand REDEFINE ROUNDGROUP [ <oGroup> ] ;
[ <label:LABEL,PROMPT> <cLabel> ] ;
[ ID <nId> ] ;
[ <of: OF, WINDOW, DIALOG> <oWnd> ] ;
[ COLOR <nClrFore>, <nClrBack> [, <nClrTitle> ] ] ;
[ ROUND WIDTH <nElliWidth> ] ;
[ ROUND HEIGHT <nElliHeight> ] ;
[ CONTROLS <aCtrls> ] ;
[ FONT <oFont> ] ;
[ GRADIENT <nClrGrad1>,<nClrGrad2> ];
[ <lRoundLabel: ROUNDLABEL> [<nRoundLabel>] ] ;
=> ;
[ <oGroup> := ] TRndGroup():ReDefine( <nId>, <cLabel>, <oWnd>,;
<nClrFore>, <nClrBack>, [<nElliWidth>], [<nElliHeight>], ;
[<nClrTitle>], [<aCtrls>], [<oFont>], [<nClrGrad1>], [<nClrGrad2>], <.lRoundLabel.>,[<nRoundLabel>] )
#endif //_ROUNDGROUP_CH
//--------------------------------------------------------------------------//
Return to FiveWin for Harbour/xHarbour
Users browsing this forum: Google [Bot] and 113 guests