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

Login Project

Started by Maj_GsL_Inc., 09 September 2016 - 09:29 PM
Maj_GsL_Inc. #1
Posted 09 September 2016 - 11:29 PM
Okay so i am currently working on a program that will display 2 boxes (one for the pass word one for the username) and then a top bar. I drew this using the "paint" program in computercraft. Currently i have got it to load the image and display it how i want but when i set the cursor position to (1, 1) it over writes my background with black and the yellow cursor is there any way around this or is that just how it is

Current Code


-- Created By: GsL Inc.	   Version: 1.1.3
-- Coded By: Majere		   Date: [08/08/16]
-- ============================================
-- Variabels
-- Functions
	    local function Cl()
   term.clear()
   term.setCursorPos(1, 1)
  end
-- Menue
Cl()
local image = paintutils.loadImage("GUIL")
paintutils.drawImage(image, 1, 1)
term.setCursorPos(1, 1)
Dog #2
Posted 09 September 2016 - 11:39 PM
Before you set the cursor position, you need to set the background color so it matches the color of the input area using term.setBackgroundColor()

If you want to make the cursor not blink use term.setCursorBlink(false)
Edited on 09 September 2016 - 09:40 PM
Maj_GsL_Inc. #3
Posted 10 September 2016 - 12:48 AM
term.setBackgroundColor did not fix my issue with the background also term.setCursorBlink did not seem to stop it from blinking


-- Created By: GsL Inc.	   Version: 1.1.3
-- Coded By: Majere		   Date: [08/08/16]
-- ============================================
-- Variabels
-- Functions
		local function Cl()
   term.clear()
   term.setCursorPos(1, 1)
  end
-- Menue
Cl()
term.setBackgroundColor(colors.gray)
term.setCursorBlink(false)
local image = paintutils.loadImage("GUIL")
paintutils.drawImage(image, 1, 1)
term.setCursorPos(17, 7)

Also note i want the background to stay the same is there a way when i load the image i can then prevent the image from being edited but still allow text to be overlayed onto it?
Edited on 09 September 2016 - 10:53 PM
KingofGamesYami #4
Posted 10 September 2016 - 12:55 AM
paintutils.drawImage changes the background color. Set it after the drawImage call.
Maj_GsL_Inc. #5
Posted 10 September 2016 - 01:02 AM
This still does not change the color behind the cursor is this a non-changeable aspect?
4
Dog #6
Posted 10 September 2016 - 01:09 AM
My apologies, I wasn't clear about which term.setCursorPos() call to put it ahead of, however KingofGamesYami pointed out the correct place to put the background color change. You might also want to place the cursor blink command after the drawImage call - see if that fixes that problem as well. Like so…

-- Created By: GsL Inc.	Version: 1.1.3
-- Coded By: Majere				Date: [08/08/16]
-- ============================================
-- Variabels
-- Functions
local function Cl()
  term.clear()
  term.setCursorPos(1, 1)
end
-- Menue
Cl()
local image = paintutils.loadImage("GUIL")
paintutils.drawImage(image, 1, 1)
term.setBackgroundColor(colors.gray)
term.setCursorBlink(false)
term.setCursorPos(17, 7)

Also note i want the background to stay the same

If by background you mean the image, then that's what changing the terminal background color will do. It'll ensure when you put text on the screen that the 'image' is 'preserved' by writing over it with the same background color.

is there a way when i load the image i can then prevent the image from being edited but still allow text to be overlayed onto it?

Other than changing to the proper background color for each area of the image, there is no other way to prevent the image onscreen from being changed. Be aware with your input boxes that the standard read() provided in CC won't allow you to limit the number of characters entered; so people will be able to type further than the input box, which will mess up your image. You'll need to write your own read function or use someone else's custom function to prevent that from happening.
Edited on 09 September 2016 - 11:18 PM
Maj_GsL_Inc. #7
Posted 10 September 2016 - 01:32 AM
Thanks for the help guys :D/>
Bomb Bloke #8
Posted 10 September 2016 - 02:12 AM
Be aware with your input boxes that the standard read() provided in CC won't allow you to limit the number of characters entered; so people will be able to type further than the input box, which will mess up your image. You'll need to write your own read function or use someone else's custom function to prevent that from happening.

A workaround for this is to redirect to a window before calling read(). The text cursor won't be able to escape the window's bounds.

local oldTerm = term.redirect( window.create( term.current(), 10, 10, 10, 1 ) )

local input = read()

term.redirect(oldTerm)