Browse Source

Squashed 'src/ted2go/' changes from f5b726f6..795d6240

795d6240 Improvements (#111)

git-subtree-dir: src/ted2go
git-subtree-split: 795d6240ae56e8305c90142d04b49378fc019a08
Mark Sibly 7 years ago
parent
commit
0f1712622b

+ 13 - 18
MainWindow.monkey2

@@ -94,6 +94,13 @@ Class MainWindowInstance Extends Window
 		'Build tab
 		
 		_buildConsole=New ConsoleExt
+		' jump to errors etc.
+		_buildConsole.RequestJumpToFile+=Lambda( path:String,line:Int )
+			
+			' emulate build error
+			Local err:=New BuildError( path,line,"" )
+			_buildActions.GotoError( err )
+		End
 		
 		'Output tab
 		
@@ -211,14 +218,9 @@ Class MainWindowInstance Extends Window
 		
 		_buildActions=New BuildActions( _docsManager,_buildConsole,_debugView )
 		_buildActions.ErrorsOccured+=Lambda( errors:BuildError[] )
+			
 			ShowBuildConsole( True )
 			_buildActions.GotoError( errors[0] )
-			
-			_buildErrorsList.Clear()
-			For Local err:=Eachin errors
-				_buildErrorsList.AddItem( New BuildErrorListViewItem( err ) )
-			Next
-			_buildErrorsList.Visible=True
 		End
 		
 		' ProjectView
@@ -437,15 +439,8 @@ Class MainWindowInstance Extends Window
 		_menuBar.AddMenu( _windowMenu )
 		_menuBar.AddMenu( _helpMenu )
 		
-		_buildErrorsList=New ListViewExt
-		_buildErrorsList.Visible=False
-		_buildErrorsList.OnItemChoosen+=Lambda()
-			Local item:=Cast<BuildErrorListViewItem>( _buildErrorsList.CurrentItem )
-			_buildActions.GotoError( item.error )
-		End
-		
+
 		_buildConsoleView=New DockingView
-		_buildConsoleView.AddView( _buildErrorsList,"right","400",True )
 		_buildConsoleView.ContentView=_buildConsole
 		
 		_statusBar=New StatusBarView
@@ -1334,17 +1329,14 @@ Class MainWindowInstance Extends Window
 	Method OnPreBuild()
 		
 		OnForceStop()
-		_buildErrorsList.Visible=False
 	End
 	
 	Method OnPreSemant()
 	
-		_buildErrorsList.Visible=False
 	End
 	
 	Method OnPreBuildModules()
 	
-		_buildErrorsList.Visible=False
 	End
 	
 	Method OnProjectClosed( dir:String )
@@ -1666,6 +1658,10 @@ Class MainWindowInstance Extends Window
 			Select event.Key
 			Case Key.Escape
 				
+				If CodeDocument.HideParamsHint()
+					Return
+				Endif
+				
 				If _fullscreenState=FullscreenState.Editor
 					SwapFullscreenEditor()
 					Return
@@ -1735,7 +1731,6 @@ Class MainWindowInstance Extends Window
 	
 	Field _ircView:IRCView
 	Field _buildConsole:ConsoleExt
-	Field _buildErrorsList:ListViewExt
 	Field _buildConsoleView:DockingView
 	Field _outputConsole:ConsoleExt
 	Field _outputConsoleView:DockingView

+ 14 - 11
Ted2.monkey2

@@ -135,7 +135,7 @@ Using sdl2..
 
 Const MONKEY2_DOMAIN:="http://monkeycoder.co.nz"
 
-Global AppTitle:="Ted2Go v2.8"
+Global AppTitle:="Ted2Go v2.8.1"
 
 
 Function Main()
@@ -193,15 +193,18 @@ Function Main()
 
 	New MainWindowInstance( AppTitle,rect,flags,jobj )
 	
-	' open docs from args
-	Local args:=AppArgs()
-	For Local i:=1 Until args.Length
-		Local arg:=args[i]
-		arg=arg.Replace( "\","/" )
-		If GetFileType( arg ) = FileType.File
-			MainWindow.OpenDocument( arg )
-		Endif
-	Next
+	App.Idle+=Lambda()
+		
+		' open docs from args
+		Local args:=AppArgs()
+		For Local i:=1 Until args.Length
+			Local arg:=args[i]
+			arg=arg.Replace( "\","/" )
+			If GetFileType( arg ) = FileType.File
+				MainWindow.OpenDocument( arg,True )
+			Endif
+		Next
+	End
 	
 	App.Run()
 	
@@ -219,7 +222,7 @@ Function SetupMonkeyRootPath:String( rootPath:String,searchMode:Bool )
 		' search for choosen-by-requester folder
 		While Not found
 	
-			Local ok:=Confirm( "Initializing","Monkey2 root directory isn't set.~nTo continue, you should to specify it." )
+			Local ok:=Confirm( "Initializing","Monkey2 root directory isn't set.~nTo continue, you should specify it." )
 			If Not ok
 				Return ""
 			End

+ 32 - 24
action/BuildActions.monkey2

@@ -368,6 +368,7 @@ Class BuildActions Implements IModuleBuilder
 		MainWindow.UpdateWindow( False )
 	
 		tv.GotoPosition( New Vec2i( err.line,0 ) )
+		tv.MakeKeyView()
 	End
 	
 	
@@ -462,39 +463,35 @@ Class BuildActions Implements IModuleBuilder
 		
 		Repeat
 		
-			Local stdout:=_console.ReadStdout()
+			Local result:=_console.ReadStdoutWithErrors()
+			Local stdout:=result.stdout
 			If Not stdout Exit
 			
 			If stdout.StartsWith( "Application built:" )
 
 '				_appFile=stdout.Slice( stdout.Find( ":" )+1 ).Trim()
 			Else
-			
-				Local i:=stdout.Find( "] : Error : " )
-				If i<>-1
+				
+				Local err:=result.error
+				If err
 					hasErrors=True
-					Local j:=stdout.Find( " [" )
-					If j<>-1
-						Local path:=stdout.Slice( 0,j )
-						Local line:=Int( stdout.Slice( j+2,i ) )-1
-						Local msg:=stdout.Slice( i+12 )
-						
-						Local err:=New BuildError( path,line,msg )
-						Local doc:=Cast<CodeDocument>( _docs.OpenDocument( GetCaseSensitivePath( path ),False ) )
-						
-						If doc
-							doc.AddError( err )
-							'If _errors.Empty
-							'	MainWindow.ShowBuildConsole( True )
-							'	GotoError( err )
-							'Endif
-							_errors.Add( err )
-						Endif
-						
+					
+					Local buildErr:=New BuildError( err.path,err.line,err.message )
+					Local doc:=Cast<CodeDocument>( _docs.OpenDocument( GetCaseSensitivePath( buildErr.path ),False ) )
+					
+					If doc
+						doc.AddError( buildErr )
+						'If _errors.Empty
+						'	MainWindow.ShowBuildConsole( True )
+						'	GotoError( err )
+						'Endif
+						_errors.Add( buildErr )
 					Endif
+					
 				Endif
+				
 				If Not hasErrors
-					i=stdout.Find( "Build error: " )
+					Local i:=stdout.Find( "Build error: " )
 					hasErrors=(i<>-1)
 				Endif
 				
@@ -510,7 +507,18 @@ Class BuildActions Implements IModuleBuilder
 		
 		MainWindow.HideStatusBarProgress()
 		
-		Local status:=hasErrors ? "{0} failed. See the build console for details." Else (_console.ExitCode=0 ? "{0} finished." Else "{0} cancelled.")
+		Local status:=""
+		If hasErrors
+			status="{0} failed. See the build console for details."
+		Else
+			If _console.ExitCode=0
+				status="{0} finished."
+			Else
+				status="{0} cancelled."
+				' notify about cancellation
+				_console.Write( "~n"+status.Replace( "{0}",title )+"~n" )
+			Endif
+		Endif
 		status=status.Replace( "{0}",title )
 		
 		If showElapsedTime

+ 22 - 25
assets/newfiles/Simple_Mojo3d_App.monkey2

@@ -16,41 +16,42 @@ Class MyWindow Extends Window
 	
 	Field _light:Light
 	
-	Field _donut:Model
+	Field _ground:Model
 	
-	Field _bloom:BloomEffect
+	Field _donut:Model
 	
 	Method New( title:String="Simple mojo3d app",width:Int=640,height:Int=480,flags:WindowFlags=WindowFlags.Resizable )
 
 		Super.New( title,width,height,flags )
 		
-		_scene=Scene.GetCurrent()
-		
-		_scene.ClearColor=Color.Black
-		
-		_bloom=New BloomEffect
-		
-		_scene.AddPostEffect( _bloom )
+		'create (current) scene
+		'
+		_scene=New Scene
+		_scene.ShadowAlpha=.75
 		
 		'create camera
 		'
-		_camera=New Camera
-		_camera.Near=.1
-		_camera.Far=100
-		_camera.Move( 0,10,-10 )
+		_camera=New Camera( Self )
 		_camera.AddComponent<FlyBehaviour>()
+		_camera.Move( 0,10,-5 )
 		
 		'create light
 		'
 		_light=New Light
-
+		_light.CastsShadow=True
 		_light.RotateX( 90 )
 		
-		Local material:=New PbrMaterial( Color.Black )
-		material.EmissiveFactor=New Color( 0,2,0 )
-		
-		_donut=Model.CreateTorus( 2,.5,48,24,material )
+		'create ground
+		'
+		Local groundBox:=New Boxf( -50,-1,-50,50,0,50 )
+		Local groundMaterial:=New PbrMaterial( Color.Green )
+		_ground=Model.CreateBox( groundBox,1,1,1,groundMaterial )
+		_ground.CastsShadow=False
 		
+		'create dount
+		'		
+		Local donutMaterial:=New PbrMaterial( Color.Brown )
+		_donut=Model.CreateTorus( 2,.5,48,24,donutMaterial )
 		_donut.Move( 0,10,0 )
 	End
 	
@@ -58,17 +59,13 @@ Class MyWindow Extends Window
 	
 		RequestRender()
 		
-		If Keyboard.KeyHit( Key.Escape ) App.Terminate()
-		
-		If Keyboard.KeyHit( Key.Space ) _donut.Visible=Not _donut.Visible
-		
 		_donut.Rotate( .2,.4,.6 )
-		
+
 		_scene.Update()
 		
-		_scene.Render( canvas,_camera )
+		_camera.Render( canvas )
 		
-		canvas.DrawText( "Width="+Width+", Height="+Height+", FPS="+App.FPS,0,0 )
+		canvas.DrawText( "FPS="+App.FPS,0,0 )
 	End
 	
 End

+ 12 - 0
document/CodeDocument.monkey2

@@ -1188,6 +1188,18 @@ Class CodeDocument Extends Ted2Document
 		ParamsHint?.Hide()
 	End
 	
+	#Rem monkeydocs Return true if ParamsHint was actually closed.
+	#End
+	Function HideParamsHint:Bool()
+		
+		If ParamsHint And ParamsHint.Visible
+			ParamsHint.Hide()
+			Return True
+		Endif
+		
+		Return False
+	End
+	
 	Method GoBack()
 		
 		Navigator.TryBack()

+ 3 - 3
document/SceneDocument.monkey2

@@ -44,7 +44,7 @@ Class SceneDocumentView Extends View
 			_anim=0
 		Endif
 		
-		_doc.Scene.Render( canvas,_doc.Camera )
+		_doc.Camera.Render( canvas )
 	End
 	
 	Method OnMouseEvent( event:MouseEvent ) Override
@@ -105,7 +105,7 @@ Class SceneDocument Extends Ted2Document
 		
 		Scene.SetCurrent( _scene )
 		
-		_camera=New Camera
+		_camera=New Camera( _view )
 		_camera.Near=.01
 		_camera.Far=10
 		_camera.MoveZ( -2.5 )
@@ -191,7 +191,7 @@ Class SceneDocumentType Extends Ted2DocumentType
 	Method New()
 		AddPlugin( Self )
 		
-		Extensions=New String[]( ".gltf",".b3d",".3ds",".obj",".dae",".fbx",".blend",".x" )
+		Extensions=New String[]( ".gltf",".glb",".b3d",".3ds",".obj",".dae",".fbx",".blend",".x" )
 	End
 	
 	Method OnCreateDocument:Ted2Document( path:String ) Override

+ 162 - 21
view/ConsoleViewExt.monkey2

@@ -2,12 +2,25 @@
 Namespace ted2go
 
 
-#if __TARGET__<>"emscripten"
-
 #rem monkeydoc The Console class.
 #end
 Class ConsoleExt Extends TextView
-
+	
+	Struct StdoutResult
+		
+		Field stdout:String
+		Field error:ErrorInfo
+		
+		Method New( stdout:String,error:ErrorInfo )
+			
+			Self.stdout=stdout
+			Self.error=error
+		End
+		
+	End
+	
+	Field RequestJumpToFile:Void( path:String,line:Int )
+	
 	#rem monkeydoc Invoked when the console finishes executing a process.
 	#end
 	Field Finished:Void( exitCode:Int )
@@ -64,7 +77,8 @@ Class ConsoleExt Extends TextView
 		
 		Repeat
 		
-			Local stdout:=ReadStdout()
+			Local result:=ReadStdoutWithErrors()
+			Local stdout:=result.stdout
 			If Not stdout Exit
 			
 			Write( stdout )
@@ -93,10 +107,6 @@ Class ConsoleExt Extends TextView
 		
 			Local stdout:=process.ReadStdout()
 			
-'			Print "**** CONSOLE STDOUT *****"
-'			Print stdout
-'			Print "***** END STDOUT *****"
-			
 			If Not stdout
 				If _stdout _stdoutBuf.Add( _stdout )
 				_stdoutOpen=False
@@ -132,6 +142,8 @@ Class ConsoleExt Extends TextView
 		_stdout=""
 		_stdoutBuf.Clear()
 		_stdoutWaiting=Null
+		_errors.Clear()
+		_linesRead=0
 		
 		Return True
 	End
@@ -161,7 +173,33 @@ Class ConsoleExt Extends TextView
 			_stdoutWaiting=Null
 		Wend
 		
-		Return _stdoutBuf.RemoveFirst()
+		Local out:=_stdoutBuf.RemoveFirst()
+		_linesRead+=1
+		Return out
+	End
+	
+	Method ReadStdoutWithErrors:StdoutResult()
+	
+		While _stdoutBuf.Empty
+	
+			If Not _stdoutOpen
+				If _procOpen
+					_stdoutWaiting=New Future<Bool>
+					_stdoutWaiting.Get()
+					_stdoutWaiting=Null
+				Endif
+				Return New StdoutResult( "",Null )
+			Endif
+	
+			_stdoutWaiting=New Future<Bool>
+			_stdoutWaiting.Get()
+			_stdoutWaiting=Null
+		Wend
+	
+		Local out:=_stdoutBuf.RemoveFirst()
+		Local err:=ProcessErrors( out )
+		_linesRead+=1
+		Return New StdoutResult( out,err )
 	End
 	
 	#rem monkeydoc Writes to process stdin.
@@ -244,17 +282,62 @@ Class ConsoleExt Extends TextView
 		'Super.OnKeyEvent( event )
 	End
 	
-'	Method OnContentMouseEvent( event:MouseEvent ) Override
-'		
-'		'select whole line by double click
-'		If event.Type = EventType.MouseDoubleClick
-'			Local line:=Document.FindLine( Cursor )
-'			SelectText( Document.StartOfLine( line ),Document.EndOfLine( line ) )
-'			Return
-'		Endif
-'		
-'		Super.OnContentMouseEvent( event )
-'	End
+	Method OnContentMouseEvent( event:MouseEvent ) Override
+		
+		Select event.Type
+			
+			Case EventType.MouseClick
+				
+				If Not _errors.Empty
+					Local err:=ErrorAt( CharAtPoint( event.Location ) )
+					If err
+						RequestJumpToFile( err.path,err.line )
+						Return
+					Endif
+				Endif
+				
+			Case EventType.MouseMove
+				
+				If Not _errors.Empty
+					Local err:=ErrorAt( CharAtPoint( event.Location ) )
+					Mouse.Cursor=err ? MouseCursor.Hand Else MouseCursor.IBeam
+				Endif
+			
+			Case EventType.MouseEnter
+				
+				Mouse.Cursor=MouseCursor.IBeam
+			
+			Case EventType.MouseLeave
+				
+				Mouse.Cursor=MouseCursor.Arrow
+				
+		End
+		
+		Super.OnContentMouseEvent( event )
+		
+	End
+	
+	Method OnRenderLine( canvas:Canvas,line:Int ) Override
+	
+		Super.OnRenderLine( canvas,line )
+		
+		If _errors.Empty Return
+		
+		Local err:=_errors[line]
+		If Not err Return
+		
+		Local text:=Document.Text
+		
+		For Local word:=Eachin WordIterator.ForLine( Self,line )
+		
+			If err.CheckRange( word.Index )
+				Local txt:=text.Slice( word.Index,word.Index+word.Length )
+				Local rect:=word.Rect
+				Local w:=RenderStyle.Font.TextWidth( txt )
+				canvas.DrawLine( rect.Left,rect.Bottom,rect.Left+w,rect.Bottom )
+			Endif
+		Next
+	End
 	
 	
 	Private
@@ -272,6 +355,9 @@ Class ConsoleExt Extends TextView
 	Field _stdoutBuf:=New StringList
 	Field _stdoutWaiting:Future<Bool>
 	
+	Field _errors:=New IntMap<ErrorInfo>
+	Field _linesRead:Int
+	
 	Method UpdateRunning()
 	
 		If Not _running Or _procOpen Or _stdoutOpen Return
@@ -300,6 +386,61 @@ Class ConsoleExt Extends TextView
 		Endif
 	End
 	
+	Method ProcessErrors:ErrorInfo( stdout:String )
+		
+		Local i:=stdout.Find( "] : Error : " )
+		If i<>-1
+			Local j:=stdout.Find( " [" )
+			If j<>-1
+				Local path:=stdout.Slice( 0,j )
+				Local line:=Int( stdout.Slice( j+2,i ) )-1
+				Local msg:=stdout.Slice( i+12 )
+				Local range:=New Vec2i( j+2+Text.Length,i+Text.Length )
+				
+				Local error:=New ErrorInfo( path,line,msg,range )
+				_errors[_linesRead]=error
+				
+				Return error
+			Endif
+		Endif
+		
+		Return Null
+	End
+	
+	Method ErrorAt:ErrorInfo( charPosition:Int )
+		
+		Local line:=Document.FindLine( charPosition )
+		Local err:=_errors[line]
+		If err And charPosition>=err.clickRange.x And charPosition<=err.clickRange.y
+			Return err
+		Endif
+		
+		Return Null
+	End
+	
 End
 
-#Endif
+
+Private
+
+Struct ErrorInfo
+	
+	Field path:String
+	Field line:Int
+	Field message:String
+	Field clickRange:Vec2i
+	
+	Method New( path:String,line:Int,msg:String,clickRange:Vec2i )
+		
+		Self.path=path
+		Self.line=line
+		Self.message=msg
+		Self.clickRange=clickRange
+	End
+	
+	Method CheckRange:Bool( pos:Int )
+		
+		Return pos>=clickRange.x And pos<clickRange.y
+	End
+	
+End

+ 0 - 2
view/DraggableViewListener.monkey2

@@ -118,8 +118,6 @@ Class DraggableViewListener<TItem,THolder>
 				_item=Null
 				_detached=False
 				
-				event.Eat()
-				
 		End
 	
 	End

+ 5 - 3
view/ProjectView.monkey2

@@ -264,7 +264,7 @@ Class ProjectView Extends ScrollView
 		OpenProject( dir )
 	End
 	
-	Method OnOpenDocument( path:String,runExec:Bool=True )
+	Method OnOpenDocument( path:String,makeFocused:Bool,runExec:Bool=True )
 		
 		If GetFileType( path )<>FileType.File Return
 			
@@ -287,6 +287,8 @@ Class ProjectView Extends ScrollView
 			
 			_docs.OpenDocument( path,True )
 			
+			If Not makeFocused Then Self.MakeKeyView()
+			
 		End )
 	End
 	
@@ -344,12 +346,12 @@ Class ProjectView Extends ScrollView
 		
 		browser.FileClicked+=Lambda( node:ProjectBrowserView.Node )
 			
-			If browser.SingleClickExpanding Then OnOpenDocument( node.Path )
+			If browser.SingleClickExpanding Then OnOpenDocument( node.Path,False )
 		End
 		
 		browser.FileDoubleClicked+=Lambda( node:ProjectBrowserView.Node )
 			
-			If Not browser.SingleClickExpanding Then OnOpenDocument( node.Path )
+			If Not browser.SingleClickExpanding Then OnOpenDocument( node.Path,True )
 		End
 		
 		browser.FileRightClicked+=Lambda( node:ProjectBrowserView.Node )

+ 8 - 1
view/TreeViewExt.monkey2

@@ -199,16 +199,22 @@ Class TreeViewExt Extends TreeView
 			Case EventType.MouseClick
 				
 				_expandStateChanged=False
+			
+			Case EventType.MouseDoubleClick
 				
+				_doubleClicked=True
 				
 			Case EventType.MouseUp
 				
-				If event.Button=MouseButton.Left
+				If Not _doubleClicked And event.Button=MouseButton.Left
 					
 					Local p:=TransformWindowPointToView( Mouse.Location )
 					Local node:=FindNodeAtPoint( p )
 					If node And Not _expandStateChanged Then NodeClicked2( node )
 				Endif
+				
+				_doubleClicked=False
+				
 		End
 		
 		Super.OnContentMouseEvent( event )
@@ -226,6 +232,7 @@ Class TreeViewExt Extends TreeView
 	Field _selColor:Color
 	Field _singleClickExpanding:Bool
 	Field _expandStateChanged:Bool
+	Field _doubleClicked:Bool
 	
 	Field NodeClicked2:Void( node:Node )