OnScreen GUI Toolkit
-
Can we get a public Issue Tracker?
-
My draw cache class. You create an instance of it and call the drawing methods you'd usually call on View to this. And in the tool's draw event to make it render out the cached drawing instructions.
Example:
<span class="syntaxdefault"><br />class MyTool<br /> def initialize<br /> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">drawing_cache </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> DrawCache</span><span class="syntaxkeyword">.new(</span><span class="syntaxdefault"> Sketchup</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_model</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">active_view </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> end<br /> def onLButtonUp</span><span class="syntaxkeyword">(</span><span class="syntaxdefault">flags</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> x</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> y</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> view</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">drawing_cache</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">line_stipple </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxstring">'-'<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">drawing_cache</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">draw</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> GL_QUADS</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">...</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">drawing_cache</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">draw</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> GL_LINES</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">...</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">drawing_cache</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">draw_points</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> GL_QUADS</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">...</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> end<br /> def draw</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> view </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">drawing_cache</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">render<br /> end<br />end </span><span class="syntaxcomment"># class<br /></span><span class="syntaxdefault"> </span>
DrawCache Class
<span class="syntaxdefault"><br /></span><span class="syntaxcomment">#-------------------------------------------------------------------------------<br />#<br /># Thomas Thomassen<br /># thomas[at]thomthom[dot]net<br />#<br />#-------------------------------------------------------------------------------<br /><br /><br /></span><span class="syntaxdefault">module TT</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">Plugins</span><span class="syntaxkeyword">;;</span><span class="syntaxdefault">BezierSurfaceTools<br /> <br /> </span><span class="syntaxcomment"># Caches drawing instructions so complex calculations for generating the<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># GL data can be reused.<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># Redirect all Skethcup;;View commands to a DrawCache object and call<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># #render in a Tool's #draw event.<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># @since 1.0.0<br /></span><span class="syntaxdefault"> class DrawCache<br /> </span><span class="syntaxcomment"># (?) Move to TT_Lib ?<br /></span><span class="syntaxdefault"> <br /> </span><span class="syntaxcomment"># @param [Sketchup;;View]<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># @since 1.0.0<br /></span><span class="syntaxdefault"> def initialize</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> view </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">view </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> view<br /> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">commands </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">[]<br /></span><span class="syntaxdefault"> end<br /> <br /> </span><span class="syntaxcomment"># Clears the cache. All drawing instructions are removed.<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># @return [Nil]<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># @since 1.0.0<br /></span><span class="syntaxdefault"> def clear<br /> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">commands</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">clear<br /> nil<br /> end<br /> <br /> </span><span class="syntaxcomment"># Draws the cached drawing instructions.<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># @return [Sketchup;;View]<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># @since 1.0.0<br /></span><span class="syntaxdefault"> def render<br /> view </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">view<br /> for command in </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">commands<br /> view</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">send</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">*</span><span class="syntaxdefault">command </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> end<br /> view<br /> end<br /> <br /> </span><span class="syntaxcomment"># Cache drawing commands and data. These methods received the finsihed<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># processed drawing data that will be executed when #render is called.<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">[<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">;</span><span class="syntaxdefault">draw</span><span class="syntaxkeyword">,<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">;</span><span class="syntaxdefault">draw2d</span><span class="syntaxkeyword">,<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">;</span><span class="syntaxdefault">draw_line</span><span class="syntaxkeyword">,<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">;</span><span class="syntaxdefault">draw_lines</span><span class="syntaxkeyword">,<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">;</span><span class="syntaxdefault">draw_points</span><span class="syntaxkeyword">,<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">;</span><span class="syntaxdefault">draw_polyline</span><span class="syntaxkeyword">,<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">;</span><span class="syntaxdefault">draw_text</span><span class="syntaxkeyword">,<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">;</span><span class="syntaxdefault">drawing_color</span><span class="syntaxkeyword">=,<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">;</span><span class="syntaxdefault">line_stipple</span><span class="syntaxkeyword">=,<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">;</span><span class="syntaxdefault">line_width</span><span class="syntaxkeyword">=,<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">;</span><span class="syntaxdefault">set_color_from_line<br /> </span><span class="syntaxkeyword">].</span><span class="syntaxdefault">each </span><span class="syntaxkeyword">{</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">|</span><span class="syntaxdefault">symbol</span><span class="syntaxkeyword">|<br /></span><span class="syntaxdefault"> define_method</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> symbol </span><span class="syntaxkeyword">)</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">{</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">|*</span><span class="syntaxdefault">args</span><span class="syntaxkeyword">|<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">commands </span><span class="syntaxkeyword"><<</span><span class="syntaxdefault"> args</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">unshift</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> this_method </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">commands</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">size<br /> </span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault"> </span><span class="syntaxkeyword">}<br /></span><span class="syntaxdefault"> <br /> </span><span class="syntaxcomment"># Pass through methods to Sketchup;;View so that the drawing cache object<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># can easily replace Sketchup;;View objects in existing codes.<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment">#<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># @since 1.0.0<br /></span><span class="syntaxdefault"> def method_missing</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">*</span><span class="syntaxdefault">args </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> view </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">@</span><span class="syntaxdefault">view<br /> method </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> args</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">first<br /> if view</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">respond_to</span><span class="syntaxkeyword">?(</span><span class="syntaxdefault"> method </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> view</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">send</span><span class="syntaxkeyword">(*</span><span class="syntaxdefault">args</span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> else<br /> raise NoMethodError</span><span class="syntaxkeyword">,</span><span class="syntaxdefault"> </span><span class="syntaxstring">"undefined method `#{method}' for #{self.class.name}"<br /></span><span class="syntaxdefault"> end<br /> end<br /> <br /> </span><span class="syntaxcomment"># @return [String]<br /></span><span class="syntaxdefault"> </span><span class="syntaxcomment"># @since 1.0.0<br /></span><span class="syntaxdefault"> def inspect<br /> hex_id </span><span class="syntaxkeyword">=</span><span class="syntaxdefault"> TT</span><span class="syntaxkeyword">.</span><span class="syntaxdefault">object_id_hex</span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> self </span><span class="syntaxkeyword">)<br /></span><span class="syntaxdefault"> </span><span class="syntaxstring">"#<#{self.class.name};#{hex_id} Commands;#{@commands.size}>"<br /></span><span class="syntaxdefault"> end<br /> <br /> private<br /> <br /> </span><span class="syntaxcomment"># http://www.ruby-forum.com/topic/75258#895569<br /></span><span class="syntaxdefault"> def this_method<br /> </span><span class="syntaxkeyword">(</span><span class="syntaxdefault"> caller</span><span class="syntaxkeyword">[</span><span class="syntaxdefault">0</span><span class="syntaxkeyword">]</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">=~</span><span class="syntaxdefault"> </span><span class="syntaxkeyword">/`</span><span class="syntaxdefault">([^']*)'/ and $1 ).intern<br /> end<br /> <br /> end # class DrawCache<br /> <br /><br />end # module<br /></span>
-
Here's how it looks on my cheap laptop. Do the sliders work? They did not work for me. It was a little slow with all 3 themes shown. When I commented out all but the native theme, it was better. I wouldnt expect the average plugin to use anywhere close to the number of widgets in the test tool, so performance wouldn't be an issue.
-
When I try to test OnScreen GUI no errors are indicated but the window never appears.
-
Sam, you need to make it the active tool..
Sketchup.active_model.select_tool(TestTool.new)
And you may need to zoom a little to get it to activate - the tool may need a view.invalidate/view.refresh in there somewhere.
-
DOH!!!
edit:
Ok now how to use it. I have played around a bit with the testGUI.rb trying to figure out how to get the value from the widget. The slider example seems to emply that variable value should be the current value of the slider but it contains something like "pos(84.0,19.0,-1.0)flags0".
-
That's a bug! (the raw data of the event and where the slider was clicked)
-
Thank you for sharing this! I want to revamp SU2KT when time permits.
I will report if I find any bugs. -
I don't even know how to call this coincidence maybe a kind of synchronicity... I mean a few weeks ago the idea to make custom UI library based on view.draw method suddenly came to my mind. And I even started to code it
Actually I needed a kind of adjustment curve editing control for one of my tools and since I didn't find any javascript ready made widget I decided to make my own control based on view.draw...
I think it would be interesting to take a look at the result in a video: http://youtu.be/QLfI1McLMa0?hd=1 (skip to 1:08 to view 'Control Curve' window).
In short, now I think there is no need to continue coding my own library since OnScreen GUI Toolkit is already exist. I'll try to adapt 'Control Curve' control in it and post result here if you don't mind.
Thanks for sharing your library -
That looks cool!
This toolkit is in early development and it's possible that there will be soon bigger changes in the architecture of the underlying code.
Dialogs like yours don't exist yet at all, one would have to create a new Dialog class as subclass of Container and then create the dialog titlebar, close buttons etc. maybe border resizing... -
Ok, I uploaded my code for the RGB color picker. I'm sure there is lots of optimization that could be done. And its just wrapped in a class. As this development kit keeps improving and adding, maybe the RGB picker could get incorporated into it as well.
http://forums.sketchucation.com/viewtopic.php?f=180&t=47808
Chris
-
Cool! It'd be really nice to see a unified framework here. We're clearly re-inventing each others work.
I have code that reads BMP files and let you draw it - but it's terrible slow. -
with this would it be possible to create a dialog that allows the user to enter a number?
(google translator)
-
Possibly, but it would not be ideal.
I also haven't yet got time to finalize this, but I might be able to finish it in future. -
Has everyone else seen this one?
http://sketchucation.com/forums/viewtopic.php?f=323&t=41982&start=45#p406363
it is in the other thread but thought it was easier to ask about if it's here...is it the same concept?
john -
I would like to do this, to make a inputbox made with OpenGL, could you please show an example of how to do this?
Advertisement