I've recently had to insert showcursor(1) into some code to get the mouse cursor to show in a window. Earlier I had used showcursor(0) to hide it, but have now removed showcursor(0) from the code.
It's no problem to include showcursor(1), but I would prefer not, to unless I can understand why it's needed.
Any pointers would be much appreciated.
Thanks
Why do I need to use showcursor()?
Re: Why do I need to use showcursor()?
Where is your code?shaker wrote:into some code to get the mouse cursor to show in a window
How should we help without the code? I think it is a problem with your eventloop but without
see anythink, i can't help.
I have never required any ShowCursor_(1)
greetings
Thomas
-
UserOfPure
- Enthusiast

- Posts: 469
- Joined: Sun Mar 16, 2008 9:18 am
Re: Why do I need to use showcursor()?
There must be a ShowCursor(0) somewhere still. That's the only logical explanation.
Re: Why do I need to use showcursor()?
I hope this comes correctly formatted.
Code: Select all
;Principles
;========
;Redraw everything for every cycle
;Only draw and flipbuffer once per cycle
;Random unit arrival in queue
;Random service speed (inverse of difficulty) for each unit
;No of allocated service points determined by corresponding F keys
;If active servers become non-allocated, they are allowed to finish units they are serving
;Preliminaries
;==========
;code
Enumeration
#ParameterContainer
#cmdOK
EndEnumeration
;Set the width, height and bit depth of the screen
Global ScrW.l = 1024
Global ScrH.l = 768
Global ScrD.l = 32
Global Quit.b = #False
Global QLength, Dim UnitBeingServed(6), Dim Servicing(6),Dim ServiceProgress(6),Dim ServiceSpeed(6),Quit,Pause,FullDisplay
Global RequiredServers=6, ActiveServers = 6,cnt1,cnt2,LastUnitServed,StartTime,RunStartTime,cnt3,ReadyToEnd = 1,Event
Global W=50,H=60,FloorLevel = 500, Dim AboveFloorLevel(6),ServPtX = 700,cycle,DisplayGraphics,ShowFinalStatistics
Declare UserInput()
Declare DrawQ()
Declare DrawServicePoints()
Declare GenerateStats()
Declare Initialise()
Declare HandleError(Result.l,Text.s)
Declare UpdateDisplay()
Declare DrawServers()
;Set up Sprite, Keyboard, Screen)
HandleError(InitSprite(), "InitSprite() command failed.")
HandleError(InitKeyboard(), "InitKeyboard() command failed.")
HandleError(OpenScreen(ScrW, ScrH, ScrD, "Blobs"), "Could not open screen.")
;set vert posns of service points
For cnt1 = 1 To 6
AboveFloorLevel(cnt1) = 80*(cnt1-1)
Next
LoadFont(1, "Arial", 10,#PB_Font_Bold)
RandomSeed(1)
;***Note*** "SetFrameRate(60)" not needed as other code gives constant cycle time
StartTime = ElapsedMilliseconds()
RunStartTime = ElapsedMilliseconds()
QLength = 1
DisplayGraphics=1
OpenWindow(0, 0, 0, 1024, 710, "QueueServe", #PB_Window_SystemMenu );| #PB_Window_ScreenCentered)
;OpenWindow(0, 0, 0, 1024, 710, "QueueServe",#PB_Window_BorderLess| #PB_Window_Maximize );| #PB_Window_ScreenCentered)
ContainerGadget(#ParameterContainer, 300, 200, 400, 400,#PB_Container_Raised)
ButtonGadget(#cmdOK,200, 200, 80, 24, "OK")
CloseGadgetList()
ShowCursor_(1)
Repeat
Event =WaitWindowEvent()
Select Event
Case #PB_Event_Gadget
Select EventGadget()
Case #cmdOK
Quit = 1
EndSelect
EndSelect
Until Quit = 1
OpenWindowedScreen(WindowID(0), 30, 30, 960, 650, 0,30,30)
;endcode
;Show first unit in Q
;==============
;code
If DisplayGraphics = #True
StartDrawing(ScreenOutput()) :DrawingFont(FontID(1)):BackColor(RGB(220,220,220)) :Box(1,1,958,648,RGB(220,220,220))
DrawServicePoints()
Box(600-H ,FloorLevel,W,H, RGB(0,0,0))
Box(600-H+1 ,FloorLevel+1,W-2,H-2, RGB(248,248,245))
;DrawText(600+25-1*H,FloorLevel-20,Str(LastUnitServed+1))
DrawText(770,530,"Queue Length = "+Str(QLength))
DrawText( 5,580,"<-<---------------------------------------------- Q U E U E ---------------------------------------------->")
Box(2,2,901,50, RGB(0,0,0) )
Box(2+1,2+1,901-2,50-2, $FFFFFF )
GenerateStats()
BackColor($FFFFFF)
DrawText(10,20,"KEY INPUTS: F1 to F6 = No. of Servers Allocated 1st Esc = Stop 2nd Esc = Close P = toggle Pause On/Off")
StopDrawing() : FlipBuffers()
EndIf
Delay(1000)
;endcode
;Main Cycle
;========
Repeat
Event = EventWindow()
;pause
If Pause = #True ;(31)
Repeat ;(31)
UserInput() ;(31)
Until Pause = #False ;(31)
EndIf :;31)
cycle = cycle+1
If (ElapsedMilliseconds()-StartTime)>MaxProcessTime ;(23)
MaxProcessTime = (ElapsedMilliseconds()-StartTime) ;(23)
EndIf
;Debug (ElapsedMilliseconds()-StartTime)
;Debug MaxProcessTime
;Give constant cycle time (to correct different process times)
;=============================================
;ensure min cycle time of 200, and accept longer cycle times when required by processing.
;(nearest I can get to constant cycle time without making it the longest (300+) which could be encountered and so slowing display)
If DisplayGraphics = #True
If ElapsedMilliseconds()-StartTime<400
Delay (400-(ElapsedMilliseconds()-StartTime))
EndIf
EndIf
StartTime=ElapsedMilliseconds()
;Increment Q siDisplayGraphicse randomly
;===================
Result = Random(5) ;for match of supply and demand, needs to match no of cycles for servicing
If Result = 1
QLength= QLength+1
EndIf
;Allow unrequired Server to finish serving before making inactive
;===============================================
If ActiveServers>RequiredServers
If Servicing(ActiveServers) = 0 ;if server to be shut down is not serving
ActiveServers = ActiveServers-1
EndIf
EndIf
;Activate extra Servers
;=================
If ActiveServers<RequiredServers
ActiveServers = ActiveServers+(RequiredServers-ActiveServers)
EndIf
UpdateDisplay()
;Get any User inputs including "end" key
;=============================
UserInput()
Until ShowFinalStatistics = #True
StartDrawing(ScreenOutput()) :DrawingFont(FontID(1)):BackColor(RGB(220,220,220)) :Box(1,1,958,648,RGB(220,220,220))
Box(2,2,901,50, RGB(0,0,0) )
Box(2+1,2+1,901-2,50-2, $FFFFFF )
GenerateStats()
BackColor($FFFFFF)
DrawText(10,20,"KEY INPUTS: F1 to F6 = No. of Servers Allocated 1st Esc = Stop 2nd Esc = Close P = toggle Pause On/Off")
StopDrawing() :FlipBuffers()
Repeat
UserInput()
Until Quit = #True
End
;===============================================================================================
Procedure DrawQ()
If DisplayGraphics = #True
;Box(0,0,1024,768,$FFFFFF);white background
DrawText(770,530,"Queue Length = "+Str(QLength))
If QLength>0
For cnt3 = 1 To QLength
Box(600-cnt3*(W+9),FloorLevel,W,H, RGB(0,0,0))
Box(600-cnt3*(W+9)+1 ,FloorLevel+1,W-2,H-2, RGB(248,248,245))
DrawText(600+19-cnt3*(W+9),FloorLevel-18,Str(cnt3+LastUnitServed ))
Next
EndIf
EndIf
EndProcedure
Procedure DrawServers()
If DisplayGraphics = #True
If Servicing(cnt2) = 1
;draw unit in position for servicing
Box(ServPtX,FloorLevel-AboveFloorLevel(cnt2),W,H,RGB(0,0,0)) ;1
Box(ServPtX+1,FloorLevel-AboveFloorLevel(cnt2)+1,W-2,H-2,RGB(127,255,0))
BackColor(RGB(220,220,220))
DrawText(720,FloorLevel-18-AboveFloorLevel(cnt2),Str( UnitBeingServed(cnt2)))
;show service progress
If ServiceProgress(cnt2)<=H And ServiceProgress(cnt2)<>0 ;(14)
Box(ServPtX, FloorLevel+H - ServiceProgress(cnt2)-AboveFloorLevel(cnt2), W, ServiceProgress(cnt2), RGB(0,0,0)) ;1
Box(ServPtX+1, FloorLevel+1+H - ServiceProgress(cnt2)-AboveFloorLevel(cnt2), W-2, ServiceProgress(cnt2)-2, RGB(100,100,255))
EndIf
DrawQ()
EndIf
EndIf
EndProcedure
Procedure DrawServicePoints()
If DisplayGraphics = #True
DrawText(770,510,"Allocated Servers = "+Str(RequiredServers))
For cnt3 = 1 To 6
If cnt3<=RequiredServers Or Servicing(cnt3) = 1 ;if active server or servicing, black outline
Box(ServPtX,FloorLevel-AboveFloorLevel(cnt3),W,H, RGB(0,0,0))
Else ;server not active
Box(ServPtX,FloorLevel-AboveFloorLevel(cnt3),W,H, RGB(211,211,211)) ;faint outline servers if not active
EndIf
Box(ServPtX+1,FloorLevel-AboveFloorLevel(cnt3)+1,W-2,H-2,$FFFFFF) ;white inside unit
Next
EndIf
EndProcedure
Procedure GenerateStats()
If DisplayGraphics = #True
cnt3 = 0
DrawText(30,95+cnt3,"No. of units served = "+Str(LastUnitServed))
cnt3 = cnt3 + 25
DrawText(30,95+cnt3,"Av. time between arrivals = "+Str(0))
cnt3 = cnt3 + 25
DrawText(30,95+cnt3,"Av. time between arrivals = "+Str(0))
cnt3 = cnt3 + 25
DrawText(30,95+cnt3,"Av. time between arrivals = "+Str(0))
cnt3 = cnt3 + 25
DrawText(30,95+cnt3,"Av. time between arrivals = "+Str(0))
cnt3 = cnt3 + 25
DrawText(30,95+cnt3,"Av. time between arrivals = "+Str(0))
cnt3 = cnt3 + 25
DrawText(30,95+cnt3,"Av. time between arrivals = "+Str(0))
EndIf
EndProcedure
Procedure HandleError(Result.l, Text.s)
If Result = 0
MessageRequester("Error", Text, #PB_MessageRequester_Ok)
End
EndIf
EndProcedure
Procedure UpdateDisplay()
For cnt1 = 1 To ActiveServers
If DisplayGraphics = #True
;Redraw Q, Servers, Stats, Labels As at End of last cycle
;==================================
StartDrawing(ScreenOutput()) :DrawingFont(FontID(1)):BackColor(RGB(220,220,220)) :Box(1,1,958,648,RGB(220,220,220))
DrawQ()
DrawServicePoints()
GenerateStats()
DrawText( 5,580,"<-<---------------------------------------------- Q U E U E ---------------------------------------------->")
Box(2,2,901,50, RGB(0,0,0) )
Box(2+1,2+1,901-2,50-2, $FFFFFF )
BackColor($FFFFFF)
DrawText(10,20,"KEY INPUTS: F1 to F6 = No. of Servers Allocated 1st Esc = Stop 2nd Esc = Close P = toggle Pause On/Off")
EndIf
;If situation has changed, update parameters
;===============================
;If there is Q And current service point is free, adjust parameters to reflect that serving will occur
If Servicing(cnt1) = 0 And QLength >0 And cnt1<=RequiredServers;(4,5,6,26)
Delay(500) ;show new arrival in Q briefly when it can be served immediately
Servicing(cnt1) = 1
QLength =QLength -1
UnitBeingServed(cnt1) = LastUnitServed+1
LastUnitServed = UnitBeingServed(cnt1)
Result = Random(4)
ServiceSpeed(cnt1) = Result +1 ;(28) assign random service speed for each unit I
EndIf
If Servicing(cnt1) = 1
If ServiceProgress(cnt1) =>H ;1
ServiceProgress(cnt1) =0 ;1
Servicing(cnt1) = 0 ;1
Else
ServiceProgress(cnt1)= (ServiceProgress(cnt1)+ServiceSpeed(cnt1)) ;(28)
EndIf
EndIf
If DisplayGraphics = #True
;Draw servers To reflect changes
;=======================
For cnt2 = 1 To ActiveServers
DrawServers()
Next cnt2
StopDrawing() :FlipBuffers() ;(12) relocated
EndIf
Next cnt1
EndProcedure
Procedure UserInput()
;Check Fn key input to change no. of required servers
ExamineKeyboard()
If KeyboardPushed(#PB_Key_1 )
RequiredServers= 1
ElseIf KeyboardPushed(#PB_Key_2 )
RequiredServers= 2
ElseIf KeyboardPushed(#PB_Key_3 )
RequiredServers= 3
ElseIf KeyboardPushed(#PB_Key_4 )
RequiredServers= 4
ElseIf KeyboardPushed(#PB_Key_5 )
RequiredServers= 5
ElseIf KeyboardPushed(#PB_Key_6 )
RequiredServers= 6
ElseIf KeyboardReleased(#PB_Key_Escape)
If ShowFinalStatistics = #True
Quit = #True
Else
ShowFinalStatistics = #True :Pause = #False
EndIf
ElseIf KeyboardReleased(#PB_Key_P) ;(31) toggle pause on and off
If Pause = #True ;(31)
Pause = #False ;(31)
Else ;(31)
Pause = #True ;(31)
EndIf ;(31)
EndIf
EndProcedure
- Kaeru Gaman
- Addict

- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: Why do I need to use showcursor()?
you are opening a screen, then opening a window, then opening a windowedscreen?
... I'm amazed that fishy thing ever worked.
... I'm amazed that fishy thing ever worked.
oh... and have a nice day.
Re: Why do I need to use showcursor()?
I hadn't realised I was opening a screen, then opening a window, then opening a windowedscreen.
I assumed the first open screen must happen with
HandleError(OpenScreen(ScrW, ScrH, ScrD, "Blobs"), "Could not open screen.")
If so (I don't doubt you, I just doubt my understanding), you have shown me somehing I can correct.
Many thanks
I assumed the first open screen must happen with
HandleError(OpenScreen(ScrW, ScrH, ScrD, "Blobs"), "Could not open screen.")
If so (I don't doubt you, I just doubt my understanding), you have shown me somehing I can correct.
Many thanks
- Kaeru Gaman
- Addict

- Posts: 4826
- Joined: Sun Mar 19, 2006 1:57 pm
- Location: Germany
Re: Why do I need to use showcursor()?
I don't want to dig deeper into this code for now...
just one thing: using the MouseLib for the Screen ( InitMouse, ExamineMouse ) hides the cursor.
don't use that MouseLib but WindowMouseX and WindowMouseY to keep the cursor visible.
just one thing: using the MouseLib for the Screen ( InitMouse, ExamineMouse ) hides the cursor.
don't use that MouseLib but WindowMouseX and WindowMouseY to keep the cursor visible.
oh... and have a nice day.
Re: Why do I need to use showcursor()?
Kaeru,
When I removed
HandleError(OpenScreen(ScrW, ScrH, ScrD, "Blobs"), "Could not open screen.")
there was no need for ShowCursor_(1)
I had copied the code from someone else and hadn't fully understood what it did. Without your help, I don't think I would have found the answer.
Many thanks.
When I removed
HandleError(OpenScreen(ScrW, ScrH, ScrD, "Blobs"), "Could not open screen.")
there was no need for ShowCursor_(1)
I had copied the code from someone else and hadn't fully understood what it did. Without your help, I don't think I would have found the answer.
Many thanks.
Re: Why do I need to use showcursor()?
I hope, you have learn, posting a coding-question without source is in most cases uselessshaker wrote:I don't think I would have found the answer.
Re: Why do I need to use showcursor()?
ts-soft
Point taken. I am still uneasy about burdening people with metres of code, but accept that if I want help, it must be done.
thanks
Point taken. I am still uneasy about burdening people with metres of code, but accept that if I want help, it must be done.
thanks

