lib/su_info/Template_Code.rb
def tool_1
    @@mse = Proc.new { |up_down_dbl, flags, x, y, view|
      button  = ''
      key_mod = ''
      if (MK_LBUTTON & flags != 0) then button << ', Left'   end
      if (MK_MBUTTON & flags != 0) then button << ', Middle' end
      if (MK_RBUTTON & flags != 0) then button << ', Right'  end

      if (MK_SHIFT   & flags != 0) then key_mod << ', Shift' end
      if (MK_CONTROL & flags != 0) then key_mod << ', Ctrl'  end
      if (MK_ALT     & flags != 0) then key_mod << ', Alt'   end
      s1 = up_down_dbl.ljust(7)
      s2 =  button.sub(/^, /, '').ljust(20)
      s3 = key_mod.sub(/^, /, '')
      puts "Mouse Button #{s1} button = #{s2} keys = #{s3}"
    }
    @tool = Object.new
    @tool.instance_eval {
      def onLButtonDown(*a)        ; @@mse.call('Down'  , *a) ; end
      def onMButtonDown(*a)        ; @@mse.call('Down'  , *a) ; end
      def onRButtonDown(*a)        ; @@mse.call('Down'  , *a) ; end

      def onLButtonUp(*a)          ; @@mse.call('Up'    , *a) ; end
      def onMButtonUp(*a)          ; @@mse.call('Up'    , *a) ; end
      def onRButtonUp(*a)          ; @@mse.call('Up'    , *a) ; end

      def onLButtonDoubleClick(*a) ; @@mse.call('DblClk', *a) ; end
      def onMButtonDoubleClick(*a) ; @@mse.call('DblClk', *a) ; end
      def onRButtonDoubleClick(*a) ; @@mse.call('DblClk', *a) ; end

      def onKeyDown(key, repeat, flags, view)
        # Some binary fun for testing
        t = flags.to_s(2).rjust(16)
        bin = "#{ t[-16,4]} #{ t[-12,4]} " \
              "#{ t[ -8,4]} #{ t[ -4,4]}".rjust(19)
        puts "#{key.to_s.ljust(4)}\t#{flags.to_s.ljust(5)}\t#{bin}"

        k    = key.to_s.rjust(3)
        alt  = (ALT_MODIFIER_MASK       & key != 0).to_s.ljust(5)
        cons = (CONSTRAIN_MODIFIER_MASK & key != 0).to_s.ljust(5)
        copy = (COPY_MODIFIER_MASK      & key != 0).to_s.ljust(5)
        puts "key = #{k}  alt = #{alt}  cons = #{cons}  copy = #{copy}"
      end
    }
    Sketchup.active_model.select_tool(@tool)
  end
# Creates a tool and and callbacks for mouse and KeyDown events
#
Creates a tool and and callbacks for mouse and KeyDown events
Creates a tool and and callbacks for mouse and KeyDown events
def tool_1
    @@mse = Proc.new { |up_down_dbl, flags, x, y, view|
      button  = ''
      key_mod = ''
      if (MK_LBUTTON & flags != 0) then button << ', Left'   end
      if (MK_MBUTTON & flags != 0) then button << ', Middle' end
      if (MK_RBUTTON & flags != 0) then button << ', Right'  end
      if (MK_SHIFT   & flags != 0) then key_mod << ', Shift' end
      if (MK_CONTROL & flags != 0) then key_mod << ', Ctrl'  end
      if (MK_ALT     & flags != 0) then key_mod << ', Alt'   end
      s1 = up_down_dbl.ljust(7)
      s2 =  button.sub(/^, /, '').ljust(20)
      s3 = key_mod.sub(/^, /, '')
      puts "Mouse Button #{s1} button = #{s2} keys = #{s3}"
    }
    @tool = Object.new
    @tool.instance_eval {
      def onLButtonDown(*a)        ; @@mse.call('Down'  , *a) ; end
      def onMButtonDown(*a)        ; @@mse.call('Down'  , *a) ; end
      def onRButtonDown(*a)        ; @@mse.call('Down'  , *a) ; end
      def onLButtonUp(*a)          ; @@mse.call('Up'    , *a) ; end
      def onMButtonUp(*a)          ; @@mse.call('Up'    , *a) ; end
      def onRButtonUp(*a)          ; @@mse.call('Up'    , *a) ; end
      def onLButtonDoubleClick(*a) ; @@mse.call('DblClk', *a) ; end
      def onMButtonDoubleClick(*a) ; @@mse.call('DblClk', *a) ; end
      def onRButtonDoubleClick(*a) ; @@mse.call('DblClk', *a) ; end
      def onKeyDown(key, repeat, flags, view)
        t = flags.to_s(2).rjust(16)
        bin = "#{ t[-16,4]} #{ t[-12,4]} " \
              "#{ t[ -8,4]} #{ t[ -4,4]}".rjust(19)
        puts "#{key.to_s.ljust(4)}\t#{flags.to_s.ljust(5)}\t#{bin}"
        k    = key.to_s.rjust(3)
        alt  = (ALT_MODIFIER_MASK       & key != 0).to_s.ljust(5)
        cons = (CONSTRAIN_MODIFIER_MASK & key != 0).to_s.ljust(5)
        copy = (COPY_MODIFIER_MASK      & key != 0).to_s.ljust(5)
        puts "key = #{k}  alt = #{alt}  cons = #{cons}  copy = #{copy}"
      end
    }
    Sketchup.active_model.select_tool(@tool)
  end
