MultiTrackBarGadget Version 0.7 (Windows+Linux)

Share your advanced PureBasic knowledge/code with the community.
Oma
Enthusiast
Enthusiast
Posts: 312
Joined: Thu Jun 26, 2014 9:17 am
Location: Germany

Re: MultiTrackBarGadget (Windows)

Post by Oma »

Hi Richard,

thanks for your rework.
With a color definition for Linux like

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_Linux
	#Red   = $0000FF
	#Green = $008000
	#Cyan  = $FFFF00
	#Yellow= $00FFFF
	#White = $FFFFFF
	#Black = $0
CompilerEndIf
and a replacement within MTrack_Service()

Code: Select all

            CompilerIf #PB_Compiler_OS = #PB_OS_Windows
               beep_(2500,50)
            CompilerElseIf #PB_Compiler_OS = #PB_OS_Linux
               RunProgram("beep", "-f 2500 -l 50", ""); 'beep' must be installed on Linux
            CompilerEndIf
it works fine on Linux.
But the line

Code: Select all

\MT_Win    = GetActiveWindow()
stays explosive if an external window (like the PB debugger window ) got the 'keep on top'-flag. In this case you get a -1 for the ActiveWindow.

Best Regards, Charly
PureBasic 5.4-5.7, Linux: (X/L/K)Ubuntus+Mint - Windows XP (32Bit)
PureBasic Linux-API-Library & Viewer: http://www.chabba.de
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Re: MultiTrackBarGadget (Windows)

Post by RichardL »

Good morning to all bar sliders,

MTrackBarGadget() now has a progress bar style, which includes a percentage indication incorporated into the display.
I will replace the code in the first post in a few minutes....

@Oma
Thank you for your Linux tweeks, I have now incorporated them into the development version.

And thank you for your comment regarding GetActiveWindow().
The safest way for me to find the window the gadget is being created in would be to pass the window number to MTrackBarGadget() as a parameter.
I did not want to do this because I would rather follow the convention / format of PB's own gadgets. (GadNum,X,Y,W,H etc)
I assumed that when gadgets were being created on a window GetActiveWindow() would return the number of the Window in which the gadgets were being written. This seems to be unreliable in Linux, can anyone please assist?

Regards
RichardL
Oma
Enthusiast
Enthusiast
Posts: 312
Joined: Thu Jun 26, 2014 9:17 am
Location: Germany

Re: MultiTrackBarGadget Version 0.5 (Windows+Linux)

Post by Oma »

Hi Richard,
i've tried your code again on Linux and got 3 problems:
- The new color #Blue is missing in Linux.
- You reactivated the Windows-beep_() again. However, the code for Linux is missing.
- You reactivated the SetCursorPos_(MX,MY) again but the Linux part is missing.

Again, change the header part to this ...

Code: Select all

CompilerIf #PB_Compiler_OS = #PB_OS_Linux
		ImportC ""
			gdk_device_manager_get_client_pointer(*device_manager);                 Gtk3
			gdk_device_warp(*device.GdkDevice, *screen.GdkScreen, x, y);            Gtk3
			gdk_display_get_default()
			gdk_display_get_device_manager(*display.GdkDisplay);                    Gtk3
			gdk_display_warp_pointer(*display.GdkDisplay, *screen.GdkScreen, x, y); Gtk2
			gdk_screen_get_default()
		EndImport
		#Red   = $0000FF
		#Green = $008000
		#Cyan  = $FFFF00
		#Yellow= $00FFFF
		#White = $FFFFFF
		#Black = $0
		#Blue  = $FF0000
	CompilerEndIf
Add this instead of your beep_()-part:

Code: Select all

	CompilerIf #PB_Compiler_OS = #PB_OS_Windows
		beep_(2500,50)
	CompilerElseIf #PB_Compiler_OS = #PB_OS_Linux
		RunProgram("beep", "-f 2500 -l 50", ""); 'beep' must be installed on Linux
	CompilerEndIf
Add this instead of your SetCursorPos_(MX,MY)-part:

Code: Select all

	CompilerIf #PB_Compiler_OS = #PB_OS_Windows
		SetCursorPos_(MX,MY)
	CompilerElseIf #PB_Compiler_OS = #PB_OS_Linux
	  gdk_display_warp_pointer(gdk_display_get_default (), gdk_screen_get_default(), MX, MY);  Gtk2, officialy deprecated
	;-> replace the line above with the following line, if 'gdk_display_warp_pointer' is finally deprecated on newer gtk3-systems...
	;  gdk_device_warp (gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gdk_display_get_default ())), gdk_screen_get_default(), MX, MY)
	CompilerEndIf
...This seems to be unreliable in Linux...
I think some Linux window managers don't be in hurry to give the focus to the window at opening, and this could be the problem. If you want to see the error that occasionally happens on Linux, then change ...

Code: Select all

