Skip to content

Commit

Permalink
Add goto function
Browse files Browse the repository at this point in the history
- Goto template by doubleclicking on template entry
- Goto template by clicking the "Goto" button in template settings
- Goto coordinate by entering coordinates into requester
  • Loading branch information
Dadido3 committed Aug 14, 2017
1 parent a26ecf4 commit b491944
Show file tree
Hide file tree
Showing 5 changed files with 239 additions and 16 deletions.
Binary file added Data/Icons/bullet_go.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
175 changes: 175 additions & 0 deletions Includes/Goto_Requester.pbi
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
; ##################################################### License / Copyright #########################################
;
; ##################################################### Dokumentation / Kommentare ##################################
;
;
;
;
;
;
;
; ##################################################### Includes ####################################################

; ###################################################################################################################
; ##################################################### Public ######################################################
; ###################################################################################################################

DeclareModule Goto_Requester
EnableExplicit
; ################################################### Constants ###################################################

; ################################################### Functions ###################################################
Declare Open()
Declare Close()
Declare Main()

EndDeclareModule

; ###################################################################################################################
; ##################################################### Private #####################################################
; ###################################################################################################################

Module Goto_Requester
; ##################################################### Includes ####################################################

; ##################################################### Prototypes ##################################################

; ##################################################### Structures ##################################################

; ##################################################### Constants ###################################################

; ##################################################### Structures ##################################################
Structure Main

EndStructure

Structure Window
ID.i
Exit.i

; #### Gadgets
Text.i [10]
Spin.i [10]
Button.i
EndStructure

; ##################################################### Variables ###################################################
Global Main.Main
Global Window.Window

; ##################################################### Icons ... ###################################################

