Skip to content

Instantly share code, notes, and snippets.

@jimfoltz
Last active August 29, 2015 14:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jimfoltz/15b0178ad353a6f7a845 to your computer and use it in GitHub Desktop.
Save jimfoltz/15b0178ad353a6f7a845 to your computer and use it in GitHub Desktop.
if not defined?(JF::ZoomCrosshairs)
UI.menu("Camera").add_item("Zoom Crosshairs") {
Sketchup.active_model.select_tool(JF::ZoomCrosshairs.new)
}
end
module JF
class ZoomCrosshairs
# Move the Camera
def do_zoom(view)
reset()
camera = view.camera
eye = camera.eye
up = camera.up
target = camera.target
direction = camera.direction
height = camera.height
# The corners of the selection are
# @pt1 and @pt2
rect_width = (@pt2.x - @pt1.x).abs
rect_height = (@pt2.y - @pt1.y).abs
camera.set(eye, target, up)
if not camera.perspective?
camera.height = height
end
end
def activate()
@h = Sketchup.active_model.active_view.vpheight
@w = Sketchup.active_model.active_view.vpwidth
@state = 1
end
def onMouseMove(flags, x, y, view)
@x = x
@y = y
if @down
if @pt1.distance([x, y]) > 10
@dragging = true
@pt2 = [x, y]
else
@dragging = false
end
end
view.invalidate
end
def onLButtonUp(flags, x, y, view)
@down = false
if @state == 2 && @dragging
@pt2 = [x, y]
view.invalidate
do_zoom(view)
end
if @state == 2
@state = 1
end
end
def onLButtonDown(flags, x, y, view)
@down = true
if @state == 1
@pt1 = [x, y]
@state = 2
end
end
def deactivate(view)
view.invalidate
end
def suspend(view)
view.invalidate
end
def draw(view)
if @x && @y
view.draw2d(GL_LINES, [@x, 1], [@x, @h-1])
view.draw2d(GL_LINES, [0, @y], [@w-1, @y])
if @dragging
pt3 = [@pt2.x, @pt1.y]
pt4 = [@pt1.x, @pt2.y]
view.drawing_color = 'red'
view.draw2d(GL_LINE_LOOP, @pt1, pt3, @pt2, pt4)
end
end
end
def reset
@state = 1
@dragging = false
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment