|
Post by rogercabo on Oct 20, 2022 18:21:57 GMT 1
Hi, this is my best and easiest mouse over in the history of my programming experience in gfabasic. I like mouse over effects, because makes the application much more modern than without. Or?
A) Add the 3 MOver functions to your code. B) Add the code for the timer
OcxOcx frm1 Timer MOverTimer MOverTimer.Interval = 33 MOverTimer.Enabled = True MOver_INIT_FindAllMouseOverControlsByTag()
C) Select any control and mark with tag="*"
Done.
PS: Or set the tag ="255,100,100" for the mouse over color. But then pass the correct color form the string into MOver_HwndsOverColor%(s)
MOver_HwndsOverColor%(s) = RGB(Random(128) + 127, Random(128) + 127, Random(128) + 127) // delete this if you add the color in the tag New Mouse Over.G32 (5.06 KB)
|
|
|
Post by rogercabo on Oct 21, 2022 17:22:57 GMT 1
Today I tried to pass a string into the control.Tag but it's buggy When passing values into the tag = "255, 0, 0, 255, 255, 255" I get a floating point error when using the Tag property Dim _forms(0) As Control ReDim _forms(App.Forms.Count - 1) // we can read in var Controls only
For Each f In App.Forms Set _forms(i) = f i++ Next
Dim i% = 0, f As Form, c As Control For i = 0 To App.Forms.Count - 1 // read through all forms For Each c In _forms(i).controls if Len(c.tag) <------- Floating point error
When I pass any other string without numbers into it, it works. Would be such a easy idea to pass fore/back color into the control. But gb32 doesn't allow me.
|
|
|
Post by dragonjim on Oct 21, 2022 17:29:17 GMT 1
Hi, At a guess this is due to the way that GFA handles strings in variants - if a string starts with a number, then it is treated as a number. An easy workaround could be to use an f or b prefix before the values to identify Fore and Backcolor; then GFA will read it as a string rather than a number and you should not have an error. For example: "f:255,0,0;b:255,255,255" - the semi-colon marker at the end would allow you to send actual colour values as a single number rather than having to break them up into RGB values.
It would be interesting to change the if Len(c.tag) to Len(Trim(c.tag)) to see what that returns: the Trim will convert the tag into a GFA string (hopefully) but may only return 3 (i.e. the number of characters in 255). Or it may return an error.
|
|
|
Post by rogercabo on Oct 21, 2022 18:32:40 GMT 1
It's totally strange.. Now I got it to work. If I press the first time F5 to run, then gb32 shows another floating error anywhere. When I compile by Compile/Build and OK, then it works as expected with F5.
Further I pass now t$ = c.Tag .. (Before it crashed also)
Here is the new code. I'm totally happy that it works now. If anyone has a better idea to translate "255,0,0,255,255,255" into fore and back color. Please post.. New Mouse Over V2.G32 (8.17 KB)
|
|
|
Post by rogercabo on Oct 21, 2022 23:58:52 GMT 1
New Mouse Over V3.G32 (7.43 KB) Another Demo V3. Just to check that it does not loose track of the mouse over ocx's.
|
|
|
Post by (X) on Oct 22, 2022 0:19:14 GMT 1
Here is a Hex string notation for the tag...
'################################################################################# ' ' DISCLAIMER: THIS CODE IS OFFERED AS IS FOR EDUCATIONAL PURPOSES. ' YOU ARE FREE TO USE, COPY AND DISTRIBUTE. ' THE USE OF THIS CODE IS AT YOUR OWN RISK. ' I ACCEPT NO LIABILITY NOR MAKE ANY CLAIM OF ' CORRECTNESS OR SUITABILITY IN PART OR IN WHOLE. ' '################################################################################# ' ' FILENAME Demo Combine Fore Back Color to Large.G32 ' ' DESCRIPTION Here is a way to store a Fore and Back Colors to & from a tag string. ' Notice that some system colors start with Hex: "8" in the Most Significant Byte ' ' AUTHOR (X) ' EMAIL xman.gb32@gmail.com ' WEBSITE https://gfatrix.proboards.com/ ' STARTED 2022-10-21 ' UPDATED <ISO date> ' ' $ManifestOff $Library "GfaWinX" $Library "UpdateRT" UpdateRuntime
OpenW 1 FontName = "Consolas" FontSize = 16 Ocx Label lbl1 = "test", 500, 300, 500, 30 : .Appearance = 1 lbl1.FontSize = 16
Print " '" Print " ' FILENAME Demo Combine Fore Back Color to Large.G32" Print " '" Print " ' DESCRIPTION Here is a way to store a Fore and Back Colors to & from a tag string." Print " ' Notice that some system colors start with Hex: 8 in the Most Significant Byte" Print " '"
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Save original fore and back colors to a "Large/Int64" hex string... ' Dim oc$ = "$" & Hex(lbl1.ForeColor, 8) & Hex(lbl1.BackColor, 8) Print Print "Original Colors Large Hex:"; oc
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ' Store new fore and back colors... ' Dim fc% = RGB($10, $80, $ff) Dim bc% = RGB($ff, $80, $10) SetForeBack2Tag(lbl1, fc, bc)
Dim n% Print Print "lbl1.ForeColor:"; Hex(lbl1.ForeColor, 8) Print "lbl1.BackColor:"; Hex(lbl1.BackColor, 8)
Print Print "Press any key to continue..." KeyGet n Print Print "Retrieved Fore & Back Colors from Tag..." lbl1.Text = "lbl1.tag:" & lbl1.Tag lbl1.ForeColor = GetForeFromTag(lbl1) lbl1.BackColor = GetBackFromTag(lbl1) Print "lbl1.ForeColor:"; Hex(lbl1.ForeColor, 8) Print "lbl1.BackColor:"; Hex(lbl1.BackColor, 8)
Print Print "Press any key to continue..." KeyGet n Print Print "Retrieved Fore & Back Colors from Tag..." lbl1.Tag = oc lbl1.Text = "lbl1.tag:" & oc lbl1.ForeColor = GetForeFromTag(lbl1) lbl1.BackColor = GetBackFromTag(lbl1) Print "lbl1.ForeColor:"; Hex(GetForeFromTag(lbl1), 8) Print "lbl1.BackColor:"; Hex(GetBackFromTag(lbl1), 8)
Print Print "Done."
Do : Sleep : Until Me Is Nothing
CloseW 1
Proc SetForeBack2Tag(c As Control, fc%, bc%) c.tag = "$" & Hex(fc, 8) + Hex(bc, 8) EndProc
Function GetForeFromTag(c As Control) As Int32 Dim L As Large = CLarge(Val(c.tag)) Return HiLarge(L) EndFunc
Function GetBackFromTag(c As Control) As Int32 Dim L As Large = CLarge(Val(c.tag)) Return LoLarge(L) EndFunc

