Jump to content




Mouse Click Flicker-How To Remove?



  • You cannot reply to this topic
30 replies to this topic

#21 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 23 September 2013 - 12:59 PM

View Postmakerimages, on 23 September 2013 - 12:34 PM, said:

-snip-
Well, gotta ask Bubba about that then - it's his tutorial, after all.
By the way, the Tutorials section is far from lacking of coroutine tutorials. True, there's less of them than of door locks, but one well made tutorial would be enough of those too.

#22 makerimages

  • Members
  • 236 posts

Posted 24 September 2013 - 08:00 AM

Allright, what am I missing here?

the coroutine manager

programCache={}
routineCache={}
local xPos=0
local yPos=0
table.insert(programCache,function() shell.run("OSCore/desktop",xPos,yPos)end)
local routine=nil;
function startCoroutines()
for i=1, #programCache,1 do
  routine=coroutine.create(programCache[i])
  table.insert(routineCache,routine)
  ok, err=coroutine.resume(routine)
end
end
function updateCoroutines()
for i=1, #routineCache,1 do
  if coroutine.status(routineCache[i])=="suspended" then
  ok, err=coroutine.resume(routineCache[i],xPos,yPos)
  end
end
end
startCoroutines()
while true do
event, button, xPos, yPos = os.pullEvent("mouse_click")
updateCoroutines()
end

current coroutine
local tArgs = {...}
os.loadAPI("Apis/DesignUtil")
os.loadAPI("Apis/AccountSytem")
os.loadAPI("Apis/windowSystem")
DesignUtil.setDesign("whiteLightGray")
local background,topBar =DesignUtil.getDesign()
local showOS1Menu = false;
term.setTextColor(colors.gray)
if #tArgs<1 then
error("Desktop: expected mouse_click coordinates X and Y, but they were not given!")
end
function registerClickEvent(x,y)
if x >=0 and x <=1+3-1 and y >=0 and y <=1+1-1 then
  showOS1Menu= not showOS1Menu
end
end
function printOS1Menu()
if showOS1Menu then
  term.setBackgroundColor(colors.lightGray)
  term.setCursorPos(1,2)
  print("About this device")
  term.setCursorPos(1,3)
  print("Software update  ")
  term.setCursorPos(1,4)
  print("Restart device   ")
  term.setCursorPos(1,5)
  print("Shut down		")
end
end
while true do

paintutils.drawImage(background,1,1)
paintutils.drawImage(topBar,1,1)

printOS1Menu()
term.setCursorPos(1,1)
term.setBackgroundColor(colors.lightGray)
print("O1|")


registerClickEvent(tonumber(tArgs[1]),tonumber(tArgs[2]))
sleep(1)
end

the coroutine still is not responding to clicks, what am I doing wrong still?

EDIT: besides having a sleep in there(any workarounds to not need that there?)

#23 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 24 September 2013 - 08:45 AM

View Postmakerimages, on 24 September 2013 - 08:00 AM, said:

what am I doing wrong still?
  • There is no code in the manager which passes the event data to the coroutines - you use a bunch of locals (xPos and yPos) but you should pass event and button as well.
  • There is no code in the coroutine which pulls a mouse_click event. The only thing which yields the coroutine is the sleep there, and that doesn't return event data.


#24 makerimages

  • Members
  • 236 posts

Posted 25 September 2013 - 08:23 AM

Most of the things are now working.. some are not

updated windowSystem
local window=nil;
function createWindow(title,x,y,w,h,closeable,text)
window=
{
  titlew=title;
  x=x;
  y=y;
  W=w;
  H=h;
  ca=closeable;
  text=text;
}
return window
end
function drawWindow(windowp)
term.setCursorPos(window.x,window.y)
term.setBackgroundColor(colors.lightGray)
for i=0, windowp.W do
  term.setCursorPos(windowp.x+i,windowp.y)
  print(" ")
  term.setCursorPos(windowp.x+i,windowp.y+windowp.H)
  print(" ")

end
for j=0, windowp.H do
  term.setCursorPos(windowp.x,windowp.y+j)
  print(" ")
  term.setCursorPos(windowp.x+windowp.W,windowp.y+j)
  print(" ")

