Here's my updated code and probably final revision. Finished adapting the mouse wheel scrolling and added a new scrolling method to mimic the 4-way scrolling seen in web browsers when you click the mouse wheel button (or whatever your 3rd button happens to be). Give it a try, it's neat! Fixed a minor display issue. Added a maximize button. Also added some menus, non-functional but shown just as demonstration for future possibilities.
Edit: Jan 22
- Scrollbars are now sized depending on amount of scrollable content.
REM **********************************
REM Title: Text Viewer
REM Author: Phaelax
REM Last Updated: Jan. 19, 2009 9:43am
REM **********************************
set display mode 800,600,32
set text font "Courier", 1
set text size 10
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 = 0 : `foreground color for text in viewport
Theme_listBackgroundColor = rgb(195,202,208) : `background color of the viewport component
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_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(0,0,0) : `color used for window icons
Theme_windowBorderSize = 2 : `size of border around the window
Theme_componentMargins = 2 : `spacing between window components
Theme_componentBorderSize = 1 : `size of border around each component
Window_x = 200
Window_y = 100
Window_width = 398
Window_height = 298
Window_vThumb# = 0.0
Window_hThumb# = 0.0
sync on
DO
cls
gosub _drawTextViewer
sync
LOOP
_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))
_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
_titleX = Window_x + _windowBorderSize : `x-position of title bar
_titleY = Window_y + _windowBorderSize : `y-position of title bar
_titleTextX = _titleX + _componentMargins : `x-position of title text
_titleTextY = _titleY + _componentMargins : `y-position of title text
_titleWidth = Window_width - _windowBorderSize*2 : `width of title bar
_titleHeight = 16 : `height of title bar
_menuX = Window_x + _windowBorderSize + _componentMargins + _componentBorderSize : `x-position of menu bar
_menuY = _titleY + _titleHeight + _componentMargins + _componentBorderSize : `y-position of menu bar
_menuWidth = Window_width - (_windowBorderSize+_componentBorderSize+_componentMargins)*2 : `width of menu bar (excludes the component's border size)
_menuHeight = text height("A") : `height of menu bar (excludes the component's border size)
_charWidth = text width("A")
_vTrackWidth = 12 : `width of vertical scrollbar track
_hTrackHeight = 12 : `height of horizontal scrollbar track
_hTrackX = Window_x + _windowBorderSize + _componentMargins + _componentBorderSize : `x-position of horizontal scrollbar
_hTrackWidth = Window_width - _windowBorderSize*2 - _componentBorderSize*2 - _componentMargins*4 - _vTrackWidth : `width of horizontal scrollbar
_hTrackY = Window_y + Window_height - (_hTrackHeight+_windowBorderSize+_componentMargins+_componentBorderSize) : `y-position horizontal scrollbar
_vTrackX = (Window_x + Window_width) - (_windowBorderSize+_componentMargins+_vTrackWidth) : `x-position of scroll bar track
_vTrackY = _menuY + _menuHeight + _componentBorderSize*2 + _componentMargins : `y-position of scroll bar track
_vTrackHeight = (_hTrackY - _vTrackY) - _componentMargins - _componentBorderSize*2 : `height of scroll bar track
_viewportX = Window_x + _windowBorderSize + _componentMargins + _componentBorderSize : `x-position of file view list
_viewportY = _menuY + _menuHeight + _componentBorderSize*2 + _componentMargins : `y-position of file view list
_viewportWidth = Window_width - (_windowBorderSize*2 + _componentBorderSize*4+_componentMargins*3) - _vTrackWidth : `width of the viewport (visible width)
_viewportHeight = _hTrackY - _viewportY - _componentMargins - _componentBorderSize*2 : `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, int(_vTrackHeight*f#)),_vTrackHeight) : `height of scrollbar thumb
_vThumbX = _vTrackX : `x-position of scrollbar thumb
_vThumbY = _vTrackY + (_viewportHeight-_vThumbHeight)*Window_vThumb# : `y-position of scrollbar thumb
f# = (_viewportWidth+0.0)/_contentPaneWidth
_hThumbWidth = getMin(getMax(12, int(_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 + (_viewportWidth-_hThumbWidth)*Window_hThumb# : `y-position of scrollbar thumb
_resizeX = _hTrackX+_hTrackWidth+_componentBorderSize
_resizeY = _vTrackY+_vTrackHeight+_componentBorderSize
_resizeX2 = Window_x+Window_width-_windowBorderSize
_resizeY2 = Window_y+Window_height-_windowBorderSize
_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_listBackgroundColor,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+_componentPadding)-extra
y = _viewportY+_lineHeight*(lineNumber-1) - _viewportPixelOffsetY
t$ = right$(viewport$(lineNumber),len(viewport$(lineNumber))-hidden)
if y < _viewportY+_viewportHeight then text x+_numberedLineWidth+_componentPadding*2, y, capLength$(t$, _viewportWidth-_componentPadding*2)
next lineNumber
rem display line number border
ink Theme_backgroundColor,0
box _viewportX, _viewportY, _viewportX+_numberedLineWidth+_componentPadding*2, _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, str$(lineNumber)
next lineNumber
ink Theme_borderColor, 0
line _viewportX+_numberedLineWidth+_componentPadding*2, _viewportY, _viewportX+_numberedLineWidth+_componentPadding*2, _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+_windowBorderSize, fillY, Window_x+Window_width-_windowBorderSize*2, fillY+_componentMargins
fillY = _viewportY+_viewportHeight+_componentBorderSize
box _viewportX, fillY, _viewportX+_viewportWidth, fillY+_componentMargins
fillX = _vTrackX - _componentBorderSize - _componentMargins
box fillX, _vTrackY-_componentBorderSize, fillX+_componentMargins-1, _vTrackY+_vTrackHeight+_componentBorderSize
fillY = _viewportY+_viewportHeight+_componentBorderSize + 1
box _viewportX-_componentBorderSize, fillY, _viewportX+_viewportWidth+_componentMargins+_componentBorderSize, fillY + _componentMargins - 2
box _resizeX, _resizeY, _resizeX2, _resizeY2
rem draw border around viewport
drawOutline(_viewportX-_componentBorderSize, _viewportY-_componentBorderSize, _viewportX+_viewportWidth+_componentBorderSize, _viewportY+_viewportHeight+_componentBorderSize,_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-_componentBorderSize, _menuY-_componentBorderSize, _menuX+_menuWidth+_componentBorderSize, _menuY+_menuHeight+_componentBorderSize,_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
box _vThumbX, _vThumbY, _vThumbX+_vThumbWidth, _vThumbY+_vThumbHeight
rem draw border around scrollbar track
drawOutline(_vTrackX-_componentBorderSize, _vTrackY-_componentBorderSize, _vTrackX+_vTrackWidth, _vTrackY+_vTrackHeight+_componentBorderSize,_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
box _hThumbX, _hThumbY, _hThumbX+_hThumbWidth, _hThumbY+_hThumbHeight
rem draw border around scrollbar track
drawOutline(_hTrackX-_componentBorderSize, _hTrackY-_componentBorderSize, _hTrackX+_hTrackWidth+_componentBorderSize, _hTrackY+_hTrackHeight+_componentBorderSize,_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 vertical 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 <> thingy
direction = scrollWheel - thingy
thingy = scrollWheel
if direction > 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
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 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# = sqrt((xx-x)^2 + (yy-y)^2)
if d# <= r
box xx,yy,x+(x-xx),yy+1
if yy <> y then box xx,y+(y-yy),x+(x-xx),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
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 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
next y
endfunction
REM **************************************************
REM Draws an outline inside the given box dimensions
REM **************************************************
function drawOutline(x1,y1,x2,y2,thickness,color)
ink color,0
box x1,y1,x2-1,y1+thickness-1
box x1,y1,x1+thickness-1,y2-1
box x2-(thickness-1),y1,x2,y2
box x1,y2-(thickness-1),x2,y2
endfunction
REM **************************************************
REM Rounds a decimal up to the nearest whole number
REM **************************************************
function ceil(x#)
a = int(x#)
if (x# - a) > 0 then a = a+1
endfunction a
rem 40-book, 62-tab
book:
DATA 40
DATA "Welcome to the world of IDG Books Worldwide."
DATA ""
DATA "IDG Books Worldwide, Inc., is a subsidiary of International Data Group,"
DATA "the worlds largest publisher of business and computer-related information"
DATA "and the leading global provider of information services on information"
DATA "technology. IDG was founded over 25 years ago and now employs more"
DATA "than 5,700 people worldwide. IDG publishes over 195 publications in 62"
DATA "countries. Forty million people read one or more IDG publications each"
DATA "month."
DATA ""
DATA "Launched in 1990, IDG Books is today the fastest growing publisher of"
DATA "computer and business books in the United States. We are proud to have"
DATA "received 3 awards from the Computer Press Association in recognition of"
DATA "editorial excellence, and our best-selling 'For Dummies' series has over"
DATA "7 million copies in print with translations in more than 20 languages. IDG"
DATA "Books, through a recent joint venture with IDGís Hi-Tech Beijing, became"
DATA "the first U.S. publisher to publish a computer book in The Peopleís Repub-"
DATA "lic of China. In record time, IDG Books has become the first choice for"
DATA "millions of readers around the world who want to learn how to better man-"
DATA "age their businesses."
DATA ""
DATA "Our mission is simple: Every IDG book is designed to bring extra value"
DATA "and skill-building instruction to the reader. Our books are written by"
DATA "experts who understand and care about our readers. The knowledge base of"
DATA "our editorial staff comes from years of experience in publishing, education,"
DATA "and journalismóexperience which we use to produce books for the 90s. In"
DATA "short, we care about books, so we attract the best people. We devote special"
DATA "attention to details such as audience, interior design, use of icons, and illus-"
DATA "trations. And because we write, edit, and produce our books electronically,"
DATA "we can spend more time ensuring superior content and spend less time on"
DATA "the technicalities of making books."
DATA ""
DATA "You can count on our commitment to deliver high quality books at compet-"
DATA "itive prices on topics you want to read about. At IDG, we value quality, and"
DATA "we have been delivering quality for over 25 years. Youíll find no better"
DATA "book on a subject than an IDG book."
DATA ""
DATA "John Kilcullen"
DATA "President and CEO"
DATA "IDG Books Worldwide, Inc."
Come on guys enter the challenge, it's not that difficult. I don't want to win by default like Nano! (just kidding)
I wanted to share a challenge idea before I forget. Create a version of hangman. Graphics would be secondary, code structure and optimization would be key objective. It's a simple concept that could lure a few more beginners into joining while being quite educational by learning from others' code techniques and trickery.
Your signature has been erased by a mod because it's larger than 600x120