-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Double click middle mouse button to show the entire map on screen Moved viewport device code into its own file Moved getMapBounds into map_item_utils
- Loading branch information
Showing
7 changed files
with
124 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
local configs = require("configs") | ||
local viewportHandler = require("viewport_handler") | ||
local mapItemUtils = require("map_item_utils") | ||
local loadedState = require("loaded_state") | ||
local utils = require("utils") | ||
|
||
local viewportDevice = {} | ||
|
||
function viewportDevice.mousedragmoved(x, y, dx, dy, button, istouch) | ||
local movementButton = configs.editor.canvasMoveButton | ||
local viewport = viewportHandler.viewport | ||
|
||
if button == movementButton then | ||
viewport.x -= dx | ||
viewport.y -= dy | ||
|
||
viewportHandler.persistCamera() | ||
|
||
return true | ||
end | ||
end | ||
|
||
function viewportDevice.mousemoved(x, y, dx, dy, istouch) | ||
local viewport = viewportHandler.viewport | ||
|
||
if istouch then | ||
viewport.x -= dx | ||
viewport.y -= dy | ||
|
||
viewportHandler.persistCamera() | ||
|
||
return true | ||
end | ||
end | ||
|
||
function viewportDevice.mouseclicked(x, y, button, istouch, presses) | ||
local zoomToExtentsButton = configs.editor.canvasZoomExtentsButton | ||
local map = loadedState.map | ||
|
||
if not map then | ||
return | ||
end | ||
|
||
if button == zoomToExtentsButton and presses % 2 == 0 then | ||
local tlx, tly, brx, bry = mapItemUtils.getMapBounds(map) | ||
local rectangle = utils.rectangle(tlx, tly, brx - tlx, bry - tly) | ||
|
||
viewportHandler.zoomToRectangle(rectangle) | ||
viewportHandler.persistCamera() | ||
end | ||
end | ||
|
||
function viewportDevice.resize(width, height) | ||
viewportHandler.updateSize(width, height) | ||
end | ||
|
||
function viewportDevice.wheelmoved(dx, dy) | ||
if dy > 0 then | ||
viewportHandler.zoomIn() | ||
|
||
return true | ||
|
||
elseif dy < 0 then | ||
viewportHandler.zoomOut() | ||
|
||
return true | ||
end | ||
end | ||
|
||
function viewportDevice.visible(visible) | ||
local viewport = viewportHandler.viewport | ||
|
||
viewport.visible = visible | ||
end | ||
|
||
return viewportDevice |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters