Draw multi-colored text on the form
Moderator: Rathinagiri
Draw multi-colored text on the form
Hello guys,
There is a small issue with rendering multi-colored text on the form.
You can get this with a Label control for each letter, but that's very inconvenient.
I prepared a new example using the ON PAINT event to draw colorful text without using any labels.
Please see the result in the image below.
Do you think this feature is useful
Your feedback is welcome.
There is a small issue with rendering multi-colored text on the form.
You can get this with a Label control for each letter, but that's very inconvenient.
I prepared a new example using the ON PAINT event to draw colorful text without using any labels.
Please see the result in the image below.
Do you think this feature is useful
Your feedback is welcome.
Kind Regards,
Grigory Filatov
"Everything should be made as simple as possible, but no simpler." Albert Einstein
Grigory Filatov
"Everything should be made as simple as possible, but no simpler." Albert Einstein
- Rathinagiri
- Posts: 5471
- Joined: Tue Jul 29, 2008 6:30 pm
- DBs Used: MariaDB, SQLite, SQLCipher and MySQL
- Location: Sivakasi, India
- Contact:
Re: Draw multi-colored text on the form
That is really nice!
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.
South or North HMG is worth.
...the possibilities are endless.
- serge_girard
- Posts: 3169
- Joined: Sun Nov 25, 2012 2:44 pm
- DBs Used: 1 MySQL - MariaDB
2 DBF - Location: Belgium
- Contact:
Re: Draw multi-colored text on the form
Great !
Serge
Serge
There's nothing you can do that can't be done...
Re: Draw multi-colored text on the form
Thanks for your feedback.
The main logic is below:
Code: Select all
#include "hmg.ch"
#include "i_winuser.ch"
*------------------------------------------------------------------------------*
FUNCTION Main
*------------------------------------------------------------------------------*
LOCAL cText := "MULTI-COLOR TEXT"
LOCAL hFont
hFont := GetFontHandle( "Font_Text" )
IF hFont == 0
DEFINE FONT Font_Text FONTNAME "IMPACT" SIZE 48
ENDIF
hFont := GetFontHandle( "Font_Text" )
SET EVENTS FUNCTION TO App_OnEvents
DEFINE WINDOW Form_Main ;
AT 0, 0 ;
WIDTH 600 HEIGHT 400 ;
TITLE cText ;
MAIN ;
ON SIZE InvalidateRect( This.Handle, 0 ) ;
ON MAXIMIZE InvalidateRect( This.Handle, 0 ) ;
ON PAINT App_OnPaint( This.Handle, hFont, cText )
DEFINE STATUSBAR FONT "Arial" SIZE 12
STATUSITEM "Color Text" BACKCOLOR HMG_n2RGB( GetSysColor( COLOR_GRADIENTINACTIVECAPTION ) )
END STATUSBAR
ON KEY ESCAPE ACTION ThisWindow.Release
END WINDOW
CENTER WINDOW Form_Main
ACTIVATE WINDOW Form_Main
RETURN NIL
#define DT_SINGLELINE 32
#define DT_CALCRECT 1024
*------------------------------------------------------------------------------*
FUNCTION App_OnPaint( hWnd, hFont, cText )
*------------------------------------------------------------------------------*
LOCAL aColors := { ;
METRO_LIME, METRO_GREEN, METRO_EMERALD, METRO_TEAL, METRO_CYAN, ;
METRO_COBALT, METRO_INDIGO, METRO_VIOLET, METRO_PINK, METRO_MAGENTA, ;
METRO_CRIMSON, METRO_RED, METRO_ORANGE, METRO_AMBER, METRO_YELLOW, ;
METRO_BROWN, METRO_OLIVE, METRO_STEEL, METRO_MAUVE, METRO_TAUPE }
LOCAL aRect := { 0, 0, 0, 0 }
LOCAL c, n, hDC, nRight, bk
GetClientRectArea( hWnd, aRect )
// Center Statusbar Text
Form_Main.Statusbar.Item( 1 ) := PadC( "Color Text", aRect[ 4 ] / 4 )
hDC := GetDC( hWnd )
// Center Text
n := DrawTextEx( hDC, cText, aRect, DT_SINGLELINE + DT_CALCRECT, hFont, 0, @nRight )
aRect[ 1 ] += ( aRect[ 3 ] - aRect[ 1 ] - n ) / 2
aRect[ 2 ] += Int( ( aRect[ 4 ] - nRight ) / 2 )
// Paint Text
bk := SetBkMode( hDC, 1 )
FOR n := 1 TO Len( cText )
c := SubStr( cText, n, 1 )
DrawTextEx( hDC, c, aRect, DT_SINGLELINE + DT_CALCRECT, hFont, aColors[ n ], @nRight )
DrawTextEx( hDC, c, aRect, DT_SINGLELINE, hFont, aColors[ n ] )
aRect[ 2 ] := nRight
NEXT
SetBkMode( hDC, bk )
ReleaseDC( hWnd, hDC )
RETURN NIL
- Attachments
-
- demo.zip
- Demo executable
- (913.99 KiB) Downloaded 136 times
Kind Regards,
Grigory Filatov
"Everything should be made as simple as possible, but no simpler." Albert Einstein
Grigory Filatov
"Everything should be made as simple as possible, but no simpler." Albert Einstein
-
- Posts: 273
- Joined: Sat May 18, 2019 2:11 pm
- DBs Used: Visual FoxPro, FoxPro
- Location: United States of America
Re: Draw multi-colored text on the form
Thank you Gregory,
If you decide to provide a complete source code example I would very much like to learn from it.
Thanks again!
Red2
If you decide to provide a complete source code example I would very much like to learn from it.
Thanks again!
Red2
- serge_girard
- Posts: 3169
- Joined: Sun Nov 25, 2012 2:44 pm
- DBs Used: 1 MySQL - MariaDB
2 DBF - Location: Belgium
- Contact:
Re: Draw multi-colored text on the form
Grigory,
Also possible to resize on RESIZE?
Serge
Also possible to resize on RESIZE?
Serge
There's nothing you can do that can't be done...
Re: Draw multi-colored text on the form
Serge,
Yes, sure.
The text will be center-aligned to the height and width of the form's client area.
You can try the demo application above in your environment.
Thanks for your interest.
Kind Regards,
Grigory Filatov
"Everything should be made as simple as possible, but no simpler." Albert Einstein
Grigory Filatov
"Everything should be made as simple as possible, but no simpler." Albert Einstein
Re: Draw multi-colored text on the form
Dear Spencer,
The full source code for this example will be available in the next MiniGUI update.
Thank you for your attention. I really appreciate it.
Kind Regards,
Grigory Filatov
"Everything should be made as simple as possible, but no simpler." Albert Einstein
Grigory Filatov
"Everything should be made as simple as possible, but no simpler." Albert Einstein