FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index FiveWin for Harbour/xHarbour Backgrd.-Tests for Wind., Dialog a Alpha-BMP's ( download )
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Backgrd.-Tests for Wind., Dialog a Alpha-BMP's ( download )
Posted: Tue Jan 13, 2009 01:38 PM
Hello,

After spending some hours with testing,
I think, it might be useful, to show a overview of the functions,
to show the different backgrounds with combinations
( Gradient, Brushes, Images and combinations with Alpha-BMP's )
from inside a MDI or MODAL-window and Dialog.
I'm still busy with testing and it is not finished yet.
There will be a Browser-selection with all 30 combinations.



For users with older FWH-versions and no Gradient-support,
the use of a extra Gradient-function is included.
For the moment, I just want to show the functions and how it works.
This post will be updated after all tests are done.





Source-Version : 13.01.2009

// ------- WINDOW - TEST ( MDI ) --------------------------

FUNCTION NEW_WIN()
LOCAL oWnd1, oBtn1, oImage1, oBmp1, oBar1, oBtn2, oBtn3

// ( 6 )  Alpha-Blended-BMP
// -----------------------------
cALPHA := ALLTRIM( W_C_ALPHA )
IF !EMPTY ( cALPHA )
   DEFINE BITMAP oBmp1 FILENAME "&c_pfad\IMAGE\" + cALPHA
ENDIF

// MDI-Window
// ---------------
DEFINE WINDOW oWnd1 TITLE "Background for Windows"  MDI MENU TMenu():New() 

DEFINE BUTTONBAR oBar1 OF oWnd1 SIZE 60, 60 2007 RIGHT 

oBar1:bClrGrad :=  { | lInvert | If( ! lInvert, ;
		{ { 0.90,11892819,16777215 },{ 0.90,16777215,11892819 } },;
		{ { 0.50,128,16777215 }, { 0.50,16777215,128 } } ) }

oBar1:nClrText := 0

DEFINE BUTTON oBtn2 OF oBar1 ACTION NIL;
RESOURCE "floppy" 

DEFINE BUTTON oBtn3 OF oBar1 ACTION oWnd1:End() ;
RESOURCE "quit" PROMPT "Exit" TOOLTIP "Close Window-Test"

oBtn2:Hide()

// ----- Table of Color- Brush and Image - Selection -------------
// -----------------------------------------------------------------------
//   1", "Black" }
//   2", "White" }
//   3", "Blue" }
//   4", "Blue+" }
//   5", "Green" }
//   6", "Green+" }
//   7", "Red" }
//   8", "Red+" }
//   9", "Yellow" }
//  10", "Select" }
// -------------------
//  11", "Borld." }
//  12", "Tiled" }
//  13", "Bricks" }
// -------------------
//  14", "BACKGRD." }
// -------------------
// -------------------

// Colors
// ---------
IF W_POS1 < 11 .and. W_STYLE = 2  // Color
      W_GRAD( hDC, oWnd1 )
ENDIF
// Picture Background
// --------------------------
*IF W_POS1 = 14      
*	W_IMAGE( oWnd1 ) 
*ENDIF
// Brush
// --------
*IF W_POS1 > 10 .and. W_POS1 < 14
*	W_BRUSH( oWnd1 )
*ENDIF

// W_POS1 < 11  (  GRADIENT and COLORS )
// W_POS1 > 10 .and. W_POS1 < 14  (  BRUSH )
// W_POS1 = 14 .and. W_LOGOTYP = "I"  ( IMAGE )
// !EMPTY( W_C_ALPHA )  ( ALPHA-BLENDED BMP )

ACTIVATE WINDOW oWnd1 MAXIMIZED ;
ON INIT  ( NEW_COLOR1a(oWnd1), IIF( lPREVIEW = .T., D_PREVIEW(oWnd1), NIL ) ) ;
ON PAINT ( IIF( W_POS1 < 11.and. W_STYLE = 1, W_GRAD( hDC, oWnd1 ), NIL ), ;
     IIF( W_POS1 = 14, W_IMAGE( oWnd1 ), NIL ), ; 
     IIF( W_POS1 > 10 .and. W_POS1 < 14, W_BRUSH( oWnd1 ), NIL ), ;
     IIF( !EMPTY( W_C_ALPHA ), ;
          ABPaint( hDC, W_L_ALPHA, W_T_ALPHA, oBmp1:hBitmap, 220 ), NIL ) )
 
RETURN NIL

// --------- ( 1 + 3 ) GRADIENT and COLORS --------------------------------------

// W_MOVE = Color-Gradient-Position
// W_COLOR1 = 1. Gradient-Color or Mono-Color
// W_COLOR2 = 2. Gradient-Color
// W_STYLE = Horizontal or Vertical

STATIC FUNCTION W_GRAD( hDC, oWnd1 )
local oNewbrush
local aGrad := { { W_MOVE, W_COLOR1, W_COLOR2 }, ;
                          { W_MOVE, W_COLOR2, W_COLOR1 } }         

IF W_STYLE = 1 
   IF W_DIRECT = 1
      IF S_FWHVERS < 7.09
         DegradeW ( hDC, oWnd1 )  
      ENDIF
      IF S_FWHVERS >= 7.09 .and. S_FWHVERS < 8.07	
         Gradient( hDC, { 0, 0, oWnd1:nHeight, oWnd1:nWidth }, W_COLOR1, W_COLOR2, .T. )
      ENDIF
      IF S_FWHVERS >= 8.07
         GradientFill( hDC,  0, 0, oWnd1:nHeight, oWnd1:nWidth, aGrad, .T. )
      ENDIF
   ELSE
      IF S_FWHVERS < 7.09
         DegradeW ( hDC, oWnd1 )  
      ENDIF
      IF S_FWHVERS >= 7.09 .and. S_FWHVERS < 8.07	
         Gradient( hDC, { 0, 0, oWnd1:nHeight, oWnd1:nWidth }, W_COLOR1, W_COLOR2, .F. )
      ENDIF
      IF S_FWHVERS >= 8.07
        GradientFill( hDC,  0, 0, oWnd1:nHeight, oWnd1:nWidth, aGrad, .F. )
      ENDIF	
   ENDIF
ELSE
   DEFINE BRUSH oNewBrush  COLOR W_COLOR1
   SET BRUSH OF oWnd1 TO oNewBrush

	*FillRect( oWnd1:hDC, 0, 0, oWnd1:nHeight, oWnd1:nWidth, oNewbrush:hBrush )
	RELEASE BRUSH oNewbrush
ENDIF

RETURN NIL

//--------- ( 4 + 5 ) IMAGES and BMP-Brush ------------------------ 

STATIC FUNCTION W_IMAGE( oWnd1 ) 
LOCAL oImage1

// Selected Image
// --------------------
cNEWLOGO := "&c_pfad\IMAGE\" + ALLTRIM(W_LOGO)

// Brush
// --------
IF W_LOGOTYP = "B"      // Brush
   IF ! Empty( cNEWLOGO ) .and. File( "&cNEWLOGO" )
      DEFINE BRUSH oImage1 FILE "&cNEWLOGO"
      SET BRUSH OF oWnd1 TO oImage1
   ELSE
      MsgAlert("No file selected !","Attention" )
   ENDIF
ENDIF

// Image
// --------
IF W_LOGOTYP = "I"      
   IF ! Empty( cNEWLOGO ) .and. File( "&cNEWLOGO" )
      ScreenWidth := GetSysMetrics(0)
      ScreenHeight := GetSysMetrics(1) - 20
      @ 0, 0 IMAGE oImage1 SIZE ScreenWidth,ScreenHeight OF oWnd1  ADJUST
      oImage1:Progress( .f. )
      oImage1:LoadBmp( "&cNEWLOGO" )
   ELSE
      MsgAlert("No file selected !","Attention" )
   ENDIF
ENDIF

RETURN NIL

//-------- ( 2 ) BRUSHES ------------------------- 

STATIC FUNCTION W_BRUSH( oWnd1 ) 
LOCAL oNewbrush

IF W_POS1 = 11
   DEFINE BRUSH oNewBrush  STYLE ("BORLAND")
ENDIF
IF W_POS1 = 12
   DEFINE BRUSH oNewBrush  STYLE ("TILED")      
ENDIF
IF W_POS1 = 13
   DEFINE BRUSH oNewBrush  STYLE ("BRICKS")   
ENDIF

SET BRUSH OF oWnd1 TO oNewBrush
RELEASE BRUSH oNewbrush

RETURN NIL

// ------  GRADIENT-Function for not supported FWH-Versions -------

STATIC FUNCTION DegradeD ( hDC, oDlg ) 

LOCAL nStep , nStepY 
LOCAL oBrush 
LOCAL i, r,g,b 
LOCAL r0,g0,b0 
LOCAL r1, g1, b1 
LOCAL rD, gD, bD 
LOCAL aRect := GETCLIENTRECT( oDlg:hWnd )

nStep  := ( aRect[ 3 ] - aRect[ 1 ] ) 
nStepY := ( aRect[ 3 ] - aRect[ 1 ] ) / nStep 
aRect[ 3 ] = aRect[ 1 ] + nStepY 

r0 := nRGBRed (D_COLOR1) 
g0 := nRGBGreen (D_COLOR1) 
b0 := nRGBBlue (D_COLOR1) 
r1 := nRGBRed (D_COLOR2) 
g1 := nRGBGreen (D_COLOR2) 
b1 := nRGBBlue (D_COLOR2) 
rD := r1-r0 
gD := g1-g0 
bD := b1-b0 

r := 256*rD/Max(nStep,1) 
g := 256*gD/Max(nStep,1) 
b := 256*bD/Max(nStep,1) 

r0*=256 
g0*=256 
b0*=256 

FOR i = 0 TO nStep-1 STEP nStepY 
   r0 += r 
   g0 += g 
   b0 += b 
   DEFINE BRUSH oBrush COLOR nRGB( r0/256, g0/256, b0/256 ) 
   FILLRECT( hDC, aRect, oBrush:hBrush ) 
   RELEASE BRUSH oBrush 
   aRect[ 1 ] += nStepY 
   aRect[ 3 ] += nStepY 
NEXT 

RETURN (nil)


Regards
Uwe :-)
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.
Posts: 4043
Joined: Wed Dec 19, 2007 06:40 PM
Re: Backgrounds for Windows, Dialogs and Alpha-BMP's
Posted: Wed Jan 14, 2009 01:15 PM
Hello,

