Skip to content

Commit

Permalink
Cursor bank and update deps
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyjor committed Jan 11, 2025
1 parent 40e5240 commit da01d96
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 8 deletions.
8 changes: 3 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,22 @@ repo = "https://github.com/Kyjor/JulGame.jl.git"
version = "0.1.0"

[deps]
CImGui = "5d785b6c-b76f-510e-a07c-3070796c7e87"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
NativeFileDialog = "e1fe445b-aa65-4df4-81c1-2041507f0fd4"
SimpleDirectMediaLayer = "98e33af6-2ee5-5afd-9e75-cbc738b767c4"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"

[compat]
julia = "^1.9"
CImGui = "^2.0"
JSON3 = "^1"
NativeFileDialog = "^0.2"
SimpleDirectMediaLayer = "^0.5"
Test = "^1"

[extras]
CImGui = "5d785b6c-b76f-510e-a07c-3070796c7e87"
NativeFileDialog = "e1fe445b-aa65-4df4-81c1-2041507f0fd4"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
test = ["Test", "NativeFileDialog", "CImGui"]
2 changes: 0 additions & 2 deletions src/editor/JulGameEditor/Components/CameraWindow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ function show_camera_window(this::CameraWindow)
this.camera.size = Vector2(this.camera.size.x, Float64(size_y32))
end

CImGui.Text("Starting Coordinates: $(this.camera.startingCoordinates.x), $(this.camera.startingCoordinates.y)")

# camera background color
# CImGui.Text("Background Color:")
# color_r = UInt8(this.camera.backgroundColor[1])
Expand Down
30 changes: 29 additions & 1 deletion src/engine/Input/Input.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ module InputModule
numHats
button

# Cursor bank
cursorBank::Dict{String, Ptr{SDL2.SDL_SystemCursor}} # Key is the name of the cursor, value is the SDL2 cursor

function Input()
this = new()

Expand Down Expand Up @@ -83,6 +86,9 @@ module InputModule
this.yDir = 0
this.button = 0

this.cursorBank = Dict{String, SDL2.SDL_SystemCursor}()
create_cursor_bank(this)

return this
end
end
Expand All @@ -109,6 +115,7 @@ module InputModule
continue
end

insideAnyButton = false
for screenButton in MAIN.scene.uiElements
if split("$(typeof(screenButton))", ".")[end] != "ScreenButton"
continue
Expand All @@ -129,9 +136,16 @@ module InputModule
if !eventWasInsideThisButton
continue
end
insideAnyButton = true

SDL2.SDL_SetCursor(this.cursorBank["hand"])

JulGame.UI.handle_event(screenButton, evt, x[1], y[1])
end

if !insideAnyButton
SDL2.SDL_SetCursor(this.cursorBank["arrow"])
end
end

handle_mouse_event(this, evt)
Expand Down Expand Up @@ -363,5 +377,19 @@ module InputModule
end
return false
end


function create_cursor_bank(this::Input)
this.cursorBank["arrow"] = SDL2.SDL_CreateSystemCursor(SDL2.SDL_SYSTEM_CURSOR_ARROW)
this.cursorBank["ibeam"] = SDL2.SDL_CreateSystemCursor(SDL2.SDL_SYSTEM_CURSOR_IBEAM)
this.cursorBank["wait"] = SDL2.SDL_CreateSystemCursor(SDL2.SDL_SYSTEM_CURSOR_WAIT)
this.cursorBank["crosshair"] = SDL2.SDL_CreateSystemCursor(SDL2.SDL_SYSTEM_CURSOR_CROSSHAIR)
this.cursorBank["waitarrow"] = SDL2.SDL_CreateSystemCursor(SDL2.SDL_SYSTEM_CURSOR_WAITARROW)
this.cursorBank["sizeall"] = SDL2.SDL_CreateSystemCursor(SDL2.SDL_SYSTEM_CURSOR_SIZEALL)
this.cursorBank["sizenesw"] = SDL2.SDL_CreateSystemCursor(SDL2.SDL_SYSTEM_CURSOR_SIZENESW)
this.cursorBank["sizenwse"] = SDL2.SDL_CreateSystemCursor(SDL2.SDL_SYSTEM_CURSOR_SIZENWSE)
this.cursorBank["sizewe"] = SDL2.SDL_CreateSystemCursor(SDL2.SDL_SYSTEM_CURSOR_SIZEWE)
this.cursorBank["sizens"] = SDL2.SDL_CreateSystemCursor(SDL2.SDL_SYSTEM_CURSOR_SIZENS)
this.cursorBank["no"] = SDL2.SDL_CreateSystemCursor(SDL2.SDL_SYSTEM_CURSOR_NO)
this.cursorBank["hand"] = SDL2.SDL_CreateSystemCursor(SDL2.SDL_SYSTEM_CURSOR_HAND)
end
end
2 changes: 2 additions & 0 deletions src/engine/UI/ScreenButton.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ module ScreenButtonModule
buttonUpSpritePath::String
buttonUpTexture
fontPath::Union{String, Ptr{Nothing}}
isHovered::Bool
isInitialized::Bool
mouseOverSprite
name::String
Expand Down Expand Up @@ -46,6 +47,7 @@ module ScreenButtonModule
this.textTexture = C_NULL
this.isInitialized = false
this.persistentBetweenScenes = false
this.isHovered = false

return this
end
Expand Down

0 comments on commit da01d96

Please sign in to comment.