end
  term.setCursorPos(windowp.x+windowp.W/2-string.len(windowp.titlew)/2,windowp.y)
  term.setTextColor(colors.gray)
  print(windowp.titlew)
  if(windowp.ca) then
  
  term.setBackgroundColor(colors.red)
term.setCursorPos(windowp.x+windowp.W+1,windowp.y)
print("X")
term.setBackgroundColor(colors.white)
end
term.setCursorPos(windowp.x+2,windowp.y+2)

for i in string.gmatch(windowp.text,"[^\n]+") do
	print(i)
	x,y=term.getCursorPos()
	if i== " " then
	 term.setCursorPos(windowp.x+1,y)
	  end
end
end

the kernel part that manages routnes(this might be what is wrong)
programCache={}
routineCache={}
local evt={}
--table.insert(programCache,function() shell.run("OSCore/desktop")end)
local routine=nil;
os.queueEvent("abc", 6, "meow")
function startCoroutines()
for i=1, #programCache,1 do
  routine=coroutine.create(programCache[i])
  table.insert(routineCache,routine)
  ok, err=coroutine.resume(routine,unpack(evt))
end
end
function updateCoroutines()
for i=1, #routineCache,1 do
  if coroutine.status(routineCache[i])=="suspended" then
  ok, err=coroutine.resume(routineCache[i],unpack(evt))
  end
end
end
function addCoroutine(functionD)
table.insert(programCache,functionD)
startCoroutines()
updateCoroutines()
end
function removeCoroutine(functionD)
for k,v in ipairs(programCache) do
  if v==functionD then
   table.remove(programCache,k)
  end
end
end
if loggedStatus then
addCoroutine(function() shell.run("OSCore/desktop")end)
end
while true do
evt={os.pullEvent()}
updateCoroutines()

end

desktop coroutine
os.loadAPI("Apis/DesignUtil")
os.loadAPI("Apis/AccountSytem")
os.loadAPI("Apis/windowSystem")
DesignUtil.setDesign("whiteLightGray")
local background,topBar =DesignUtil.getDesign()
local showOS1Menu = false;

term.setTextColor(colors.gray)
local OS1MenuB={
text="O1|";
x=1;
y=1;
W=3;
H=1;
}
local OS1MenuSelections=
{
s1Text="About this device";
s1X=1;
s1Y=2;
s1W=17;
s1H=1;
s2Text="Software update  ";
s2X=1;
s2Y=3;
s2W=17;
s2H=1;
s3Text="Restart device   ";
s3X=1;
s3Y=4;
s3W=17;
s3H=1;
s4Text="Shut down		";
s4X=1;
s4Y=5;
s4W=17;
s4H=1;
}
function registerClickEvent(x,y)
if x >=OS1MenuB.x and x <=OS1MenuB.x+OS1MenuB.W-1 and y >=OS1MenuB.y and y <=OS1MenuB.y+OS1MenuB.H-1 then
  if showOS1Menu then
   showOS1Menu=false
   else
	showOS1Menu=true
   end
end
if x >=OS1MenuSelections.s1X and x <=OS1MenuSelections.s1X+OS1MenuSelections.s1W-1 and y >=OS1MenuSelections.s1Y and y <=OS1MenuSelections.s1Y+OS1MenuSelections.s1H-1 then
  addCoroutine(function() shell.run("OSCore/aboutW.app")end)
  print("added routine")

end
end
function printOS1Menu()
if showOS1Menu then
  term.setBackgroundColor(colors.lightGray)
  term.setCursorPos(OS1MenuSelections.s1X,OS1MenuSelections.s1Y)
  print(OS1MenuSelections.s1Text)
  term.setCursorPos(OS1MenuSelections.s2X,OS1MenuSelections.s2Y)
  print(OS1MenuSelections.s2Text)
  term.setCursorPos(OS1MenuSelections.s3X,OS1MenuSelections.s3Y)
  print(OS1MenuSelections.s3Text)
  term.setCursorPos(OS1MenuSelections.s3X,OS1MenuSelections.s3Y)
  print(OS1MenuSelections.s3Text)
  term.setCursorPos(OS1MenuSelections.s4X,OS1MenuSelections.s4Y)
  print(OS1MenuSelections.s4Text)


end
end
while true do
local e = {os.pullEvent()}
paintutils.drawImage(background,1,1)
paintutils.drawImage(topBar,1,1)


