xsharp.eu • Gradient Fill on VOGUI ShellWindow
Page 1 of 1

Gradient Fill on VOGUI ShellWindow

Posted: Mon Nov 07, 2022 6:59 am
by Chris
Hi all,

I received a request about providing a way to draw a VOGUI ShellWindow background with a gradient text, similar to XIDE's background. Of course XIDE uses windows forms and GDI+, but to my surprise the same code (almost) works for the VOGUI, too, see below. Only problem is that unfortunately the Expose() callback seems not to be called when moving a window over the shell window, so the text is not being redrawn in this case. Now it's been a lot of years since I last dealt with similar things in the VOGUI, and before I spend too much time looking into this, maybe one of you VOGUI/Win32 gurus can have a quick look and adjust the following code to make it work better?

Code: Select all

METHOD Expose(oExposeEvent) // CLASS StandardShellWindow
	SUPER:Expose(oExposeEvent)
	SELF:DrawGradient()
RETURN NIL

METHOD DrawGradient() AS VOID
	LOCAL cText := "Text to print" AS STRING
	
	LOCAL oFont AS System.Drawing.Font
	oFont := System.Drawing.Font{"Arial" , REAL4(SELF:Size:Width/9.0) , System.Drawing.FontStyle.Bold}

	LOCAL oSF AS System.Drawing.StringFormat
	oSF := System.Drawing.StringFormat{}
	oSF:LineAlignment:= System.Drawing.StringAlignment.Center
	oSF:Alignment := System.Drawing.StringAlignment.Center
	
	LOCAL oBrush AS System.Drawing.Brush
	oBrush := System.Drawing.Drawing2D.LinearGradientBrush{System.Drawing.Point{0,0} , System.Drawing.Point{SELF:Size:Width,SELF:Size:Height} , System.Drawing.Color.Blue , System.Drawing.Color.Yellow}

	LOCAL oRect AS System.Drawing.Rectangle
	oRect := System.Drawing.Rectangle{3 , 3 , SELF:Size:Width , SELF:Size:Height}

	LOCAL g AS System.Drawing.Graphics
	g := System.Drawing.Graphics.FromHwnd(SELF:Handle(4))
	g:DrawString(cText , oFont , System.Drawing.Brushes.Gray , oRect , oSF) // this is for the "shadow"
	oRect := System.Drawing.Rectangle{0 , 0 , SELF:Size:Width , SELF:Size:Height}
	g:DrawString(cText , oFont , oBrush , oRect , oSF)
	g:Dispose()
RETURN

Gradient Fill on VOGUI ShellWindow

Posted: Mon Nov 07, 2022 7:44 am
by ecos
Hi Chris,
things are not so easy with the VO-GUI... You can't simply call your drawing stuff from the expose-method. I attach a simple example how this can be done. Hope this helps a little...

Karl

Gradient Fill on VOGUI ShellWindow

Posted: Mon Nov 07, 2022 4:10 pm
by Chris
Hi Karl,

Thanks a lot, looking good! Although it also has some problems when resizing, like when making it half size so the text is half visible and then enlarge it again. After that, also moving a window over the shell, does not repaint the background.

Gradient Fill on VOGUI ShellWindow

Posted: Tue Nov 08, 2022 7:22 am
by ecos
Same behaviour here in my x#-application. Vo-application works fine for many, many years.

This should help:

Code: Select all

METHOD dispatch(uEvent)	// class StandardShellWindow
LOCAL liRt		AS INT
LOCAL oEvent	AS @@Event

oEvent	:= uEvent

DO CASE

CASE oEvent:message = WM_PAINT
	SELF:BkPaint(SELF:handle(4))	
	liRt := SUPER:dispatch(oEvent)


OTHERWISE
	liRt := SUPER:dispatch(oEvent)
ENDCASE

RETURN liRt