OpenWindow(1,0,0,600,380,"MultiBar_Test Rev 0.3", #PB_Window_ScreenCentered|#PB_Window_SystemMenu)
;to ...
OpenWindow(1,0,0,600,380,"MultiBar_Test Rev 0.3", #PB_Window_ScreenCentered|#PB_Window_NoActivate|#PB_Window_SystemMenu)
and eventually disable the following line ...
;SetActiveWindow(1)

Probably this shows on Windows what occasionally happens on Linux (don't tried it on Windows).
I think the most solid alternative would be an additional 'window'-parameter in MTrackBarGadget()
Thus, the reliable operation no longer depends on how the user applies the MTrackBarGadget and and he no longer needs to force the window focus.

Best Regards, Charly
PureBasic 5.4-5.7, Linux: (X/L/K)Ubuntus+Mint - Windows XP (32Bit)
PureBasic Linux-API-Library & Viewer: http://www.chabba.de
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Re: MultiTrackBarGadget Version 0.5 (Windows+Linux)

Post by RichardL »

Good Morning All,
@Oma
Thank you for your comments, I have included your kind suggestions in the most recent version.

@All
The code in the first posting has been updated to include some new features and includes Oma's suggestions to make it Linux compatible.

Anyone for OSX?

RichardL
davido
Addict
Addict
Posts: 1890
Joined: Fri Nov 09, 2012 11:04 pm
Location: Uttoxeter, UK

Re: MultiTrackBarGadget Version 0.6 (Windows+Linux)

Post by davido »

@RichardL,

Thank you for a great gadget!
I have been using it on my MacBook Pro since version ~0.2.
All I did was to remove the API dependent bits you pointed out.
I did, however, include the colour definitions by oma.

All I can say is that it just works. So far I have had no problems. Of course, I don't have the benefit of the bell. That is not a problem as I would not want it anyway.
In fact when I am certain I will use it to replace my own version as yours is superior.

The code that runs on the Mac also runs on Windows 10 - and again I see no difference.

The difference is obviously too subtle for me!
DE AA EB
Oma
Enthusiast
Enthusiast
Posts: 312
Joined: Thu Jun 26, 2014 9:17 am
Location: Germany

Re: MultiTrackBarGadget Version 0.6 (Windows+Linux)

Post by Oma »

Hello Richard.

It is looking good and now it works on Linux, with 1 exception: the Windows 'beep_()' isn't compatible (but also not really necessary :wink: ). Thank you!

Best Regards, Charly
PureBasic 5.4-5.7, Linux: (X/L/K)Ubuntus+Mint - Windows XP (32Bit)
PureBasic Linux-API-Library & Viewer: http://www.chabba.de
RichardL
Enthusiast
Enthusiast
Posts: 532
Joined: Sat Sep 11, 2004 11:54 am
Location: UK

Re: MultiTrackBarGadget Version 0.7 (Windows+Linux)

Post by RichardL »

Good morning,
Fairly major update... see Rev0.7 in first posting.
Regards to all
RichardL
mestnyi
Addict
Addict
Posts: 1098
Joined: Mon Nov 25, 2013 6:41 am

Re: MultiTrackBarGadget Version 0.7 (Windows+Linux)

Post by mestnyi »

Is not that supposed to be?

Code: Select all

Procedure SetGadgetMouseXY(Gadget,MX,MY)       ; Position mouse pointer at specified co-ordinated within a gadget
  MX + GadgetX(Gadget, #PB_Gadget_ScreenCoordinate) 
  MY + GadgetY(Gadget, #PB_Gadget_ScreenCoordinate)
  
  CompilerIf #PB_Compiler_OS = #PB_OS_Windows
    SetCursorPos_(MX,MY)
    CompilerElseIf #PB_Compiler_OS = #PB_OS_Linux
    gdk_display_warp_pointer(gdk_display_get_default (), gdk_screen_get_default(), MX, MY);  Gtk2, officialy deprecated
    ;-> replace the line above with the following line, if 'gdk_display_warp_pointer' is finally deprecated on newer gtk3-systems...
    ;  gdk_device_warp (gdk_device_manager_get_client_pointer(gdk_display_get_device_manager(gdk_display_get_default ())), gdk_screen_get_default(), MX, MY)
  CompilerEndIf
  
EndProcedure
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: MultiTrackBarGadget Version 0.7 (Windows+Linux)

Post by Psychophanta »

Nice collection of trackbars.
I have been looking for a workaround to make the trackbar cursor to return to a given position after it is unholded by the mouse.
At the moment no success to perform it nicely.
I will continue searching a way to do it, but I guess there is no way to do it elegantly, and for all platforms. :|

For example this tip shows 2 trackbars; the left one is just a value, and the right one is to fine-tune that value.
The nice behaviour would be a smooth return to the middle in the fine-tuning track bar.

Code: Select all

OpenWindow(0,100,100,45,200,"")
StringGadget(1,50,20,60,20,"",#PB_Text_Center)
TrackBarGadget(2,4,5,20,180,0,100,#PB_TrackBar_Vertical)
TrackBarGadget(3,24,5,20,180,0,100,#PB_TrackBar_Vertical):GadgetToolTip(3,"salida 1 ajuste fino")
SetGadgetState(3,50)
s1.d
Repeat
  If 0=EventWindow()
    evento=WaitWindowEvent()
    Select evento
    Case #PB_Event_Gadget
      Select EventGadget()
      Case 2
        s1=GetGadgetState(2)
        SetGadgetText(1,StrD(s1))
        GadgetToolTip(2,StrD(s1))
      Case 3
        Repeat
          evento=WaitWindowEvent(100)
          valor.d=GetGadgetState(3)/100-0.5
          GadgetToolTip(3,StrD(valor,4))
          s1+valor
          SetGadgetText(1,StrD(s1))
          SetGadgetState(2,s1)
          GadgetToolTip(2,StrD(s1))
        Until evento<>#PB_Event_GadgetDrop Or evento<>#PB_Event_LeftClick Or evento<>#PB_Event_Gadget Or evento<>#PB_Event_WindowDrop
        evento=WaitWindowEvent()
        If evento<>#PB_Event_Gadget:SetGadgetState(3,50):EndIf
      EndSelect
    EndSelect
  EndIf
Until evento=#PB_Event_CloseWindow
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Post Reply