def tool_1 @@mse = Proc . new { | up_down_dbl , flags , x , y , view | button = '' key_mod = '' if ( MK_LBUTTON & flags != 0 ) then button << ', Left' end if ( MK_MBUTTON & flags != 0 ) then button << ', Middle' end if ( MK_RBUTTON & flags != 0 ) then button << ', Right' end if ( MK_SHIFT & flags != 0 ) then key_mod << ', Shift' end if ( MK_CONTROL & flags != 0 ) then key_mod << ', Ctrl' end if ( MK_ALT & flags != 0 ) then key_mod << ', Alt' end s1 = up_down_dbl . ljust ( 7 ) s2 = button . sub ( / ^,  / , '' ) . ljust ( 20 ) s3 = key_mod . sub ( / ^,  / , '' ) puts "Mouse Button #{s1} button = #{s2} keys = #{s3}" } @tool = Object . new @tool . instance_eval { def onLButtonDown ( * a ) ; @@mse . call ( 'Down' , * a ) ; end def onMButtonDown ( * a ) ; @@mse . call ( 'Down' , * a ) ; end def onRButtonDown ( * a ) ; @@mse . call ( 'Down' , * a ) ; end def onLButtonUp ( * a ) ; @@mse . call ( 'Up' , * a ) ; end def onMButtonUp ( * a ) ; @@mse . call ( 'Up' , * a ) ; end def onRButtonUp ( * a ) ; @@mse . call ( 'Up' , * a ) ; end def onLButtonDoubleClick ( * a ) ; @@mse . call ( 'DblClk' , * a ) ; end def onMButtonDoubleClick ( * a ) ; @@mse . call ( 'DblClk' , * a ) ; end def onRButtonDoubleClick ( * a ) ; @@mse . call ( 'DblClk' , * a ) ; end def onKeyDown ( key , repeat , flags , view ) t = flags . to_s ( 2 ) . rjust ( 16 ) bin = "#{ t[-16,4]} #{ t[-12,4]} " "#{ t[ -8,4]} #{ t[ -4,4]}" . rjust ( 19 ) puts "#{key.to_s.ljust(4)}\t#{flags.to_s.ljust(5)}\t#{bin}" k = key . to_s . rjust ( 3 ) alt = ( ALT_MODIFIER_MASK & key != 0 ) . to_s . ljust ( 5 ) cons = ( CONSTRAIN_MODIFIER_MASK & key != 0 ) . to_s . ljust ( 5 ) copy = ( COPY_MODIFIER_MASK & key != 0 ) . to_s . ljust ( 5 ) puts "key = #{k}  alt = #{alt}  cons = #{cons}  copy = #{copy}" end } Sketchup . active_model . select_tool ( @tool ) end
Creates a tool and and callbacks for mouse and KeyDown events
Creates a tool and and callbacks for mouse and KeyDown events
# Some binary fun for testing