GUI and Multitasking Library

Showcase your libraries, tools and other projects that help your fellow love users.
Post Reply
rayaman
Prole
Posts: 10
Joined: Sat May 17, 2014 6:18 pm

GUI and Multitasking Library

Post by rayaman »

Hello Everyone, I have been working on a GUI and Multitasking library for a while and I want to tell what it can do, and how I could add it to the list of libraries.

Features in a nutshell
Create:
Frames
TextButtons
TextLabels
TextButtons
TextBoxes
ImageButtons
ImmageLabels
Items

do so by calling this method

Code: Select all

Frame=gui:newFrame([name],ox,oy,ow,oh,sx,sy,sw,sh)
--[[
creates a frame
name is optional
ox is offset position x
oy is offset position x
ow is offset size width
oh is offset size height
sx is scale position x
sy is scale position x
sw is scale size width
sh is scale size height
]]
TextButton=gui:newTextButton([name],text,ox,oy,ow,oh,sx,sy,sw,sh)
TextBox=gui:newTextBox([name],text,ox,oy,ow,oh,sx,sy,sw,sh)
TextLabel=gui:newTextLabel([name],text,ox,oy,ow,oh,sx,sy,sw,sh)
--[[
creates a textbutton
creates a textbox
creates a textlabel
text is the text you want it to display
]]
ImageButton=gui:newImageButton([name],image,ox,oy,ow,oh,sx,sy,sw,sh)
ImageLabel=gui:newImageLabel([name],image,ox,oy,ow,oh,sx,sy,sw,sh)
image can be a string such as
ImageButton=gui:newImageButton("sun","Images/sun.png",0,0,100,100,0,0,0,0) --or a image object
img=love.graphics.newImage("Images/sun.png")
ImageButton=gui:newImageButton("sun",img,0,0,100,100,0,0,0,0)
ImageLabels work the same way
Items are special they act as all of the elements combined
So what are functions specific to certain objects

Frames and Items are the only things that have drag events don't worry though draging other elements are possible as i will show later on

Code: Select all

Frame.Draggable=true -- can be dragged
Frame.dragbut="r" or "m" or "l" -- the button that activates drag defult is "m"
Frame:OnDrag(function(element) end) -- fired when dragged
--^^^ the only special thing about a frame
--TextButtons,Labels, and Boxes have almost all the same methods

TextBoxes have an additional command
TextBox:OnEnter(function(textbutton,text) end) -- when enter is pressed this event is fired
TextBox.ClearOnFocus=false -- when focus is given to the textbox should I clear the text that was there?
What do they all have in common

TextElement.Tween(number) -- offset of text on the y axis Why well with all the fonts and sizes I could not programm all that is so you tween so it fits to your needs :)

Code: Select all

TextElement.text(string) -- holds a string that you want displayed
TextElement.Font(string/userdata) -- can set a font as a string to a font file or an already loaded font
TextElement.FontSize(number/string) -- size of the text
TextElement.TextFormat(string) -- "left","center","right" where the text is located
TextElement.AutoScaleTest(bool) -- WIP auto scales the font size in ratio to the size of the TextElements height
TextElement.TextVisibility(number 0-1) -- 0 can't see 1 completly visible
TextElement.textColor(colordata) -- color of text if you have my color library you can do this:
TextElement.textColor=Color.Red or red or RED -- all three work
a full list of colors will not be given but there are many just type Color[color you want] it probely is there

ImageElements are all identical so here is what they do

Code: Select all

ImageElement:SetImage(string/userdata) -- change an image realtime
--that is there special feature for now later we'll discuses more.

--so every element has these methods and valueholders

Element:SetDualDim(x, y, w, h, sx ,sy ,sw ,sh) -- sets offset and scale realtime
Element:ApplyGradient(rule,rs,gs,bs,t,var,wwd) -- WIP makes nice shades from one color to another
Element:TopStack() -- brings element to the top of the draw queue
Element:BottomStack() -- brings element to the bottom of the draw queue
Element:newMenu(names,onL,x,y,w,h,c) -- Obsolete or not worth using may be removed
Element:Destroy() -- destroys self and children (I will get to inheritance soon :) )
Element:SetName(name) -- remember when creating you can set a name well here you can change it (used in inheritance)
Element:GetChild(name) -- returns a child by its name from an element
Element:Move(x,y) -- you don't really need this if every thing you do is simple but if you advance you can
Element:OnClicked(function(b,element,x,y) end) -- click event b="r" or "m" or "l" depends on mouse button pressed x,y position on the element that was pressed
Element:OnRelease(function(b,element,x,y) end) -- released event same as above
Element:OnEnter(function(element) end) -- fired when mouse enters an element's domain
Element:OnExit(function(element) end) -- fired when exit elements domain
Element:OnUpdate(function(element) end) -- fired every step
Element:setVisiblity(val) -- sets visibility of all children and self
Element:getChildren() -- returns all children in the element as a table
Element:newScrollMenu(title,tabN,onloop,x, y, w, h, sx ,sy ,sw ,sh) -- WIP but stable interactive example will show usage
Element:Cast(type,arg1) -- arg1 can be a string or image
Element.Color
Element.x -- editing does nothing use SetDualDim() used to get value
Element.y -- editing does nothing use SetDualDim() used to get value
Element.width -- editing does nothing use SetDualDim() used to get value
Element.height -- editing does nothing use SetDualDim() used to get value
Element.Visibility -- (0-1)
Element.Visible -- (bool) can i see it or not Note:Tick this all children are hidden 
Element.BorderColor -- color of the border
Element.BorderSize -- size of the border defult 1
Element.Type -- (string) type of element
Element.Name -- name of element
Only variables you may use without breaking everything has been listed

Examples and applications will be in a .love file which i will provide soon

Remember Items have all functions of all Elements except the text button for now

So Inheritance works like this

Code: Select all

Element=gui:newFrame(0,0,0,0,0,0,1,1) -- fills entire screen
subElement=Element:newTextLabel("sub","I am a sub element :)",0,0,0,60,0,0,1,0)-- x axis will fill entire frame while the y axis fills on 60 px from top
if i did

Code: Select all

Element.Draggable=true
and

Code: Select all

Element.dragbut="l"
activating drag on the frame drags the elements inside also

subElement.Parent==Element -->> true

Code: Select all

t=Element:getChildren()
--t={[address to subelement]}
if i did
-- Note name is optional but very useful if you have it
test=Element:newImageLabel("img","Images/example.png",0,60,100,100)-- under the text element and width and height are 100 px

Code: Select all

t=Element:getChildren()
--t={[address to subelement],[address to test]}
--the thing is it won't be easy to access elements like this. Use this when effecting everything

if i did

Code: Select all

Element:GetChild("sub")-- it will return subElement object
or

Code: Select all

Element:GetChild("img")-- it will return test object
You can change a name real time using

Code: Select all

Element:SetName(name) -- You can not do this subElement.Name="whatever" it wont work for speed reasons I did not include this ability
Note: If you set two children in the same element to the same name the last one will be linked to it and the first won't

If you need any clarifications I will soon provide a .love file with examples.

Now time to get into the MultiTasking Library

Side Note: I will never be able to list all the applications for both the the gui or the multitasking library They have virtually limitless possibilities and uses But I welcome questions for how to do this or that :)

The MultiTasking Library had gone throw many changes and the gui library will not work without it

Brief History:

Started out with a benchmark from ~2000 steps per second -- Very Slow
Next version benchmark ~300,000 -- Nice increase why because loadstring() was eliminated
Next was a complete over haul now it can do 600,000+ on a 1.70GHz system on 1 core -- multi core functions comming soon :)
to test your pc do multi:benchMark(1) -- 1 second but you can do any amount

so if your pc is beefy it can handle way over 600,000 steps per second
Note: This is the number of steps that the bench object does not collectively so if other objects are running then even though there is a low bench things will still run smooth
Also The more objects you have the greater the collective performance is so 1 bench may give me 600,000 where 2 seperate give me 325,000+325,000
600,000 vs 650,000 you can try this on your own as well

Ok so what can I do with this library?

Here are all the objects you can use

object Events --when a condition is met i fire
object Alarms --when certain amount of time has passed i fire
object Loops --I constantly fire as fast as i can
object Steps --I am like a loop i fire and i also count
object TSteps --I am like an alarm but i count also
object Triggers --I am basiclly a function that allows the Pause(n) function Details on this later
object Tasks --I am a function that isn't fired until all conponents of the library are met Note: prevents load issues

Note: inhertance is not in this library I couldn't because of complexity When i did it slowed down proformance but tips to bypass this will be given

so this is valid but won't do anything with inheritance it will create the object though

Code: Select all

test=multi:newEvent(function() return g==45 end)
alarm=test:newAlarm(12)
short examples of uses:

Code: Select all

event=multi:newEvent(function(env) return (_G.a==7) end) -- env is linv to the event object when a==7 then it will fire
event:OnEvent(function(env) print("a=7") end) this is how you connect to the event

alarm=multi:newAlarm(10) -- set to 10 seconds
alarm:OnRing(function(alarm) print("10 seconds have passed") alarm:Reset(n) end)
Note: alarms don't reset them self and the 'n' in Reset(n) is optional you can change its time og leave it blank to reset using the same time

Code: Select all

loop=multi:newLoop()
loop:OnLoop(function(t,loop) print("looping!!!!!!!!!!!!!!") end)-- that will flood your output so don't do that 't' is the time from creation in seconds
newStep(start,reset,count,skip)

