{"id":548,"date":"2011-08-29T12:28:00","date_gmt":"2011-08-29T11:28:00","guid":{"rendered":"http:\/\/shadowcovenant.com\/blog\/2011\/08\/29\/gui-stuff\/"},"modified":"2011-08-29T12:28:00","modified_gmt":"2011-08-29T11:28:00","slug":"gui-stuff","status":"publish","type":"post","link":"http:\/\/shadowcovenant.com\/blog\/2011\/08\/29\/gui-stuff\/","title":{"rendered":"GUI stuff&hellip;"},"content":{"rendered":"<p align=\"justify\">I\u2019ve been working on and off on \u201cAmoeba\u201d, mainly focusing on the GUI work (area selection, level selection, etc), and it has been a struggle:<\/p>\n<p><a href=\"http:\/\/shadowcovenant.com\/blog\/wp-content\/uploads\/2011\/08\/gui_work.jpg\"><img loading=\"lazy\" decoding=\"async\" style=\"background-image: none; border-bottom: 0px; border-left: 0px; padding-left: 0px; padding-right: 0px; display: inline; border-top: 0px; border-right: 0px; padding-top: 0px\" title=\"gui_work\" border=\"0\" alt=\"gui_work\" src=\"http:\/\/shadowcovenant.com\/blog\/wp-content\/uploads\/2011\/08\/gui_work_thumb.jpg\" width=\"223\" height=\"402\" \/><\/a><\/p>\n<p align=\"justify\">First, the \u201csimple\u201d problems: font aliasing was hard to get rid of (and its not completely solved, but on my Android phone you can\u2019t see any major artifacts, specially if you aren\u2019t looking for them).<\/p>\n<p align=\"justify\">Then the complex problems: different screen resolutions\/orientations. I want \u201cAmoeba\u201d to work on all devices I can possibly put it on, and that means different resolutions and orientations. We got 480&#215;800, 1024&#215;768, 640&#215;960 and many more\u2026 And these means different aspect ratios, which just add more confusion to the problem.<\/p>\n<p align=\"justify\">The game itself is easy to adjust to the resolution (I have a virtual resolution system coupled with some \u201cmargins\u201d disguised with some GUI elements), but if I do the same on the GUI, it looks amateurish, and that\u2019s a definitely no-no on indy game development\u2026 <\/p>\n<p align=\"justify\">I could program a kind of interchangeable file with the positions of the elements (or use structures in C++, whatever), but even that is hard to tweak, because of dynamic scaling, and I have to consider ALL the possible resolutions. But this might be a solution in the future; I\u2019ve already decided that all my next mobile games will only support one orientation anyway, since it\u2019s too much work supporting multiple ones\u2026<\/p>\n<p align=\"justify\">So, getting the GUI working on different resolutions\/orientations\/aspect ratios has been a though fight\u2026 and it\u2019s only half the battle\u2026<\/p>\n<p>Then we have the code problem, where we hook behaviors\u2026 what happens when I left click and drag the mouse (equivalent to taping the screen and dragging my finger on it)? What\u2019s the reaction\u2026<\/p>\n<p align=\"justify\">On this project, I initially had all the code in C++ in the animation loop of the screen, but it was becoming unmanageable. Every change implied going through loads of conditions to get to the right place, and half the time I\u2019d just get it wrong anyway\u2026 <img decoding=\"async\" style=\"border-bottom-style: none; border-left-style: none; border-top-style: none; border-right-style: none\" class=\"wlEmoticon wlEmoticon-confusedsmile\" alt=\"Confused smile\" src=\"http:\/\/shadowcovenant.com\/blog\/wp-content\/uploads\/2011\/08\/wlEmoticon-confusedsmile1.png\" \/> I decided to scrap that and go for scripted GUI. While it\u2019s not much better, it\u2019s easier to control a GUI with LUA co-routines, specially transitions between \u201cpages\u201d of GUI. It\u2019s still not optimal, but a bit better\u2026<\/p>\n<p align=\"justify\">Working on this (and on my previous experiences with GUI elements), I got thinking\u2026 I hate GUI work, but mainly because it seems to be much less organic than the rest of my code (at least the end result). Why is that?<\/p>\n<p align=\"justify\">One reason I can think of is that \u201cI HATE GUI WORK\u201d, so I do sloppier code to try to get it over with\u2026 the other possible reason is lack of planning of the GUI and its elements. Finally, the lack of a really defined GUI framework on Spellbook might hinder me aswell\u2026<\/p>\n<p align=\"justify\">Basically, I see 7 different ways of creating a GUI\/GUI logic:<\/p>\n<ol>\n<li>\n<div align=\"justify\">All GUI elements on a particular game are a separate C++ object that can handle itself. This was the approach I used on \u201cBlitz and Massive\u201d and it worked very well, from a code organization point of view. This was further facilitated due to the fact that most of the \u201cend result\u201d of the GUI actions were script calls.<\/div>\n<\/li>\n<li>\n<div align=\"justify\">We have a generalized object system (with sprites, text, aggregate objects, etc) and we instance it in C++. Control is done by using the animation pump that reacts to specific events. This results in long, hard-to-manage code, and loads of \u201ctemporary\u201d variables to handle the state of the system.<\/div>\n<\/li>\n<li>\n<div align=\"justify\">Same as last, but using scripting to instance the objects and registering events. Events trigger script calls that change the system. The \u201ctemporary\u201d variables are more contained and can be handled locally by the scripting. Problem is that a language like Lua has great facilities for co-routines (superior to all languages I\u2019ve ever seen!), but it\u2019s terrible for flow control (because of syntax\u2026 seriously, on the 21st century, someone still requires the \u201cTHEN\u201d keywork for an \u201cIF\u201d clause!?!?)<\/div>\n<\/li>\n<li>\n<div align=\"justify\">Same as 2), but use a more sophisticated event system for the event handling, instead of the animation pump.<\/div>\n<\/li>\n<li>\n<div align=\"justify\">Use a GUI middleware (from native stuff like Win32 or iOS stuff (not cross-platform), to more \u201cgame-like\u201d alternatives like <a href=\"http:\/\/www.scaleform.com\/gfxtech\" target=\"_blank\">Scaleform<\/a> (expensive) or \u201cweb-like\u201d like <a href=\"http:\/\/www.webkit.org\/\" target=\"_blank\">Webkit<\/a>\/<a href=\"http:\/\/awesomium.com\/\" target=\"_blank\">Awesomium<\/a> (I hate web-technologies and don\u2019t want to have 2 scripting languages involved in a single project)).<\/div>\n<\/li>\n<li>\n<div align=\"justify\">Roll your own GUI middleware (a giant enterprise by itself!)<\/div>\n<\/li>\n<li>\n<div align=\"justify\">Hire a gnome to do it!<\/div>\n<\/li>\n<\/ol>\n<p align=\"justify\">&#160;<\/p>\n<p align=\"justify\">I see pros and cons in all of these, but I think that most of my problems can be addressed with taking the time to think about the GUI, to plan it appropriately, like I do with the rest of the game components\u2026In the meantime\u2026. I REALLY HATE GUI WORK! <\/p>\n<div id=\"tweetbutton548\" class=\"tw_button\" style=\"\"><a href=\"http:\/\/twitter.com\/share?url=http%3A%2F%2Fshadowcovenant.com%2Fblog%2F2011%2F08%2F29%2Fgui-stuff%2F&amp;text=GUI%20stuff%26hellip%3B&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fshadowcovenant.com%2Fblog%2F2011%2F08%2F29%2Fgui-stuff%2F\" class=\"twitter-share-button\"  style=\"width:55px;height:22px;background:transparent url('http:\/\/shadowcovenant.com\/blog\/wp-content\/plugins\/wp-tweet-button\/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;\">Tweet<\/a><\/div>","protected":false},"excerpt":{"rendered":"<p>I\u2019ve been working on and off on \u201cAmoeba\u201d, mainly focusing on the GUI work (area selection, level selection, etc), and it has been a struggle: First, the \u201csimple\u201d problems: font aliasing was hard to get rid of (and its not completely solved, but on my Android phone you can\u2019t see any major artifacts, specially if [&hellip;]<\/p>\n<div id=\"tweetbutton548\" class=\"tw_button\" style=\"\"><a href=\"http:\/\/twitter.com\/share?url=http%3A%2F%2Fshadowcovenant.com%2Fblog%2F2011%2F08%2F29%2Fgui-stuff%2F&amp;text=GUI%20stuff%26hellip%3B&amp;related=&amp;lang=en&amp;count=horizontal&amp;counturl=http%3A%2F%2Fshadowcovenant.com%2Fblog%2F2011%2F08%2F29%2Fgui-stuff%2F\" class=\"twitter-share-button\"  style=\"width:55px;height:22px;background:transparent url('http:\/\/shadowcovenant.com\/blog\/wp-content\/plugins\/wp-tweet-button\/tweetn.png') no-repeat  0 0;text-align:left;text-indent:-9999px;display:block;\">Tweet<\/a><\/div>","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[23,6],"tags":[],"class_list":["post-548","post","type-post","status-publish","format-standard","hentry","category-development","category-games"],"_links":{"self":[{"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/posts\/548","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/comments?post=548"}],"version-history":[{"count":0,"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/posts\/548\/revisions"}],"wp:attachment":[{"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/media?parent=548"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/categories?post=548"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/shadowcovenant.com\/blog\/wp-json\/wp\/v2\/tags?post=548"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}