Resize gradient with Dialog Resize

Resize gradient with Dialog Resize

Postby Rick Lipkin » Fri Oct 02, 2015 1:49 pm

To All

I am re-sizing a dialog and am using the SetGradient() function to color my dialog box. When I re-size the dialog .. the gradient just tiles itself ( repeats ) and does not flow with the resize. Any suggestions .. here is the code

Rick Lipkin
Code: Select all  Expand view  RUN

LightYellow()

DEFINE DIALOG oDlg RESOURCE "TRANSACT";
      TITLE "TRANSACTION History for INVENTORY RECORD  "+ltrim(str(nInventEid))

   REDEFINE xBROWSE oLbx     ;
      ID 111 of oDlg         ;
      RECORDSET oRsTran      ;
      COLUMNS "HISTORY",     ;
              "ENTRYBY",     ;
              "TABLENAME",   ;
              "INVENTEID"    ;
      COLSIZES 370,90,90,110 ;
      HEADERS "History",     ;
              "EntryBy",     ;
              "Table",       ;
              "InventEid"    ;
   AUTOSORT AUTOCOLS LINES CELL

   ADD oCol TO oLbx AT 2 DATA {|x| x := If ( oRsTran:Eof, ,_ChkDate(oRsTran:Fields("EntryDate"):Value)) } HEADER "Date"

   oLbx:aCols[2]:nDataStrAlign := AL_LEFT  //  date
   oLbx:aCols[2]:nHeadStrAlign := AL_LEFT

   WITH OBJECT oLbx
       :lTabLikeExcel := .t.
   END

   oLbx:lRecordSelector := .f.
   oLbx:lFooter   := .t.
   oCol           := oLbx:aCols[ 1 ]
   oCol:bFooter   := { || Ltrim( Str( oLbx:KeyNo() ) ) + " / " + LTrim( Str( oLbx:KeyCount() ) ) }
   oLbx:bChange   := { || oCol:RefreshFooter() }

   oLbx:nStretchCol  := 1

   REDEFINE BTNBMP oBtn1 ID 112 OF oDlg  ;
         RESOURCE "OK", "DOK", "DOK" ;
         PROMPT "&Ok" LEFT 2007;
         ACTION ( oDLG:END() )     ;

   REDEFINE BTNBMP oBtn2 ID 113 OF oDlg  ;
         RESOURCE "MINUS16", "DMINUS16", "DMINUS16" ;
         PROMPT "&Del" LEFT 2007;
         ACTION ( _DelUm( oRsTran, oLbx ) )

    oDlg:bResized = { | nSizeType, nWidth, nHeight | ResizeControls( nSizeType, nWidth, nHeight, oDlg )}

ACTIVATE DIALOG oDlg ;
    ON INIT( oLbx:SetFocus(), IF( (xSUPER = 'Y' .or. xAdmin = "Y"), , oBtn2:Hide() ));
    VALID(!GETKEYSTATE( 27 ))

//-------------------------
Static Func ResizeControls( nSizeType, nWidth, nHeight, oDlg )

                                                         
if nSizeType = 0 //SIZE_MAXIMIZED        
   oDlg:aControls[ 1  ]:SetSize( nWidth - 60, nHeight - 10 ) //txbrowse
endif

Return(nil)

//-----------------
Static Func LightYellow()

SetDlgGradient( { { 0.01,8440801,16777215 },{ 0.75,16777215,8440801 } })

Return(nil)
 

Image
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Resize gradient with Dialog Resize

Postby ukoenig » Fri Oct 02, 2015 1:59 pm

Rick,

I think no problem.
I will use Your source to create a sample.

best regards
Uwe :D
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: Resize gradient with Dialog Resize

Postby ukoenig » Fri Oct 02, 2015 4:43 pm

Rick,

keeping controls transparent on resize.
Background adjusted to new dialog-size.
Gradient- and image-test.
Image on Image-background.


Image

Code: Select all  Expand view  RUN

#include "FiveWin.ch"

STATIC oDlg

FUNCTION MAIN()
Local oLbx, oBtn1, oBtn2, oImg, oFontMed

//LightYellow()

// I am re-sizing a dialog and am using the SetGradient() function to color my dialog box.
// When I re-size the dialog .. the gradient just tiles itself ( repeats ) and does not flow with the resize.

DEFINE IMAGE oImg FILENAME "Logo4.bmp"
DEFINE FONT oFontMed   NAME "Arial" SIZE 0, -36 BOLD

DEFINE DIALOG oDlg RESOURCE "TRANSACT";
TITLE "Resize - test"

REDEFINE SAY ID 110 PROMPT "Transparent SAY" FONT oFontMed COLOR 255, NIL OF oDlg TRANSPARENT

oDlg:bResized = { |nSizeType, nWidth, nHeight| ( DLG_BACK( oDlg, 2, 8440801,16777215, .T., 0.01, "Picture8.jpg" ), ;
ResizeControls( nSizeType, nWidth, nHeight, oDlg ) ) }

//oDlg:bResized = { | nSizeType, nWidth, nHeight | ResizeControls( nSizeType, nWidth, nHeight, oDlg )}

ACTIVATE DIALOG oDlg ;
ON PAINT ABPaint( hDC, 50, 30, oImg:hBitmap, 255 ) ;
ON INIT  DLG_BACK( oDlg, 2, 8440801,16777215, .T., 0.01, "Picture8.jpg" )

oImg:End()
oFontMed:End()

RETURN( NIL )

// --------  Background ---------------

FUNCTION DLG_BACK( oDlg, nStyle, nColor1, nColor2, lDirect, nMove, cImage )
LOCAL hDC, oBrush, oImage, aGrad
LOCAL aRect := GETCLIENTRECT( oDlg:hWnd )

IF nStyle = 1 // GRADIENT
    aGrad := { { nMove, nColor1, nColor2 }, { nMove, nColor2, nColor1 } }
    hDC = CreateCompatibleDC( oDlg:GetDC() )
    hBmp = CreateCompatibleBitMap( oDlg:hDC, aRect[4], aRect[3] )  
    hBmpOld = SelectObject( hDC, hBmp )
    GradientFill( hDC, 0, 0, aRect[3], aRect[4], aGrad, lDirect ) // .T: = Vertical
    oBrush := TBrush():New( ,,,, hBmp )
    oBrush:Cargo  := aGrad
    SelectObject( hDC, hBmpOld )
    ReleaseDC(hDC)
ENDIF
IF nStyle = 2 // Image ADJUSTED
    IF FILE( cImage )
        DEFINE IMAGE oImage FILE cImage
        oBrush := TBrush():new( ,,,, ResizeBmp( oImage:hBitmap, aRect[4], aRect[3], .F. ) )
        oImage:End()
    ELSE
        IF !EMPTY(cImage)
            MsgAlert( "File  : " + cImage + CRLF + ;
                       "does not exist" + CRLF + ;
                           "to create Background !", "ATTENTION" )
        ENDIF
    ENDIF
ENDIF
oDlg:SetBrush( oBrush )

AEVAL( oDlg:aControls, { | oCtl | IF( oCtl:lTransparent, oCtl:SetBrush( oDlg:oBrush ), ) } )

RELEASE BRUSH oBrush

RETURN( oBrush )
 


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: Resize gradient with Dialog Resize

Postby Rick Lipkin » Fri Oct 02, 2015 5:01 pm

Uwe

Let me digest this .. thank you for your solution .. I appreciate it !

Rick Lipkin
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Resize gradient with Dialog Resize

Postby nageswaragunupudi » Sat Oct 03, 2015 6:11 am

I advise not to complicate extremely simple things.
FWH gradient and image brushes are automatically re-sizable. FWH intends to do all complex UI work leaving the programmers to concentrate on business logic only.

Please try this sample:
Code: Select all  Expand view  RUN
#include "fivewin.ch"

function main()

   local oDlg, oBrush

   DEFINE BRUSH oBrush GRADIENT { { 1, CLR_BLUE, CLR_WHITE } }
   DEFINE DIALOG oDlg BRUSH oBrush ;
      STYLE nOR( DS_MODALFRAME, WS_POPUP, WS_CAPTION, WS_SYSMENU, WS_MAXIMIZEBOX, WS_MINIMIZEBOX, WS_THICKFRAME )
       // The style is used for resizing
   ACTIVATE DIALOG oDlg CENTERED
   RELEASE BRUSH oBrush