Code: Select all

step=multi:newStep(1,10,.1,0)
step:OnStep(function(pos,step) print(pos) end)-- steps auto loop
step:OnEnd(function(step) step:Pause() end) -- when it gets to 10 and resets this event is fired
start is where it starts reset is where it resets (inclusive) count is how it counts and skip is ait i do this every step every other ...

so this example will produce

>>
1
1.1
1.2
...
9.8
9.9
10
it stops here because of Pause()

otherwise it would do this

9.9
10
1.1
...

TSteps work similarly

newTStep(start,reset,count,timer)
start and reset and count are the same

timer is how long in seconds i wait before the next step

Code: Select all

tstep=multi:newTStep(1,10,1,1)
tstep:OnStep(function(pos,step) print(pos) end)-- steps auto loop
tstep:OnEnd(function(step) step:Pause() end) -- when it gets to 10 and resets this event is fired
>>output
1
(wait one second)
2
(wait one second)
3
...
9
(wait one second)
10
Pause()

count can be negative just make sure "start" and "reset" reflect that change

Bugs: (Its a lua one not mine I think) count can't be more than .01 in detail or the numbers start getting weird decimals round off errors

newTrigger(func)

Code: Select all

trigger=multi:newTrigger(function(trig,...) print("Fire!!!") end)

trigger:Fire(...)
>>
Fire!!!

newTask(func) -- function called when every conponent of the multitask manager is loaded When allowing custom scripts this might be useful but you really don't need it

Well that is all for object only methods here is what they all can do

Code: Select all

Object:Pause(n) -- pauses an object if 'n' is given Do not use Resume()!!!!!!
Object:Resume() -- resumes a paused object
Object:Destroy() -- destroys an object
Object:Hold(n,func) -- pauses an object at location called until certian time has passed or a condition has been met
Examples of Hold will be given because it is a very complex feature that is nice but if not used right there will be problems

Code: Select all

loop=multi:newLoop()
a=0
loop:OnLoop(function(loop) a=a+1 end)
loop2=multi:newLoop()
loop2:OnLoop(function(loop) Hold(function() return (a>=100000) end) print("a now >= 100000") end)-- this would in less than a second because it is a small number.
--after the event is fired this will happen continually

--or

loop:OnLoop(function(loop) a=a+1 end)
loop2=multi:newLoop()
loop2:OnLoop(function(loop) Hold(2) print("a = "..a.." after 2 seconds") end)-- this would produce 'a' in the +1,000,000 area
--every 2 seconds this would happen
Now the oneTime() function

What it does is only execute a function once

but the function must not be anonymous

use like so

Code: Select all

function SetUp(...)
	print("Doing stuff :)")
end

loop=multi:newLoop()
loop:OnLoop(function(t,loop)
	multi:oneTime(SetUp,...)-- do once
	print("Doing other stuff not that the setup is done")
end)
that is it for both libraries if you need help with anything feel free to post here. Ideas and comments welcomed

Also Examples will be made because I am not the best at explaining like this in a day or 2 I will release examples with the .love. unless i am busy otherwise it shouldn't take more then 2 days
Last edited by rayaman on Mon Oct 06, 2014 1:25 pm, edited 2 times in total.
User avatar
Roland_Yonaba
Inner party member
Posts: 1563
Joined: Tue Jun 21, 2011 6:08 pm
Location: Ouagadougou (Burkina Faso)
Contact:

Re: GUI and Multitasking Library

Post by Roland_Yonaba »

Screnshoots, perhaps ?
User avatar
artofwork
Citizen
Posts: 91
Joined: Mon Sep 15, 2014 1:17 am
Location: East Coast USA

Re: GUI and Multitasking Library

Post by artofwork »

You should reformat your original post so that the things that are code related are easier to identify, because its kind of a turn off to read :(
rayaman
Prole
Posts: 10
Joined: Sat May 17, 2014 6:18 pm

Re: GUI and Multitasking Library

Post by rayaman »

I will try to reorginize all of this but here are some screen shots of the program in action
Just some shots of the layout
Just some shots of the layout
shot3.png (376.92 KiB) Viewed 3371 times
Project I am making using these libraries
Project I am making using these libraries
shot2.png (352.85 KiB) Viewed 3371 times
this one has moving parts Gif stuff in code but still a WIP but it is there anyway requires the gif library and the lovebind library
this one has moving parts Gif stuff in code but still a WIP but it is there anyway requires the gif library and the lovebind library
shot1.png (248.73 KiB) Viewed 3371 times
oh the audio manager is something else i was working on it adds OnStop() event to sound objects os you can do something when a sound stops easily.

Tell me what you thing I will be making an interactive example of this library soon.
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests