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

Desktop

Started by DubbelSoftware, 18 July 2017 - 06:58 PM
DubbelSoftware #1
Posted 18 July 2017 - 08:58 PM
Hello,

I need to know somethings about programs on the desktop. I want to make a folder called "Programs". And in that folder wil be more folders with a program name. With in each folder a icon and a main file that wil run. I want to draw each program, and that if i rightclick. That it wil know what program i rightclicked. I dont know how to do that. I have seen so much Operating Systems. And checked there files. But i cannot learn from it. Because that it is too advanced. Can somebody give me a example or explain how to do this.

-DubbelSoftware
KingofGamesYami #2
Posted 18 July 2017 - 09:10 PM
I really hate to bring it up, since we have WAY TOO MANY NDF-Jay clones already, but he does cover pretty much exactly what you're asking.

Start here.

It's not precisely what you want, as your thing is going to be dynamic and probably not just a drop-down menu, but it's a bunch of stuff I won't have to explain myself.
DubbelSoftware #3
Posted 19 July 2017 - 09:46 AM
I really hate to bring it up, since we have WAY TOO MANY NDF-Jay clones already, but he does cover pretty much exactly what you're asking.

Start here.

It's not precisely what you want, as your thing is going to be dynamic and probably not just a drop-down menu, but it's a bunch of stuff I won't have to explain myself.

Its something where i can start with, but it is not what i looking for. I want that it wil draw al desktop icons from a folder where the icons are stored to the desktop. And that in one function. So if i add a icon, and dont change the code. That it wil draw that icon too. Not that i need to change the code for that.
And that if i click on that icon, that it wil run that program. And that if i do rightclick on that icon. That it wil give a little menu.

-DubbelSoftware
Edited on 19 July 2017 - 07:46 AM
KingofGamesYami #4
Posted 19 July 2017 - 12:07 PM
Let's break this down into two categories: graphical and non-graphical.

Graphical:

For this part, you'll need to figure out the width and height of each icon, as well as the spacing you want. Then you're going to need to iterate through a table of all the things you want an icon of. While doing this, you'll be tracking where each icon should be placed, and checking if it should be in the next row. This is rather important information, so store it somewhere!

non-graphical:

For this part, you'll need to figure out where the user clicked, then figure out which icon is there (if any). You can do this by a mathematical formula, if you know the width, height, and spacing. This is rather difficult, however. The easy way would be to record the positions of each icon, then compare those positions to the clicked position.

For now, focus on getting the graphical part to work. Once that is done, get the click stuff to work (just print something when it's clicked). After both of those are done, you can change the code to be dynamic (ei updating the table automatically) and figure out how to make a right-click menu.
Lupus590 #5
Posted 19 July 2017 - 12:08 PM
so something like this?

for each file in icon folder do
    read file
    draw icon --#may want to add checks that the icon is not broken or something
end

have a look at the API section of the computercraft wiki and see what will do what you need: http://www.computercraft.info/wiki/Category:APIs
DubbelSoftware #6
Posted 19 July 2017 - 01:10 PM
so something like this?

for each file in icon folder do
	read file
	draw icon --#may want to add checks that the icon is not broken or something
end

have a look at the API section of the computercraft wiki and see what will do what you need: http://www.computerc...i/Category:APIs

Yes i know that, but what if it is not possible to draw at that place? And what if i rightclick on the icon? How do it know that it is that icon??
Thats what i ask.

Let's break this down into two categories: graphical and non-graphical.

Graphical:

For this part, you'll need to figure out the width and height of each icon, as well as the spacing you want. Then you're going to need to iterate through a table of all the things you want an icon of. While doing this, you'll be tracking where each icon should be placed, and checking if it should be in the next row. This is rather important information, so store it somewhere!

non-graphical:

For this part, you'll need to figure out where the user clicked, then figure out which icon is there (if any). You can do this by a mathematical formula, if you know the width, height, and spacing. This is rather difficult, however. The easy way would be to record the positions of each icon, then compare those positions to the clicked position.

For now, focus on getting the graphical part to work. Once that is done, get the click stuff to work (just print something when it's clicked). After both of those are done, you can change the code to be dynamic (ei updating the table automatically) and figure out how to make a right-click menu.

Thank you very much! This is what i searched for! With this i can make it! Thank you!

-DubbelSoftware
DubbelSoftware #7
Posted 19 July 2017 - 01:47 PM
Let's break this down into two categories: graphical and non-graphical.

Graphical:

For this part, you'll need to figure out the width and height of each icon, as well as the spacing you want. Then you're going to need to iterate through a table of all the things you want an icon of. While doing this, you'll be tracking where each icon should be placed, and checking if it should be in the next row. This is rather important information, so store it somewhere!

non-graphical:

For this part, you'll need to figure out where the user clicked, then figure out which icon is there (if any). You can do this by a mathematical formula, if you know the width, height, and spacing. This is rather difficult, however. The easy way would be to record the positions of each icon, then compare those positions to the clicked position.

For now, focus on getting the graphical part to work. Once that is done, get the click stuff to work (just print something when it's clicked). After both of those are done, you can change the code to be dynamic (ei updating the table automatically) and figure out how to make a right-click menu.

But how do i know that the place where a icon place is. already is a icon there?
KingofGamesYami #8
Posted 19 July 2017 - 01:54 PM
Since you know the width, height, and placement of the icon you can do the same thing most button apis do: compare the difference of the coordinates to the width and height.
DubbelSoftware #9
Posted 19 July 2017 - 02:09 PM
– Snip
– IconPlaces
local currentRow = 3
local row1 = 3
local row2 = 9
local row3 = 15

local icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8 = false

local firstIconX = 4


– Loading
function drawIcons()
list = fs.list("programs")
for i,file in pairs(list) do
sleep(0.5)
drawIcon("programs/"..file.."/icon")
end
end

– Drawing
function drawIcon(path)
if icon1 == false then
paintutils.drawImage(paintutils.loadImage(path), firstIconX, currentRow) – 4
icon1 = true
elseif icon2 == false then
paintutils.drawImage(paintutils.loadImage(path), firstIconX + 6, currentRow) – 10
icon2 = true
elseif icon3 == false then
paintutils.drawImage(paintutils.loadImage(path), firstIconX + 12, currentRow) – 16
icon3 = true
elseif icon4 == false then
paintutils.drawImage(paintutils.loadImage(path), firstIconX + 18, currentRow) – 22
icon4 = true
elseif icon5 == false then
paintutils.drawImage(paintutils.loadImage(path), firstIconX + 24, currentRow) – 28
icon5 = true
elseif icon6 == false then
paintutils.drawImage(paintutils.loadImage(path), firstIconX + 30, currentRow) – 34
icon6 = true
elseif icon7 == false then
paintutils.drawImage(paintutils.loadImage(path), firstIconX + 36, currentRow) – 40
icon7 = true
elseif icon8 == false then
paintutils.drawImage(paintutils.loadImage(path), firstIconX + 42, currentRow) – 46
currentRow = currentRow + 6
icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8 = false
end
end


– Shell / Terminal


– Settings


– Config


– Main
drawIcons()

It isnt working very well.
Edited on 19 July 2017 - 12:11 PM
Lupus590 #10
Posted 19 July 2017 - 04:03 PM
 tags please

close with [./code] (remove the .)
DubbelSoftware #11
Posted 19 July 2017 - 04:07 PM
 tags please

close with [./code] (remove the .)

I try that, but there is something with my keyboard or computer. That it wil not do that. I have set code tags, but it dont work.
Lupus590 #12
Posted 19 July 2017 - 09:42 PM
try the <> button under the Smily face
valithor #13
Posted 20 July 2017 - 01:50 AM
local icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8 = false

That line is essentially saying:

local icon1 = false
local icon2 = nil
local icon3 = nil
local icon4 = nil
local icon5 = nil
local icon6 = nil
local icon7 = nil
local icon8 = nil

Change it to:

local icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8 = false, false, false, false, false, false, false, false

Also, since you are using elseif's only one of the if statements will run.

Break it up into separate if statements.
Edited on 19 July 2017 - 11:52 PM
Dave-ee Jones #14
Posted 20 July 2017 - 06:55 AM
I really hate to bring it up, since we have WAY TOO MANY NDF-Jay clones already, but he does cover pretty much exactly what you're asking.

Start here.

It's not precisely what you want, as your thing is going to be dynamic and probably not just a drop-down menu, but it's a bunch of stuff I won't have to explain myself.

You're just jealous that you didn't make a mainstream OS GUI for CC first :P/>
You can't discredit something that works and works well. It's easily the easiest, and possibly best, way to quickly setup an OS GUI that looks decent. The next thing up could be oeed's OS', which are a fair bit more in-depth.

local icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8 = false

That line is essentially saying:

local icon1 = false
local icon2 = nil
local icon3 = nil
local icon4 = nil
local icon5 = nil
local icon6 = nil
local icon7 = nil
local icon8 = nil

Change it to:

local icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8 = false, false, false, false, false, false, false, false

Also, since you are using elseif's only one of the if statements will run.

Break it up into separate if statements.

Why not just make a table..

local tIcons = {}
for i=1,8 do
	tIcons[i] = false
end

Looking at that solution almost makes me cry..
Edited on 20 July 2017 - 04:57 AM
KingofGamesYami #15
Posted 20 July 2017 - 11:58 AM
Oh I'm not saying it's a bad "OS", I just don't like the sheer number of people who copied line-for-line his tutorial, with perhaps a couple color changes. They're not as common now, but a year or two ago…
valithor #16
Posted 21 July 2017 - 12:17 AM
I really hate to bring it up, since we have WAY TOO MANY NDF-Jay clones already, but he does cover pretty much exactly what you're asking.

Start here.

It's not precisely what you want, as your thing is going to be dynamic and probably not just a drop-down menu, but it's a bunch of stuff I won't have to explain myself.

You're just jealous that you didn't make a mainstream OS GUI for CC first :P/>
You can't discredit something that works and works well. It's easily the easiest, and possibly best, way to quickly setup an OS GUI that looks decent. The next thing up could be oeed's OS', which are a fair bit more in-depth.

local icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8 = false

That line is essentially saying:

local icon1 = false
local icon2 = nil
local icon3 = nil
local icon4 = nil
local icon5 = nil
local icon6 = nil
local icon7 = nil
local icon8 = nil

Change it to:

local icon1, icon2, icon3, icon4, icon5, icon6, icon7, icon8 = false, false, false, false, false, false, false, false

Also, since you are using elseif's only one of the if statements will run.

Break it up into separate if statements.

Why not just make a table..

local tIcons = {}
for i=1,8 do
	tIcons[i] = false
end

Looking at that solution almost makes me cry..

A table is the obvious solution, however I took the opportunity to teach him how to actually use the syntax he was attempting to use.