Advertisement
7Roses

computercraft window api

Feb 25th, 2013
428
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.97 KB | None | 0 0
  1. --[[
  2.  
  3. hi, this is a temp script, for an upcomming api/os
  4. this will give people the opportunity to make applications without direct contact to the events. (so no picking events from other applications)
  5. 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
  6.  
  7. features implemented:
  8. - function for handling the mouse_click event and give it to the most upfront window
  9.  
  10. features in dev:
  11. - logging
  12. - functions for focusing
  13. - content drawing? thinking out a easy way to give as much freedom to the app while supporting as much as possible (non advanced computers?)
  14.  
  15. features planned:
  16. - a single api call to register your window
  17. - show/hide windows (enable/disable too)
  18. - standard window buttons ([-][o][x][...??])
  19. - make titleBox optional (with window buttons)
  20.  
  21. ALSO:
  22. if you have some things you think could be improved please improve them end try to contact me
  23.  
  24. found out that if you make a public submit with the word 7Roses in it pastbin will notify me :)
  25. or just pm me on the computercraft.info forum :) (recommend this communication)
  26.  
  27.  
  28.  
  29. ]]
  30.  
  31. --when a click event occurs the os will first try to find the current highest window
  32. --afther that it will give the action though to the windowhandler of that program
  33.  
  34. emptyWindow = {xstart,ystart,xend,yend,depth,drawn,windowhandlerMethod,content}
  35. emptyWindow = {xstart = 0,ystart=0,xend =0,yend=0,nil,mouseEventHandler=function showof() print("nothing")end,drawFunction=nil}
  36.  
  37.  
  38.  
  39. globalWindowTable = {}
  40. startupPopup
  41. -- globalWindowTable[uid] = ...
  42. globalWindowTable["myWindowTag"] = startupPopoup
  43. --click event handler
  44. windows = {}
  45. function globalWindowHandler()
  46.   while (true) do
  47.     event, button, xPos, yPos = os.pullEvent("mouse_click")
  48.     currentWindow = nil
  49.     currentDepth = -32000
  50.     for k,v in pairs(globalWindowTable) do
  51.       if (v[xstart]<xPos && v[xend]>xPos && v[ystart]<yPos && v[yend]>yPos && v.depth>currentDepth) then
  52.         currentWindow = v
  53.         currentDepth = v.depth
  54.     end
  55.     if (currentWindow.mouseEventHandler != nil) then
  56.       currentWindow.mouseEventHandler(button,xPos,yPos)
  57.     else
  58.       print("your application didn't register an mouse even handler!")
  59.     end
  60.   end
  61. end
  62.  
  63.  
  64.  
  65. --[[
  66.  
  67. a window is focussed when the global depth is equal to the windows depth
  68. 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
  69.  
  70. ]]
  71. function windows.focus(uid)
  72.   if (globalCurrentFocusedWindow != uid) then
  73.     globalCurrentFocusedWindow = uid
  74.     maxdepth = -32000
  75.     for k,v in pairs(globalWindowTable) do
  76.       if (v.depth>-32000) then
  77.         v.depth = v.depth-1
  78.       else
  79.         print("your program has probably a problem with focussing!")
  80.       end
  81.       if(v.depth>maxdepth) then
  82.         maxdepth = v.depth
  83.       end
  84.     end
  85.     globalWindowTable[uid].depth = maxdepth+1
  86.   end
  87. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement