Forum Replies Created
-
AuthorPosts
-
There is still some work to do on reflection, mostly ‘selective’ reflection. Currently reflection is ‘all or nothing’, and adds considerable size overhead to builds.
But this will happen eventually and apart from that I reckon it works well.
Have you looked at the reflectiontest banana? There’s an exampole dynamically creating an object there…
Ok, my bad, looks like there were some errors in the stb-image module externs. I have committed a new version of stb-image.monkey2 to the develop branch, here:
https://github.com/blitz-research/monkey2/blob/master/modules/stb-image/stb-image.monkey2
A few things to note:
- The stbi_load() filename param is an ‘OS’ filename, it can’t contain ‘asset::’ in path (std-image module is just a thin wrapper around the c lib). You can find the filesystem path of the assets dir with ‘AssetsDir’ function in std.filesystem, but note this will not work on targets that don’t store assets in the OS filesystem such as android.
- You can also just use Pixmap.Load in std module. This will return a Pixmap with Width/Height/Data etc properties. This will also allow you to use ‘asset::’ in the path on all targets.
I don’t know if I’d call this ‘letterbox’ anymore – IMO, ‘letterbox’ implies (optional) borders – but I think I see what you mean. You just want a fixed virtual height and to preserve aspect ratio, correct?
Here’s my attempt at something similar using OnMeasure and “stretch” Layout. The main benefit to doing it this way is that mouse/touch etc coords are already scaled for you, and of course no need to scale inside OnRender.
I have often thought about adding something like a ‘UIMatrix’ to View. This would be an additional post transform matrix that would be applied to rendering, but also to mouse/touch etc coords. So you could do something like this in OnRender to achieve what your version does:
UIMatrix=AffineMat3f.Scaling( scaleRatio )
Is this a good idea? Each thing I add seems to confuse things a bit!
Also: Use Window Frame.Width, Frame.Height or Frame.Size etc to get ‘physical’ window size. Rect.Width, Rect.Height will return ‘virtual’ size as you’ve noticed.
Monkey12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758Namespace myapp#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class MyWindow Extends WindowField _virtualY:FloatMethod New( title:String, width:Int, height:Int, flags:WindowFlags = Null )Super.New( title, width, height, flags )Layout="stretch"ClearColor=Color.Red_virtualY=288End MethodMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()canvas.Color=Color.Bluecanvas.DrawRect( 1,1,Width-2,Height-2 )canvas.Color=Color.Whitecanvas.DrawText( "Hello World!",Width/2,Height/2,.5,.5 )End MethodMethod OnMeasure:Vec2i() OverrideLocal scale:=Float(Frame.Height)/Float(_virtualY)Local size:=New Vec2i( Frame.Width/scale,_virtualY )Print "Virtual Size="+sizeReturn sizeEndEnd ClassFunction Main()New AppInstanceNew MyWindow( "Hello",640,480,WindowFlags.Resizable )App.Run()EndWell, you can do this, but I wouldn’t advise it.
List/Node hasn’t been designed to be extended, and there may or may not be 1001 other problems you encounter trying to do so!
Monkey123456789101112131415161718192021#Import "<std>"Using std..Class MyNode<T> Extends List<T>.NodeMethod New( value:T )Super.New( value )EndEndFunction Main()Local t:=New MyNode<Int>( 10 )Print t.ValueEndI am trying to extend the Node class but can’t do it because it needs a default New Method.
Not necessarily – suibclass ctors can call ‘Super.New( blah )’ if super class has no default new.
One obvious opt. would be to use uvStack.Data and vertStack.Data instead of ToArray() method. This provides direct access to the stack array, whereas ToArray() creates/copies a new array.
Example of problem please…and this should really probably be a github issue if you want to be 100% I’ll (eventually) take a look at it.
> What’s the logic behind this decision?
Becasue it’s hard to do and I haven’t found a need for it myself or had requests for it yet!
What I want to achieve is the scaling of the letterbox but with a floating size on one axis.
Don’t quite understand this – you want a letterbox *without* the same aspect ratio as returned by OnMeasure?
Letter box does ‘float’ on the minor axis, ie: the axis where the border appears, so you can use View.Gravity to control where letterbox is positioned horizontally/vertically within it’s border. This is shown in the view_layout banana I think.
But letterbox will always fill the major axis, and it’s aspect ratio will always be the same as the aspect ratio returned by OnMeasure.
You may also be able to achieve what you want by nesting a letterbox view within a ‘normal’ view, or vice versa.
Mx2 doesn’t have ‘var’ params so you can’t pass a ‘variable’ to a function.
An array can be used here though – this is preferred to Varptr as it will prevent the object potentially being GC prematurely:
Monkey123456789101112131415Function Blah()Local ref:=New Image[1]MyLoadImage( ref )Local img:=ref[0]EndFunction MyLoadImage( ref:Image[] )ref[0]=LoadImage...EndSomething like ‘Out’ or Var’ params will likely happen at some point, not sure when.
Works fine here!
Can I add it to bananas?
There are no nullable types in mx2. There are variants though – see reflection in monkey2 language docs.
could it be added to MX2?
quite possibly – can you post an issue on github?
Not as yet – please post an issue to github!
This works…
Monkey1234567891011121314Function Main()Local t:=New String[][](New String[]( "Cat","Dog" ),New String[]( "Kitten","Puppy" ) )For Local x:=Eachin tFor Local y:=Eachin xPrint yNextNextEnd -
AuthorPosts