Class: ModraUp::Tool
- Inherits:
-
Object
- Object
- ModraUp::Tool
Overview
Callback list for custom tools. SketchUp's official API does not have this class (cannot be written as class MyTool < ModraUp::Tool), so it is implemented by duck typing, providing the necessary methods and then passing them to ModraUp::Model#select_tool.
ModraUp makes the same protocol into a browsable class for internal training: no inheritance is required; missing methods are skipped by the host. When determining if a tool has implemented a callback, it ignores the documentation stub methods in this class, consistent with SketchUp's duck typing. Dynamic Components' DCInteractTool is an example of such a regular Ruby class.
Currently, it forwards: activate, deactivate, suspend, resume, onSetCursor, draw (calls getExtents before drawing), onMouseMove, left/middle/right mouse clicks and double-clicks, onMouseWheel (returns true to prevent viewport scaling), onMouseEnter, onMouseLeave, onKeyDown, onKeyUp, onCancel, onReturn, enableVCB? / onUserText, getMenu. Middle mouse button still navigates the viewport. getInstructorContentDirectory is queried at activate, and the HTML files in that directory are loaded when the "Instructor" window menu is opened.
Modifier key constants are found at VK_SHIFT, CONSTRAIN_MODIFIER_MASK, COPY_MODIFIER_MASK.
Instance Method Summary # collapse
-
#activate ⇒ nil
This method is called when the tool is selected by ModraUp::Model#select_tool. It is suitable for initializing the tool's state.
-
#deactivate(view) ⇒ nil
Called when switching to another tool or by select_tool(nil).
-
#draw(view) ⇒ nil
Redraw temporary graphics in the viewport when the tool is drawn. SketchUp requires implementing #getExtents when drawing outside the model's bounding box; #getExtents is called before drawing.
-
#enableVCB? ⇒ Boolean
Controls input in the Measurements box (VCB). Implementing #onUserText enables input. Implement this method to return false when the tool is not ready, for example before the first click. If omitted, the box stays enabled when the tool implements #onUserText. Empty callbacks inherited from ModraUp::Tool do not count as implementations.
-
#getExtents ⇒ Geom::BoundingBox, nil
Tell SketchUp how large the temporary graphics are to avoid being clipped. This can be omitted if there is no temporary drawing.
-
#getInstructorContentDirectory ⇒ String, nil
Directory where the instructor panel HTML content is located. It is queried when activated; the directory is loaded when the "Window / Instructor" opens.
-
#getMenu(menu) ⇒ nil
Provides a tool's own right-click menu. If implemented, only the items added by this method are displayed, and they do not mix with the default menu or UI.add_context_menu_handler. If not implemented, the default menu is displayed based on the hit object or blank area.
-
#onCancel(reason, view) ⇒ nil
Cancel the current operation. reason: 0 Esc, 1 reselecting the same tool, 2 undo (before an undo operation).
-
#onKeyDown(key, repeat, flags, view) ⇒ Boolean, nil
Press the keyboard. To read a value from VCB, implement #onUserText instead of this method. Return true for Esc to prevent triggering #onCancel. Use top-level VK_SHIFT instead of writing ModraUp::VK_SHIFT.
-
#onKeyUp(key, repeat, flags, view) ⇒ Boolean, nil
Release the keyboard.
-
#onLButtonDoubleClick(flags, x, y, view) ⇒ nil
Left mouse button double-click.
-
#onLButtonDown(flags, x, y, view) ⇒ nil
Left mouse button down. flags contains MK_LBUTTON, CONSTRAIN_MODIFIER_MASK, etc.
-
#onLButtonUp(flags, x, y, view) ⇒ nil
Left mouse button released. DC Interact performs onclick here.
-
#onMButtonDoubleClick(flags, x, y, view) ⇒ nil
Mouse middle button double-click.
-
#onMButtonDown(flags, x, y, view) ⇒ nil
Mouse middle button down.
-
#onMButtonUp(flags, x, y, view) ⇒ nil
Mouse middle button up.
-
#onMouseEnter(view) ⇒ nil
The mouse pointer entered the viewport.
-
#onMouseLeave(view) ⇒ nil
The mouse pointer has left the viewport.
-
#onMouseMove(flags, x, y, view) ⇒ nil
Called when the pointer moves within the viewport. Use ModraUp::View#pick_helper for picking.
-
#onMouseWheel(flags, delta, x, y, view) ⇒ Boolean, nil
Mouse wheel. Returns true if the tool has handled the event.
-
#onRButtonDoubleClick(flags, x, y, view) ⇒ nil
Mouse right button double-click.
-
#onRButtonDown(flags, x, y, view) ⇒ nil
Right mouse button down. Implement with #getMenu to customize the menu.
-
#onRButtonUp(flags, x, y, view) ⇒ nil
Right button up.
-
#onReturn(view) ⇒ nil
The user presses Return. When the measurement box is open, pressing Return exits it without calling this method. #onUserText
-
#onSetCursor ⇒ Boolean, nil
The host calls this after a mouse event to change the cursor using UI.set_cursor.
-
#onUserText(text, view) ⇒ nil
The user inputs a measurement in the measurement box and presses Enter. Calling this method opens the measurement box (similar to SketchUp's engine). Pass the current text within the box, including the value set by ModraUp.vcb_value= which should be entered by pressing Enter.
-
#resume(view) ⇒ nil
The tool becomes the current tool again after ModraUp::Tools#pop_tool.
-
#suspend(view) ⇒ nil
Called when ModraUp::Tools#push_tool pushes this tool onto the stack.
Instance Method Details
tool.activate ⇒ nil
This method is called when the tool is selected by ModraUp::Model#select_tool. It is suitable for initializing the tool's state.
tool.deactivate(view) ⇒ nil
Called when switching to another tool or by select_tool(nil).
tool.draw(view) ⇒ nil
Redraw temporary graphics in the viewport when the tool is drawn. SketchUp requires implementing #getExtents when drawing outside the model's bounding box; #getExtents is called before drawing.
tool.enableVCB? ⇒ Boolean
Controls input in the Measurements box (VCB). Implementing #onUserText enables input. Implement this method to return false when the tool is not ready, for example before the first click. If omitted, the box stays enabled when the tool implements #onUserText. Empty callbacks inherited from ModraUp::Tool do not count as implementations.
tool.getExtents ⇒ Geom::BoundingBox, nil
Tell SketchUp how large the temporary graphics are to avoid being clipped. This can be omitted if there is no temporary drawing.
tool.getInstructorContentDirectory ⇒ String, nil
Directory where the instructor panel HTML content is located. It is queried when activated; the directory is loaded when the "Window / Instructor" opens.
tool.getMenu(menu) ⇒ niltool.getMenu(menu, flags, x, y, view) ⇒ nil
Provides a tool's own right-click menu. If implemented, only the items added by this method are displayed, and they do not mix with the default menu or UI.add_context_menu_handler. If not implemented, the default menu is displayed based on the hit object or blank area.
tool.onCancel(reason, view) ⇒ nil
Cancel the current operation. reason: 0 Esc, 1 reselecting the same tool, 2 undo (before an undo operation). If #onKeyDown returns true for Esc, this method is not called.
tool.onKeyDown(key, repeat, flags, view) ⇒ Boolean, nil
Press the keyboard. To read a value from VCB, implement #onUserText instead of this method. Return true for Esc to prevent triggering #onCancel. Use top-level VK_SHIFT instead of writing ModraUp::VK_SHIFT.
tool.onKeyUp(key, repeat, flags, view) ⇒ Boolean, nil
Release the keyboard.
tool.onLButtonDoubleClick(flags, x, y, view) ⇒ nil
Left mouse button double-click.
tool.onLButtonDown(flags, x, y, view) ⇒ nil
Left mouse button down. flags contains MK_LBUTTON, CONSTRAIN_MODIFIER_MASK, etc.
tool.onLButtonUp(flags, x, y, view) ⇒ nil
Left mouse button released. DC Interact performs onclick here.
tool.onMButtonDoubleClick(flags, x, y, view) ⇒ nil
Mouse middle button double-click.
tool.onMButtonDown(flags, x, y, view) ⇒ nil
Mouse middle button down.
tool.onMButtonUp(flags, x, y, view) ⇒ nil
Mouse middle button up.
tool.onMouseEnter(view) ⇒ nil
The mouse pointer entered the viewport.
tool.onMouseLeave(view) ⇒ nil
The mouse pointer has left the viewport.
tool.onMouseMove(flags, x, y, view) ⇒ nil
Called when the pointer moves within the viewport. Use ModraUp::View#pick_helper for picking.
tool.onMouseWheel(flags, delta, x, y, view) ⇒ Boolean, nil
Mouse wheel. Returns true if the tool has handled the event.
tool.onRButtonDoubleClick(flags, x, y, view) ⇒ nil
Mouse right button double-click.
tool.onRButtonDown(flags, x, y, view) ⇒ nil
Right mouse button down. Implement with #getMenu to customize the menu.
tool.onRButtonUp(flags, x, y, view) ⇒ nil
Right button up.
tool.onReturn(view) ⇒ nil
The user presses Return. When the measurement box is open, pressing Return exits it without calling this method. #onUserText
tool.onSetCursor ⇒ Boolean, nil
The host calls this after a mouse event to change the cursor using UI.set_cursor.
tool.onUserText(text, view) ⇒ nil
The user inputs a measurement in the measurement box and presses Enter. Calling this method opens the measurement box (similar to SketchUp's engine). Pass the current text within the box, including the value set by ModraUp.vcb_value= which should be entered by pressing Enter.
tool.resume(view) ⇒ nil
The tool becomes the current tool again after ModraUp::Tools#pop_tool.
tool.suspend(view) ⇒ nil
Called when ModraUp::Tools#push_tool pushes this tool onto the stack.