This is sort of an unrelated question, as it involves getting input, but I thought I'd post it here rather than start a whole new topic.
For the last day or so, I've been trying to make it so that when the user clicks on a text entry field, it changes color from grey to white, and the user can enter the text they desire. To do this, I created an input function that IanM outlined a few months ago in a different thread (it also uses his Matrix Utilities dll).
The function:
function get_input(x as integer, y as integer)
local in as string
local return_pos as integer
local result as string
result = ""
in = entry$(1)
return_pos = find char(in, cr$())
if return_pos > 0
result = fast left$(in, return_pos-1)
set entry buffer remove$(in, 1, return_pos)
else
text x,y,in
endif
endfunction result
The "get text" field:
`Get input if user clicks on "edit" box
if mx < current_sw/2+122 and my > current_sh/2-80 and mx > current_sw/2-122 and my < current_sh/2-60
if mouseclick()=1 then get_text1=1 : last_mc=0
if get_text1=1 and last_mc=0
box current_sw/2+122,current_sh/2-80,current_sw/2-122,current_sh/2-60,black,black,black,black
box current_sw/2+121,current_sh/2-79,current_sw/2-121,current_sh/2-61,white,white,white,white
set cursor screen width()/2-120,screen height()/2-75
print "New Screen Width: "
ink rgb(0,0,0),rgb(0,0,0)
input$=get_input(current_sw/2-40,current_sh/2-75)
if input$ <> ""
last_input$=input$
new_sw=val(last_input$)
endif
set cursor screen width()/2-120,screen height()/2-75
if new_sw > 0
print "New Screen Width: "+str$(new_sw)
else
print "New Screen Width: "
endif
text current_sw/2-36,current_sh/2-75,input$
get_text1=0
last_mc=1
endif
endif
All of my code:
Rem Project: Editor 2.0
Rem Created: Thursday, January 13, 2011
Rem ***** Main Source File *****
gosub program_setup
do
sync
loop
function get_input(x as integer, y as integer)
local in as string
local return_pos as integer
local result as string
result = ""
in = entry$(1)
return_pos = find char(in, cr$())
if return_pos > 0
result = fast left$(in, return_pos-1)
set entry buffer remove$(in, 1, return_pos)
else
text x,y,in
endif
endfunction result
Rem ***** Program Procedures *****
Rem ------------------------
Rem Program setup procedure
Rem ------------------------
program_setup:
`Tell the program where to look for the config file
file_path$="Data\Setup.INI"
`Open the file
if file exist(file_path$)
open to read 1,file_path$
`Read the header and ignore it
read string 1,ST$ : `Ignore this line
read string 1,ST$ : `Ignore this line
read string 1,ST$ : `Ignore this line
`Load in screen values
read string 1,ST$ : SW=val(ST$)
read string 1,ST$ : SH=val(ST$)
read string 1,ST$ : DP=val(ST$)
read string 1,ST$ : WM=val(ST$)
read string 1,ST$ : WW=val(ST$)
read string 1,ST$ : WH=val(ST$)
close file 1
`Apply data to program
Set Display Mode SW,SH,DP
`Create a window if WM=1
if WM=1
set window on
set window size WW,WH
set window position SW/100,SH/100
set window title "'A Little Epic' Level Editor [v2.0.1]"
endif
else
`Go to the options screen
gosub options_screen
endif
return
Rem ------------------------
Rem Options screen
Rem ------------------------
options_screen:
set display mode 800,600,32
`Get current display size
current_sw=screen width()
current_sh=screen height()
click_timer=250
set window title "'A Little Epic' Level Editor [v2.0.1]"
set window position 0,0
`Set text font and size
set text font "Microsoft Sans Serif Regular"
set text size 12
set text transparent
load image "cursor.jpg",1
`Options screen loop
while escapekey()=0
show mouse
`clear screen
cls
`Create the colors
blue as dword : blue=rgb(0,0,255)
black as dword : black=rgb(0,0,0)
white as dword : white=rgb(255,255,255)
red as dword : red=rgb(255,0,0)
green as dword : green=rgb(0,255,0)
gree2 as dword : gree2=rgb(0,55,0)
`Create colors for buttons
grey as dword : grey=rgb(55,55,55)
grey2 as dword : grey2=rgb(15,15,15)
ink rgb(white,white,white), rgb(white,white,white)
center text current_sw/2,10,"LEVEL EDITOR SETTINGS SCREEN"
`information box
box current_sw/2+220,current_sh-215,current_sw/2-220,current_sh-100,white,white,white,white
box current_sw/2+219,current_sh-214,current_sw/2-219,current_sh-101,grey2,grey2,grey2,grey2
ink rgb(grey,grey,grey), rgb(grey,grey,grey)
line current_sw/2+218,current_sh-197,current_sw/2-219,current_sh-197
ink rgb(255,0,0), RGB(255,0,0)
center text current_sw/2,current_sh-210,"SETTINGS CHANGE LOG"
ink rgb(0,90,255), rgb(0,90,255)
text current_sw/2-215,current_sh-195,"New Screen Resolution: "+str$(new_sw)+"x"+str$(new_sh)
text current_sw/2-215,current_sh-175,"New File path (saving) "+new_save_path$
text current_sw/2-215,current_sh-155,"New File path (loading) "+new_load_path$
`Create the resolution button
ink rgb(white,white,white), rgb(white,white,white)
box current_sw/2+120,current_sh/2-75,current_sw/2-120,current_sh/2-95,green,green,green,green
box current_sw/2+119,current_sh/2-76,current_sw/2-119,current_sh/2-94,grey,grey2,grey,grey2
center text current_sw/2,current_sh/2-90,"CHANGE RESOLUTION ("+str$(current_sw)+"x"+str$(current_sh)+")"
`Create the default paths button
box current_sw/2+120,current_sh/2-65,current_sw/2-120,current_sh/2-45,green,green,green,green
box current_sw/2+119,current_sh/2-64,current_sw/2-119,current_sh/2-46,grey2,grey,grey2,grey
center text current_sw/2,current_sh/2-60,"CHANGE DEFAULT FILE PATHS"
`Create the sound button
box current_sw/2+120,current_sh/2-35,current_sw/2-120,current_sh/2-15,green,green,green,green
box current_sw/2+119,current_sh/2-34,current_sw/2-119,current_sh/2-16,grey2,grey,grey2,grey
center text current_sw/2,current_sh/2-30,"CHANGE SOUND SETTINGS"
`Create save and exit button
box current_sw/2+120,current_sh/2-5,current_sw/2-120,current_sh/2+15,green,green,green,green
box current_sw/2+119,current_sh/2-4,current_sw/2-119,current_sh/2+14,grey2,grey,grey2,grey
center text current_sw/2,current_sh/2,"APPLY CHANGES"
`Get the mouse coordinates
mx=mousex() : my=mousey() : mc=mouseclick()
`Check for mouse hover on resolution button
if mx < current_sw/2+120 and my < current_sh/2-75 and mx > current_sw/2-120 and my > current_sh/2-95
box current_sw/2+120,current_sh/2-75,current_sw/2-120,current_sh/2-95,red,red,red,red
box current_sw/2+119,current_sh/2-76,current_sw/2-119,current_sh/2-94,grey,grey,grey,grey
center text current_sw/2,current_sh/2-90,"CHANGE RESOLUTION ("+str$(current_sw)+"x"+str$(current_sh)+")"
center text current_sw/2,current_sh-15,"Change current screen resolution"
`If user clicks the button....
if mc=1
button_press=0
while button_press=0
cls
`Draw the window
ink rgb(255,255,255),rgb(255,255,255)
box screen width()/2+130,screen height()/2-4,screen width()/2-130,screen height()/2-100,green,green,green,green
box current_sw/2+129,current_sh/2-5,current_sw/2-129,current_sh/2-99,black,black,black,black
box screen width()/2+128,screen height()/2-6,screen width()/2-128,screen height()/2-98,grey,grey2,grey,grey2
center text screen width()/2,screen height()/2-95,"ENTER VALUES FOR NEW SCREEN RESOLUTION"
`Draw inactive "get text" backgrounds
box screen width()/2+122,screen height()/2-80,screen width()/2-122,screen height()/2-60,green,green,green,green
box screen width()/2+121,screen height()/2-79,screen width()/2-121,screen height()/2-61,grey2,grey2,grey2,grey2
box screen width()/2+122,screen height()/2-50,screen width()/2-122,screen height()/2-30,green,green,green,green
box screen width()/2+121,screen height()/2-49,screen width()/2-121,screen height()/2-31,grey2,grey2,grey2,grey2
set cursor screen width()/2-120,screen height()/2-75
ink rgb(grey,grey,grey), rgb(grey,grey,grey)
if new_sw > 0
print "New Screen Width: "+str$(new_sw)
else
print "New Screen Width: "
endif
set cursor screen width()/2-120,screen height()/2-45
if new_sh > 0
print "New Screen Height: "+str$(new_sh)
else
print "New Screen Height: "
endif
`Draw the OK and Cancel buttons
while okay=0
`Get input if user clicks on "edit" box
if mx < current_sw/2+122 and my > current_sh/2-80 and mx > current_sw/2-122 and my < current_sh/2-60
if mouseclick()=1 then get_text1=1 : last_mc=0
if get_text1=1 and last_mc=0
box current_sw/2+122,current_sh/2-80,current_sw/2-122,current_sh/2-60,black,black,black,black
box current_sw/2+121,current_sh/2-79,current_sw/2-121,current_sh/2-61,white,white,white,white
set cursor screen width()/2-120,screen height()/2-75
print "New Screen Width: "
ink rgb(0,0,0),rgb(0,0,0)
input$=get_input(current_sw/2-40,current_sh/2-75)
if input$ <> ""
last_input$=input$
new_sw=val(last_input$)
endif
set cursor screen width()/2-120,screen height()/2-75
if new_sw > 0
print "New Screen Width: "+str$(new_sw)
else
print "New Screen Width: "
endif
text current_sw/2-36,current_sh/2-75,input$
get_text1=0
last_mc=1
endif
endif
if mx < current_sw/2+122 and my > current_sh/2-50 and mx > current_sw/2-122 and my < current_sh/2-30
get_text2=1
if get_text2=1
if last_input$ > "" then last_input$=""
box screen width()/2+122,screen height()/2-50,screen width()/2-122,screen height()/2-30,black,black,black,black
box screen width()/2+121,screen height()/2-49,screen width()/2-121,screen height()/2-31,white,white,white,white
set cursor screen width()/2-120,screen height()/2-45
print "New Screen Height: "
set cursor current_sw/2-38,current_sh/2-45
ink rgb(0,0,0),rgb(0,0,0)
input$=get_input(current_sw/2-38,current_sh/2-45)
if input$ <> ""
last_input$=input$
new_sh=val(last_input$)
endif
text current_sw/2-42,current_sh/2-45,input$
set cursor screen width()/2-120,screen height()/2-45
if new_sh > 0
print "New Screen Height: "+str$(new_sh)
else
print "New Screen Height: "
endif
endif
get_text2=0
endif
`reset color
ink rgb(white,white,white), rgb(white,white,white)
`ok button
box screen width()/2+25,screen height()/2-7,screen width()/2+75,screen height()/2-27,black,black,black,black
box screen width()/2+26,screen height()/2-8,screen width()/2+74,screen height()/2-26,grey,grey2,grey,grey2
text screen width()/2+38,screen height()/2-22,"SAVE"
`cancel button
box screen width()/2+127,screen height()/2-7,screen width()/2+77,screen height()/2-27,black,black,black,black
box screen width()/2+126,screen height()/2-8,screen width()/2+78,screen height()/2-26,grey,grey2,grey,grey2
text screen width()/2+84,screen height()/2-22,"CANCEL"
`check for mouse hover...
mx=mousex() : my=mousey()
if mx > screen width()/2+25 and my < screen height()/2-7 and mx < screen width()/2+75 and my > screen height()/2-27
box screen width()/2+25,screen height()/2-7,screen width()/2+75,screen height()/2-27,white,white,white,white
box screen width()/2+26,screen height()/2-8,screen width()/2+74,screen height()/2-26,grey,grey2,grey,grey2
text screen width()/2+38,screen height()/2-22,"SAVE"
if mouseclick()=1 then okay=1 : button_press=1
endif
if mx > screen width()/2+77 and my < screen height()/2-7 and mx < screen width()/2+127 and my > screen height()/2-27
box screen width()/2+127,screen height()/2-7,screen width()/2+77,screen height()/2-27,white,white,white,white
box screen width()/2+126,screen height()/2-8,screen width()/2+78,screen height()/2-26,grey,grey2,grey,grey2
text screen width()/2+84,screen height()/2-22,"CANCEL"
if mouseclick()=1 then okay=1 : button_press=1 : new_sw=current_sw : new_sh=current_sh
endif
okay=0
sync
endwhile
sync
endwhile
endif
endif
`Check for mouse hover on default paths button
if mx < current_sw/2+120 and my > current_sh/2-65 and mx > current_sw/2-120 and my < current_sh/2-45
box current_sw/2+120,current_sh/2-65,current_sw/2-120,current_sh/2-45,red,red,red,red
box current_sw/2+119,current_sh/2-64,current_sw/2-119,current_sh/2-46,grey,grey,grey,grey
center text current_sw/2,current_sh/2-60,"CHANGE DEFAULT FILE PATHS"
center text current_sw/2,current_sh-15,"Change file saving/loading locations"
endif
`check for mouse hove on sound button
if mx < current_sw/2+120 and my > current_sh/2-35 and mx > current_sw/2-120 and my < current_sh/2-15
box current_sw/2+120,current_sh/2-35,current_sw/2-120,current_sh/2-15,red,red,red,red
box current_sw/2+119,current_sh/2-34,current_sw/2-119,current_sh/2-16,grey,grey,grey,grey
center text current_sw/2,current_sh/2-30,"CHANGE SOUND SETTINGS"
center text current_sw/2,current_sh-15,"Adjust volume and other sound settings"
endif
sync
endwhile
return
The problem I'm having is that I can't make the text entry field stay white UNLESS the user holds down the mouse button. How do I stop this from happening?
Also, I've noticed that even though the get_input function is called only twice under certain conditions, somehow it's active ALL OF THE TIME. This means that I could type some random numbers, hit enter, and then the next time I go to the "change screen resolution" window and click the first entry field, the number I typed randomly is there! How do I stop that from happening?