; ##################################################### Init ########################################################
;Global Font = LoadFont(#PB_Any, "Courier New", 20)

; ##################################################### Procedures ##################################################
Procedure Button_Event()
Protected Event_Window = EventWindow()
Protected Event_Gadget = EventGadget()
Protected Event_Type = EventType()

Select Event_Type
Case #PB_EventType_LeftClick
Main::Canvas_Goto(-GetGadgetState(Window\Spin[0]), -GetGadgetState(Window\Spin[1]))

EndSelect
EndProcedure

Procedure Event_SizeWindow()
Protected Event_Window = EventWindow()
Protected Event_Gadget = EventGadget()
Protected Event_Type = EventType()

EndProcedure

Procedure Event_ActivateWindow()
Protected Event_Window = EventWindow()
Protected Event_Gadget = EventGadget()
Protected Event_Type = EventType()

EndProcedure

Procedure Event_Menu()
Protected Event_Window = EventWindow()
Protected Event_Gadget = EventGadget()
Protected Event_Type = EventType()
Protected Event_Menu = EventMenu()

EndProcedure

Procedure Event_CloseWindow()
Protected Event_Window = EventWindow()
Protected Event_Gadget = EventGadget()
Protected Event_Type = EventType()

Window\Exit = #True
EndProcedure

Procedure Open()
Protected Width, Height

If Window\ID
SetActiveWindow(Window\ID)
ProcedureReturn #True
EndIf

Width = 150
Height = 100

Window\ID = OpenWindow(#PB_Any, 0, 0, Width, Height, "Goto", #PB_Window_SystemMenu | #PB_Window_WindowCentered, WindowID(Main::Window\ID))
If Window\ID

Window\Text[0] = TextGadget(#PB_Any, 10, 10, 20, 20, "X:", #PB_Text_Right)
Window\Spin[0] = SpinGadget(#PB_Any, 40, 10, 100, 20, -1000000, 1000000, #PB_Spin_Numeric)
Window\Text[1] = TextGadget(#PB_Any, 10, 30, 20, 20, "Y:", #PB_Text_Right)
Window\Spin[1] = SpinGadget(#PB_Any, 40, 30, 100, 20, -1000000, 1000000, #PB_Spin_Numeric)
Window\Button = ButtonGadget(#PB_Any, 10, Height-40, Width-20, 30, "Goto")

SetGadgetState(Window\Spin[0], -Main::Settings\X / Main::Settings\Zoom) : SetGadgetText(Window\Spin[0], Str(-Main::Settings\X / Main::Settings\Zoom))
SetGadgetState(Window\Spin[1], -Main::Settings\Y / Main::Settings\Zoom) : SetGadgetText(Window\Spin[1], Str(-Main::Settings\Y / Main::Settings\Zoom))

BindGadgetEvent(Window\Button, @Button_Event())

BindEvent(#PB_Event_SizeWindow, @Event_SizeWindow(), Window\ID)
BindEvent(#PB_Event_Menu, @Event_Menu(), Window\ID)
BindEvent(#PB_Event_CloseWindow, @Event_CloseWindow(), Window\ID)

ProcedureReturn #True
EndIf

ProcedureReturn #False
EndProcedure

Procedure Close()
If Window\ID

UnbindGadgetEvent(Window\Button, @Button_Event())

UnbindEvent(#PB_Event_SizeWindow, @Event_SizeWindow(), Window\ID)
UnbindEvent(#PB_Event_Menu, @Event_Menu(), Window\ID)
UnbindEvent(#PB_Event_CloseWindow, @Event_CloseWindow(), Window\ID)

CloseWindow(Window\ID)
Window\ID = 0
EndIf
EndProcedure

Procedure Main()
If Window\Exit
Window\Exit = #False
Close()
EndIf

EndProcedure

; ##################################################### Initialisation ##############################################

; ##################################################### Data Sections ###############################################

EndModule

; IDE Options = PureBasic 5.60 beta 6 (Windows - x64)
; CursorPosition = 127
; FirstLine = 117
; Folding = --
; EnableXP
22 changes: 20 additions & 2 deletions Includes/Templates.pbi
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ Module Templates
DisableGadget(Window\Button[0], #False)
DisableGadget(Window\Button[1], #False)
DisableGadget(Window\Button[2], #False)
DisableGadget(Window\Button[4], #False)
Else
SetGadgetText(Window\String, "")
SetGadgetState(Window\Spin[0], 0)
Expand All @@ -309,6 +310,7 @@ Module Templates
DisableGadget(Window\Button[0], #True)
DisableGadget(Window\Button[1], #True)
DisableGadget(Window\Button[2], #True)
DisableGadget(Window\Button[4], #True)
EndIf
EndProcedure

Expand Down Expand Up @@ -342,6 +344,8 @@ Module Templates
Protected Event_Gadget = EventGadget()
Protected Event_Type = EventType()

Protected Index = GetGadgetState(Event_Gadget)

Select Event_Type
Case #PB_EventType_LeftClick
Refresh_Fields()
Expand All @@ -355,6 +359,11 @@ Module Templates
EndIf
Next

Case #PB_EventType_LeftDoubleClick
If Index <> -1 And SelectElement(Object(), Index)
Main::Canvas_Goto(-Object()\Settings\X - Object()\Width/2, -Object()\Settings\Y - Object()\Height/2, 0)
EndIf

EndSelect

EndProcedure
Expand Down Expand Up @@ -457,6 +466,11 @@ Module Templates
Refresh_ListIcon()
Refresh_Fields()

Case Window\Button[4]
If Index <> -1 And SelectElement(Object(), Index)
Main::Canvas_Goto(-Object()\Settings\X - Object()\Width/2, -Object()\Settings\Y - Object()\Height/2, 0)
EndIf

EndSelect
EndProcedure

Expand Down Expand Up @@ -494,6 +508,7 @@ Module Templates
ResizeGadget(Window\Button [1], 60, Y, 50, 20)
ResizeGadget(Window\Button [2], 110, Y, 50, 20)
ResizeGadget(Window\Button [3], 160, Y, 50, 20)
ResizeGadget(Window\Button [4], Width-60, Y, 50, 20)
EndProcedure

Procedure Event_Menu()
Expand Down Expand Up @@ -571,6 +586,7 @@ Module Templates
Window\Button [1] = ButtonGadget(#PB_Any, 60, Y, 50, 20, "Down")
Window\Button [2] = ButtonGadget(#PB_Any, 110, Y, 50, 20, "Delete")
Window\Button [3] = ButtonGadget(#PB_Any, 160, Y, 50, 20, "Create")
Window\Button [4] = ButtonGadget(#PB_Any, Width-60, Y, 50, 20, "Goto")

BindGadgetEvent(Window\ListIcon, @Event_ListIcon())
BindGadgetEvent(Window\Spin [0], @Event_Spin())
Expand All @@ -583,6 +599,7 @@ Module Templates
BindGadgetEvent(Window\Button [1], @Event_Button())
BindGadgetEvent(Window\Button [2], @Event_Button())
BindGadgetEvent(Window\Button [3], @Event_Button())
BindGadgetEvent(Window\Button [4], @Event_Button())

BindEvent(#PB_Event_SizeWindow, @Event_SizeWindow(), Window\ID)
;BindEvent(#PB_Event_Repaint, @Event_SizeWindow(), Window\ID)
Expand Down Expand Up @@ -612,6 +629,7 @@ Module Templates
UnbindGadgetEvent(Window\Button [1], @Event_Button())
UnbindGadgetEvent(Window\Button [2], @Event_Button())
UnbindGadgetEvent(Window\Button [3], @Event_Button())
UnbindGadgetEvent(Window\Button [4], @Event_Button())

UnbindEvent(#PB_Event_SizeWindow, @Event_SizeWindow(), Window\ID)
;UnbindEvent(#PB_Event_Repaint, @Event_SizeWindow(), Window\ID)
Expand Down Expand Up @@ -1052,8 +1070,8 @@ Module Templates
EndModule

; IDE Options = PureBasic 5.60 beta 6 (Windows - x64)
; CursorPosition = 1020
; FirstLine = 1000
; CursorPosition = 363
; FirstLine = 341
; Folding = ------
; EnableXP
; Executable = ..\Pixelcanvas Client.exe
Expand Down
Loading

0 comments on commit b491944

Please sign in to comment.