all tests are done. Here is the final result :
All combinations are tested ( 20 are possible )
It is a nice overview, how to use the different functions.
If You like, You can download the complete working-directory ( everything is included )

Download Version 1.0 / Jan 2009 :
http://www.pflegeplus.com/fw_downloads/backgrdTest.zip

Some nice Windows 7 - wallpapers for testing :
http://www.pflegeplus.com/fw_downloads/ ... 7_wall.zip



Preview on the next version : 2.0 / Jan 2009


#include "fivewin.ch"
#include "xbrowse.ch"
#include "Image.ch"

STATIC S_FWHVERS := 8.09
STATIC nARRAYPOS := 1

FUNCTION Main()
local oDlg, oFont, oButton

DEFINE FONT oFont NAME "TAHOMA" SIZE 0,-14
SetBalloon( .T. ) // Balloon shape required for tooltips

DEFINE DIALOG oDlg SIZE 362, 560 TITLE "Testing Windows- and Dialog-Backgrounds " PIXEL FONT oFont

@ 255, 60 BUTTONBMP oButton ;
     SIZE 60, 20 ;
     ACTION oDlg:End() OF oDlg ;
     FONT oFont PIXEL ;     
     BITMAP "Quit.bmp" ;    
     PROMPT "   Exit" TEXTRIGHT

oButton:cToolTip =  { "Exit Background-Test","Background", 1, CLR_BLACK, 14089979 } 

ACTIVATE DIALOG oDlg CENTERED ;
ON INIT DataBrowse( oDlg, oFont )  

RELEASE FONT oFont

RETURN NIL

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

FUNCTION DataBrowse( oDlg, oFont )
local oBrw, aData := {}

AAdd( aData, {  1, 'Window', '     ', 'Gradient    ' } )
AAdd( aData, {  2, 'Window', '     ', 'Color       ' } )
AAdd( aData, {  3, 'Window', '     ', 'Image- Brush' } )
AAdd( aData, {  4, 'Window', '     ', 'Style- Brush' } )
AAdd( aData, {  5, 'Window', '     ', 'Image       ' } )
AAdd( aData, {  6, 'Window', 'Alpha', 'Gradient    ' } )
AAdd( aData, {  7, 'Window', 'Alpha', 'Color       ' } )
AAdd( aData, {  8, 'Window', 'Alpha', 'Image- Brush' } )
AAdd( aData, {  9, 'Window', 'Alpha', 'Style- Brush' } )
AAdd( aData, { 10, 'Window', 'Alpha', 'Image       ' } )
AAdd( aData, { 11, 'Dialog', '     ', 'Gradient    ' } ) 
AAdd( aData, { 12, 'Dialog', '     ', 'Color       ' } ) 
AAdd( aData, { 13, 'Dialog', '     ', 'Image- Brush' } ) 
AAdd( aData, { 14, 'Dialog', '     ', 'Style- Brush' } ) 
AAdd( aData, { 15, 'Dialog', '     ', 'Image       ' } ) 
AAdd( aData, { 16, 'Dialog', 'Alpha', 'Gradient    ' } ) 
AAdd( aData, { 17, 'Dialog', 'Alpha', 'Color       ' } ) 
AAdd( aData, { 18, 'Dialog', 'Alpha', 'Image- Brush' } ) 
AAdd( aData, { 19, 'Dialog', 'Alpha', 'Style- Brush' } ) 
AAdd( aData, { 20, 'Dialog', 'Alpha', 'Image       ' } ) 