term.setCursorPos(OS1MenuB.x,OS1MenuB.y)
term.setBackgroundColor(colors.lightGray)
print(OS1MenuB.text)

if e[1]=="mouse_click" then
  registerClickEvent(e[3],e[4])
   printOS1Menu()
end
end

and aboutW.app coroutine
os.loadAPI("Apis/windowSystem")
local afData = {}
local x,y=0;
function exit()


end
local SysU=
{
text="Software update";
x=22;
y=7;
W=15;
H=1;
}

function loadAbout()
local abF=fs.open("data/osInfo","r")
local line = abF.readLine()
repeat
  table.insert(afData,line) -- Puts the value of the current line into the table we have.
  line = abF.readLine() -- read the next line
until line == nil -- readLine() returns nil when the end of the file is reached.
abF.close() -- Close up the file ready for use again.
end
loadAbout()
function registerClick(xPos,yPos)
shell.run("OSCore/loginUtil")
if xPos==window.x+window.W+1 and yPos==window.y then
   exit()
  end
if xPos >= SysU.x and xPos <= SysU.x + SysU.W - 1 and yPos >= SysU.y and yPos <=  SysU.y + SysU.H then
   shell.run("OSCore/updateManager.app")
  end
end
local window=windowSystem.createWindow("About this Device",21,3,18,13,true,"Version:"..afData[1].." \n \n \n System: "..afData[2])
while true do
	local e = {os.pullEvent()}
windowSystem.drawWindow(window)
term.setBackgroundColor(colors.white)

   if e[1]=="mouse_click" then
		registerClick(e[3],e[4])
	end


end

heres what Id still need to make working
  • The menu in desktop wont close if I click outside of it
  • When I add the aboutW.app coroutine, the said routine starts to flicker onscreen, displays errors: No such program and AboutW:37 attemp to index ? (a nil value) (but I pass in the x and y, dont I?)
  • After a short while: TOO LONG WITHOUT YIELDING can be briefly seen, comsole spills out java.lang.ThreadDeath
How can a I make those problems dissapear aswell?? Should I load the apis inside the handler aswell, not separately in each coroutine???

#25 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 25 September 2013 - 08:38 AM

First of all :D use spoilers: [spoiler]something[/spoiler] (don't copy that exactly, beacuse it won't work - type it in manually).

The problem with aboutW.app is that window is declared after the declaration of registerClick ([methinks] so Lua won't recognize window as an upvalue when it's indexed from registerClick [/methinks]). The menu is buggy because the line which would make it disappear is inside a block which executes only if you click inside the menu.

#26 makerimages

  • Members
  • 236 posts

Posted 26 September 2013 - 07:18 AM

the aboutW.app now looks like this
Spoiler
  • it still flickers
  • and occasionally showes too long without yielding
  • It still shows java.lang.ThreadDeath in the console

EDIT: issue seems to be the addCoroutine method... It keeps adding multiple routines of the same thing, is there any way to stop that from happening?

#27 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 02 October 2013 - 09:23 AM

This will fix the flickering... (kernel/kernelProgramRunner)
Spoiler


#28 makerimages

  • Members
  • 236 posts

Posted 03 October 2013 - 07:05 AM

Indeed it did! but.. i need to click once more after i click the button in desktop, to have the routine appear. and also, removeCoroutine wont remove the program from running... how to add those?

ACTUALLY, if I also run the updateManager app, it will allow to close routines... but not just when one is running, AND NOT in any order I want and after that, the screen sometimes flickers again on mouse cli nevermind, updatemanager not set up yet :)

#29 LBPHacker

  • Members
  • 766 posts
  • LocationBudapest, Hungary

Posted 03 October 2013 - 08:36 AM

removeCoroutine doesn't work because you remove a function from the programCache table, not a coroutine from coroutineCache. I didn't see that earlier, but yeah, that's all.

#30 makerimages

  • Members
  • 236 posts

Posted 04 October 2013 - 12:13 AM

I tried
function removeCoroutine(functionD)
    for k, v in ipairs(programCache) do
	    if v == functionD then
		    table.remove(programCache, k)
		    table.remove(routineCache, k)

	    end
    end
end
wont work aswell

#31 makerimages

  • Members
  • 236 posts

Posted 05 October 2013 - 08:18 AM

Anything folks?





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users