I have always had problems with transparency using Ownerdraw.
Here is a sample program I wrote that would show how to create a dialog window using XbpStatic() and ownerdraw.
The idea is to create a modal dialog with a gradient filled title bar and rounded edges.
I'm having problems with background transparency on the edges. Any ideas?
Code: Select all
#INCLUDE "dcdialog.CH"
#INCLUDE "appevent.CH"
FUNCTION Main()
LOCAL oStatic, mp1, mp2, oXbp, nEvent, oDlg
oDlg := XbpDialog():new(,,{100,100},{200,200})
oDlg:border := XBPDLG_NO_BORDER
oDlg:titleBar := .f.
oDlg:drawingArea:colorBG := XBPSYSCLR_TRANSPARENT
oDlg:create()
oStatic := CustomStatic():new( oDlg:drawingArea,,{0,0},oDlg:drawingArea:currentSize())
oStatic:drawMode := XBP_DRAW_OWNER
oStatic:radius := 20
oStatic:create()
oStatic:setColorBG(XBPSYSCLR_TRANSPARENT)
oStatic:lbDown := {|a,b,c|DC_MoveParentWindow(a,b,c)}
oStatic:show()
DO WHILE .t.
nEvent := AppEvent(@mp1,@mp2,@oXbp,.1)
IF nEvent > 0
oXbp:handleEvent(nEvent,mp1,mp2)
ENDIF
IF nEvent == xbeP_Keyboard .AND. mp1 == xbeK_ESC
EXIT
ENDIF
ENDDO
RETURN nil
PROC appsys ; return
* ------------
CLASS CustomStatic FROM XbpStatic
EXPORTED:
VAR titleColor
VAR titleHeight
VAR fillColor
VAR radius
VAR gradientStep
VAR titleCaption
INLINE METHOD Init(a,b,c,d,e,f,g,h)
::titleColor := { 200, 200, 200 }
::titleHeight := 30
::fillColor := { 200, 245, 245 }
::radius := 20
::gradientStep := 2
::titleCaption := 'Testing'
::XbpStatic:init(a,b,c,d,e,f,g,h)
RETURN self
INLINE METHOD Draw( oPS, aInfo )
LOCAL aStringAttr, i, oFont, aPos, aRect, aSize, nTmp
LOCAL aColors, nColor
LOCAL aStartPos := {aInfo[4][1],aInfo[4][2]}
LOCAL aEndPos := {aInfo[4][3],aInfo[4][4]}
LOCAL aStartPosSave, aEndPosSave
LOCAL aAttrArea := Array(GRA_AA_COUNT)
aColors := AClone(::titleColor)
aStartPosSave := AClone(aStartPos)
aEndPosSave := AClone(aEndPos)
FOR i := 1 TO ::titleHeight
aColors[1] += ::gradientStep
aColors[2] += ::gradientStep
aColors[3] += ::gradientStep
GraSetColor( oPS, GraMakeRGBColor(aColors), XBPSYSCLR_TRANSPARENT )
GraBox( oPS, aStartPos, aEndPos, GRA_OUTLINEFILL, ::radius, ::radius )
aStartPos[2]++
aEndPos[2]--
NEXT
aStartPos := aStartPosSave
aEndPos := aEndPosSave
aEndPos[2] -= ::titleHeight
GraSetColor( oPS, GraMakeRGBColor( ::fillColor ), XBPSYSCLR_TRANSPARENT )
GraBox( oPS, aStartPos, aEndPos, GRA_OUTLINEFILL, ::radius, ::radius)
aStartPos[2] += ::titleHeight
GraBox( oPS, aStartPos, aEndPos, GRA_OUTLINEFILL, 0, 0)
aStringAttr := Array( GRA_AS_COUNT )
aStringAttr[GRA_AS_COLOR] := GRA_CLR_BLACK
aStringAttr[GRA_AS_VERTALIGN] := GRA_VALIGN_TOP
GraSetAttrString( oPS, aStringAttr )
aSize := ::CurrentSize()
aPos := {40,::CurrentSize()[2]-::titleHeight/2+10}
GraPos( oPS, aPos )
GraStringAt( oPS,,::titleCaption )
RETURN self
ENDCLASS