oBrw := TXBrowse():New( oDlg )
oBrw:SetArray( aData )

oBrw:aCols[ 1 ]:cHeader = Padr("No.", 10)
oBrw:aCols[ 2 ]:cHeader = Padr("Type", 11)
oBrw:aCols[ 3 ]:cHeader = Padr("Alpha", 11)
oBrw:aCols[ 4 ]:cHeader = Padr("Test", 18)

oBrw:nRecSelColor = 15512898 
oBrw:bClrSelFocus = { || { 16777215, 15512898 } } 
oBrw:bClrSel = { || { 16777215, 15512898 } }   // LostFocus

oBrw:nColDividerStyle	 := LINESTYLE_BLACK
oBrw:nRowDividerStyle := LINESTYLE_BLACK
oBrw:nMarqueeStyle := MARQSTYLE_HIGHLROWMS

WITH OBJECT oBrw
      :nTop		:= 10
      :nLeft		:= 20
      :nBottom   := 500
      :nRight	:= 340
END

oBrw:bLClicked := { | nRow, nCol | nArrayPos := oBrw:nRowSel, ;
				                        IIF( nArrayPos < 11, WINDOW(oFont), NIL ), ;
				                        IIF( nArrayPos > 10 , DIALOG(oFont), NIL ) }

oBrw:CreateFromCode()

RETURN NIL


// ------- WINDOW  --------------------------

FUNCTION WINDOW(oFont)
LOCAL oWnd1, hDC, oButton, oImage1, oBmp1, oBar1, oBtn2, oBtn3

