• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

Position of SU viewport versus computer screen

Scheduled Pinned Locked Moved Developers' Forum
6 Posts 3 Posters 1.5k 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.
  • F Offline
    fredo6
    last edited by 3 Apr 2016, 10:04

    After so many SU versions, there is still now way to know where the top-left corner of the SU viewport versus the computer screen (that is taking into account the SU titlebar and toolbars, top and left)

    Am I correct, or someone did crack it?
    .
    This would allow to have a positioning of web dialog boxes by reference to position of objects in the SU viewport.

    Currently Web dialogs only position by reference to the computer screen.

    Fredo

    1 Reply Last reply Reply Quote 0
    • D Offline
      driven
      last edited by 3 Apr 2016, 15:33

      Fredo,
      there's still no cross platform methods that I know of...

      you can do this with a simple bin script that can run from the plugin sub-folder on a mac...

      clk_dlg_mac.gif

      the onLButtonDown sends the x,y to the bin script, which returns the screen co-ords for the web dialog...

      # use a class to create a tool
      class ClicTool
        def activate
          puts 'ClickTool has been activated.'
          @clk_dlg = UI;;WebDialog.new
          # get the scale for retina
          @scale = @clk_dlg.screen_scale_factor.to_i
          p " @scale = #{@scale} "
        end
      
        #----------------------------------------------------------------------------------------#
      
        def set_dlg_position(mod_pt)
          # this utility reports the screen position of the last click, i.e. tthe one that invokes it...
          clk_pt = `/usr/local/bin/cliclick -r p;.`.split(/; /)[1].chomp!.split(',')
          msg = "mod_pt = #{mod_pt} and clk_pt = #{clk_pt}"
          w = 200
          h = 100
          @clk_dlg.set_html(msg)
          @clk_dlg.set_size(w, h)
          # play with positioning by
          pw = clk_pt[0].to_i - (w / 2)
          ph = clk_pt[1].to_i - (h / 2)
          @clk_dlg.set_position(pw, ph)
          @clk_dlg.show_modal
        end
      
        #----------------------------------------------------------------------------------------#
      
        def onLButtonDown(_flags, x, y, _view)
          mod_pt = [x / @scale, y / @scale]
          set_dlg_position(mod_pt)
          # puts "onLButtonDown; flags = #{flags}"
        end
      
        #----------------------------------------------------------------------------------------#
      end # class
      
      #----------------------------------------------------------------------------------------#
      
      clk_dlg = ClicTool.new
      Sketchup.active_model.select_tool(clk_dlg)
      #----------------------------------------------------------------------------------------#
      
      

      john

      learn from the mistakes of others, you may not live long enough to make them all yourself...

      1 Reply Last reply Reply Quote 0
      • F Offline
        fredo6
        last edited by 3 Apr 2016, 20:05

        John,

        Thanks. Good to know, even if it requires an extra library (Cliclick).

        The web dialogs in SU is really an unfinished job. I wonder why, because this is actually very powerful. This problem of coordinates and the problem of controlling the focus are definitely to be addressed, but counting the number of releases of SU without any evolution in the Web Dialog area makes me think I may be the only one to care!

        Fredo

        1 Reply Last reply Reply Quote 0
        • D Offline
          driven
          last edited by 3 Apr 2016, 21:07

          @fredo6 said:

          ... even if it requires an extra library (Cliclick).

          even my modified version of cliclick is only 99 KB and if all you want is mousePosition it could shrink a lot...

          I believe you can use getMousePosition via ruby on a PC...

          I also really like webDialogs and wish we had more control over them...

          john

          learn from the mistakes of others, you may not live long enough to make them all yourself...

          1 Reply Last reply Reply Quote 0
          • D Offline
            driven
            last edited by 4 Apr 2016, 19:59

            fredo,
            I just compiled my own mouse_position bin script and it comes in at 19kb...

            I also played around with that script so the dialog never overhangs the viewport...

            in reality it only needs to be run once per model with a corresponding click in SU to give you the variation between the 2 [ x, y] returns...

            john

            learn from the mistakes of others, you may not live long enough to make them all yourself...

            1 Reply Last reply Reply Quote 0
            • A Offline
              Anton_S
              last edited by 5 Apr 2016, 07:32

              Hello fredo. For windows, you can use Win32 API or a C++ extension to get viewport origin in screen coordinates. It has been discussed here: http://sketchucation.com/forums/viewtopic.php?f=180%26amp;t=61867#p566233

              It won't work on Mac, however, I guess you could try what driven suggested.

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

              Advertisement