return nil
 

You see the gradient gets resized when you resize the dialog.
You can use this with any window or control.
What all needs is just one line of code defining the brush.
Regards

G. N. Rao.
Hyderabad, India
User avatar
nageswaragunupudi
 
Posts: 10656
Joined: Sun Nov 19, 2006 5:22 am
Location: India

Re: Resize gradient with Dialog Resize

Postby ukoenig » Mon Oct 05, 2015 8:29 pm

Mr. Rao,
thank You very much
still the direction must be defined

Rick,

Some improvements testing dialog resizing
A complete sample with style and color change at runtime
Diagonal-gradient added.

To define the gradient-direction
DEFINE BRUSH oBrush GRADIENT aGrad STYLE "HORIZONTAL"
or
DEFINE BRUSH oBrush GRADIENT aGrad STYLE "VERTICAL"
Creating a DIAGONAL-gradient, the solution is different.

I added a INI, to save the values
I noticed a problem with using < GetPvProfString >
and used another solution that works as well.
Maybe it is possible to find out what's wrong with using < GetPvProfString > ?

Download :
http://www.pflegeplus.com/DOWNLOADS/Dlgadjust.zip

Image

best regards
Uwe :D
Last edited by ukoenig on Wed Oct 07, 2015 4:35 pm, edited 3 times in total.
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: Resize gradient with Dialog Resize

Postby Rick Lipkin » Mon Oct 05, 2015 9:33 pm

Uwe and Rao

Thank you both very much !!

Rick
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Resize gradient with Dialog Resize

Postby ukoenig » Wed Oct 07, 2015 4:12 pm

Hello Rick,

I noticed < Gradient CIRCLE > is included now in new FWH-release
before it was included in a sample < gradcirc.prg >
Using a older FWH-release, You must add the function from the sample.

I added circle paintings as a option, to complete the sample.
Maybe it is useful for You

Download :
http://www.pflegeplus.com/DOWNLOADS/Dlgadjust1.zip

Image

Code: Select all  Expand view  RUN

oBrush := TBrush():New()
IF lDirect = .T.
     nOffX := nGrdPos * 500
     nOffY := nGrdPos * 500
ELSE
     nOffX := - nGrdPos * 500 // change the position using a combination of nOffX and nOffY adding -
     nOffY := - nGrdPos * 500
ENDIF
DeleteObject( oBrush:hBrush )
oBrush:hBrush := CircleGradient( 0, { 0, 0, aRect[3], aRect[4] }, nColor1, nColor2, nOffX, nOffY, 1 )
 


best regards
Uwe :D
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: Resize gradient with Dialog Resize

Postby Rick Lipkin » Fri Oct 09, 2015 12:58 pm

Uwe, Rao

I looked back on some old code where I used gradients before SetDlgGradient() .. here is my solution, note the ON PAINT ..thank you both for your inspiration !

Rick Lipkin
Code: Select all  Expand view  RUN

xGrad := { { 0.01,8440801,16777215 },{ 0.75,16777215,8440801 } }     // light yellow

DEFINE DIALOG oDlg RESOURCE "TRANSACT";
      TITLE "TRANSACTION History for INVENTORY RECORD  "+ltrim(str(nInventEid))

   REDEFINE xBROWSE oLbx     ;
      ID 111 of oDlg         ;
      RECORDSET oRsTran      ;
      COLUMNS "HISTORY",     ;
              "ENTRYBY",     ;
              "TABLENAME",   ;
              "INVENTEID"    ;
      COLSIZES 370,90,90,110 ;
      HEADERS "History",     ;
              "EntryBy",     ;
              "Table",       ;
              "InventEid"    ;
   AUTOSORT AUTOCOLS LINES CELL

   ADD oCol TO oLbx AT 2 DATA {|x| x := If ( oRsTran:Eof, ,_ChkDate(oRsTran:Fields("EntryDate"):Value)) } HEADER "Date"

   oLbx:aCols[2]:nDataStrAlign := AL_LEFT  //  date
   oLbx:aCols[2]:nHeadStrAlign := AL_LEFT

   WITH OBJECT oLbx
       :lTabLikeExcel := .t.
   END

   oLbx:lRecordSelector := .f.
   oLbx:lFooter   := .t.
   oCol           := oLbx:aCols[ 1 ]
   oCol:bFooter   := { || Ltrim( Str( oLbx:KeyNo() ) ) + " / " + LTrim( Str( oLbx:KeyCount() ) ) }
   oLbx:bChange   := { || oCol:RefreshFooter() }

   oLbx:nStretchCol  := 1

   REDEFINE BTNBMP oBtn1 ID 112 OF oDlg  ;
         RESOURCE "OK", "DOK", "DOK" ;
         PROMPT "&Ok" LEFT 2007;
         ACTION ( oDLG:END() )     ;

   REDEFINE BTNBMP oBtn2 ID 113 OF oDlg  ;
         RESOURCE "MINUS16", "DMINUS16", "DMINUS16" ;
         PROMPT "&Del" LEFT 2007;
         ACTION ( _DelUm( oRsTran, oLbx ) )

    oDlg:bResized = { | nSizeType, nWidth, nHeight | ResizeControls( nSizeType, nWidth, nHeight, oDlg )}

