Forum Replies Created
-
AuthorPosts
-
@Mark
Woohoo! Just tried the latest GIT release and have been playing around with the tinyxml module. Works nicely so far. Thanks!
Here’s an example that builds a mojox tree from that “dream.xml” file included with the banana:
[/crayon]Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384[crayon-5cba87f0b7a76904297376 inline="true" ]#Import "<std>"#Import "<mojo>"#import "<mojox>"#Import "<tinyxml2>"#Import "dream.xml"Using std..Using mojo..Using mojox..Using tinyxml2..Function Main()New AppInstanceNew MyWindow("asset::dream.xml")App.Run()EndClass MyWindow Extends WindowField _tree:TreeViewMethod New(url:String)Super.New("XML TreeView Test", 640, 480, WindowFlags.Resizable)Local xml := LoadString(url)Local doc := New XMLDocument()If doc.Parse(xml) <> XMLError.XML_SUCCESSPrint "Failed to parse: " + urlReturnEndifLocal _tree := New TreeView_tree.RootNode.Text = "XML document"AddXMLNodeToTree(doc, _tree.RootNode)ContentView = _treedoc.Destroy()EndMethod AddXMLNodeToTree(xmlNode:XMLNode, parent:TreeView.Node)Local str := ""If xmlNode.ToElement()str += "<" + xmlNode.Value() + ">"Elsestr += xmlNode.Value()EndifLocal treeNode:TreeView.NodeIf strtreeNode = New TreeView.Node(str, parent)EndifLocal xmlChild := xmlNode.FirstChild()While xmlChildIf Not xmlChild.NoChildren()If treeNode Then parent = treeNodeEndifAddXMLNodeToTree(xmlChild, parent)xmlChild = xmlChild.NextSibling()WendEndEndThanks for posting your code. I’ll experiment with that later, see how it compares to Mark’s tinyxml wrapper solution.
@Mark
Anyway, I’m more of a JSON guy myself, but is this pretty much what you need from an xml module?
That’s exactly what I’m looking for.
Regarding JSON, XML, etc. I’m usually an INI or CSV or pure binary data guy, but I’m working on a project where I can actually see the benefit of using XML-formatted data. JSON has never really “gelled” with me, I tend to avoid it.
Wish people would staring using that module manager thingy though…
Indeed, that would be nice. :). I have a few half-finished modules I hope to finish soon. I’ll upload them when I do.
That Monkey1 module by skn3 is the one I had planned to port if nobody else had started on an XML module…
Looks like you need to hack Mojo to support dragging items onto the application window.
Rough “proof of concept” example:
monkey2/modules/mojo/app/app.monkey2
Add the following field, property and method to to the AppInstance class:
[/crayon]Monkey12345678910111213[crayon-5cba87f0c003c015925370 inline="true" ]PrivateField _draggedFileName:StringPublicProperty DraggedFileName:String()Return _draggedFileNameEndMethod ClearDraggedFileName:Void()_draggedFileName = NullEndAdd the following function call to the bottom of the AppInstance class constructor, just before the End statement:
[/crayon]Monkey123456789[crayon-5cba87f0c0042876237605 inline="true" ]Method New()...SDL_EventState(SDL_DROPFILE, SDL_ENABLE)EndAdd the following to the Select statement in the DispatchEvent method:
[/crayon]Monkey1234567891011121314151617[crayon-5cba87f0c0047436511167 inline="true" ]Method DispatchEvent( event:SDL_Event Ptr )Select event->type...Case SDL_DROPFILELocal devent:=Cast<SDL_DropEvent Ptr>( event )_draggedFileName = String.FromCString(devent->file)Print _draggedFileNameSDL_free(devent->file)EndEndCompile the mojo module. Test it out with the following example.
sdl2DragTest.monkey2:
[/crayon]Monkey1234567891011121314151617181920212223242526272829[crayon-5cba87f0c004c748742256 inline="true" ]#Import "<std>"#Import "<mojo>"Using std..Using mojo..Class MyWindow Extends WindowMethod New()Super.New("Window",640, 480)EndMethod OnRender( canvas:Canvas ) OverrideApp.RequestRender()If App.DraggedFileNamecanvas.DrawText(App.DraggedFileName, Width/2, Height/2, .5, .5)Elsecanvas.DrawText("Drag something onto the window...", Width/2, Height/2, .5, .5)EndifEndEndFunction Main()New AppInstanceNew MyWindowApp.Run()EndAs I said, that’s just a proof of concept that works for me (on Windows).
To make DropEvent behave like the other Mojo event types requires extra work… Something for another time…
Though recognized by the MX2 lexer, “Friend” is an unimplemented keyword. Mark has probably reserved it for possible future inclusion in MX2.
Assuming “Friend” will allow functionality similar to the C++ equivalent, it can be useful.
Wikipedia link:
https://en.wikipedia.org/wiki/Friend_classAlso read the first “answer” in this stackoverflow thread:
http://stackoverflow.com/questions/17434/when-should-you-use-friend-in-c
EDIT: The best example I’ve seen that makes use of “Friend” classes (in C++) is in the object pooling chapter of Game Programming Patterns by Robert Nystrom. BTW, I highly recommend that book.
The same chapter he also demonstrates good use of Unions (something else not (yet?) in MX2), but I digress…
August 21, 2016 at 12:05 am in reply to: Detecting the size of the window automatically outside OnRender? Desktop size? #3270I just noticed that global App variable myself. Was going to correct myself but you beat me to it.
August 20, 2016 at 11:53 pm in reply to: Detecting the size of the window automatically outside OnRender? Desktop size? #3268And is there a way to detect the size of the desktop in mojo?
Store a reference to the AppInstance object and read the DesktopSize property:
[/crayon]Monkey12345678910[crayon-5cba87f0ca80f512760920 inline="true" ] Function Main()Local app := New AppInstancePrint app.DesktopSize.X + ", " + app.DesktopSize.YNew MyWindowApp.Run()EndThough in my case the returned result is incorrect. I’m running my desktop at 4k (3840×2160) yet the DesktopSize property returns 2560×1440. Not sure what’s going on there…
In a relatively high-end system like that, I’d get 32GB RAM and a 1000W power supply. Aside from that, the other components look good.
What’s your intended OS?
August 19, 2016 at 9:02 am in reply to: Ted2 1.0.3 crashes when trying to open a file on W10 and W7 #3215The best way to debug ted2 problems is in ted2 – just run src/ted2/ted2.monkey2 in debug mode.
You’re correct of course. So I tracked down a bug in your “fix”.
The RequestFile method in the MainWindowInstance class should be:
[/crayon]Monkey123456789101112[crayon-5cba87f0cfd4f277931247 inline="true" ]Method RequestFile:String( title:String,path:String,save:Bool )Local future:=New Future<String>App.Idle+=Lambda()'future.Set( requesters.RequestFile( "Save As","",True ) )future.Set(requesters.RequestFile(title, path, save))EndReturn future.Get()End“Open” was showing the “Save As” requester.
I’ve also noticed a bug/issue with the Find dialog when pressing CTRL+F but I’ve run out of time to find it today.
I suppose I should create a git account and post bug reports and potential fixes the proper way in future…
I was planning on posting some “simple” mojox examples demonstrating the various principles and widgets but have encountered “conceptual” issues myself.
Reading TED2 source is useful for some things but leaves me wondering for others.
But this isn’t very flexible – in most cases you probably want to use a DockingView as the ‘main’ window/content view. This way, the docking view fills the window (unless you change its Layout!) and you can then add things at the top, left, etc of the dockingview/window.
Ah, that actually makes sense now…
August 19, 2016 at 1:21 am in reply to: Ted2 1.0.3 crashes when trying to open a file on W10 and W7 #3197This is happening for me too. Latest git master zip. Win10. The recommended compiler installed in monkey2’s devtools folder.
EDIT: I just tried on another Win10 system and had the same problem.
The first 1.03 TED2 did function correctly. The following “TED2 tweaks” release, however, did suffer the problem.
You could write a little “ResizeArray()” function that uses generics and the array CopyTo() method. Rough example:
[/crayon]Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293[crayon-5cba87f0d7ed5310612865 inline="true" ]#include "<std>"Using std..'***Function ResizeArray<T>:T[](arr:T[], length:ULong)Local tmp := New T[length]Local count := arr.LengthIf count > tmp.Length Then count = tmp.Lengtharr.CopyTo(tmp, 0, 0, count)Return tmpEnd'***Function Main:Void()'--- Primitive typeLocal arr:= New Int[](0, 1, 2, 3, 4)arr = ResizeArray<Int>(arr, arr.Length * 2)Print "~n--Primitive type array after resize (new element values = 0)--"For Local i := 0 Until arr.LengthPrint i + ": " + arr[i]Next'--- ClassLocal arr2 := New Obj[5]Obj.InitArray(arr2)Print "~n--Class object array Before Resize--"Obj.PrintArray(arr2)arr2 = ResizeArray<Obj>(arr2, arr2.Length * 2)Print "~n--Class object array After Resize --"Print "--New elements have an incremental id value --"Obj.InitArray(arr2)Obj.PrintArray(arr2)End'***Class ObjPrivateGlobal IdValue:UInt = 0Field _id:UIntPublicMethod New()_id = IdValueIdValue += 1End'---Property Id:UInt()Return _idEndMethod ToString:String()Return String(_id)End'---Function InitArray:Void(arr:Obj[])If Not arr Then ReturnFor Local i:= 0 Until arr.LengthIf arr[i] = Null Then arr[i] = New ObjNextEndFunction PrintArray:Void(arr:Obj[])If Not arr Then ReturnFor Local i:= 0 Until arr.LengthIf arr[i] <> Null Then Print i + ": " + arr[i].ToString()NextEndEndEDIT: I should add that the above basically replicates Monkey 1 behavior – slicing and array.Resize() create new arrays rather than truly contracting/extending existing arrays.
Interesting.
I’m using 1.0.2 (latest git clone zip) and don’t see that error…
One thing I find a bit annoying is I keep mistyping ‘asset::’ as ‘assets::’ – anyone else encountered this?
Meh, not really bothered mainly just wondered whether other people found it weird too – the physical dir is called ‘assets’ but you access it with ‘asset’.
Yes, I have found it weird and have been “caught” by it. I would suggest offering both plural and non-plural variations.
Does this not work for you?
globals.monkey2
Global MyVar := 1.0
start.monkey2
[/crayon]Monkey123456[crayon-5cba87f0e1754020223470 inline="true" ]#import "globals.monkey2"Function Main:Void()Print MyVarEnd[/crayon]Monkey123456789[crayon-5cba87f0e49b9803294885 inline="true" ]#import "<std>"Using std..Function Main()Print String.FromChar(65)Print "A"[0]End -
AuthorPosts