From 9c1ac67a9cb53eceeb12be9438c2867d1eb44362 Mon Sep 17 00:00:00 2001 From: pavle Date: Tue, 27 Nov 2018 01:29:34 +0100 Subject: [PATCH] Abstracted menu mouse as a separate function. --- menus.bi | 54 +++++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 25 deletions(-) diff --git a/menus.bi b/menus.bi index 8ac4616..d2b2414 100644 --- a/menus.bi +++ b/menus.bi @@ -37,6 +37,34 @@ Function drawbutton(text As String, keypress As String = "", row As Byte, column End Function +Function menumouse(buttons() As button) As String + Dim e As EVENT + Dim As Integer mousex, mousey, pressed + + If (ScreenEvent(@e)) Then + Select Case e.type + Case EVENT_MOUSE_BUTTON_PRESS + pressed = e.button=1 + If e.button=2 Then Return Chr(27) + If pressed Then + GetMouse(mousex,mousey) + Dim a as UByte + For a = 0 to UBound(buttons) + If isin(mousex,mousey,buttons(a).x, buttons(a).y,buttons(a).w,buttons(a).h) Then keypress = buttons(a).keypress + Next + End If + Case EVENT_MOUSE_BUTTON_RELEASE + pressed = 0 + Case EVENT_MOUSE_MOVE + If (pressed) Then + ScreenControl GET_WINDOW_POS, mousex, mousey + ScreenControl SET_WINDOW_POS, mousex + e.dx, mousey + e.dy + End If + End Select + End If +End Function + + Function openloader(directory As String, page As UByte = 0, resize As Boolean = True) As String If title = "" Then title = "Generic Block Game" If resize Then @@ -44,8 +72,6 @@ Function openloader(directory As String, page As UByte = 0, resize As Boolean = Else Cls End If - Dim e As EVENT - Dim As Integer mousex, mousey, pressed Dim buttons(6) As button @@ -74,29 +100,7 @@ Function openloader(directory As String, page As UByte = 0, resize As Boolean = Do keypress=InKey - ' handle mouse - If (ScreenEvent(@e)) Then - Select Case e.type - Case EVENT_MOUSE_BUTTON_PRESS - pressed = e.button=1 - If e.button=2 Then Exit Do - If pressed Then - GetMouse(mousex,mousey) - Dim a as UByte - For a = 0 to UBound(buttons) - If isin(mousex,mousey,buttons(a).x,buttons(a).y,buttons(a).w,buttons(a).h) Then keypress = buttons(a).keypress - Next - End If - Case EVENT_MOUSE_BUTTON_RELEASE - pressed = 0 - Case EVENT_MOUSE_MOVE - If (pressed) Then - ScreenControl GET_WINDOW_POS, mousex, mousey - ScreenControl SET_WINDOW_POS, mousex + e.dx, mousey + e.dy - End If - End Select - End If - 'end mouse + menumouse(buttons()) Loop Until keypress <> "" If Val(keypress) >= 1 And Val(keypress) <= 9 And Len(filenames(Val(keypress) + page*4 - 1)) Then Return directory + "/" + filenames(Val(keypress) + page*4 - 1) -- 2.11.4.GIT