ACTIVATE DIALOG oDlg ;
    ON INIT( oLbx:SetFocus(), IF( xAdmin = "Y", , oBtn2:Hide() ));
    ON PAINT ( GradientFill( hDC, 0, 0, oDlg:nHeight, oDlg:nWidth, xGrad, .T. ));     // note GradientFill
    VALID(!GETKEYSTATE( 27 ))


oRsTran:Close()
oRsTran := nil
 
User avatar
Rick Lipkin
 
Posts: 2666
Joined: Fri Oct 07, 2005 1:50 pm
Location: Columbia, South Carolina USA

Re: Resize gradient with Dialog Resize

Postby ukoenig » Fri Oct 09, 2015 3:06 pm

Rick,

Yes, on startup I use ON INIT

ACTIVATE DIALOG oDlg ;
ON PAINT ABPaint( hDC, 100, 20, oImg:hBitmap, 255 ) ;
ON INIT ( DLG_BACK( oDlg, nDStyle, nColor1, nColor2, lDirect, nGrdPos, nCGrdPos, cBrush, cImage ), ;
FLD_BACK( oFld, nTColor, nColor1, nColor2, lDirect, nGrdPos, nCGrdPos, cBrush, cImage ) )

viewing the sample, You can see that all kind of paintings are defined inside these functions.
That makes a quick change to any style possible.
Painting images is different to gradient.
The gradientstyles : horiz., vert., diagonal and circle also needed different solutions.
Changing the background only the functions DLG_BACK and FLD_BACK are needed.

My new extended release is testing any style-combination
and the transparent painting of the different controls.
New I added a FOLDER that behaves like the dialog with all possible
combinations and control-tests

I added the calculation to define the position of a circle gradient

The screenshot shows the same defined circle inside the dialog and the folder

Image

another samples

Image

the calculation to define any circle-position

Code: Select all  Expand view  RUN

// nCGrdPos = 4 radios to define the position
// nGrdpos = position-finetuning between 0.1 - 0.9
// aRect := GETCLIENTRECT( oDlg:hWnd )

ELSEIF nDStyle = 4 // GRADIENT circle
    oBrush := TBrush():New()
    IF nCGrdPos = 1 // bottom / right
        nOffX := nGrdPos * ( aRect[4] / 2 )
        nOffY := nGrdPos * ( aRect[3] / 2 )
    ELSEIF nCGrdPos = 2 // top / left
        nOffX := - nGrdPos * ( aRect[4] / 2 )
        nOffY := - nGrdPos * ( aRect[3] / 2 )
    ELSEIF  nCGrdPos = 3    // bottom / left
        nOffX := - nGrdPos * ( aRect[4] / 2 )
        nOffY :=  nGrdPos * ( aRect[3] / 2 )
    ELSEIF  nCGrdPos = 4    // top / right
        nOffX :=  nGrdPos * ( aRect[4] / 2 )
        nOffY := - nGrdPos * ( aRect[3] / 2 )
    ENDIF
    DeleteObject( oBrush:hBrush )
    oBrush:hBrush = CircleGradient( 0, { 0, 0, aRect[3], aRect[4] } , nColor1, nColor2, nOffX, nOffY, 1 )
 


best regards
Uwe :D
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 51 guests