Labels and OnMouseHover

HMG Samples and Enhancements

Moderator: Rathinagiri

User avatar
mol
Posts: 3195
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 214 times
Been thanked: 120 times
Contact:

Labels and OnMouseHover

Post by mol » Mon Jun 20, 2016 8:19 am

Hi guys!
I was interested if there is a method to create use interface similar to webpage, where label color is changed on mouse hover.
I want to share small sample which realize this idea.
Thanks to Andyglez for his tip

Code: Select all

// OnMouseHover demo
// 2016.06.20 Marek Olszewski

#include "hmg.ch"

Function Main

	private aLabelColors := { => }
	
	aLabelColors [ "KAFEL1" ] := {100,100,100}
	aLabelColors [ "KAFEL2" ] := {100,200,0}
	aLabelColors [ "KAFEL3" ] := {0,200,200}
	
	// turn off case sensitive hash keys matching
	hb_HCaseMatch(aLabelColors, .F.)
	
	DEFINE WINDOW Form_Main ;
		AT 0,0 ;
		WIDTH 640 HEIGHT 600 ;
		TITLE 'Main Window' ;
		MAIN 

		@ 60,10 LABEL KAFEL1 ;
			WIDTH 200 HEIGHT 200 ;
			VALUE "OPTION 1";
			BACKCOLOR aLabelColors [ "KAFEL1" ];
			CENTERALIGN
			
		@ 60,220 LABEL KAFEL2 ;
			WIDTH 200 HEIGHT 200 ;
			VALUE "OPTION 2";
			BACKCOLOR aLabelColors [ "KAFEL2" ];
			CENTERALIGN
			
		@ 270,220 LABEL KAFEL3 ;
			WIDTH 200 HEIGHT 200 ;
			VALUE "OPTION 3";
			BACKCOLOR aLabelColors [ "KAFEL3" ];
			CENTERALIGN

		@ 270,10 LABEL KAFEL4 ;
			WIDTH 200 HEIGHT 200 ;
			VALUE "STATIC OPTION NOT COLORIZED";
			BACKCOLOR {255,255,255};
			CENTERALIGN

	END WINDOW

	CENTER WINDOW Form_Main

	CREATE EVENT PROCNAME OnMouseHover( EventWPARAM(), "FORM_MAIN" )  HWND Form_Main.Handle
	
	ACTIVATE WINDOW Form_Main

Return 
*---------------------
function OnMouseHover
	param hWnd, cFormName
	
	LOCAL cControl := ""
	LOCAL cForm := ""
	static cPrevious := ""
	
	GetControlNameByHandle( hWnd, @cControl, @cForm )
		
	if empty(cControl)
		if !empty(cPrevious)
			// set oryginal color to previous control
			SetProperty(cFormName, cPrevious, "BackColor",aLabelColors [ cPrevious ])
			//to prevent flickering
			cPrevious := ""
			return
		endif
	endif
	
	// to avoid errors - eliminate changes for absent controls in aLabelColors array
	if HB_HPOS( aLabelColors,  cControl) == 0
		return
	endif

	
	if !empty(cPrevious)
		// to avoid flickering
		if !(cControl == cPrevious)
			SetProperty(cFormName, cPrevious, "BackColor",aLabelColors [ cPrevious ])
		endif
	endif

	SetProperty(cForm, cControl, "BackColor",{255,255,0})
	cPrevious := cControl
return
I was proposed additional feature for LABEL control to Claudio for vertical center align.
In connection with this, It's possible to create interface similar to Windows 10 or www page.
Image

Nice testing!

User avatar
mustafa
Posts: 829
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Been thanked: 117 times
Contact:

Post by mustafa » Mon Jun 20, 2016 9:24 am

Hola amigo Mol:
Felicidades por su aportación
Una pregunta en mi PC Windows 10 Home 64 bits
al compilar me salen la letras en la cabecera
del recuadro.
Como hago para bajarlas más al centro del recuadro.
saludos
*-------------------------------------------------------*
Hello friend Mol:
Congratulations on your contribution
A question on my PC Windows 10 Home 64-bit
when compiling I get the letters in the head
of the box.
As I do to lower them closer to the center of the box.
regards
Mustafa
Attachments
Imagen3.jpg
Imagen3.jpg (39.06 KiB) Viewed 7005 times

