About Monkey 2 › Forums › Monkey 2 Development › Request – Native GUI module
Tagged: nativeGUI
This topic contains 18 replies, has 4 voices, and was last updated by
codifies
2 years, 3 months ago.
-
AuthorPosts
-
December 17, 2016 at 7:55 am #5864
Hi
this is the point: to port my current applications (so many!) in Monkey2 I need a native OS-GUI support.
What I’m looking for is a sort of MaxGUI for Monkey2
– small footprint of the final applications
– easy to program (no problem if it’s OOP or not)
– easy to use (for the final user – they fear if something is different in the UX!!!)
– that implements/allows to be ‘extended’ (like the ProxyGadgets in MaxGUI)
– integrated with the OS (copy, paste, drag & drop etc)At the moment I’m only on Windows (XP/Vista/7/8/10) – so other systems are not needed.
I would pay for a module like this between 20/30 USD.
ps: I don’t know if this is the right place to post this ‘announce’ – and it’s open to anyone.
December 17, 2016 at 12:14 pm #5867Am I right in thinking that GTK either does or can use “native” GUI widgets in Windows ?
although something like GTK would rule out web targets, it would at least work on the main three of Linux, MacOS and Windows….
December 18, 2016 at 12:45 pm #5874Ok, thanks.
But does this mean the final user need to install something else (GTK lib) or any other dependencies?In any case a ‘universal’ GUI is impossible: it should be usable on mobile devices (phone and tablet), web, smart-tv, desktop. Too much confusion.
I think it’s better having different (and with high performance) solutions for any single target/UX.December 19, 2016 at 12:27 am #5899html5 is about the only truly “universal” GUI, and that *does* work nearly everywhere… you might want to look at the litehtml module…
December 19, 2016 at 7:26 am #5906you might want to look at the litehtml module
Are there any examples on how to use the litehtml module?
I would like to implement an HtmlView like mojox does. Does mojox use litehtml for it’s HtmlView?
December 19, 2016 at 9:22 am #5907I think it must do – if for example if you grep the build directory of the calculator banana you’ll for litehtml, i was looking for an example myself as documentation is so much more than api docs…
If i get chance i’ll nail a simple example together if only so i can grok it myself…
December 19, 2016 at 10:01 am #5908Let me know what you come up with.
I’ll try to have a look at how mojox implements it’s HtmlView.
Maybe Mark is out there lurking and has a tip or two.
December 19, 2016 at 7:33 pm #5921I had a little play with litehtml awhile ago and got a mojox view that loaded local html with images, just add a html file and images to assets and you can also hook in to hyperlinks being pressed:
Monkey123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422#Import "assets/about.html"#Import "assets/RedbrushAlpha.png"#Import "<std>"#Import "<mojo>"#Import "<mojox>"Using std..Using mojo..Using mojox..Class MyWindow Extends WindowField htmlView:CustomHtmlViewMethod New()Super.New( "HTML Test",800,600,WindowFlags.Resizable )htmlView=New CustomHtmlViewhtmlView.Go( "asset::about.html" )htmlView.ScrollBarsVisible=False'htmlView.AnchorClicked("test")Local dockingView:=New ScrollableViewdockingView.Style.BackgroundColor=Color.WhitedockingView.AddView( htmlView,"top", "100%" )ContentView=dockingViewEnd MethodEnd ClassClass CustomHtmlView Extends ScrollableViewField AnchorClicked:Void( url:String )Method New()Layout="fill"Style=GetStyle( "HtmlView" )_context=New litehtml.context_context.load_master_stylesheet( stringio.LoadString( "theme::htmlview_master_css.css" ) )_container=New document_container( Self )_baseUrl=filesystem.CurrentDir()AnchorClicked=GoEndProperty BaseUrl:String()Return _baseUrlSetter( baseUrl:String )If Not baseUrl.EndsWith( "/" ) baseUrl+="/"_baseUrl=baseUrlEndProperty HtmlSource:String()Return _sourceSetter( htmlSource:String )_source=htmlSource_document=New litehtml.document( _source,_container,_context )_layoutSize=Null_renderSize=NullRequestRender()EndMethod Go( url:String )Print "GO:"+urlIf url.Contains( "#" )ReturnEndifLocal root:=ExtractRootDir( url )If root="http://" Or root="https://"#If __DESKTOP_TARGET__requesters.OpenUrl( url )#EndifReturnEndifIf Not rooturl=BaseUrl+urlEndifLocal src:=stringio.LoadString( url )If ExtractExt( url )=".md"src=hoedown.MarkdownToHtml( src )Local wrapper:=stringio.LoadString( "theme::markdown_wrapper.html" )src=wrapper.Replace( "${CONTENT}",src )EndBaseUrl=ExtractDir( url )HtmlSource=srcEnd MethodPrivateField _context:litehtml.contextField _container:litehtml.document_containerField _anchorClicked:StringField _baseUrl:StringField _source:StringField _document:litehtml.documentField _layoutSize:Vec2iField _renderSize:Vec2iMethod OnThemeChanged() Override_document=New litehtml.document( _source,_container,_context )_layoutSize=Null_renderSize=NullEnd MethodMethod OnMeasureContent2:Vec2i( size:Vec2i ) OverrideIf Not _document Return New Vec2i( 0,0 )If size.x=_layoutSize.x Return _renderSize_layoutSize=size_document.render( size.x )_renderSize=New Vec2i( _document.width(),_document.height() )Return _renderSizeEnd MethodMethod OnRenderContent( canvas:Canvas ) OverrideIf Not _document ReturnLocal clip:litehtml.positionclip.x=canvas.Scissor.Xclip.y=canvas.Scissor.Yclip.width=canvas.Scissor.Widthclip.height=canvas.Scissor.Height_document.draw( canvas,0,0,Varptr clip )End MethodMethod OnContentMouseEvent( event:MouseEvent ) OverrideIf Not _document ReturnLocal x:=event.Location.XLocal y:=event.Location.Y_anchorClicked=""Select event.TypeCase EventType.MouseDown_document.on_lbutton_down( x,y,x,y )Case EventType.MouseMove_document.on_mouse_over( x,y,x,y )Case EventType.MouseUp_document.on_lbutton_up( x,y,x,y )_document.on_mouse_leave()Case EventType.MouseWheelReturnEndevent.Eat()RequestRender() 'Not ideal, but necessary for link highlighting...If _anchorClicked AnchorClicked( _anchorClicked )End MethodEnd ClassClass document_container Extends litehtml.document_containerField _view:CustomHtmlViewMethod ToFont:Font( hfont:Object )Return Cast<Font>( hfont )End MethodMethod ToCanvas:Canvas( hdc:Object )Return Cast<Canvas>( hdc )End MethodMethod GetImage:Image( src:String )Return App.Theme.OpenImage( src )End MethodMethod New( view:CustomHtmlView )_view=viewEnd MethodMethod set_color( canvas:Canvas,color:litehtml.web_color )canvas.Color=New Color( color.red/255.0,color.green/255.0,color.blue/255.0,1 )End MethodMethod make_url:String( href:String )Return _view._baseUrl+hrefEnd MethodMethod create_font:Object( faceName:String,size:Int,weight:Int,style:litehtml.font_style,decoration:UInt,fm:litehtml.font_metrics Ptr ) OverrideLocal face:="DejaVuSans"If faceName.Contains( "monospace" ) face+="Mono"Local font:=App.Theme.OpenFont( face,size )Local height:=font.Heightfm->height=heightfm->ascent=heightfm->descent=0fm->x_height=heightfm->draw_spaces=TrueReturn fontEnd MethodMethod delete_font( font:Object ) OverrideEnd MethodMethod text_width:Int( text:String,hfont:Object ) OverrideLocal font:=ToFont( hfont )Return font.TextWidth( text )End MethodMethod draw_text( hdc:Object,text:String,hfont:Object,color:litehtml.web_color Ptr,pos:litehtml.position Ptr ) OverrideLocal canvas:=ToCanvas( hdc )Local font:=ToFont( hfont )canvas.Font=fontset_color( canvas,color[0] )canvas.DrawText( text,pos->x,pos->y )ReturnEnd MethodMethod pt_to_px:Int( pt:Int ) OverrideReturn 0End MethodMethod get_default_font_size:Int() OverrideReturn 16 * App.Theme.Scale.yEnd MethodMethod get_default_font_name:String() OverrideReturn "DejaVuSans"End MethodMethod draw_list_marker( hdc:Object,marker:litehtml.list_marker Ptr ) OverrideIf marker->marker_type=litehtml.list_style_type_none ReturnLocal canvas:=ToCanvas( hdc )set_color( canvas,marker->color )Select marker->marker_typeCase litehtml.list_style_type_disccanvas.DrawOval( marker->pos.x,marker->pos.y,marker->pos.width,marker->pos.height )Defaultcanvas.DrawRect( marker->pos.x,marker->pos.y,marker->pos.width,marker->pos.height )End SelectEnd MethodMethod load_image( src:String,baseurl:String,redraw_on_ready:Bool ) OverrideGetImage( src )End MethodMethod get_image_size( src:String,baseurl:String,sz:litehtml.size Ptr ) OverrideLocal image:=GetImage( src )If Not image Returnsz->width=image.Widthsz->height=image.HeightEnd MethodMethod draw_background( hdc:Object,img_src:String,img_baseurl:String,bg:litehtml.background_paint Ptr ) OverrideLocal canvas:=ToCanvas( hdc )Local image:=GetImage( img_src )If imagecanvas.Color=Color.Whitecanvas.DrawImage( image,bg->position_x,bg->position_y )ReturnEndifset_color( canvas,bg->color )' canvas.DrawRect( bg->clip_box.x,bg->clip_box.y,bg->clip_box.width,bg->clip_box.height )canvas.DrawRect( bg->border_box.x,bg->border_box.y,bg->border_box.width,bg->border_box.height )End MethodMethod draw_border( canvas:Canvas,border:litehtml.border,x:Int,y:Int,w:Int,h:Int )If border.style<>litehtml.border_style_solid Or border.width<1 Returnset_color( canvas,border.color )canvas.DrawRect( x,y,w,h )End MethodMethod draw_borders( hdc:Object,borders:litehtml.borders Ptr,pos:litehtml.position Ptr,root:Bool ) OverrideLocal canvas:=ToCanvas( hdc )Local x:=pos->x,y:=pos->yLocal w:=pos->width,h:=pos->heightdraw_border( canvas,borders->left,x,y,1,h )draw_border( canvas,borders->top,x,y,w,1 )draw_border( canvas,borders->right,x+w-1,y,1,h )draw_border( canvas,borders->bottom,x,y+h-1,w,1 )End MethodMethod set_caption( caption:String ) OverrideEnd MethodMethod set_base_url( baseurl:String ) OverrideEnd MethodMethod on_anchor_click( url:String ) Override_view._anchorClicked=urlEnd MethodMethod set_cursor( cursor:String ) OverrideEnd MethodMethod import_css:String( url:String,baseurl:String ) OverrideLocal css:=stringio.LoadString( make_url( url ) )Return cssEnd MethodMethod set_clip( pos:litehtml.position Ptr,radiuses:litehtml.border_radiuses Ptr ) OverrideEnd MethodMethod del_clip() OverrideEnd MethodMethod get_client_rect( client:litehtml.position Ptr ) Override' If _view._rendering Print "get client rect"client->x=0client->y=0client->width=_view._layoutSize.xclient->height=_view._layoutSize.yEnd MethodMethod get_media_features( media:litehtml.media_features Ptr ) Override' If _view._rendering Print "get media features"media->type=litehtml.media_type_screenmedia->width=_view._layoutSize.xmedia->height=_view._layoutSize.ymedia->device_width=1920media->device_height=1080media->color=8media->color_index=0media->monochrome=0media->resolution=96End MethodMethod get_language:String() OverrideReturn ""End MethodMethod get_culture:String() OverrideReturn ""End MethodEnd ClassFunction Main()New AppInstanceNew MyWindowApp.Run()End FunctionDecember 19, 2016 at 10:23 pm #5925Thanks for sharing…
December 20, 2016 at 12:32 am #5929December 20, 2016 at 7:18 am #5930@Richard Betson just nail together any old page, one caveat tho… resource paths must include asset::
[/crayon]Monkey123[crayon-5cb9d27185c07391471290 inline="true" ]<img src="asset::image.png" />for example
@coppercircle I might take this code further and develop a blog post about making a simple UI with HTML and monkey if you don’t mind me using this code…
December 20, 2016 at 9:18 am #5931Hi, yes feel free to use it how ever.
December 20, 2016 at 10:03 am #5932Thanks. I tried to build and run the litehtml example that CopperCircle posted but it crashed and burned. The asset path was probably the issue which is why I wanted a look at the about.html file. I’ll give it a try.
might take this code further and develop a blog post about making a simple UI with HTML and monkey
Right on. I’m planning on integrating litehtml into my Alien Phoenix project and it’s GUI should really work well for this kind of thing. I’ll be interested in anything you come up with so let us know when you have something more.
December 20, 2016 at 12:41 pm #5933just
#import “assets/”then throw all the junk in there, it should “just work” (famous last words)
I have issues when trying to use it as a gui, I tried opening another window with a link – which works, but the GL state in the second window seems messed up somehow (text printed as filled in blocks)
ideally I’d want to somehow magically morph the htmlview window into a glwindow (so you can then render the “game”) in the same window you used for the htmlview…
but I’m thinking really the html should be rendered to a GL texture, but I’m not sure what is the best way to proceed for now…
December 20, 2016 at 5:59 pm #5935I’ve hacked together using HTML as a game menu that can start a “game” that uses Mojo and GL…
http://bedroomcoders.co.uk/monkey2-using-html-for-your-game-menu/
-
AuthorPosts
You must be logged in to reply to this topic.