Update:
cleaned up the code a bit. added simple autocomplete.
disabled escape key, the editor can be closed with the "X" button on the window. the window now has no border, but it can still be dragged around (custom code).
still more to do.
i was using the matrix1 commands so casually, i forgot that they are not part of normal dbpro. that plugin will be needed to run the code. next would be removing matrix1 dependence.
Rem Project: DarkCeption
Rem Created: Thursday, April 13, 2017
remstart
TODO:
stop commands from being parsed if they are inside of " marks
fix math parsing
fix print command. if print doesn't have parameters, it outputs 0 where it should output an empty string
add more commands
etc.
remend
disable escapekey
set window layout 0,0,0
global winPosX as integer
global winPosY as integer
winPosX=(desktop width()-640)/2
winPosY=(desktop height()-480)/2
set window position winPosX,winPosY
type buttonType
id as integer
x as integer
y as integer
w as integer
h as integer
value as string
func as string
params as string
endtype
dim button() as buttonType
type cursorType
x as integer
y as integer
w as integer
endtype
global cursor as cursorType
cursor.y=0
cursor.x=0
cursor.w=0
dim lines(0) as string
type autocType
txt as string
pos as integer
endtype
dim autoc() as autocType
global ACselector as integer
ACselector=-1
addButton(2,2,60,24,"Run","run","")
addButton(screen width()-22,2,20,24,"X","exit","")
updateDisplay(0)
do
mousemovex()=0
mousemovey()=0
getInput()
if ACselector>-1
box 0,(cursor.y+1+ACselector)*text height("Mg")+30,300,(cursor.y+1+ACselector)*text height("Mg")+30+text height("Mg"),0xff666666
endif
for i=0 to array count(autoc())
text 0,(cursor.y+1+i)*text height("Mg")+30,str$(i)+": "+autoc(i).txt
NEXT i
// show buttons
winCanMove=1
for i=0 to array count(button())
x1=button(i).x
y1=button(i).y
x2=x1+button(i).w
y2=y1+button(i).h
drawButton(i)
if mouseinside(x1,y1,x2,y2)
winCanMove=0
if mouseclick()=1 then runButton(i)
endif
next i
// move window
if mousey()<30 and winCanMove=1 and mouseclick()=1
repeat
winPosX=winPosX+mousemovex()
winPosY=winPosY+mousemovey()
set window position winPosX,winPosY
UNTIL mouseclick()=0
ENDIF
// run parser
if keystate(63)=1
repeat
UNTIL keystate(63)=0
prepare()
parse()
prepare()
updateDisplay(0)
ENDIF
sleep 1
LOOP
end
function updateDisplay(noAutoCompleteFlag)
cls
line 0,28,screen width(),28
for i=0 to array count(lines())
updateLine(i,text height("Mg")*i+30)
next i
ink 0xffffffff,0
line cursor.x*text width("A"),cursor.y*text height("Mg")+30,cursor.x*text width("A"),cursor.y*text height("Mg")+text height("Mg")+30-1
endfunction
function addLine()
array insert at bottom lines()
index=array count(lines())
cursor.y=index
endfunction
function removeLine()
if cursor.y=0 then exitfunction
t$=lines(cursor.y)
array delete element lines(),cursor.y
moveCursorY(-1)
lines(cursor.y)=lines(cursor.y)+t$
endfunction
function addChar(c$)
lines(cursor.y)=left$(lines(cursor.y),cursor.x)+c$+right$(lines(cursor.y),len(lines(cursor.y))-cursor.x)
moveCursorX(1)
endfunction
function removeChar()
lines(cursor.y)=left$(lines(cursor.y),cursor.x-1)+right$(lines(cursor.y),len(lines(cursor.y))-cursor.x-1)
moveCursorX(-1)
endfunction
function moveCursorX(move)
cursor.x=cursor.x+move
if cursor.x<0 then cursor.x=0
if cursor.x>len(lines(cursor.y)) then cursor.x=len(lines(cursor.y))
endfunction
function moveCursorY(move)
cursor.y=cursor.y+move
if cursor.y<0 then cursor.y=0
if cursor.y>array count(lines()) then cursor.y=array count(lines())
endfunction
function getInput()
uD=0
a=asc(entry$())
clear entry buffer
select a
case 8:
removeChar()
uD=1
showAutoC()
endcase
case 13:
if ACselector=-1
addLine()
cursor.x=len(lines(cursor.y))
uD=1
showAutoC()
else
lines(cursor.y)=left$(lines(cursor.y),autoc(ACselector).pos)+autoc(ACselector).txt
cursor.x=len(lines(cursor.y))
uD=1
clearAutoC()
endif
endcase
case 27:
clearAutoC()
uD=1
endcase
case default:
if a>0
addChar(chr$(a))
uD=1
showAutoC()
endif
endcase
endselect
if leftkey() then xm=-1
if rightkey() then xm=1
if upkey() then ym=-1
if downkey()
if array count(autoc())=-1
ym=1
else
repeat
UNTIL downkey()=0
inc ACselector
uD=1
endif
endif
if xm<>0 or ym<>0
if cursor.w<>1
oldx=cursor.x
oldy=cursor.y
moveCursorX(xm)
moveCursorY(ym)
endif
if cursor.w<2 then inc cursor.w : wait 150
wait 50
uD=1
showAutoC()
else
cursor.w=0
endif
if ACselector>array count(autoc()) then ACselector=-1
if uD=1 then updateDisplay(0)
endfunction
function showAutoC()
ink 0xffffffff,0
txt$=lines(cursor.y)
clearAutoC()
restore _keywords
read c
for i=1 to c
read tc$
if txt$=""
addToAutoC(tc$,1)
else
t$=right$(txt$,1)
f=1
f=find char(tc$,t$,f)
if f>0
if f>1
if left$(tc$,f)=right$(txt$,f) then addToAutoC(tc$,len(txt$)-f)
else
if mid$(txt$,len(txt$)-1)=" " or mid$(txt$,len(txt$)-1)="" then addToAutoC(tc$,len(txt$)-f)
endif
endif
endif
NEXT i
ENDFUNCTION
function addToAutoC(txt$,pos)
array insert at bottom autoc()
autoc(array count(autoc())).txt=txt$
autoc(array count(autoc())).pos=pos
ENDFUNCTION
function clearAutoC()
for i=0 to array count(autoc())
autoc(i).txt=free string$()
NEXT i
empty array autoc()
ACselector=-1
ENDFUNCTION
function prepare()
ink 0xffffffff,0
clear entry buffer
cls
ENDFUNCTION
function parse()
for i=0 to array count(lines())
txt$=lines(i)
commentFlag=0
for l=1 to len(txt$)
if left$(right$(txt$,len(txt$)-l+1),2)="//"
commentFlag=1
ENDIF
if commentFlag=0
if left$(right$(txt$,len(txt$)-l+1),5)="print"
subt$=right$(txt$,len(txt$)-l+1-5)
t$=first token$(subt$,";")
repeat
first=find first char$(t$,chr$(34))
if first>0
last=find last char$(t$,chr$(34))-first-1
if last>0
print left$(right$(t$,len(t$)-first),last);
endif
else
print str$(calc(t$));
endif
t$=next token$(";")
UNTIL t$=""
print ""
ENDIF
if left$(right$(txt$,len(txt$)-l+1),8)="wait key"
wait key
ENDIF
if left$(right$(txt$,len(txt$)-l+1),3)="end"
exitfunction
ENDIF
endif
rem end
NEXT l
NEXT i
ENDFUNCTION
function calc(s$)
for l=1 to len(s$)
if mid$(s$,l)="+" then first=val(nr$) : nr$=""
nr$=nr$+mid$(s$,l)
NEXT l
last=val(nr$)
output=first+last
ENDFUNCTION output
function updateLine(linenr,y)
box 0,y,screen width(),y+text height("Mg"),0xff000000
if linenr>array count(lines()) or linenr<0 then exitfunction
txt$=lines(linenr)
if txt$="" then exitfunction
ink 0xffffffff,0
text 0,y,txt$
restore _keywords
read c
for i=1 to c
t$=txt$
x=0
read k$
f=find sub string$(t$,k$)
while f>0
ink 0xff5555ff,0
x=x+text width(left$(t$,f-1))
t$=right$(t$,len(t$)-f-len(k$))
text x,y,k$
x=x+text width(k$)
f=find sub string$(t$,k$)
endwhile
NEXT i
ENDFUNCTION
function mouseInside(x1,y1,x2,y2)
mx=mousex()
my=mousey()
if mx>x1 and my>y1 and mx<x2 and my<y2 then exitfunction 1
ENDFUNCTION 0
function runButton(index)
select button(index).func
case "exit"
clearAutoC()
end
endcase
case default
prepare()
parse()
prepare()
updateDisplay(0)
endcase
endselect
ENDFUNCTION
function alert(txt$)
sw=screen width()
sh=screen height()
t$=""
for i=0 to len(txt$)-1
t$=t$+" "
NEXT i
text (sw-text width(txt$))/2,(sh-text height(txt$))/2,t$
text (sw-text width(txt$))/2,(sh-text height(txt$))/2,txt$
wait key
ENDFUNCTION
function addButton(x,y,width,height,value$,func$,params$)
array insert at bottom button()
index = array count(button())
button(index).x=x
button(index).w=width
button(index).y=y
button(index).h=height
button(index).value=value$
button(index).func=func$
button(index).params=params$
ENDFUNCTION index
function drawButton(index)
if index<0 or index>array count(button()) then exitfunction
x1=button(index).x
y1=button(index).y
x2=x1+button(index).w
y2=y1+button(index).h
if mouseinside(x1,y1,x2,y2)
color=0xffffffff
ink 0xff333333,0
else
color=0xff333333
ink 0xffffffff,0
endif
box x1,y1,x2,y2,color
text x1,y1,button(index).value
ENDFUNCTION
_keywords:
data 4
data "print","wait key","end","point camera"