User avatar
mol
Posts: 3195
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 214 times
Been thanked: 120 times
Contact:

Post by mol » Mon Jun 20, 2016 9:35 am

Positioning in the middle of label needs modification of hmg h_label.prg and c_label.c library files.
I've duplicated _definelabel funcction to MOL_DefineLabel - sources in attachment.
Attachments
label_SOURCE.ZIP
(4.66 KiB) Downloaded 140 times

User avatar
mustafa
Posts: 829
Joined: Fri Mar 20, 2009 11:38 am
DBs Used: DBF
Location: Alicante - Spain
Been thanked: 117 times
Contact:

Post by mustafa » Mon Jun 20, 2016 9:46 am

OK, thanks

Regards

User avatar
mol
Posts: 3195
Joined: Thu Sep 11, 2008 5:31 am
Location: Myszków, Poland
Has thanked: 214 times
Been thanked: 120 times
Contact:

Post by mol » Mon Jun 20, 2016 9:53 am

Code: Select all

MOL_DefineLabel("KAFEL3","Form_Main", 220, 270, "My option nr 3", 200, 200,;
						"ARIAL",14, .t., .F., .T.,;
						.f., .f., .f., aLabelColors [ "KAFEL3" ], {64,64,64},;
						NIL,"kafel 3",NIL, .f., .f.,;
						.f., .f., .f. , .F. , .t. ,;
						.f.,.F.,.T.)
Last parameter causes center vertical alignment.
It's important - label defined with center vertical alignment does not supports word wrapping.

User avatar
serge_girard
Posts: 2310
Joined: Sun Nov 25, 2012 2:44 pm
DBs Used: 1 MySQL - MariaDB
2 DBF
Location: Belgium
Has thanked: 554 times
Been thanked: 116 times
Contact:

Post by serge_girard » Mon Jun 20, 2016 11:17 am

Thanks Marek !

Serge

User avatar
Rathinagiri
Posts: 5263
Joined: Tue Jul 29, 2008 6:30 pm
DBs Used: MariaDB, SQLite, SQLCipher and MySQL
Location: Sivakasi, India
Has thanked: 169 times
Been thanked: 172 times
Contact:

Post by Rathinagiri » Mon Jun 20, 2016 11:52 am

Nice addition. I think we can include this in the next version.
East or West HMG is the Best.
South or North HMG is worth.
...the possibilities are endless.

User avatar
bpd2000
Posts: 1074
Joined: Sat Sep 10, 2011 4:07 am
Location: India
Has thanked: 196 times
Been thanked: 95 times

Post by bpd2000 » Mon Jun 20, 2016 12:29 pm

Rathinagiri wrote:Nice addition. I think we can include this in the next version.
+1
BPD
Convert Dream into Reality through HMG

User avatar
danielmaximiliano
Posts: 2117
Joined: Fri Apr 09, 2010 4:53 pm
Location: Argentina
Has thanked: 144 times
Been thanked: 20 times
Contact:

Post by danielmaximiliano » Mon Jun 20, 2016 6:01 pm

Gracias por compartir Mol !!!!
*´¨)
¸.·´¸.·*´¨) ¸.·*¨)
(¸.·´. (¸.·` *
.·`.HMG : It's magic !
(¸.·``··*

Saludos / Regards
DaNiElMaXiMiLiAnO

Whatsapp. : +54901169026142
Telegram Name : DaNiElMaXiMiLiAnO

trmpluym
Posts: 245
Joined: Tue Jul 15, 2014 6:52 pm
Location: The Netherlands
Has thanked: 6 times
Been thanked: 22 times

Post by trmpluym » Sun Nov 20, 2016 2:55 pm

Rathinagiri wrote:Nice addition. I think we can include this in the next version.
Would be nice !

Post Reply