// ---- Alpha-BMP -------
// ---------------------------
DEFINE BITMAP oBmp1 FILENAME "A_LOGO.BMP"

DEFINE WINDOW oWnd1 TITLE "Background for Windows"  //   MDI MENU TMenu():New() 

// ImageBrush
// ----------------
IF nArrayPos = 3 .or. nArrayPos = 8
	WB_IMAGE( oWnd1 )
ENDIF

@ 620, 800 BUTTONBMP oButton ;
     SIZE 120, 50 ;
     ACTION oWnd1:End() OF oWnd1 ;
     FONT oFont PIXEL ;     
     BITMAP "Quit.bmp" ;    
     PROMPT "   Exit" TEXTRIGHT

ACTIVATE WINDOW oWnd1 MAXIMIZED ;
ON PAINT ( IIF( nArrayPos = 1 .or. nArrayPos = 6, W_GRAD( hDC, oWnd1 ), NIL ), ;  // Gradient
		    IIF( nArrayPos = 2 .or. nArrayPos = 7, W_COLOR( oWnd1 ), NIL ), ;  // Color
		    IIF( nArrayPos = 4 .or. nArrayPos = 9, W_BRUSH( oWnd1 ), NIL ), ;  // Brush
		    IIF( nArrayPos = 5 .or. nArrayPos = 10, WL_IMAGE( hDC, oWnd1 ), NIL ), ;  // Image
		    IIF( nArrayPos > 5 .and. nArrayPos < 11, W_ALPHA( hDC, oWnd1 ), NIL ) )

RETURN NIL



// ---------- DIALOG  - PREVIEW -------------------------------------

FUNCTION DIALOG(oFont)
LOCAL oDlg5, oButton, oImage1, oBmp1

oProgFont1 := TFont():New("Arial", ,-14,.F.,.F. , , , ,.F. )

DEFINE DIALOG oDlg5 FROM 5, 5 TO 600, 800 TITLE  "Dialog-Test"  PIXEL ;
FONT oProgFont1

@ 250, 320 BUTTONBMP oButton ;
     SIZE 60, 25 ;
     ACTION oDlg5:End() OF oDlg5 ;
     FONT oFont PIXEL ;     
     BITMAP "Quit.bmp" ;    
     PROMPT "   Exit" TEXTRIGHT

// Color
// -------
IF nArrayPos = 12 .or. nArrayPos = 17
	W_COLOR( oDlg5 )   
ENDIF

// ImageBrush
// ----------------
IF nArrayPos = 13 .or. nArrayPos = 18
	WB_IMAGE( oDlg5 ) 
ENDIF

// Style-Brush
IF nArrayPos = 14 .or. nArrayPos = 19
	W_BRUSH( oDlg5 ) 
ENDIF

ACTIVATE DIALOG oDlg5 CENTERED  ;
ON PAINT ( IIF( nArrayPos = 11 .or. nArrayPos = 16, W_GRAD( hDC, oDlg5 ), NIL ), ;  // Gradient
		    IIF( nArrayPos = 15 .or. nArrayPos = 20, WL_IMAGE( hDC, oDlg5 ), NIL ), ;  // Image
		    IIF( nArrayPos > 15, W_ALPHA( hDC, oDlg5 ), NIL ) )

oProgFont1:End()

RETURN(  NIL )

// --------- GRADIENT  --------------------------------------

STATIC FUNCTION W_GRAD( hDC, oWnd )
local oNewbrush

// Gradient Blue / White
// ----------------------------
local aGrad := { { 0.50, 8388608, 16777215 }, ;  
                          { 0.50, 16777215, 8388608 } }         

IF S_FWHVERS < 7.09
	DegradeW ( hDC, oWnd )  
ENDIF
IF S_FWHVERS >= 7.09 .and. S_FWHVERS < 8.07	
	Gradient( hDC, { 0, 0, oWnd:nHeight, oWnd:nWidth }, 8388608, 16777215, .T. )
ENDIF
IF S_FWHVERS >= 8.07
	GradientFill( hDC,  0, 0, oWnd:nHeight, oWnd:nWidth, aGrad, .T. )
ENDIF

RETURN NIL

// --------- COLORS  --------------------------------------

STATIC FUNCTION W_COLOR( oWnd )
local oNewbrush

DEFINE BRUSH oNewBrush COLOR 8388608   // Blue
SET BRUSH OF oWnd TO oNewBrush
RELEASE BRUSH oNewbrush

RETURN NIL

//--------- IMAGE - LOGO ------------------------ 

STATIC FUNCTION WL_IMAGE(  hDC, oWnd ) 
LOCAL oImage1
LOCAL nWidth  := oWnd:nWidth()
LOCAL nHeight := oWnd:nHeight()

// Selected Image
// --------------------
DEFINE IMAGE oImage1 FILENAME "FANTASY.jpg" 
PalBmpDraw( hDC, 0, 0, oImage1:hBitmap, , nWIDTH, nHEIGHT, , .T. ) 

RETURN NIL

//--------- IMAGE - BRUSH ------------------------ 

STATIC FUNCTION WB_IMAGE( oWnd ) 
LOCAL oImage1

DEFINE BRUSH oImage1 FILE "FLOPPY.bmp"
SET BRUSH OF oWnd TO oImage1
RELEASE BRUSH oImage1

RETURN NIL

//-------- STYLE- BRUSH ------------------------- 

STATIC FUNCTION W_BRUSH( oWnd ) 
LOCAL oNewbrush

DEFINE BRUSH oNewBrush  STYLE "BRICKS"   
SET BRUSH OF oWnd TO oNewBrush
RELEASE BRUSH oNewbrush

RETURN NIL

// --------- ALPHA-BMP  --------------------------------------

STATIC FUNCTION W_ALPHA( hDC, oWnd )
LOCAL oBmp1 

DEFINE BITMAP oBmp1 FILENAME "A_LOGO.BMP"
ABPaint( hDC, 50, 50, oBmp1:hBitmap, 220 )

RETURN NIL

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

STATIC FUNCTION DegradeW ( hDC, oWnd ) 

LOCAL nStep , nStepY 
LOCAL oBrush 
LOCAL i, r,g,b 
LOCAL r0,g0,b0 
LOCAL r1, g1, b1 
LOCAL rD, gD, bD 
LOCAL aRect := GETCLIENTRECT( oWnd:hWnd )

nStep  := ( aRect[ 3 ] - aRect[ 1 ] ) 
nStepY := ( aRect[ 3 ] - aRect[ 1 ] ) / nStep 
aRect[ 3 ] = aRect[ 1 ] + nStepY 

r0 := nRGBRed (8388608)   // Blue
g0 := nRGBGreen (8388608) 
b0 := nRGBBlue (8388608) 
r1 := nRGBRed (16777215)  // White
g1 := nRGBGreen (16777215) 
b1 := nRGBBlue (16777215) 
rD := r1-r0 
gD := g1-g0 
bD := b1-b0 

r := 256*rD/Max(nStep,1) 
g := 256*gD/Max(nStep,1) 
b := 256*bD/Max(nStep,1) 

r0*=256 
g0*=256 
b0*=256 

FOR i = 0 TO nStep-1 STEP nStepY 
	r0 += r 
	g0 += g 
	b0 += b 
	DEFINE BRUSH oBrush COLOR nRGB( r0/256, g0/256, b0/256 ) 
	FILLRECT( hDC, aRect, oBrush:hBrush ) 
	RELEASE BRUSH oBrush 

	aRect[ 1 ] += nStepY 
	aRect[ 3 ] += nStepY 
NEXT 

RETURN (nil)


Regards
Uwe :-)
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.

Continue the discussion