src/jwm_draw_framing/draw_framing.rb
##------------------
## onKeyDown is called when the user presses a key on the keyboard.
## We are checking it here to see if the user pressed an arrow key to toggle axis lock on/off 
## so that we can lock the plane of the chosen cross-section
## VK_xxx keys are built-in Sketchup Ruby constants defining (some) of the keys on the keyboard
onKeyDown is called when the user presses a key on the keyboard.
We are checking it here to see if the user pressed an arrow key to toggle axis lock on/off
so that we can lock the plane of the chosen cross-section
VK_xxx keys are built-in Sketchup Ruby constants defining (some) of the keys on the keyboard
onKeyDown is called when the user presses a key on the keyboard . We are checking it here to see if the user pressed an arrow key to toggle axis lock on / off so that we can lock the plane of the chosen cross - section VK_xxx keys are built - in Sketchup Ruby constants defining ( some ) of the keys on the keyboard
def onKeyDown(key, repeat, flags, view)
    case key 
    when VK_RIGHT 
      if @@axis_lock == X_AXIS then 
        @@axis_lock = NO_LOCK
        @cursor_text = "\n\n" + @profile[1]
      else
        @@axis_lock = X_AXIS 
        @reported_normal = @@axis_lock
        @vec5 = Z_AXIS.cross @reported_normal
        @cursor_text = "\n\n" + @profile[1] + "\nX locked"
      end
    when VK_LEFT 
      if @@axis_lock == Y_AXIS then 
        @@axis_lock = NO_LOCK
        @cursor_text = "\n\n" + @profile[1]
      else
       @@axis_lock = Y_AXIS 
       @reported_normal = @@axis_lock
       @vec5 = Z_AXIS.cross @reported_normal
       @cursor_text = "\n\n" + @profile[1] + "\nY locked"
      end
    when VK_DOWN 
      if @@axis_lock == Z_AXIS then 
        @@axis_lock = NO_LOCK
        @cursor_text = "\n\n" + @profile[1]
      else
        @@axis_lock = Z_AXIS 
        @reported_normal = @@axis_lock
        @vec5 = Y_AXIS
        @cursor_text = "\n\n" + @profile[1] + "\nZ locked"
      end
    when VK_UP  
      if @@axis_lock == Z_AXIS then 
        @@axis_lock = NO_LOCK
      else
        @@axis_lock = Z_AXIS 
        @reported_normal = @@axis_lock
        @vec5 = Y_AXIS
        @cursor_text = "\n\n" + @profile[1] + "\nZ locked"
      end
    when CONSTRAIN_MODIFIER_KEY
      if( repeat == 1 )
      @shift_down_time = Time.now
        if( view.inference_locked? )
          view.lock_inference
        elsif( @state == 0 && @ip1.valid? )
          view.lock_inference @ip1
          view.line_width = 3
        elsif( @state <= 2 && @ip2.valid? )
          view.lock_inference @ip2, @ip1
          view.line_width = 3
        end
      end
    when 9 
    if @state == 1   
        @flip = (@flip + 1)%4 
      end 
    end 
    self.onSetCursor() 
    false
  end
def onKeyDown ( key , repeat , flags , view ) case key when VK_RIGHT if @@axis_lock == X_AXIS then @@axis_lock = NO_LOCK @cursor_text = "\n\n" + @profile [ 1 ] else @@axis_lock = X_AXIS @reported_normal = @@axis_lock @vec5 = Z_AXIS . cross @reported_normal @cursor_text = "\n\n" + @profile [ 1 ] + "\nX locked" end when VK_LEFT if @@axis_lock == Y_AXIS then @@axis_lock = NO_LOCK @cursor_text = "\n\n" + @profile [ 1 ] else @@axis_lock = Y_AXIS @reported_normal = @@axis_lock @vec5 = Z_AXIS . cross @reported_normal @cursor_text = "\n\n" + @profile [ 1 ] + "\nY locked" end when VK_DOWN if @@axis_lock == Z_AXIS then @@axis_lock = NO_LOCK @cursor_text = "\n\n" + @profile [ 1 ] else @@axis_lock = Z_AXIS @reported_normal = @@axis_lock @vec5 = Y_AXIS @cursor_text = "\n\n" + @profile [ 1 ] + "\nZ locked" end when VK_UP if @@axis_lock == Z_AXIS then @@axis_lock = NO_LOCK else @@axis_lock = Z_AXIS @reported_normal = @@axis_lock @vec5 = Y_AXIS @cursor_text = "\n\n" + @profile [ 1 ] + "\nZ locked" end when CONSTRAIN_MODIFIER_KEY if ( repeat == 1 ) @shift_down_time = Time . now if ( view . inference_locked? ) view . lock_inference elsif ( @state == 0 && @ip1 . valid? ) view . lock_inference @ip1 view . line_width = 3 elsif ( @state <= 2 && @ip2 . valid? ) view . lock_inference @ip2 , @ip1 view . line_width = 3 end end when 9 if @state == 1 @flip = ( @flip + 1 ) % 4 end end self . onSetCursor ( ) false end
onKeyDown is called when the user presses a key on the keyboard.
onKeyDown is called when the user presses a key on the keyboard .
## puts "onKeyDown called" ## Check for Arrow keys to toggle axis lock ## Right arrow key pressed: toggle red axis lock on/off ## Red axis lock was on: turn all axis locks off ## turn red axis lock on ## Reset long axis to axis lock and recalculate @vec5 ## Left arrow key pressed: toggle green axis lock on/off ## Y-axis lock was on: turn all axis locks off ## turn green axis lock on ## Reset long axis to axis lock and recalculate @vec5 ##view.refresh ## Down  arrow key pressed: toggle blue axis lock on/off ## Axis lock was on: turn all axis locks off ## turn blue axis lock on ## Reset long axis to axis lock  ## Up arrow key pressed: toggle blue axis lock on/off ## Axis lock was on: turn all axis locks off ## turn blue axis lock on ## Reset long axis to axis lock and recalculate @vec5 ## puts "CONSTRAINED" ## if we already have an inference lock, then unlock it ## calling lock_inference with no arguments actually unlocks ## Tab key: Cycle through flipX, flipY, flipXY, noflip ## puts "@state = " + @state.to_s ## Only applicable when cross-section has been drawn ## puts "flip state = " + @flip.to_s ##Reorient inserted profile ##If needed, flip profile in x, y, or both directions ## if @comp_defn.instances[-1] ## don't try unless there's something created  ## case @flip  ## when 0 ## flip X ## @comp_defn.instances[-1].transform! flip_x ## when 1 ## flip Y ## @comp_defn.instances[-1].transform! flip_y ## when 2 ## flip X & Y (Y was already flipped)  ## @comp_defn.instances[-1].transform! flip_x          ## when 3 ## flip back to original ## @comp_defn.instances[-1].transform! flip_y ## end ## case @flip ## end ## if@comp_defn.instances[-1] ## if @state ## case key ##   puts"Selected axis = " + @@axis_lock.inspect.to_s ## force change of cursor on screen
key
<not_specific>
repeat
<not_specific>
flags
<not_specific>
view
<not_specific>