Brushed Group Object

Brushed Group Object

Postby fraxzi » Fri May 27, 2011 3:10 am

Dear All,

How can I make group similar to this:
Image

Inside of group border has brush or color.

Any Idea?


Kind regards,
Frances
Kind Regards,
Frances

Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
User avatar
fraxzi
 
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines

Re: Brushed Group Object

Postby ukoenig » Fri May 27, 2011 9:21 am

Frances,

Image

Code: Select all  Expand view

...
...
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
 


I tested a Image with Top and Left = 0 :

oGroup:=TGroup():New( 0, 0, 15, 50, "Label1", oDlg, NIL, NIL,.F. , .F. , NIL )

Image

But there is a Problem with the Image-adjustment ( top and left )

oGroup:=TGroup():New( 5, 5, 15, 50, "Label1", oDlg, NIL, NIL,.F. , .F. , NIL )

STATIC FUNCTION GROUP_TEST(oGroup)
local oBrush, oTmp
DEFINE IMAGE oTmp FILENAME c_path + "\Bitmaps\Fantasy2.jpg"
oBrush := TBrush():new( ,,,, ResizeBmp( oTmp:hBitmap, oGroup:nWidth, oGroup:nHeight, .T. ) )
SET BRUSH OF oGroup TO oBrush
oTmp:End()
RELEASE BRUSH oBrush
RETURN .T.


Image

Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany

Re: Brushed Group Object

Postby Marcelo Via Giglio » Fri May 27, 2011 6:53 pm

Hola,

could be enough for you, some think like this

http://imageshack.us/photo/my-images/231/rgroup.gif/

regards

Marcelo
Marcelo Via Giglio
 
Posts: 1064
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: Brushed Group Object

Postby Marcelo Via Giglio » Fri May 27, 2011 7:45 pm

Hello,

here is the source code and header file
Code: Select all  Expand view

/*
   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

//--------------------------------------------------------------------------//


Header file

Code: Select all  Expand view

/*
   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
//--------------------------------------------------------------------------//

 
Marcelo Via Giglio
 
Posts: 1064
Joined: Fri Oct 07, 2005 3:33 pm
Location: Cochabamba - Bolivia

Re: Brushed Group Object

Postby fraxzi » Sat May 28, 2011 12:21 am

Dear Mr. Uwe and Mr. Marcelo,

Thank you so much for the great help.


Kind regards,
Frances
Kind Regards,
Frances

Fivewin for xHarbour v18.07
xHarbour v1.2.3.x
BCC 7.3 + PellesC8 ( Resource Compiler only)
ADS 10.1 / MariaDB
Crystal Reports 8.5/9.23 DE
xMate v1.15
User avatar
fraxzi
 
Posts: 811
Joined: Tue May 06, 2008 4:28 am
Location: Philippines

Re: Brushed Group Object

Postby ukoenig » Sat May 28, 2011 12:33 pm

I added Gradient-options to the Class :

TRndGroup():New( ;
30, ; // 1 nTop
30, ; // 2 nLeft
150, ; // 3 nBottom
200, ; // 4 nRight
" Title ", ; // 5 Text
oGroup, ; // 6 Object
16314573, ; // 7 nText-color
0, ; // 8 nBackground
.T., ; // 9 Pixel
, ; // 10 lDesign
170, ; // 11 nWidth
120, ; // 12 nHeight
, ; // 13 nColor-Title
, ; // 14 aCtrls
oGrpFont, ; // 15 Font
128, ; // 16 Grad 1 14853684
16314573, ; // 17 Grad 2
.T., ; // 18 Round
10, ; // 19 Circle
.T., ; // 20 lGradient-direction
0.5 ) // 21 nGradient-position


...
...
.F., ; // 20 lGradient-direction
0.2 ) // 21 nGradient-position


Image

IF ::nClrGrad1 != NIL .AND. ::nClrGrad2 != NIL
GradientFill( hDC, 4 + 3, 0, ::nHeight, ::nWidth, ;
{ { ::nPos, ::nClrGrad1, ::nClrGrad2 }, { ::nPos, ::nClrGrad2, ::nClrGrad1 } }, ::lDirect )
ELSE
RoundRect( hDC, 4 + 3, 0, ::nHeight, ::nWidth, ::nElliHeight, ::nElliWidth )
ENDIF

Best Regards
Uwe :lol:
Since 1995 ( the first release of FW 1.9 )
i work with FW.
If you have any questions about special functions, maybe i can help.
User avatar
ukoenig
 
Posts: 4043
Joined: Wed Dec 19, 2007 6:40 pm
Location: Germany


Return to FiveWin for Harbour/xHarbour

Who is online

Users browsing this forum: No registered users and 109 guests