|
|
|
Post by rogercabo on Oct 22, 2022 11:57:00 GMT 1
Thank you. Cool! A question: If you like to colorize any form or rectangle, do you think of the color in Hex or Dec? My personally imagination of colors is decimal like RGB(0-255, 0-255, 0-255). If I try to imagine the color value $D7CFEA I'm going out of brain ram. But I can imagine the color values 205,47,137 much more better. What is your favorite method?
|
|
|
Post by (X) on Oct 22, 2022 15:00:27 GMT 1
My color intuition is based on decimal or normalized decimal values (0..255)/255 which is normalised to a range of: (0.0 to 1.0)
When I need to analyse what the computer is doing, hex or binary notation is more revealing.
|
|
|
Post by rogercabo on May 18, 2023 12:25:49 GMT 1
New super tiny mouse over demo! // .............................................................................................................................. // ... Tiny Demo for Mouse-Over. Works perfect and does not loose the focus at any time. // ... Simply write fore and back color into the Tag of the control. "255,0,0,255,255,255" // ... // ... How it works: Simply copy the 3 functions into your code. Done! // ... Set the desired control.tag to "255,255,255,255,0,0" (first rgb normal color, 2nd rgb pair mouse over) // ... Timer MOverTimer is required in the main form anywhere to execute Mouse-Over effect. // ... // ... Call the MOver_INIT_FindAllMouseOverControlsByTag(True/False) once to INIT the Mouse-Over effect. // ... (True) displays how many Move Over controls was found! // ... MOver_INIT_FindAllMouseOverControlsByTag searchs through all forms and control-tags if there is anything inside. // ... // ... Then is completely done! You don't have to care about anything no matter how many controls you use in any form. // ..............................................................................................................................
New Mouse Over V4.G32 (7.38 KB)
|
|
|
Post by (X) on May 19, 2023 14:24:55 GMT 1
This is an excellent way to initiate a coder-defined event.
To account for all potential error scenarios, consider incorporating ‘Try … Catch … EndCatch’ statements.
For instance, this can help manage errors that may arise when attempting to modify the ‘.forecolor’ of an image control.
|
|