sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    Rendering_options pause start_timer?

    Scheduled Pinned Locked Moved Developers' Forum
    4 Posts 3 Posters 187 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A Offline
      Aerilius
      last edited by

      I want to call a messagebox when the user clicks. On the mouse click, I first want to draw something on the screen (not included in this example code), but since the messagebox is modal, I have to keep some time in between to update the view before the messagebox appears. So far it would work by using UI.start_timer.

      But it seems changing the Sketchup.active_model.rendering_options pauses the timer until the cursor hovers the UI (toolbar etc.).
      If you disable the lines marked with ###, the messagebox appears like normal. Why could that be?

      
      class TestTool
        def initialize
          @ip = Sketchup;;InputPoint.new
          @model = Sketchup.active_model
        end
      
        def onMouseMove(flags, x, y, view)
          @ip.pick(view, x, y)
          view.invalidate
        end
      
        def onLButtonDown(flags, x, y, view)
          @ip.pick(view, x, y)
          #@model.select_tool(nil) # no good workaround
          id = UI.start_timer(1, false){ 
            UI.stop_timer(id)
            UI.messagebox("When did this messagebox appear?", MB_YESNOCANCEL)
          }
        end
      
        def draw(view)
          if @ip.valid? && @ip.display?
            @ip.draw view
            text = "text"
            c = @model.rendering_options['ForegroundColor']
            @model.rendering_options['ForegroundColor'] = Sketchup;;Color.new("white") ###
            view.draw_text( view.screen_coords(@ip.position), text )
            @model.rendering_options['ForegroundColor'] = c ###
          end
        end
      end
      
      Sketchup.active_model.select_tool(TestTool.new)
      
      
      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        This is odd.

        When I click on empty space the timer triggers as expected. (No text is displayed then.)

        But when I click on geometry things get delayed. (Text is displayed.)

        Don't know why this is.

        But - I wouldn't set @model.rendering_options['ForegroundColor'] in the draw event. The operation adds to the undo-stack. So if you do that in the draw event you're flooding the undo-stack and effectively zaps it.

        Because it adds to the undo stack I decided not use set forground colour to control the draw_text colour - because adding these events to the undo stack will just confuse the user and he/she tried to go back in the stack - even if you set it at the activation and deactivation of the tool.

        Thomas Thomassen — SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • Dan RathbunD Offline
          Dan Rathbun
          last edited by

          The id reference should be @id, otherwise it's local to the method and may get GC'd.

          The first arg to start_timer should be a Float.

          I'm not here much anymore.

          1 Reply Last reply Reply Quote 0
          • A Offline
            Aerilius
            last edited by

            Thanks for the replies and for the correction about @id. I changed both, but it doesn't solve the problem.

            It seems the timer starts correctly and counts until the end, only the action (code block) isn't executed until the user hovers empty space or give focus to other UI elements.

            @unknownuser said:

            I wouldn't set @model.rendering_options['ForegroundColor'] in the draw event.

            I agree (I didn't think about that), although I didn't notice it in Edit → Undo... I now chose to get along without text color.

            1 Reply Last reply Reply Quote 0
            • 1 / 1
            • First post
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement