Forum Replies Created
-
AuthorPosts
-
Sure, the main missing MacOS keys are:
Option+Up: Page Up
Option+Down: Page Down
Option+Left: Jump to previous word
Option+Right: Jump to next word
Adding shift to any of these should select from the current position.Also, after commenting/uncommenting a selection, selection shouldn’t be cleared (not MacOs specific)
Bonus: Being able to scroll past the end of the document, let’s say by a half page height, would be lovely!The issue I had with the toolbar was in fact related to my theme, “Warm”. Sorry about that. Will fix the theme and try to do a pull request for it in GitHub (my first pull request ever, whoo-hoo!).
You guys are amazing!
I’m enjoying MojoX now that I understand it better, and diving into it led me to rework my “Game” class so it extends View instead of Window. That way I can more easily stick it into a GUI with all kinds of docks and toolbars, and even have two or more different instances of that class, each one showing something different, in the same interface.
Thanks!
I got the scrolling and the resizing working perfectly, thanks for the help!
I agree percentage sizes should probably have a resize knob too if ‘resizable=true’ and the percentage should mean ‘initial’ size. Will have a look at fixing this.
That seems like it would be really helpful, thanks Mark!
Here’s the revised example. Only one thing I’m not being able to get right: I’d like the initial Scroll coordinates to be centered in the frame when the App starts, but setting Scroll in New() seems to have no effect. I could make a ‘_firstFrame:Bool” field and check for it in OnRender, but it feels like it would be unnecessary clutter if there’s a place where Scroll can be initialized. Where is it?
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111#Import "<mojo>"#Import "<mojox>"Using std..Using mojo..Using mojox..Function Main()New AppInstanceNew TestGuiApp.Run()EndClass TestGui Extends WindowField mainDock:DockingViewField rgtDock:ScrollViewField graphView:GraphViewConst smallFont:Font = Font.Load( "font::DejaVuSans.ttf", 10 )Method New()Super.New( "Test", 1024, 640, WindowFlags.Resizable )mainDock = New MainDock()rgtDock = New RightDock()mainDock.AddView( rgtDock, "right", "400", True )ContentView = mainDockEndEndClass MainDock Extends DockingViewMethod New()Layout="fill"Local newStyle := Style.Copy()newStyle.BackgroundColor = Color.DarkGreynewStyle.BorderColor = Color.BlacknewStyle.Font = TestGui.smallFontStyle = newStyleEndMethod OnRender( canvas:Canvas ) OverrideSuper.OnRender( canvas )canvas.Color = New Color( Rnd(), Rnd(), Rnd() )canvas.DrawCircle( 200, 200, 50 )canvas.Color = Color.Aluminumcanvas.DrawText( "gameview:" + App.FPS + " fps", 5, 5 )EndEndClass RightDock Extends ScrollViewPrivateField _panSpeed := 5.0PublicMethod New()Layout="fill"ScrollBarsVisible = TrueLocal newStyle := Style.Copy()newStyle.BackgroundColor = Color.GreynewStyle.BorderColor = Color.BlacknewStyle.Font = TestGui.smallFontStyle = newStyleLocal graph:=New GraphViewContentView = graphScroll = New Vec2i( graph.Frame.Width/2, graph.Frame.Height/2 ) 'Doesn't work!EndMethod OnRender( canvas:Canvas ) OverrideSuper.OnRender( canvas )canvas.Color = Color.Aluminumcanvas.DrawText( "size:" + Frame + " ,scroll:" + Scroll , 5, 5 )EndMethod OnMouseEvent( event:MouseEvent ) OverrideSelect event.TypeCase EventType.MouseWheelScroll = New Vec2i( Scroll.X+(event.Wheel.X*_panSpeed), Scroll.Y-(event.Wheel.Y*_panSpeed) )App.RequestRender()EndEndEndClass GraphView Extends ViewPrivateField _panSpeed := 5.0Field _size := New Vec2i( 1024, 1024 )PublicMethod New()MinSize=New Vec2i( _size.X, _size.Y )EndMethod OnRender( canvas:Canvas ) OverrideLocal r:= 20.0For Local x := 1 Until 10For Local y := 1 Until 10Local v := (x/10.0) -0.05canvas.Color = New Color( v, v, v )canvas.DrawCircle( (x*100)+r, (y*100)+r, r )NextNextEndEndIn both cases (yours and the linked one) it’s Windows running on a Macbook. Is it a retina screen macbook? If yes, seems like windows doesn’t handle the hi dpi scaling well.
Have you tried on MacOS, since you’re on a Mac? Looks razor sharp here, the only minor problem is that sometimes when I uninstall and reinstall it the fonts look absolutely tiny, and you have to hit Window/Zoom In several times to go back to normal. Another benefit is that Monkey2 seems to compile much faster on MacOS, at least for me.
More info about other IDE options here:
http://monkeycoder.co.nz/forums/topic/monkey2-3rd-party-ide/Although it’s true I don’t use the ‘micro view’…
Hah! As soon as I read that, I turned off the Codemap in the preferences and… CPU usage went from over 40% to… about 2% most of the time!
I’ve been using the dev branch from yesterday, and it sits between 40% and 50% CPU use when I’m not doing anything. Don’t think this happened in whatever previous version I was using.
MacOS, quad core processor laptop.
Thanks Mark!
If you decide to add a SpriteFrames class or similar I’ll update my stuff, but for now I made an “AnimSprite” class that extends Sprite and stores the coordinates internally. I also have an “AnimationClip” class that simply stores a named frame sequence, so you refer to it by name and “grab” different frames from the same sprite sheet.
Here’s the class, complete with Json file loading for animation clips (use example attached at the bottom). This is more or less super untested!
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231Namespace mojo3d.graphicsClass AnimSprite Extends Sprite'Event functionsField onLastFrame :Void()Field onFirstFrame :Void()Protected'Atlas valuesField _frame:Int = 0 'The frame currently displayedField _coordinates:= New Stack<Rect<Double>> 'A stack containing the UV coordinates for each cell'Animation clip managementField _timeScale := 1.0 'Adjusts playback speed. Can be used to create slow motion effects without changing the framerate.Field _anim :AnimationClip 'The animation clip currently playingField _animations := New StringMap< AnimationClip > 'List of available animation clipsField _offset :Int 'Current frame offsetField _framerate:Double = 15.0 'Frame rate, if a clip is not provided'MiscField _firstFrame := TrueField _hasReachedEnd := FalseField _hasReachedStart := False'******************************* Public Properties *******************************Public'Current frameProperty Frame:Int()Return _frameSetter( number:Int )If number <> _frame_frame = Clamp( number, 0, _coordinates.Length-1 )TextureRect = _coordinates[ _frame ]If _frame >= LastFrameIf Not _hasReachedEndonLastFrame()_hasReachedEnd = True_hasReachedStart = FalseEndEndIf _firstFrameonFirstFrame()_firstFrame = FalseElseIf _frame = FirstFrameIf Not _hasReachedStartonFirstFrame()_hasReachedStart = True_hasReachedEnd = FalseEndEndEndEndEnd'current AnimationClipProperty Animation:String()Return _anim.nameSetter( name:String )If _animations[ name ]_anim = _animations[ name ]ElsePrint( "AnimSprite: animation '" + name + "' Not found!" )EndEnd'Map with all animations as values and their names as keysProperty AllAnimations:StringMap< AnimationClip >()Return _animationsEnd'Offsets the current frame, useful when creating multiple copies of the same spriteProperty FrameOffset:Int()Return _offsetSetter( number:Int )_offset = numberEnd'Sets the frame rate. If a clip is in use, that clip's frame rate will be set.Property FrameRate:Double()If _animReturn _anim.framerateElseReturn _framerateEndSetter( value:Double )If _anim_anim.framerate = valueElse_framerate = valueEndEnd'Duration (in seconds) of the current animation clip. If none, duration of the entire spritesheet is provided.Property Duration:Double()Local _period:Double = ( 1.0 / FrameRate ) * _timeScaleIf _animReturn _period * _anim.frames.LengthElseReturn _period * _coordinates.LengthEndEnd'First frame in clipProperty FirstFrame:Int()If _animReturn _anim.frames[ 0 ]ElseReturn 0EndEnd'Last frame in clipProperty LastFrame:Int()If _animReturn _anim.frames[ _anim.frames.Length-1 ]ElseReturn _coordinates.Length - 1EndEnd'******************************* Public Methods *******************************Method New( path:String, cellWidth:Int, cellHeight:Int, padding:Int = 0, border:Int = 0, flags:TextureFlags = TextureFlags.FilterMipmap )'Creates new Sprite with materialSuper.New( SpriteMaterial.Load( path, flags ) )Local texture := Cast<SpriteMaterial>( Material ).ColorTextureLocal _paddedWidth:Double = cellWidth + ( padding * 2 )Local _paddedHeight:Double = cellHeight + ( padding * 2 )Local _rows:Int = ( texture.Height - border - border ) / _paddedHeightLocal _columns:Int = ( texture.Width - border - border ) / _paddedWidth'Generates UV coordinates for each frameLocal numFrames := _rows * _columnsLocal w:Double = texture.WidthLocal h:Double = texture.HeightFor Local i:= 0 Until numFramesLocal col := i Mod _columnsLocal x:Double = ( col * _paddedWidth ) + padding + borderLocal y:Double = ( ( i / _columns ) * _paddedHeight ) + padding + border_coordinates.Push( New Rectf( x/w, y/h, (x+cellWidth)/w, (y+cellHeight)/h ) )Next'Defaults to frame 0Frame = 0End'Update time is in seconds (Double), not millisecondsMethod Update( time:Double )Local frameLength:Double = ( 1.0 / FrameRate ) / _timeScaletime += ( _offset * frameLength )If _animIf _anim.loopFrame = _anim.frames[ Int( ( time Mod Duration ) / frameLength ) ]ElseFrame = _anim.frames[ Int( time / frameLength ) ]EndElseFrame = Int( ( time Mod Duration ) /frameLength )EndEnd'Adds new animation clips.Method AddAnimationClip( _name:String, _loop:Bool = True, framerate:Int, _frames:Int[] )local animClip := New AnimationClipanimClip.name = _nameanimClip.loop = _loopanimClip.frames = _framesanimClip.framerate = framerate_animations.Add( _name, animClip )End'Loads Json fileMethod LoadAnimations( path:String )Local json := JsonObject.Load( path )If jsonLocal anims := json.GetObject( "animations" )If animsFor Local a := Eachin anims.ToObject()Local obj := a.Value.ToObject()Local loop := obj[ "loop" ].ToBool()Local rate := obj[ "rate" ].ToNumber()Local frameStack := obj[ "frames" ].ToArray()Local frames:Int[] = New Int[ frameStack.Length ]For Local n := 0 Until frameStack.Lengthframes[n] = frameStack[n].ToNumber()NextAddAnimationClip( a.Key, loop, rate, frames )NextEndElsePrint( "AnimSprite: Warning, json file not found or invalid" )EndEndEnd'**************************************************************************************************************************************'Class AnimationClip 'AnimationClips contain a sequence of frames to be played, its name, framerate and loop state.field name :String 'Animation namefield loop := True 'looping can be controlled per animationfield frames :Int[] 'Frame list array, contains the sequence in which the frames playField framerate := 15.0 'frame rate per clipProperty FrameCount:Int()Return frames.LengthEndEndAnd here’s an example use, with a little animated explosion sprite!
http://monkeycoder.co.nz/wp-content/uploads/2017/08/animSprite-1.zipOnly thing missing now is a way to “flash” a color on the sprite!
Cheers.That’s coming along really well!
I’m trying to set the flags after creating the material, like this:
Monkey123material = SpriteMaterial.Load( path )material.ColorTexture.Flags = TextureFlags.NoneLocal cat := New Sprite( material )Hi Mark, it’s just an experiment. But I do want the ability to use “traditional” 2D systems in 3D, so I can mix & match depending on the aesthetics I want ( the game “Don’t Starve” is probably a good example of that). Besides, it’s a lot of fun for me since I can play with generating the meshes from scratch, something I’ve never done before!
Also, even if the look is completely 2D, doing it in 3D still has a lot of advantages, like proper occlusion behind objects without breaking things into multiple layers, easily adding “line scrolling” (which, in this case, would be real geometry) and 3D elements to the graphics, even adding real lighting and shadows to seemingly 2d graphics.
Cheers!
While I can look at a shader and more or less understand what it does, the way it “connects” to Mojo (how you pass a variable or a texture from within Monkey2 code, for instance) is still very opaque to me… are there are shader tutorials specifically made for Mojo?
(yes I’m a programming noob)
It’s good as is, makes more sense to be familiar to programmers who know OpenGL than to artists learning programming. Thanks!
Question: naming wise, wouldn’t it be more clear to name the texture arguments “u” and “v”, instead of “s” and “t”, since most CG artists refer to texture coordinates as UV coordinates, or just UVs?
Got it. For some reason I didn’t realize you can just add those extra channels in the Vertex class itself.
Actually, how to manipulate UVs would be my next question, so that covers it as well!Cheers!
Attaching zip works…
http://monkeycoder.co.nz/wp-content/uploads/2017/08/3dgrid.monkey2-1.zip -
AuthorPosts