Gradient Fill on VOGUI ShellWindow

This forum is meant for questions and discussions about the X# language and tools
Post Reply
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Gradient Fill on VOGUI ShellWindow

Post 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
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
ecos
Posts: 91
Joined: Tue Nov 10, 2015 6:49 am

Gradient Fill on VOGUI ShellWindow

Post 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
Attachments
VOMDIApp2.zip
(2.65 MiB) Downloaded 36 times
User avatar
Chris
Posts: 4562
Joined: Thu Oct 08, 2015 7:48 am
Location: Greece

Gradient Fill on VOGUI ShellWindow

Post 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.
Chris Pyrgas

XSharp Development Team test
chris(at)xsharp.eu
ecos
Posts: 91
Joined: Tue Nov 10, 2015 6:49 am

Gradient Fill on VOGUI ShellWindow

Post 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
Post Reply