I haven't been able to work on this lately because every time I try to run the program I get this error:
Failed to 'CreateASMFooter::FindLabel'
I may just need to reboot or something.
So I'm posting the code that I have available now because it sounds like a few people were interested.
The frame rates could probably be improved by moving several of the variables out of the loop so they're not constantly being recalculated. The biggest slowdown really is the text drawing, but you should still be pulling over 100fps regardless.
REM **********************************
REM Title: Text Editor
REM Author: Phaelax
REM Last Updated: Jan. 29, 2009 4:00am
REM **********************************
set display mode 800,600,32
set text font "Courier", 1
set text size 8
#CONSTANT FALSE = 0
#CONSTANT TRUE = 1
#CONSTANT VK_ENTER = 13
#CONSTANT VK_BACK = 8
#CONSTANT VK_TAB = 9
#CONSTANT TABSPACE = 4
#CONSTANT KEYWORD = 1
#CONSTANT NUMBERS = 2
#CONSTANT STRG = 3
#CONSTANT COMMENT = 4
#CONSTANT NORM = 5
dim colors(5) as dword
colors(KEYWORD) = rgb(0,128,255)
colors(NUMBERS) = rgb(255,128,0)
colors(STRG) = rgb(128,0,128)
colors(COMMENT) = rgb(0,128,0)
colors(NORM) = rgb(255,255,255)
remstart
* Each segment contains the character
* indices of what code is to be
* highlighted between them, inclusive.
remend
type ColorSegment
lineNumber as integer
beginIndex as integer
endIndex as integer
keyType as integer
endtype
rem Array of ColorSegments
dim segments() as ColorSegment
thingy$ = "testing"
`dim keywords() as string
`loadKeywords("C:Program FilesDark Basic SoftwareDark Basic ProfessionalEditorKeywordskeywords105.ini")
rem load keywords
restore KeywordsFile
read t
dim keywords(t) as string
for i = 1 to t
read z$
keywords(i) = z$
next i
sortKeywordsArray()
rem array to hold lines of text
restore book
read Window_lineCount
dim viewport$(Window_lineCount)
`for i = 1 to Window_lineCount
` read z$
` viewport$(i) = z$
` Window_maxTextWidth = getMax(Window_maxTextWidth,text width(z$))
`next i
Theme_borderColor = rgb(66,75,82) : `color of border around window components
Theme_backgroundColor = rgb(114,122,128) : `background color of window body (and spacing between components)
Theme_foregroundColor = rgb(255,255,255)
`Theme_listBackgroundColor = rgb(195,202,208) : `background color of the viewport component
Theme_viewportBackgroundColor = 0
Theme_titleFontColor = rgb(22,69,110) : `text color for title bar
Theme_titleGradient1 = rgb(115,132,145) : `title bar fades from this color
Theme_titleGradient2 = rgb(74,100,120) : `title bar fades into this color
Theme_scrollBarTrackColor = rgb(93,103,111) : `scrollbar track color
Theme_scrollBarThumbColor = rgb(66,75,82) : `color of scrollbar thumb
Theme_scrollBarThumbHoverColor = rgb(162,177,189)
Theme_menuBackgroundColor = rgb(93,103,111) : `background color of the menu bar
Theme_menuForegroundColor = rgb(162,177,189) : `text color for menu bar items
Theme_iconColor = rgb(66,75,82) : `color used for window icons
Theme_windowBorderSize = 3 : `size of border around the window
Theme_componentMargins = 3 : `spacing between window components
Theme_componentBorderSize = 1 : `size of border around each component
Window_x = 10
Window_y = 10
Window_width = 498
Window_height = 498
Window_vThumb# = 0.0
Window_hThumb# = 0.0
_caretX = 0
_caretY = 0
Window_maxTextWidth = loadFile("E:ProgrammingDBPro Sourcetext editor.dba")
`Window_maxTextWidth = loadFile("E:ProgrammingDBClassic Challengesscrollable text viewer2.dba")
Window_lineCount = array count(viewport$())
parseDocument(1,Window_lineCount)
clear entry buffer
sync on
DO
cls
`parseDocument(1,Window_lineCount)
gosub _drawTextViewer
gosub _handleInput
set cursor 0,0
print _caretX," : ",_caretY
print screen fps()
sync
LOOP
function z(s$)
endfunction 0
REM ///////////////////////////////////////////////////
REM Draws the window and text while handling mouse
REM input and the component controls
REM \\\\\\\\\\\\\\\\\\\\\\\\\
_drawTextViewer:
_windowBorderSize = Theme_windowBorderSize
_componentMargins = Theme_componentMargins
_componentBorderSize = Theme_componentBorderSize
_componentPadding = 2 : `mainly used to offset displayed text from border edge
_numberedLineWidth = text width(str$(Window_lineCount)) + _componentPadding*2
_lineHeight = 16 : `spacing between lines of text
_contentPaneWidth = Window_maxTextWidth : `overall width of content that can be displayed in the viewport
_contentPaneHeight = Window_lineCount * _lineHeight : `overall height of content that can be displayed in the viewport
rem toggle maximize window
if changeWindow = 1
if isMaximized = 1
delta = (Window_width - _viewportWidth) + _numberedLineWidth + _componentPadding*3
Window_oldX = Window_x
Window_oldY = window_y
Window_oldWidth = Window_width
Window_oldHeight = Window_height
Window_x = 0
Window_y = 0
Window_width = getMin(_contentPaneWidth+delta, screen width()-2)
Window_height = getMin(_contentPaneHeight, screen height()-2)
else
Window_x = Window_oldX
Window_y = Window_oldY
Window_width = Window_oldWidth
Window_height = Window_oldHeight
endif
changeWindow = 0
endif
_charWidth = text width("A")
_charHeight = text height("Q")
_titleX = Window_x : `x-position of title bar
_titleY = Window_y : `y-position of title bar
_titleTextX = _titleX + _componentMargins : `x-position of title text
_titleTextY = _titleY + _componentMargins : `y-position of title text
_titleWidth = Window_width : `width of title bar
_titleHeight = _charHeight + _componentMargins*2 : `height of title bar
_menuX = Window_x + _componentMargins : `x-position of menu bar
_menuY = _titleY + _titleHeight + _componentMargins : `y-position of menu bar
_menuWidth = Window_width - _componentMargins*2 : `width of menu bar (excludes the component's border size)
_menuHeight = _charHeight : `height of menu bar (excludes the component's border size)
_vTrackWidth = 12 : `width of vertical scrollbar track
_hTrackHeight = 12 : `height of horizontal scrollbar track
_hTrackX = Window_x + _componentMargins : `x-position of horizontal scrollbar
_hTrackWidth = Window_width - _componentMargins*3 - _vTrackWidth : `width of horizontal scrollbar
_hTrackY = Window_y + Window_height - (_hTrackHeight+_componentMargins) : `y-position horizontal scrollbar
_vTrackX = (Window_x + Window_width) - (_componentMargins+_vTrackWidth) : `x-position of scroll bar track
_vTrackY = _menuY + _menuHeight + _componentMargins : `y-position of scroll bar track
_vTrackHeight = (_hTrackY - _vTrackY) - _componentMargins : `height of scroll bar track
_viewportX = Window_x + _componentMargins : `x-position of file view list
_viewportY = _vTrackY : `y-position of file view list
_viewportWidth = Window_width - (_componentMargins*3 + _vTrackWidth) : `width of the viewport (visible width)
_viewportHeight = _hTrackY - _viewportY - _componentMargins : `height of viewport (visible height)
f# = (_viewportHeight+0.0)/_contentPaneHeight
_vThumbWidth = _vTrackWidth : `width of scrollbar thumb (should be no larger than track width)
_vThumbHeight = getMin(getMax(12, _vTrackHeight*f#),_vTrackHeight) : `height of scrollbar thumb
_vThumbX = _vTrackX : `x-position of scrollbar thumb
_vThumbY = _vTrackY + (_vTrackHeight-_vThumbHeight)*Window_vThumb# : `y-position of scrollbar thumb
f# = (_viewportWidth+0.0)/_contentPaneWidth
_hThumbWidth = getMin(getMax(12, _hTrackWidth*f#),_hTrackWidth) : `width of scrollbar thumb
_hThumbHeight = _hTrackHeight : `height of scrollbar thumb (should be no larger than track height)
_hThumbY = _hTrackY : `x-position of scrollbar thumb
_hThumbX = _hTrackX + (_hTrackWidth-_hThumbWidth)*Window_hThumb# : `y-position of scrollbar thumb
_resizeX = _hTrackX+_hTrackWidth+_componentBorderSize
_resizeY = _vTrackY+_vTrackHeight+_componentBorderSize
_resizeX2 = Window_x+Window_width
_resizeY2 = Window_y+Window_height
_maximizeSize = 14
_maximizeX = _titleX+_titleWidth-(_maximizeSize+_componentMargins)
_maximizeY = _titleY + (_titleHeight-_maximizeSize)/2
_wheelDelay = 35 : `mouse wheel scroll speed (lower is faster)
_wheelStep = 12 : `how much to scroll with mouse wheel
_scrollSensitivity = 10 : `1 or higher; lower number means faster scrolling
_showCount = getMin(ceil((_viewportHeight+0.0) / _lineHeight), Window_lineCount) : `number of visible text lines shown within the viewport
_offscreenContentHeight = getMax(_contentPaneHeight-_viewportHeight, 0) : `how much viewable content is off-screen
_viewportPixelOffsetY = _offscreenContentHeight*Window_vThumb# : `Y-offset of viewable content pane (in pixels)
_startingIndex = _viewportPixelOffsetY / _lineHeight + 1 : `line index to show first in the viewable text
_endingIndex = getMin(_startingIndex + _showCount, Window_lineCount) : `last text index to be displayed in the viewable text
_offscreenContentWidth = getMax(_contentPaneWidth-(_viewportWidth-_numberedLineWidth-_componentPadding*3),0) : `how much viewable content is offsecreen
_viewportPixelOffsetX = _offscreenContentWidth * Window_hThumb# : `X-offset of viewable content pane (in pixels)
rem draw background of entire window
ink Theme_backgroundColor,0
box Window_x,Window_y,Window_x+Window_width,Window_y+Window_height
rem draw border around window
drawOutline(Window_x,Window_y,Window_x+Window_width,Window_y+Window_height,_windowBorderSize,Theme_borderColor)
rem draw viewport background
ink Theme_viewportBackgroundColor,0
box _viewportX, _viewportY, _viewportX+_viewportWidth, _viewportY+_viewportHeight
rem display lines of text
ink Theme_foregroundColor, 0
for lineNumber = _startingIndex to _endingIndex
hidden = _viewportPixelOffsetX / _charWidth
extra = _viewportPixelOffsetX - hidden*_charWidth
x = (_viewportX + _numberedLineWidth + _componentPadding) - extra
y = _viewportY+_lineHeight*(lineNumber-1) - _viewportPixelOffsetY
t$ = right$(viewport$(lineNumber),len(viewport$(lineNumber))-hidden)
t2$ = right$(viewport$(lineNumber),len(viewport$(lineNumber))-hidden)
capLimit = (_viewportWidth - _numberedLineWidth) + _charWidth
if y < _viewportY+_viewportHeight
text x, y, capLength$(t$, capLimit)
for i=0 to array count(segments())
if segments(i).lineNumber = lineNumber
lx = x + (segments(i).beginIndex-1)*_charWidth - _viewportPixelOffsetX+extra
t$ = substring$(viewport$(lineNumber),segments(i).beginIndex,segments(i).endIndex)
w = (segments(i).endIndex - segments(i).beginIndex+1)*_charWidth
ink colors(segments(i).keyType), 0
t$ = capLength$(t$,capLimit - (lx-x))
`text lx+d*_charWidth,y,right$(t$,len(t$)-d)
diff = (_viewportX + _numberedLineWidth + _componentPadding) - lx
offChar = diff/_charWidth
t$ = right$(t$,len(t$)-offChar)
tx = (_viewportX + _numberedLineWidth + _componentPadding) + (segments(i).beginIndex-1)*_charWidth - _viewportPixelOffsetX
if tx < x then tx = tx + (x-tx)
text tx, y, t$
`drawOutline(lx,y,lx+w,y+_charHeight, 1, rgb(0,0,255))
endif
next i
rem text selection
if _oldCaretX <> _caretX OR _oldCaretY <> _caretY
LY1 = getMin(_oldCaretY,_caretY)
LY2 = getMax(_oldCaretY,_caretY)
if LY1 = _oldCaretY : LX1 = _oldCaretX : LX2 = _caretX : else : LX1 = _caretX : LX2 = _oldCaretX : endif
if LY1 <> LY2
if lineNumber = LY1
r$ = capLength$(t2$, capLimit)
r$ = right$(r$,len(r$)-LX1)
ink rgb(0,0,255),0
box x+(LX1*_charWidth), y,x+(LX1*_charWidth)+(len(r$)*_charWidth), y+_charHeight
ink rgb(255,255,255),0
text x+(LX1*_charWidth), y, r$
endif
if lineNumber = LY2
r$ = capLength$(t2$, capLimit)
r$ = left$(r$, LX2)
ink rgb(0,0,255),0
box x,y,x+len(r$)*_charWidth,y+_charHeight
ink rgb(255,255,255),0
text x, y, r$
endif
if lineNumber > LY1 and lineNumber < LY2
r$ = capLength$(t2$, capLimit)
ink rgb(0,0,255),0
box x,y,x+len(r$)*_charWidth,y+_charHeight
ink rgb(255,255,255),0
text x, y, r$
endif
else
if lineNumber = LY1
LX1 = getMin(_oldCaretX, _caretX)
LX2 = getMax(_oldCaretX, _caretX)
r$ = capLength$(t2$, capLimit)
r$ = substring$(r$, LX1+1, LX2)
ink rgb(0,0,255),0
xx = x + LX1*_charWidth
box xx,y,xx+len(r$)*_charWidth,y+_charHeight
ink rgb(255,255,255),0
text xx, y, r$
endif
endif
endif
ink Theme_foregroundColor, 0
rem show caret
if lineNumber = _caretY
cx = x + _caretX*_charWidth - _viewportPixelOffsetX + extra
if cx >= x and cx <= _viewportX+_viewportWidth
cy = _viewportY+_lineHeight*(_caretY-1) - _viewportPixelOffsetY
if cx > _viewportX+_viewportWidth
Window_hThumb# = (_viewportPixelOffsetX + _charWidth) / _offscreenContentWidth
endif
ink rgb(0,255,0),0
box cx, cy, cx+2, cy+_charHeight
ink Theme_foregroundColor, 0
endif
endif
endif
next lineNumber
rem display line number border
ink Theme_backgroundColor,0
box _viewportX, _viewportY, _viewportX+_numberedLineWidth, _viewportY+_viewportHeight
ink Theme_titleFontColor,0
for lineNumber = _startingIndex to _endingIndex
x = _viewportX + _componentPadding
y = _viewportY+_lineHeight*(lineNumber-1) - _viewportPixelOffsetY
if y < _viewportY+_viewportHeight then text x, y, rightAlignText$(str$(lineNumber),len(str$(Window_lineCount)))
next lineNumber
ink Theme_borderColor, 0
line _viewportX+_numberedLineWidth, _viewportY, _viewportX+_numberedLineWidth, _viewportY+_viewportHeight
rem redraw background between components above and below the viewport
rem this is to give the appearance that the text stays within the list view
rem (which is also why the title and scrollbars are drawn after the viewport)
ink Theme_backgroundColor,0
fillY = _menuY+_menuHeight+_componentBorderSize
box Window_x, fillY, Window_x+Window_width, fillY+_componentMargins
fillY = _viewportY+_viewportHeight+_componentBorderSize
box _viewportX, fillY, _viewportX+_viewportWidth, fillY+_componentMargins
fillX = _vTrackX - _componentBorderSize - _componentMargins
box fillX, _vTrackY-_componentBorderSize, fillX+_componentMargins, _vTrackY+_vTrackHeight+_componentBorderSize
box _resizeX, _resizeY, _resizeX2, _resizeY2
rem draw border around viewport
drawOutline(_viewportX, _viewportY, _viewportX+_viewportWidth, _viewportY+_viewportHeight,_componentBorderSize,Theme_borderColor)
rem draw title bar
ink Theme_titleGradient2,0
drawVerticalGradient(_titleX, _titleY, _titleX+_titleWidth, _titleY+_titleHeight, Theme_titleGradient1,Theme_titleGradient2)
ink Theme_titleFontColor,0
text _titleTextX, _titleTextY, capLength$("To Infinity and Beyond! ~Buzz Lightyear", _maximizeX-Window_x)
rem draw maximize icon
ink Theme_iconColor,0
drawMaximize(_maximizeX, _maximizeY, _maximizeSize)
rem draw menu bar
ink Theme_menuBackgroundColor,0
box _menuX, _menuY, _menuX+_menuWidth, _menuY+_menuHeight
rem draw border around menu bar
drawOutline(_menuX, _menuY, _menuX+_menuWidth, _menuY+_menuHeight,_componentBorderSize,Theme_borderColor)
ink Theme_menuForegroundColor,0
text _menuX+6,_menuY, "File Edit View Tools Help"
rem handle non-functional drop-down menus with mouse hover (just a little eye-candy)
if showScrollMouse = 0
textWidth = text width("File")
if mouseWithin(_menuX+6,_menuY,_menuX+6+textWidth,_menuY+_menuHeight)
drawFileMenu(_menuX+6,_menuY,_menuX+6+textWidth,_menuY+_menuHeight,Theme_menuBackgroundColor,Theme_menuForegroundColor)
endif
textWidth = text width("Edit")
offset = text width("File ")+6
if mouseWithin(_menuX+offset,_menuY,_menuX+offset+textWidth,_menuY+_menuHeight)
drawEditMenu(_menuX+offset,_menuY,_menuX+offset+textWidth,_menuY+_menuHeight,Theme_menuBackgroundColor,Theme_menuForegroundColor)
endif
endif
rem draw vertical scrollbar track
ink Theme_scrollBarTrackColor,0
box _vTrackX, _vTrackY, _vTrackX+_vTrackWidth, _vTrackY+_vTrackHeight
rem draw vertical scrollbar thumb
ink Theme_scrollBarThumbColor,0
if (mouseWithin(_vThumbX, _vThumbY, _vThumbX+_vThumbWidth, _vThumbY+_vThumbHeight) and showScrollMouse = 0) or Window_verticalScrollIsDragging = 1 then ink Theme_scrollBarThumbHoverColor, 0
box _vThumbX, _vThumbY, _vThumbX+_vThumbWidth, _vThumbY+_vThumbHeight
rem draw border around scrollbar track
drawOutline(_vTrackX, _vTrackY, _vTrackX+_vTrackWidth, _vTrackY+_vTrackHeight,_componentBorderSize,Theme_borderColor)
rem draw horizontal scrollbar track
ink Theme_scrollBarTrackColor,0
box _hTrackX, _hTrackY, _hTrackX+_hTrackWidth, _hTrackY+_hTrackHeight
rem draw horizontal scrollbar thumb
ink Theme_scrollBarThumbColor,0
if (mouseWithin(_hThumbX, _hThumbY, _hThumbX+_hThumbWidth, _hThumbY+_hThumbHeight) and showScrollMouse = 0) or Window_horizontalScrollIsDragging = 1 then ink Theme_scrollBarThumbHoverColor, 0
box _hThumbX, _hThumbY, _hThumbX+_hThumbWidth, _hThumbY+_hThumbHeight
rem draw border around scrollbar track
drawOutline(_hTrackX, _hTrackY, _hTrackX+_hTrackWidth, _hTrackY+_hTrackHeight,_componentBorderSize,Theme_borderColor)
_M_C = mouseclick()
rem mouse events
if _M_C = 1
rem turn off mouse scrolling if mouse button was clicked
if Window_mFlag = 0 then showScrollMouse = 0
rem if clicked on title bar
if mouseWithin(_titleX, _titleY, _titleX+_titleWidth, _titleY+_titleHeight)=1 and mouseWithin(_maximizeX,_maximizeY,_maximizeX+_maximizeSize,_maximizeY+_maximizeSize)=0 and Window_mFlag = 0 and isMaximized = 0
Window_mFlag = 1
Window_titleIsDragging = 1
Window_tx = Window_x - mousex()
Window_ty = Window_y - mousey()
endif
rem if clicked on vertical scrollbar thumb
if mouseWithin(_vThumbX, _vThumbY, _vThumbX+_vThumbWidth, _vThumbY+_vThumbHeight) and Window_mFlag = 0
Window_mFlag = 1
Window_ty = _vThumbY - mousey()
Window_verticalScrollIsDragging = 1
endif
rem if clicked on horizontal scrollbar thumb
if mouseWithin(_hThumbX, _hThumbY, _hThumbX+_hThumbWidth, _hThumbY+_hThumbHeight) and Window_mFlag = 0
Window_mFlag = 1
Window_tx = _hThumbX - mousex()
Window_horizontalScrollIsDragging = 1
endif
rem if clicked on corner to resize window
if mouseWithin(_resizeX, _resizeY, _resizeX2, _resizeY2) and Window_mFlag = 0 and isMaximized = 0
Window_mFlag = 1
Window_tx = (Window_x + Window_width) - mousex()
Window_ty = (Window_y + Window_height) - mousey()
Window_isResizing = 1
endif
rem if mouse clicked on maximize icon
if mouseWithin(_maximizeX,_maximizeY,_maximizeX+_maximizeSize,_maximizeY+_maximizeSize) and Window_mFlag = 0
Window_mFlag = 1
Window_maxClick = 1
endif
rem if dragging vertical scrollbar thumb
if Window_verticalScrollIsDragging = 1
_vThumbY = (mousey() + Window_ty) - _viewportY
Window_vThumb# = ((mousey() + Window_ty) - _viewportY) / (_viewportHeight-_vThumbHeight+0.0)
if Window_vThumb# < 0.0 then Window_vThumb# = 0.0
if Window_vThumb# > 1.0 then Window_vThumb# = 1.0
endif
rem if dragging horizontal scrollbar thumb
if Window_horizontalScrollIsDragging = 1
_hThumbX = (mousex() + Window_tx) - _viewportX
Window_hThumb# = ((mousex() + Window_tx) - _viewportX) / (_viewportWidth-_hThumbWidth+0.0)
if Window_hThumb# < 0.0 then Window_hThumb# = 0.0
if Window_hThumb# > 1.0 then Window_hThumb# = 1.0
endif
rem if resizing the window
if Window_isResizing = 1
Window_width = (mousex() - Window_X) + Window_tx
Window_height = (mousey() - Window_Y) + Window_ty
if Window_width < 284 then Window_width = 284
if Window_height < 100 then Window_height = 100
endif
rem if dragging title bar
if Window_titleIsDragging = 1
Window_x = mousex() + Window_tx
Window_y = mousey() + Window_ty
endif
endif
if _M_C = 0
rem reset flag states
Window_mFlag = 0
Window_isResizing = 0
Window_titleIsDragging = 0
Window_verticalScrollIsDragging = 0
Window_horizontalScrollIsDragging = 0
if Window_maxClick = 1
Window_maxClick = 0
rem if mouseclick was pressed AND released over maximize icon
if mouseWithin(_maximizeX,_maximizeY,_maximizeX+_maximizeSize,_maximizeY+_maximizeSize)
isMaximized = abs(isMaximized-1)
changeWindow = 1
endif
endif
endif
rem only allow wheel scrolling if mouse scrolling is not currently in progress
if showScrollMouse = 0
rem detect if mouse wheel was used and determine which direction it was scrolled
scrollWheel = mousemovez()
if scrollWheel <> 0
if scrollWheel > 0
if Window_vThumb# = 0.0 : Window_wheelFlag = 0 : else : Window_wheelFlag = -1 : endif
else
if Window_vThumb# = 1.0 : Window_wheelFlag = 0 : else : Window_wheelFlag = 1 : endif
endif
Window_wheelStep = _wheelStep
endif
rem if mouse wheel was triggered, adjust smooth scroll
if Window_wheelFlag <> 0
if Window_wheelTimer + _wheelDelay <= timer()
Window_wheelTimer = timer()
_viewportPixelOffsetY = _viewportPixelOffsetY + Window_wheelStep*Window_wheelFlag
Window_vThumb# = _viewportPixelOffsetY / (_offscreenContentHeight+0.0)
if Window_vThumb# < 0.0 then Window_vThumb# = 0.0 : Window_wheelFlag = 0
if Window_vThumb# > 1.0 then Window_vThumb# = 1.0 : Window_wheelFlag = 0
Window_wheelStep = Window_wheelStep - 1
if Window_wheelStep = 0 then Window_wheelFlag = 0
endif
endif
endif
rem if middle mouse button (scroll button) is clicked
if _M_C = 4 and Window_mFlag = 0
Window_mFlag = 1
showScrollMouse = abs(showScrollMouse-1)
_mScrollX = mousex()
_mScrollY = mousey()
endif
if showScrollMouse = 1
drawScrollIcon(_mScrollX,_mScrollY)
_viewportPixelOffsetX = _viewportPixelOffsetX + (mousex()-_mScrollX)/_scrollSensitivity
if _offscreenContentWidth = 0
Window_hThumb# = 0
else
Window_hThumb# = _viewportPixelOffsetX / (_offscreenContentWidth+0.0)
endif
if Window_hThumb# < 0.0 then Window_hThumb# = 0.0
if Window_hThumb# > 1.0 then Window_hThumb# = 1.0
_viewportPixelOffsetY = _viewportPixelOffsetY + (mousey()-_mScrollY)/_scrollSensitivity
if _offscreenContentHeight = 0
Window_vThumb# = 0
else
Window_vThumb# = _viewportPixelOffsetY / (_offscreenContentHeight+0.0)
endif
if Window_vThumb# < 0.0 then Window_vThumb# = 0.0
if Window_vThumb# > 1.0 then Window_vThumb# = 1.0
endif
if _M_C = 1 and Window_mFlag = 0
for lineNumber = _startingIndex to _endingIndex
hidden = _viewportPixelOffsetX / _charWidth
extra = _viewportPixelOffsetX - hidden*_charWidth
x = (_viewportX + _numberedLineWidth + _componentPadding) - extra
y = _viewportY+_lineHeight*(lineNumber-1) - _viewportPixelOffsetY
capLimit = (_viewportWidth - _numberedLineWidth) + _charWidth
if y < _viewportY+_viewportHeight
if mouseWithin(x, y, x+capLimit, y+_charHeight)
_caretX = ((mousex() - (_viewportX + _numberedLineWidth + _componentPadding)) + _viewportPixelOffsetX) / _charWidth
_caretY = lineNumber
if _caretX > len(viewport$(lineNumber)) then _caretX = len(viewport$(lineNumber))
if shiftFlag = 0
_oldCaretX = _caretX
_oldCaretY = _caretY
endif
endif
endif
next lineNumber
endif
rem if nothing triggered mouse flag, throw it anyway to avoid "click wander"
if _M_C > 0 : Window_mFlag = 1 : else : Window_mFlag = 0 : endif
RETURN
REM ///////////////////////////////////////////////////
REM Handles the keyboard input
REM \\\\\\\\\\\\\\\\\\\\\\\\\
_handleInput:
if shiftkey() = 1 and shiftFlag = 0
`_oldCaretX = _caretX
`_oldCaretY = _caretY
shiftFlag = 1
endif
if shiftkey() = 0 then shiftFlag = 0
key$ = entry$()
if key$ <> ""
clear entry buffer
if controlkey() = 0
if asc(key$) = VK_BACK
if _caretX = 0 and _caretY > 1
_caretX = len(viewport$(_caretY-1))
viewport$(_caretY-1) = viewport$(_caretY-1) + viewport$(_caretY)
array delete element viewport$(), _caretY
dec _caretY, 1
dec Window_lineCount, 1
gosub _revalidateMaxTextWidth
for i = 1 to array count(segments())
if segments(i).lineNumber > _caretY
segments(i).lineNumber = segments(i).lineNumber - 1
endif
next i
checkLineSyntax(_caretY,_caretY)
else
if _caretX > 0
edit$ = viewport$(_caretY)
if text width(edit$) = Window_maxTextWidth then revalidate = 1
leftChunk$ = left$(edit$,_caretX-1)
L = len(viewport$(_caretY))-len(leftChunk$)-1
edit$ = leftChunk$ + right$(edit$,L)
viewport$(_caretY) = edit$
dec _caretX, 1
if revalidate = 1 then gosub _revalidateMaxTextWidth
checkLineSyntax(_caretY,_caretY)
endif
endif
goto skipAdd
endif
if asc(key$) = VK_ENTER
edit$ = viewport$(_caretY)
leftChunk$ = left$(edit$,_caretX)
L = len(viewport$(_caretY))-len(leftChunk$)
viewport$(_caretY) = leftChunk$
array insert at element viewport$(),_caretY+1
viewport$(_caretY+1) = right$(edit$,L)
_caretX = 0
inc _caretY, 1
Window_hThumb# = 0
inc Window_lineCount, 1
if Window_maxTextWidth = text width(edit$) then gosub _revalidateMaxTextWidth
for i = 1 to array count(segments())
if segments(i).lineNumber > _caretY-1
segments(i).lineNumber = segments(i).lineNumber + 1
endif
next i
checkLineSyntax(_caretY-1,_caretY)
goto skipAdd
endif
if asc(key$) = VK_TAB
edit$ = viewport$(_caretY)
leftChunk$ = left$(edit$,_caretX)
L = len(viewport$(_caretY))-len(leftChunk$)
edit$ = leftChunk$ + space$(TABSPACE) + right$(edit$,L)
viewport$(_caretY) = edit$
inc _caretX, TABSPACE
Window_maxTextWidth = getMax(Window_maxTextWidth,text width(edit$))
checkLineSyntax(_caretY,_caretY)
goto skipAdd
endif
`edit$ = viewport$(_caretY)
`leftChunk$ = left$(edit$,_caretX)
`L = len(viewport$(_caretY))-len(leftChunk$)
`edit$ = leftChunk$ + key$ + right$(edit$,L)
`viewport$(_caretY) = edit$
`inc _caretX, len(key$)
`Window_maxTextWidth = getMax(Window_maxTextWidth,text width(edit$))
_caretX = insertText(key$, _caretY, _caretX)
Window_maxTextWidth = getMax(Window_maxTextWidth,text width(viewport$(_caretY)))
checkLineSyntax(_caretY,_caretY)
skipAdd:
_oldCaretX = _caretX
_oldCaretY = _caretY
else : `if control key is being pressed+
rem DBP doesn't register other keys while control is pressed
`if lower$(key$) = "c"
thingy$ = "<CONTROL> + "+ key$
if asc(key$) = asc("c") OR asc(key$) = asc("C")
_caretX = insertText(get clipboard$(), _caretY, _caretX)
Window_maxTextWidth = getMax(Window_maxTextWidth,text width(viewport$(_caretY)))
checkLineSyntax(_caretY,_caretY)
endif
endif
endif
if upkey() and kFlag = 0 then dec _caretY, 1 : kFlag = 1 :_oldCaretX = _caretX : _oldCaretY = _caretY
if downkey() and kFlag = 0 then inc _caretY, 1 : kFlag = 1 :_oldCaretX = _caretX : _oldCaretY = _caretY
if rightkey() and kFlag = 0 then inc _caretX, 1 : kFlag = 1 :_oldCaretX = _caretX : _oldCaretY = _caretY
if leftkey() and kFlag = 0 then dec _caretX, 1 : kFlag = 1 :_oldCaretX = _caretX : _oldCaretY = _caretY
if _caretY < 0 then _caretY = 0
if _caretY > Window_lineCount then _caretY = Window_lineCount
if _caretX < 0 then _caretX = 0
if _caretX > len(viewport$(_caretY)) then _caretX = len(viewport$(_caretY))
if upkey()=0 and downkey()=0 and rightkey()=0 and leftkey()=0 then kFlag = 0
RETURN
function insertText(txt$, lineNumber, pos)
edit$ = viewport$(lineNumber)
leftChunk$ = left$(edit$, pos)
L = len(edit$) - len(leftChunk$)
edit$ = leftChunk$ + txt$ + right$(edit$,L)
viewport$(lineNumber) = edit$
x = pos+len(txt$)
endfunction x
REM ///////////////////////////////////////////////////
REM The width of the longest line of text is needed
REM for proper scrolling. Call this anytime a line's
REM width becomes greater than "Window_maxTextWidth"
REM or if the current line represents the longest
REM width prior to the edit.
REM \\\\\\\\\\\\\\\\\\\\\\\\\
_revalidateMaxTextWidth:
Window_maxTextWidth = 0
TW = 0
for i = 1 to Window_lineCount
Window_maxTextWidth = getMax(Window_maxTextWidth,text width(viewport$(i)))
TW = getMax(TW, len(z$))
next i
RETURN
REM _______________________________________________________________________________________
REM | |
REM | ******** FUNCTIONS ******** |
REM |_______________________________________________________________________________________|
REM **************************************************
REM Draws the 'File' dropdown menu
REM **************************************************
function checkLineSyntax(l1, l2)
for i = 1 to array count(segments())
if segments(i).lineNumber >= l1 and segments(i).lineNumber <= l2
array delete element segments(),i
endif
next i
parseDocument(l1,l2)
endfunction
REM **************************************************
REM Draws the 'File' dropdown menu
REM **************************************************
function drawFileMenu(x1,y1,x2,y2,foreground,background)
thickness = 1
expand = 3
height = 100
width = 64
ext = width - ((x2+expand) - (x1-expand))
rem shadow
ink rgb(48,48,48), 0
box (x1-expand)+2,(y1-expand)+2,(x2+expand)+2,(y2+expand)+2
box (x1-expand)+2,(y2+expand)+2,(x2+expand+ext)+2,(y2+expand+height)+2
rem background
ink background, 0
box x1-expand,y1-expand,x2+expand,y2+expand
box x1-expand,y2+expand,x2+expand+ext,y2+expand+height
rem menu items
y3 = y2+expand+4
ink foreground, 0
text x1,y1,"File"
text x1,y3,"New"
text x1,y3+16,"Open"
text x1,y3+32,"Save"
text x1,y3+48,"Save As"
text x1,y3+64,"Print"
text x1,y3+80,"Exit"
rem outline
box x1-expand,y1-expand,x2+expand,y1-expand
box x1-expand,y1-expand,x1-expand,y2+expand+height
box x2+expand,y1-expand,x2+expand,y2+expand
box x2+expand,y2+expand,x2+expand+ext,y2+expand
box x2+expand+ext,y2+expand,x2+expand+ext,y2+expand+height
box x1-expand,y2+expand+height,x2+expand+ext,y2+expand+height
endfunction
REM **************************************************
REM Draws the 'Edit' dropdown menu
REM **************************************************
function drawEditMenu(x1,y1,x2,y2,foreground,background)
thickness = 1
expand = 3
height = 132
width = 112
ext = width - ((x2+expand) - (x1-expand))
rem shadow
ink rgb(48,48,48), 0
box (x1-expand)+2,(y1-expand)+2,(x2+expand)+2,(y2+expand)+2
box (x1-expand)+2,(y2+expand)+2,(x2+expand+ext)+2,(y2+expand+height)+2
rem background
ink background, 0
box x1-expand,y1-expand,x2+expand,y2+expand
box x1-expand,y2+expand,x2+expand+ext,y2+expand+height
rem menu items
y3 = y2+expand+4
ink foreground, 0
text x1,y1,"Edit"
text x1,y3,"Undo"
text x1,y3+16,"Redo"
text x1,y3+32,"Cut"
text x1,y3+48,"Copy"
text x1,y3+64,"Paste"
text x1,y3+80,"Delete"
text x1,y3+96,"Select All"
text x1,y3+112,"Edit Options"
rem outline
box x1-expand,y1-expand,x2+expand,y1-expand
box x1-expand,y1-expand,x1-expand,y2+expand+height
box x2+expand,y1-expand,x2+expand,y2+expand
box x2+expand,y2+expand,x2+expand+ext,y2+expand
box x2+expand+ext,y2+expand,x2+expand+ext,y2+expand+height
box x1-expand,y2+expand+height,x2+expand+ext,y2+expand+height
endfunction
REM **************************************************
REM Draws the mouse scroll icon
REM **************************************************
function drawScrollIcon(x,y)
rem shadow
ink rgb(48,48,48),0
fillCircle(x+2,y+2,10)
rem center
ink rgb(114,122,128),0
fillCircle(x,y,10)
ink 0,0
rem arrows
line x,y-8,x,y+8
line x-8,y,x+8,y
line x,y-8,x-3,y-5
line x,y-8,x+3,y-5
line x,y+8,x-3,y+5
line x,y+8,x+3,y+5
line x-8,y,x-5,y-3
line x-8,y,x-5,y+3
line x+8,y,x+5,y-3
line x+8,y,x+5,y+3
rem outline
ink rgb(66,75,82), 0
circle x,y,10
endfunction
REM **************************************************
REM Draws a filled in circle
REM **************************************************
function fillCircle(x,y,r)
for yy = y-r to y
for xx = x-r to x
d# = (xx-x)*(xx-x) + (yy-y)*(yy-y)
if d# <= r*r
box xx,yy,x+(x-xx)+1,yy+1
if yy <> y then box xx,y+(y-yy),x+(x-xx)+1,y+(y-yy)+1
exit
endif
next xx
next yy
endfunction
REM **************************************************
REM Draws the window maximize icon at [X,Y] with the
REM given 'size'.
REM **************************************************
function drawMaximize(x, y, size)
box x, y, x+size, y+3
box x,y,x+1,y+size
box x+size-1,y,x+size,y+size
box x, y+size-1, x+size, y+size
`pBox(x, y, x+size, y+3,0)
`pBox(x,y,x+1,y+size,0)
`pBox(x+size-1,y,x+size,y+size,0)
`pBox(x, y+size-1, x+size, y+size,0)
endfunction
REM **************************************************
REM Returns the string truncated to a specified width
REM in pixels.
REM **************************************************
function capLength$(string$, width)
if text width(string$) < width then exitfunction string$
L = len(string$)
min = width / text width("A")
for j = min to L
if text width(left$(string$,j)) > width then exitfunction left$(string$,j-1)
next j
endfunction string$
REM **************************************************
REM Returns a string with left padding so the end of
REM the text aligns to the right. If the text is 7
REM characters long, and 'amount' is set to 10, the
REM function will return the text with 3 spaces (10-7)
REM padding at the beginning of the string.
REM **************************************************
function rightAlignText$(txt$, amount)
x = amount - len(txt$)
if x < 1 then exitfunction txt$
txt$ = space$(x)+txt$
endfunction txt$
REM **************************************************
REM Checks to see if mouse is within the specified
REM coordinates
REM **************************************************
function mouseWithin(x1,y1,x2,y2)
if mousex() > x1 and mousex() < x2 and mousey() > y1 and mousey() < y2 then exitfunction 1
endfunction 0
REM **************************************************
REM Returns a linear interpolated color between base
REM color and target color. Percent ranges from 0 to 1
REM **************************************************
function getTransitionalColor(base, target, percent#)
br = rgbr(base)
bg = rgbg(base)
bb = rgbb(base)
tr = rgbr(target)
tg = rgbg(target)
tb = rgbb(target)
tr = br + (tr-br)*percent#
tg = bg + (tg-bg)*percent#
tb = bb + (tb-bb)*percent#
color = rgb(tr,tg,tb)
endfunction color
REM **************************************************
REM Get smallest of two values
REM **************************************************
function getMin(x,y)
if x > y then exitfunction y
endfunction x
REM **************************************************
REM Get smallest of two values
REM **************************************************
function getMax(x,y)
if x < y then exitfunction y
endfunction x
REM **************************************************
REM Returns a color with an alpha value
REM **************************************************
function argb(a,r,g,b)
c = (a*16777216)+(r*65536)+(g*256)+b
endfunction c
REM **************************************************
REM Draws a filled box with a color fading from color1
REM to color2 going from top to bottom
REM **************************************************
function drawVerticalGradient(x1,y1,x2,y2, color1, color2)
height# = y2-y1
for y = 1 to height#
p# = y / height#
ink getTransitionalColor(color1, color2, p#), 0
box x1, y1+y-1, x2, y1+y
`pBox(x1, y1+y-1, x2, y1+y,getTransitionalColor(color1, color2, p#))
next y
endfunction
REM **************************************************
REM Draws an outline outside the given box dimensions
REM **************************************************
function drawOutline(x1,y1,x2,y2,thickness,color)
ink color,0
box x1-thickness,y1-thickness,x2+thickness,y1
box x1-thickness,y1,x1,y2
box x2,y1,x2+thickness,y2
box x1-thickness,y2,x2+thickness,y2+thickness
endfunction
remstart
function pOutline2(x1,y1,x2,y2,thickness,color)
pBox(x1-thickness,y1-thickness,x2+thickness,y1,color)
pBox(x1-thickness,y1,x1,y2,color)
pBox(x2,y1,x2+thickness,y2,color)
pBox(x1-thickness,y2,x2+thickness,y2+thickness,color)
endfunction
remend
REM **************************************************
REM Checks if a single char 'c' is a special character
REM **************************************************
function isSpecial(c as string)
if c = ":" or c = "(" or c = ":" or c = ")" or c = "," or c = "." or asc(c) = 13 or asc(c) = 9 or asc(c) = 0 then exitfunction TRUE
endfunction FALSE
REM **************************************************
REM Adds color segment to array
REM **************************************************
function addColorSegment(lineNumber as integer, beginIndex as integer, endIndex as integer, keyType as integer)
array insert at bottom segments()
index = array count(segments())
segments(index).lineNumber = lineNumber
segments(index).beginIndex = beginIndex
segments(index).endIndex = endIndex
segments(index).keyType = keyType
endfunction
REM **************************************************
REM Returns a substring of 's'
REM indices are inclusive
REM **************************************************
function substring$(s as string, beginIndex as integer, endIndex as integer)
r$ = left$(s, endIndex)
r$ = right$(r$, len(r$)-(beginIndex-1))
endfunction r$
REM **************************************************
REM Returns true if 's' starts with the substring 'sub'
REM **************************************************
function startsWith(s as string, sub as string)
if len(sub) > len(s) then exitfunction FALSE
for i = 1 to len(sub)
if mid$(s, i) <> mid$(sub, i) then exitfunction FALSE
next i
endfunction TRUE
REM **************************************************
REM Scans for keywords from 'fromLine' to 'toLine' and
REM adds the appropriate highlighting segments
REM **************************************************
function parseDocument(fromLine as integer, toLine as integer)
quoteFound = 0
remFound = 0
qLine = 0
qStart = 0
for lineNumber = fromLine to toLine
txt$ = viewport$(lineNumber)
possibleMatches = 0
multipleChecks=0
match$ = ""
start = 1
for i = 1 to len(txt$)
if quoteFound = 0 and mid$(txt$,i) = "`"
addColorSegment(lineNumber, i, len(txt$), COMMENT)
exit
endif
if asc(mid$(txt$,i)) = 34
inc quoteFound
if quoteFound = 1
qLine = lineNumber
qStart = i
endif
if quoteFound = 2
quoteFound = 0
addColorSegment(qLine, qStart, i, STRG)
endif
else
if quoteFound = 0
if isSpecial(mid$(txt$,i)) = 1
if possibleMatches = 1 and len(match$) = i-start
if match$ = "remstart"
remFound = 1
addColorSegment(lineNumber, start, len(viewport$(lineNumber)), COMMENT)
else
if remFound = 0
if match$ = "rem"
addColorSegment(lineNumber, start, len(viewport$(lineNumber)), COMMENT)
exit
else
addColorSegment(lineNumber, start, i-1, KEYWORD)
endif
multipleChecks=0
endif
endif
endif
start = i+1
endif
if mid$(txt$,i) = " "
if possibleMatches = 0 then start = i+1 : goto nextIt
if possibleMatches = 1 and len(match$) = i-start
if match$ = "remstart"
remFound = 1
addColorSegment(lineNumber, start, len(viewport$(lineNumber)), COMMENT)
else
if remFound = 0
if match$ = "rem"
addColorSegment(lineNumber, start, len(viewport$(lineNumber)), COMMENT)
exit
else
addColorSegment(lineNumber, start, i-1, KEYWORD)
start = i+1
goto nextIt
endif
multipleChecks = 0
endif
endif
endif
if possibleMatches > 1 then multipleChecks = 1
endif
possibleMatches = 0
chunk$ = lower$(substring$(txt$,start,i))
if len(chunk$) > 1
for k = 0 to array count(keywords())
if startsWith(keywords(k), chunk$)
inc possibleMatches
match$ = keywords(k)
endif
next k
endif
if possibleMatches = 0 and multipleChecks = 1
chunk$ = chomp$(left$(chunk$,len(chunk$)-1))
if isKeyword(chunk$) = 1
if chunk$ = "rem"
addColorSegment(lineNumber, start, len(txt$), COMMENT)
exit
else
addColorSegment(lineNumber, start, start+len(chunk$)-1, KEYWORD)
endif
endif
multipleChecks = 0
endif
rem end of line
if i = len(txt$)
if remFound = 0
if possibleMatches = 1 and len(match$) = i-start+1
if match$ = "remstart"
addColorSegment(lineNumber, start, len(txt$), COMMENT)
remFound = 1
else
addColorSegment(lineNumber, start, i, KEYWORD)
endif
multipleChecks=0
endif
if possibleMatches > 1
if isKeyword(chunk$) = 1
if chunk$ = "rem"
addColorSegment(lineNumber, start, len(txt$), COMMENT)
exit
else
if chunk$ = "remstart"
addColorSegment(lineNumber, start, len(txt$), COMMENT) : remFound = 1
else
addColorSegment(lineNumber, start, i, KEYWORD)
endif
endif
endif
multipleChecks=0
endif
else
if match$ = "remend"
addColorSegment(lineNumber, start, i, COMMENT)
remFound = 0
else
if i = len(txt$)
addColorSegment(lineNumber, 1, i, COMMENT)
endif
endif
endif
endif
endif
endif
nextIt:
next i
if lineNumber = toLine and remFound = 1
if toLine+1 <= array count(viewport$()) then inc toLine
endif
next lineNumber
endfunction
REM **************************************************
REM Returns true if 'key$' is contained in the
REM keywords() array by using a linear search
REM **************************************************
function isKeyword2(key$)
for k = 0 to array count(keywords())
if keywords(k) = key$ then exitfunction 1
next k
endfunction 0
REM **************************************************
REM Returns true if 'key$' is contained in the
REM keywords() array by using a binary search
REM **************************************************
function isKeyword(key$)
low = 1
high = array count(keywords())
while low <= high
mid = (low+high)/2
midVal$ = keywords(mid)
if midVal$ < key$
low = mid + 1
else
if midVal$ > key$
high = mid - 1
else
exitfunction 1
endif
endif
endwhile
endfunction 0
REM **************************************************
REM Removes trailing white space from string 's$'
REM **************************************************
function chomp$(s$)
for i = len(s$) to 1 step -1
if mid$(s$,i) <> " " then exitfunction left$(s$,i)
next i
endfunction ""
REM **************************************************
REM Reads a file into the 'viewport$' array
REM **************************************************
function loadFile(file as string)
open to read 1, file
undim viewport$()
dim viewport$(0)
width = 0
while file end(1) = FALSE
read string 1, r$
array insert at bottom viewport$()
viewport$(array count(viewport$())) = r$
width = getMax(width, text width(r$))
endwhile
close file 1
endfunction width
REM **************************************************
REM Returns index of character 'c' if found in string 's'
REM **************************************************
function findChar(s as string, c as string)
for i = 1 to len(s)
if mid$(s,i) = c then exitfunction i
next i
endfunction 0
REM **************************************************
REM Loads keywords from keyword.ini file
REM **************************************************
function loadKeywords(path as string)
`dim keywords() as string
open to read 1, path
while file end(1) = FALSE
read string 1, z$
i = findChar(z$, "=")
if i > 0
array insert at bottom keywords()
keywords(array count(keywords())) = lower$(substring$(z$,1,i-1))
endif
endwhile
close file 1
endfunction
REM **************************************************
REM Sorts the keywords array in ascending order using
REM bubble sort
REM **************************************************
function sortKeywordsArray()
flag = 1
while flag = 1
flag = 0
for i = 2 to array count(keywords())
if keywords(i) < keywords(i-1)
flag = 1
temp$ = keywords(i)
keywords(i) = keywords(i-1)
keywords(i-1) = temp$
endif
next i
endwhile
endfunction
KeywordsFile:
data 62
data "#constant", "function","endfunction", "string", "if", "then", "else", "for", "to", "next","endif"
data "dim","integer","byte","dword","print","wait","wait key","end", "and","line","upkey"
data "type", "endtype", "ink", "rgb", "read string", "array insert at bottom", "array count", "open to read", "close file"
data "while", "endwhile", "exitfunction", "file end", "as", "upper$", "inc", "len", "data", "sync", "dec"
data "sync on", "sync rate", "repeat", "until", "spacekey","read","restore","gosub", "remstart","remend"
data "rem", "set display mode", "set text font", "set text size","do","loop","downkey","cls","set cursor"
[url="http://dbcc.zimnox.com"]
[/url]