This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
DubbelSoftware's profile picture

Desktop Icons and detection

Started by DubbelSoftware, 08 September 2017 - 07:03 PM
DubbelSoftware #1
Posted 08 September 2017 - 09:03 PM
The next few weeks, i am working on a new Operating System. I need a desktop where you can add a icon, with a startfile. So you can start the file when you click on. Is there a sort of API that i can use for this? So i can know:
Where the icon is
What program it is


-DubbelSoftware
Exerro #2
Posted 08 September 2017 - 09:15 PM
The API you're after is native Lua tables. Just keep a list of objects like {x, y, file [, icon]}. You can iterate through it for click detection and drawing.
DubbelSoftware #3
Posted 09 September 2017 - 08:08 PM
The API you're after is native Lua tables. Just keep a list of objects like {x, y, file [, icon]}. You can iterate through it for click detection and drawing.

I am currently making this, and trying this. But when loading the logo and store it in the table. It wil not loadable. Is this normal?
Exerro #4
Posted 09 September 2017 - 08:20 PM
Sorry, I don't know what you mean. Do you mean loading something from a file? An icon, or the list of shortcuts?

If you mean the icon, it depends on the file format you're using. If you're using paint to draw the icon, it'll be paintutils.loadImage(). Otherwise, use a loading function for the file format you use.

If you mean the list of shortcuts, you can use textutils.[un]serialize() to load and save the list.
DubbelSoftware #5
Posted 09 September 2017 - 08:23 PM
Sorry, I don't know what you mean. Do you mean loading something from a file? An icon, or the list of shortcuts?

If you mean the icon, it depends on the file format you're using. If you're using paint to draw the icon, it'll be paintutils.loadImage(). Otherwise, use a loading function for the file format you use.

If you mean the list of shortcuts, you can use textutils.[un]serialize() to load and save the list.

I am storing a path (in string) to the table. But when i want to load if from the table with:

paintutils.drawImage(paintutils.loadImage(iconData[i]), tonumber(iconData["1_x"]), tonumber(iconData["1_y"]))
it doesnt load, and says unexpected path. By the way the 1_x and 1_y are correctly. These are loaded with a function.
Edited on 09 September 2017 - 06:23 PM
KingofGamesYami #6
Posted 09 September 2017 - 10:27 PM
Without knowing what exactly is in iconData, it's very difficult to debug. May I suggest adding some print statements? If the UI drawing does not allow you to view the results, I suggest writing the data to a file.
DubbelSoftware #7
Posted 10 September 2017 - 08:02 AM
UPDATE:
I have found out why it was not working.
Edited on 10 September 2017 - 06:12 AM
Lupus590 #8
Posted 10 September 2017 - 02:54 PM
UPDATE:
I have found out why it was not working.

Please share so that others who find this post with simular issues have the solution.
Dave-ee Jones #9
Posted 11 September 2017 - 01:03 AM
UPDATE:
I have found out why it was not working.

Please share so that others who find this post with simular issues have the solution.

IF anyone does ["1_y"] instead of [1]["y"]..
DubbelSoftware #10
Posted 11 September 2017 - 04:13 PM
UPDATE:
I have found out why it was not working.

Please share so that others who find this post with simular issues have the solution.

I wil release the code soon in this topic when my OS is finished and released.

UPDATE:
I have found out why it was not working.

Please share so that others who find this post with simular issues have the solution.

IF anyone does ["1_y"] instead of [1]["y"]..

I am not that good at creating tables, i also dont know much about tables. I only know how to use them like that.
Also, this wil be changed when the OS is stable.

-DubbelSoftware
Dave-ee Jones #11
Posted 12 September 2017 - 02:03 AM
I am not that good at creating tables, i also dont know much about tables. I only know how to use them like that.
Also, this wil be changed when the OS is stable.

-DubbelSoftware

You can do some pretty powerful things with tables.
Look at this:

local testTable = {
  [1] = {
	test = "this is a test"
  },
  ["lollies"] = {
	test = "yummy"
  }
}

local testString = "lollies"

print(testTable[1].test) -- output: "this is a test"
print(testTable[1]["test"]) -- output: "this is a test"
print(testTable.lollies.test) -- output: "yummy"
print(testTable["lollies"].test) -- output: "yummy"
print(testTable["lollies"]["test"]) -- output: "yummy"
print(testTable.lollies["test"]) -- output: "yummy"
print(testTable[testString].test) -- output: "yummy"
print(testTable.testString.test) -- output: attempt to index (error)

for k,v in pairs(testTable) do
  print(k)
  print(v.test)
end
-- output:
-- 1
-- "this is a test"
-- "lollies"
-- "yummy"
Edited on 12 September 2017 - 12:04 AM