Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- hi, this is a temp script, for an upcomming api/os
- this will give people the opportunity to make applications without direct contact to the events. (so no picking events from other applications)
- also it's meant to support multithreading (or an simple form of it at least) and give you the opportunity to support multiple windows across your screen with mouse support
- features implemented:
- - function for handling the mouse_click event and give it to the most upfront window
- features in dev:
- - logging
- - functions for focusing
- - content drawing? thinking out a easy way to give as much freedom to the app while supporting as much as possible (non advanced computers?)
- features planned:
- - a single api call to register your window
- - show/hide windows (enable/disable too)
- - standard window buttons ([-][o][x][...??])
- - make titleBox optional (with window buttons)
- ALSO:
- if you have some things you think could be improved please improve them end try to contact me
- found out that if you make a public submit with the word 7Roses in it pastbin will notify me :)
- or just pm me on the computercraft.info forum :) (recommend this communication)
- ]]
- --when a click event occurs the os will first try to find the current highest window
- --afther that it will give the action though to the windowhandler of that program
- emptyWindow = {xstart,ystart,xend,yend,depth,drawn,windowhandlerMethod,content}
- emptyWindow = {xstart = 0,ystart=0,xend =0,yend=0,nil,mouseEventHandler=function showof() print("nothing")end,drawFunction=nil}
- globalWindowTable = {}
- startupPopup
- -- globalWindowTable[uid] = ...
- globalWindowTable["myWindowTag"] = startupPopoup
- --click event handler
- windows = {}
- function globalWindowHandler()
- while (true) do
- event, button, xPos, yPos = os.pullEvent("mouse_click")
- currentWindow = nil
- currentDepth = -32000
- for k,v in pairs(globalWindowTable) do
- if (v[xstart]<xPos && v[xend]>xPos && v[ystart]<yPos && v[yend]>yPos && v.depth>currentDepth) then
- currentWindow = v
- currentDepth = v.depth
- end
- if (currentWindow.mouseEventHandler != nil) then
- currentWindow.mouseEventHandler(button,xPos,yPos)
- else
- print("your application didn't register an mouse even handler!")
- end
- end
- end
- --[[
- a window is focussed when the global depth is equal to the windows depth
- when a window uses windows.focus(uid_window) and the current window wasn't focus, every window with a depth high than the calling window will be decreased with 1, and the calling window will be set to the top window+1
- ]]
- function windows.focus(uid)
- if (globalCurrentFocusedWindow != uid) then
- globalCurrentFocusedWindow = uid
- maxdepth = -32000
- for k,v in pairs(globalWindowTable) do
- if (v.depth>-32000) then
- v.depth = v.depth-1
- else
- print("your program has probably a problem with focussing!")
- end
- if(v.depth>maxdepth) then
- maxdepth = v.depth
- end
- end
- globalWindowTable[uid].depth = maxdepth+1
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement