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

icons/buttons?

Started by makerimages, 24 October 2012 - 05:46 AM
makerimages #1
Posted 24 October 2012 - 07:46 AM
Hey!

Im planning to do so that my OS will have program icons that function as buttons to start the program. The question is-HOW?

How can i load the icons(unique for every program) and have them work as clickable buttons to open the program?

also-how to color the entire terminal window not just the area with text?
ChunLing #2
Posted 24 October 2012 - 08:09 AM
There's an event type for mouse clicks in the console area. And there are already programs that use mouse input, check out how they work.
KaoS #3
Posted 24 October 2012 - 08:10 AM
unfortunately you cannot load images or change the color of the terminal window, you will have to use clickable links
makerimages #4
Posted 24 October 2012 - 08:16 AM
so i cant color the entire console background? but how sould i go about using ASCII as the icons?
KaoS #5
Posted 24 October 2012 - 08:21 AM
I thought you meant the border around the console. to change the entire background just set the background colour and use term.clear()

just use a normal name that you can click on
makerimages #6
Posted 24 October 2012 - 08:23 AM
so i color it and then i clear it ? hmm, what happens when i display text on it?

EDIT: works like a charm, thanks, but now i need to get rid of the cursor, the > is making an area around it blcak, the rest is perfectly lightblue
KaoS #7
Posted 24 October 2012 - 08:54 AM
surely if you set the background colour to blue and leave it as blue then that cursor will also have the same background, be careful of making small blocks of colour, you must set the background back again
makerimages #8
Posted 24 October 2012 - 03:26 PM
well i aint doing a thing to it, but do i have to reset the color after term.setCursorPos()?????

and how do i create small color boxes? i would need a taskbar thats on 1,16 and is yellow the background of the rest is lightBlue
briman0094 #9
Posted 25 October 2012 - 07:11 AM
well i aint doing a thing to it, but do i have to reset the color after term.setCursorPos()?????

and how do i create small color boxes? i would need a taskbar thats on 1,16 and is yellow the background of the rest is lightBlue



width, height = term.getSize()

term.setBackgroundColor(colors.blue)
term.clear()
term.setCursorPos(1, height)
term.setBackgroundColor(colors.yellow)
for i = 1, width - 2, 1 do
  write(" ")
end

This should work.
KaoS #10
Posted 25 October 2012 - 07:18 AM
it is always better to make a function. I'll post one when I'm not so busy

EDIT

local function icon(x1,y1,x2,y2,color)
if colors[color] then
  term.setBackgroundColor(colors[color])
  for y=y1,y2 do
   for x=x1,x2 do
    term.setCursorPos(x,y)
    write(' ')
   end
  end
end
end
icon(1,3,1,3,blue)
makerimages #11
Posted 25 October 2012 - 09:53 AM
well i aint doing a thing to it, but do i have to reset the color after term.setCursorPos()?????

and how do i create small color boxes? i would need a taskbar thats on 1,16 and is yellow the background of the rest is lightBlue



width, height = term.getSize()

term.setBackgroundColor(colors.blue)
term.clear()
term.setCursorPos(1, height)
term.setBackgroundColor(colors.yellow)
for i = 1, width - 2, 1 do
  write(" ")
end

This should work.

it doesnt, it gives me a taskbar that looks like the one in the photo below, i need a taskbar that goes from 1,16 to the low end of the terminal and doesnt scroll the terminal area, and i should be able to print in the taskbar as i want, not like it is now with the word taskbar? filling it, i need to be able to choose, what to show there and when and where, any ideas?

[attachment=618:2012-10-25_11.50.41.png]
KaoS #12
Posted 25 October 2012 - 10:00 AM
ok, by taskbar you mean a line of colour across the top or bottom

TOP:

local size={term.getSize()}
term.setCursorPos(1,1)
for x=1,size[1]-1 do
  write(' ')
end

BOTTOM:

local size={term.getSize()}
term.setCursorPos(1,size[2])
for x=1,size[1]-1 do
  write(' ')
end

if the bottom one scrolls then just use


local size={term.getSize()}
term.setCursorPos(1,size[2]-1)
for x=1,size[1]-1 do
  write(' ')
end

EDIT: Don't forget to change the background colour to whatever you need first
makerimages #13
Posted 25 October 2012 - 10:05 AM
works, but now how do i get the bar bit bigger(upwards) and get rid of the cursor?

EDIT: the same text writing thing still remains!!
EDIT2: do i use the last code you gave if i want it to scroll or if i dont want it to?
KaoS #14
Posted 25 October 2012 - 10:11 AM
ignore the text writing thing, when you have a complete program it will not show. to get it bigger just use this

top

local width=3
local size={term.getSize()}
for w=1,width do
  term.setCursorPos(1,w)
  for x=1,size[1]-1 do
    write(' ')
  end
end

bottom

local width=3
local size={term.getSize()}
for w=1,width do
  term.setCursorPos(1,size[2]-w+1)
  for x=1,size[1]-1 do
    write(' ')
  end
end
makerimages #15
Posted 25 October 2012 - 10:23 AM
but then, how do i display my own text on the taskbar wihtout that happening?
KaoS #16
Posted 25 October 2012 - 10:48 AM
Ok, let me explain lol

Computercraft has an interface, that '>' is part of the interface, it means that you can enter input there, it does not show while a program is running, only after the program is finished. you run your program and it generates the taskbar and then closes, when it closes the '>' is shown. when the program is ready it will continue to run after you generate the taskbar so that '>' will not show, nothing to worry about

to display text on the taskbar just setCursorPos on it, set the background colour to the taskbar colour and use write(text). I will post an example in a minute
makerimages #17
Posted 25 October 2012 - 10:51 AM
so i should just write other things, intregate the homescreen with other stuff and i wont get the > when done?
KaoS #18
Posted 25 October 2012 - 11:13 AM
exactly, as long as a program is running no '>'

example code

local function pCenter(text,colour)
  local pos={term.getCursorPos()}
  local col=term.getBackgroundColor()
  term.setCursorPos(math.floor(({term.getSize()})[1]/2-#text/2),pos[2])
  if colors[colour] then term.setBackgroundColor(colors[color]) end
  local output=write(text)
  term.setCursorPos(unpack(pos))
  if col then term.setBackgroundColor(col) end
  return output
end

term.setBackgroundColor(colors.blue)
local width=3
local size={term.getSize()}
for w=1,width do
  term.setCursorPos(1,w)
  for x=1,size[1]-1 do
	write(' ')
  end
end
term.setCursorPos(1,2)
pCenter('--TASKBAR--','blue')
RoD #19
Posted 30 March 2014 - 05:42 PM
Can i program my OS to display the files that are in a directory in the desktop as icons? i mean automaticaly take the files and display icons no matter how many they are.
I have looked up everywhere and i cant find a way of doing this. :/
KaoS #20
Posted 03 April 2014 - 02:03 PM
Can i program my OS to display the files that are in a directory in the desktop as icons? i mean automaticaly take the files and display icons no matter how many they are.
I have looked up everywhere and i cant find a way of doing this. :/

yes, it is very similar to what was done above in fact. Just parse a table of all the files…