Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- rGUI Alpha 0.x
- -- robhol
- term.clear();
- if not redirect then error("redirect required"); end
- if not robapi or not robapi.version or robapi.version() < 1.11 then error("robapi 1.11+ required"); end
- if not term.isColor() then error("advanced computer required"); end
- local swidth, sheight = term.getSize();
- buffer = redirect.createRedirectBuffer( swidth, sheight + 1, nil, nil, true );
- RGUI_DEBUG = true;
- -- load other components
- local loc = shell.getRunningProgram();
- loc = loc:sub(1, loc:len() - fs.getName(loc):len());
- dofile(loc .. "util");
- dofile(loc .. "prototypes");
- if RGUI_DEBUG then sleep(0.5); end
- -- set up vital engine functions and stuff
- local lastId = 0;
- local id_increment = 0.001;
- local exiting = false;
- function createObject(otype, x, y, fc, bc)
- local obj =
- {
- name=false,
- type=otype,
- x=round(x),
- y=round(y),
- forecolor=(fc or colors.white),
- backcolor=bc
- };
- inherit(obj, prototypes.object)
- --make sure objects are rendered/processed in the order they were created, unless changed
- lastId = lastId + id_increment;
- obj.order = lastId;
- return obj;
- end
- function createEvent(event, ...)
- return {name=event, handled=false, args={...}};
- end
- -- internal loading - root object and prototypes
- root = createObject("root", 0, 0 );
- root:addHandlerCC("mouse_click", function ( self )
- prototypes.window._dragData = false;
- end);
- -- set up public API
- rgui =
- {
- createApp = function ( name )
- local obj = createObject("app", 0, 0, nil, nil);
- inherit(obj, prototypes.obj_creator); -- allow object creation on this object
- inherit(obj, prototypes.app);
- obj.name = name;
- obj.width = swidth;
- obj.height = sheight;
- root:addChild(obj);
- root.focusedChild = obj;
- return obj;
- end,
- forceUpdate = function ()
- os.queueEvent("_forceDraw");
- end,
- getRoot = function ()
- return root;
- end,
- getScreenSize = function ()
- return swidth, sheight;
- end,
- execute = function ( file, args )
- end,
- exit = function()
- exiting = true;
- end,
- }
- --alias
- rgui.exitToDOS = rgui.exit;
- -- TEST STUFF TEST STUFF TEST STUFF TEST STUFF
- -- TEST STUFF TEST STUFF TEST STUFF TEST STUFF
- -- TEST STUFF TEST STUFF TEST STUFF TEST STUFF
- -- debug app loading, replace with some kind of proper system later.
- local rgui_args = {...};
- dofile(loc .. (rgui_args[1] or ("test/" .. "controls")) );
- --dofile(loc .. (rgui_args[1] or "demo/rsctl") );
- -- TEST STUFF TEST STUFF TEST STUFF TEST STUFF
- -- TEST STUFF TEST STUFF TEST STUFF TEST STUFF
- -- TEST STUFF TEST STUFF TEST STUFF TEST STUFF
- --main event loop
- rgui.forceUpdate();
- local timer = false;
- while not exiting do
- timer = timer and timer or os.startTimer(0.0501);
- --process events
- local event = createEvent( os.pullEventRaw() );
- if event.name == "timer" and event.args[1] == timer then
- --hijack event and replace with our animation event
- timer = false;
- event = createEvent( "animation" );
- elseif event.name == "terminate" then
- exiting = true;
- end
- root:handle(event);
- --(re)draw screen
- buffer.setBackgroundColor(colors.black);
- buffer.clear();
- root:draw();
- buffer.blit(1,1,1,0,swidth,sheight + 1);
- end
- --exiting; get rid of stuff
- rgui = nil;
- term.clear();
- term.setCursorPos(1, 1);
- print("Goodbye :)");
- sleep(0.2);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement