Cursor in ruby tutorial

I’m looking for a great tutorial for creating a new cursor in Ruby.

To create Icon I try to use Layout then export as pdf for mac and convert it into svg with online service.
But it didn’t work
I was suspecting the size of the pdf 72x72.[icons.zip|attachment]

After I try an online service to create and svg and convert it into pdf with another online service
the dimension of the pdf is now 24x24
But it didn’t work.

please find enclosed the all theicons.zip (61,5 Ko) file

So as alway , I use the same bad method that I always use with 64x64 png where I change the hot point depending of the platform ( mac or pc)

Please find enclosed fin actual code that work but not with svg or pdf (only png)

	class SimpleMoveTool


  	 	###################
  	 	###################
  	 	##### ICON  #####
  	 	###################
  	 	###################


        if(RUBY_PLATFORM =~ /darwin/)
		  middle_cursor_point = 45
          #iConeDeLoutil = "move_copy.pdf"
        else
		  middle_cursor_point = 22
          #iConeDeLoutil = "move_copy.svg"
        end

		extension_dir = __dir__.dup
		extension_dir.force_encoding('UTF-8') if extension_dir.respond_to?(:force_encoding)

		cursorDir = File.join(extension_dir, "..", "icon")

        iConeDeLoutil = "move_yes.png"
		cursor_path = File.join(cursorDir, iConeDeLoutil)
		CURSOR_ID = UI.create_cursor(cursor_path, middle_cursor_point, middle_cursor_point) if File.exist?(cursor_path)


	def initialize
         ....... 
		@current_cursor = C    URSOR_ID
    end

    def onSetCursor
			UI.set_cursor(@current_cursor)
	end

Don’t worry about file name (there is 3 icons )

I 'm looking an complete explanation about cursor inruby. Thanks for your help

There is one thing I can say about your previous example here …

… is that the pixel indices are zero based and therefore if cursors were standard on 64 pixels square, … then your y index is out of bounds because the first index is 0 and the last is 63.


I think Thomas has explained it in an older topic here somewhere.

On Windows at 100% display scaling the cursors are the same size as the large toolbar icons. (ie, 24 x 24 pixels, … small icons being based upon 16 x 16 pixels.) [The Ruby API documentation does not really note any difference between the Win and MacOS platforms.]

Which brings us to …

if(RUBY_PLATFORM =~ /darwin/)

BTW, Ruby doesn’t use parenthesis around conditional expressions unless we need to control the order of evaluation. Doing this makes code harder to read.

The test against the global RUBY_PLATFORM has always been discouraged in favor of other methods. Use it as a last resort. Since SketchUp 2014 the API has had the Sketchup::platform module method which should be preferred …

if Sketchup.platform == :platform_osx

If you support pre-2014 SketchUp versions (running Ruby 1.8.x) the method call to Sketchup::platform would raise a NoMethodError so a rescue in modifier position can trap this and use the fallback …

if Sketchup.platform == :platform_osx rescue RUBY_PLATFORM =~ /darwin/

Most coders set a platform constant(s) at the top of their extension module so that the platform test is only done once when the module loads. All conditional expressions depending upon platform then reference the boolean constant(s).

WIN = Sketchup.platform == :platform_win
MAC = !WIN

Continuing on the cursor subject …

SketchUp’s display scaling (aka scaled resolution on Mac) support will automatically scale up toolbar button images, cursors and click apertures. This should mean if you base your cursor hotpoint coordinates on the standard, then SketchUp should scale the location as appropriate for the users display scale setting.

If it doesn’t then it is a bug in the API and should be logged in the API Issue Tracker.

  • I’ll try and see if I can find Thomas’ previous example in the forum.
1 Like

This old topic seems to indicate that the standard size for cursors is 32 x 32 …

… the topic starter Bruce was also having issues trying to use 64 x 64 PNG images for cursors.

I change the hot spot and the way to check plateform and its works !

I put my final code below:

  ...
  	WIN = Sketchup.platform == :platform_win
  	MAC = !WIN
  ...

if MAC
	  middle_cursor_point = 12
	  icon_extension = ".pdf"
else
	  middle_cursor_point = 12
	  icon_extension = ".svg"
end

	extension_dir = __dir__.dup
	extension_dir.force_encoding('UTF-8') if extension_dir.respond_to?(:force_encoding)
	cursorDir = File.join(extension_dir, "..", "icon")

iConeDeLoutil = "move_yes#{icon_extension}"
	cursor_path = File.join(cursorDir, iConeDeLoutil)
	SSIMPLE_MOVE_CURSOR_ID = UI.create_cursor(cursor_path, middle_cursor_point, middle_cursor_point) if File.exist?(cursor_path)
1 Like

Sorry, im back about cursor :frowning:
The svg that I use for cursor appear as a black square on a Windows10surface pro, Sketchup pro 2020
I check the svg with W3C validator and its ok.
I compare with a native cursor of sketchup (cursor_offset.svg) and the only difference was on svg structure.
I make this try:

  • On mine svg I don’t have < title > and < desc > markup. I try to add it be nothing change.
  • A another difference was the width and height. They are define as “24” instead of “24px”. I update it but nothing change.

On my svg I have something in the markup. On the offset svg I haven’t. I don’t know the way to change that.

Please find the svg file
simple_move_yes.svg.zip (1,8 Ko)

find the original sketchup cursor cursor_offset.svg.zip (2,2 Ko)

The code to load the SVG ( that work for the pdf on mac)

...
    if MAC
	  middle_cursor_point = 12
	  icon_extension = ".pdf"
    else
	  middle_cursor_point = 12
	  icon_extension = ".svg"
    end

	extension_dir = __dir__.dup
	extension_dir.force_encoding('UTF-8') if extension_dir.respond_to?(:force_encoding)
	cursorDir = File.join(extension_dir, "..", "icon")
	# NORMAL CURSOR
    iConeDeLoutil = "simple_move_yes#{icon_extension}"
	cursor_path = File.join(cursorDir, iConeDeLoutil)
	SSIMPLE_MOVE_CURSOR_ID = UI.create_cursor(cursor_path, middle_cursor_point,

There are old topics about this. Try using Inkscape to resave the SVG. Or perhaps GIMP ?

argggggggggggg
Inkscape isn’t compatible on the last release of Mac and Gimp rasted the svg , …
I will try all free tool on the web and comeback

Thanks @DanRathbun

A Cursor manual is missing.

After few quick and unsuccessful research and try, I decide to use png :sob: