home *** CD-ROM | disk | FTP | other *** search
- ********************
- ********************
- **
- ** Source File ... U_MouseP.PRG
- **
- ** Application ...
- ** Copyright (c) 1989 Philip de Lisle Associates
- ** All Rights Reserved
- **
- ** Author ........ Philip de Lisle
- ** Last Update ... 15 September 1990 at 12:16 AM
- ** Purpose ....... High level Mouse UDFs
- **
- ********************
- ********************
-
- *|
- *| MUST BE COMPILED WITH /N SWITCH
- *|
-
-
- #include 'inkey.ch'
- #include 'object.ch'
- #include 'mouse.ch'
-
- #define Keypressed() (nextkey() # 0)
-
- static _Is_Mouse := .f.
-
-
- function MouseNew
- **
- ** Syntax ..... MOUSENEW()
- **
- ** Purpose .... Create a new Instance of a Mouse Object
- **
- ** Argument ... None
- **
- ** Returns .... Object/Array
- **
-
- ////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
- ////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
- // \\
- // Mouse Object Structure \\
- // \\
- // [1] Object Name \\
- // [2] Instance Vars:- Y Coordinate, \\
- // X " \\
- // Button No, \\
- // Cursor visible, \\
- // " Character, \\
- // " Colour, \\
- // Time to wait between clicks (for double clicks etc), \\
- // No. of Clicks, \\
- // Inkey() value of key press, \\
- // Cargo \\
- // \\
- // [3] Methods:- Activate (Respond to mouse/keyboard activity), \\
- // Info (refresh data in mouse object), \\
- // Initialise (check mouse driver loaded etc), \\
- // Wait (wait for mouse movement, keystroke etc), \\
- // Goto (position mouse to specific place on screen), \\
- // Show mouse \\
- // Hide mouse, \\
- // Set/Assign Exported Instance Variables \\
- // \\
- ////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
- ////////////////////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\
-
- local oM[3]
-
- oM[OBJ_NAME] := 'Mouse'
- oM[OBJ_INSTANCE] := {;
- -1, ; // Y Coordinate (assume no mouse)
- -1, ; // X " " " "
- -1, ; // Button #
- .f., ; // Cursor Visible
- 0, ; // " Character ASCII Code
- nil, ; // " Colour
- 0.2, ; // Time to wait
- 0, ; // # of Clicks
- nil, ; // Inkey() value
- nil ; // Cargo
- }
- oM[OBJ_METHOD] := {;
- {|o| Activate(o)}, ;
- {|o| Info(o)}, ;
- {|o| Init(o)}, ;
- {|o, cArg| Wait(o, cArg)}, ;
- {|o| Goto(o)}, ;
- {|o| Show(o)}, ;
- {|o| Hide(o)}, ;
- {|o, cArg, lSet| InstanceVar(o, MI_Y, cArg, lSet)}, ;
- {|o, cArg, lSet| InstanceVar(o, MI_X, cArg, lSet)}, ;
- {|o, cArg, lSet| InstanceVar(o, MI_BUTTON, cArg, lSet)}, ;
- {|o, cArg, lSet| InstanceVar(o, MI_VISIBLE, cArg, lSet)}, ;
- {|o, cArg, lSet| InstanceVar(o, MI_CHAR, cArg, lSet)}, ;
- {|o, cArg, lSet| InstanceVar(o, MI_COLOR, cArg, lSet)}, ;
- {|o, cArg, lSet| InstanceVar(o, MI_DELAY, cArg, lSet)}, ;
- {|o, cArg, lSet| InstanceVar(o, MI_CLICKS, cArg, lSet)}, ;
- {|o, cArg, lSet| InstanceVar(o, MI_ASCII, cArg, lSet)}, ;
- {|o, cArg, lSet| InstanceVar(o, MI_CARGO, cArg, lSet)} ;
- }
-
- return ( oM )
- *| EOF MouseNew
-
- *|----------------------------------------------------------------------------|*
-
- function EvalMouse(oM, cMsg, cArg, lSet)
- **
- ** Syntax ..... EVALMOUSE(<A>, <C>, <exp>, <L>)
- **
- ** Purpose .... Evaluate a Mouse Object
- **
- ** Argument ... <A> = Mouse Array/Object
- ** <C> = Message
- ** <exp> = Expression of some sort/Argument for Message
- ** <L> = Assign Instance Variable?
- **
- ** Returns .... Expression
- **
-
- local xRet
-
- do case
- case cMsg == 'ACTIVATE'
- xRet := eval(oM[OBJ_METHOD, MM_ACTIVATE], oM)
- case cMsg == 'INFO'
- xRet := eval(oM[OBJ_METHOD, MM_INFO], oM)
- case cMsg == 'INSTALL'
- xRet := eval(oM[OBJ_METHOD, MM_INSTALL], oM)
- case cMsg == 'WAIT'
- xRet := eval(oM[OBJ_METHOD, MM_WAIT], oM, cArg)
- case cMsg == 'GOTO'
- xRet := eval(oM[OBJ_METHOD, MM_GOTO], oM)
- case cMsg == 'SHOW'
- xRet := eval(oM[OBJ_METHOD, MM_SHOW], oM)
- case cMsg == 'HIDE'
- xRet := eval(oM[OBJ_METHOD, MM_HIDE], oM)
- case cMsg == 'YPOS'
- xRet := eval(oM[OBJ_METHOD, MM_YPOS], oM, cArg, lSet)
- case cMsg == 'XPOS'
- xRet := eval(oM[OBJ_METHOD, MM_XPOS], oM, cArg, lSet)
- case cMsg == 'BUTTON'
- xRet := eval(oM[OBJ_METHOD, MM_BUTTON], oM, cArg, lSet)
- case cMsg == 'SHAPE'
- xRet := eval(oM[OBJ_METHOD, MM_CHAR], oM, cArg, lSet)
- case cMsg == 'VISIBLE'
- xRet := eval(oM[OBJ_METHOD, MM_VISIBLE], oM, cArg, lSet)
- case cMsg == 'COLOR'
- xRet := eval(oM[OBJ_METHOD, MM_COLOR], oM, cArg, lSet)
- case cMsg == 'DELAY'
- xRet := eval(oM[OBJ_METHOD, MM_DELAY], oM, cArg, lSet)
- case cMsg == 'CLICKS'
- xRet := eval(oM[OBJ_METHOD, MM_CLICKS], oM, cArg, lSet)
- case cMsg == 'ASCII'
- xRet := eval(oM[OBJ_METHOD, MM_ASCII], oM, cArg, lSet)
- case cMsg == 'CARGO'
- xRet := eval(oM[OBJ_METHOD, MM_CARGO], oM, cArg, lSet)
- endcase
-
- return (xRet)
- *| EOF EvalMouse
-
- *|----------------------------------------------------------------------------|*
-
- static function Activate(oM)
- **
- ** Syntax ..... ACTIVATE(<A>)
- **
- ** Purpose .... Activate Mouse
- **
- ** Argument ... <A> = Mouse Object
- **
- ** Returns .... Nothing
- **
-
- local nM_Y, nM_X, nButton, nClick, nDelay, nOldButton, ;
- nASCII, nY, nX, nTime
-
- SEND oM:Delay TO nDelay
-
- nButton := -1 // Assume keyboard will be hit
- nClick := 0
-
- if nextkey() = K_CTRL_LEFT
- nASCII := 19
- inkey()
- else
- nY := nM_Y
- nX := nM_X
-
- do while .t.
- if Keypressed()
- nASCII := inkey() // see if user pressed a key
- nM_Y := row()
- nM_X := col()
- exit
- elseif _Is_Mouse
- SEND oM:Info()
- SEND oM:Button TO nButton
-
- if nButton # 0
- SEND oM:YPos TO nM_Y
- SEND oM:XPos TO nM_X
-
- nASCII := nil
-
- Pause(0.02) // Necessary to stop (nY = nM_Y) etc
-
- *|
- *| The F1=Help Horizontal Menu Button
- *|
- if (nButton == LEFT_BUTTON) .and. ;
- RadioButtonPress(oM, 0, (maxcol()-8), maxcol())
- keyboard chr(K_F1)
- loop
- endif
- *|
- *| Both "heavy handed blocks are necessary - they check for different types
- *| of clicks which can not be joined into one block - I've tried!!
- *|
- if nClick = 1
- nClick := 0
- do while M_ButtonHold(nButton) // for the
- enddo // heavy-handed!
- endif
-
- if (nY = nM_Y) .and. (nX = nM_X) .and. (nClick # 0)
- do while M_ButtonHold(nButton) // for the
- enddo // heavy-handed!
-
- nTime := seconds()
- nClick := 0
- nY := 0
- nX := 0
- do while nClick < 2
- SEND oM:Info()
- SEND oM:Button TO nOldButton
-
- if nOldButton = nButton
- SEND oM:YPos TO nM_Y
- if (nY == nM_Y)
- nClick++
- M_ClearButton(nButton)
- endif
- endif
-
- if StopWatch(nTime, seconds()) > nDelay
- exit
- endif
- enddo
- endif
-
- exit
- endif
- endif
- enddo
- endif
-
- SEND oM:YPos := nM_Y
- SEND oM:XPos := nM_X
- SEND oM:Button := nButton
- SEND oM:ASCII := nASCII
- SEND oM:Clicks := nClick
-
- return (nil)
- *| EOF Activate
-
- *|----------------------------------------------------------------------------|*
-
- static function Info(oM)
- **
- ** Syntax ..... INFO(<A>)
- **
- ** Purpose .... Refresh Mouse object with Button No and Coordinates
- **
- ** Argument ... <A> = Mouse Object
- **
- ** Returns .... Nothing
- **
-
- if _Is_Mouse
- SEND oM:YPos := (m_Func3Y() / 8)
- SEND oM:XPos := (m_Func3X() / 8)
- SEND oM:Button := m_Func3B()
- endif
-
- return (nil)
- *| EOF M_Info
-
- *|----------------------------------------------------------------------------|*
-
- static function Init(oM)
- **
- ** Syntax ..... INIT(<A>)
- **
- ** Purpose .... Initialise Mouse
- **
- ** Argument ... <A> = Mouse Object
- **
- ** Returns .... Nothing
- **
-
- local cShape, cColor
-
- #ifdef DEBUG
- if type('oMouse') = 'U'
- Bell()
- cls
- ?
- ? 'No PUBLIC declaration for "oMouse"'
- ?
- quit
- endif
- #endif
-
- _Is_Mouse := (m_Func0() = -1) // File-wide Statics
-
- if _Is_Mouse
- SEND oM:Visible := .f.
-
- SEND oM:Shape TO cShape
- SEND oM:Color TO cColor
-
- M_CursType(oM, cShape, cColor)
- endif
-
- return (nil)
- *| EOF Init
-
- *|----------------------------------------------------------------------------|*
-
- static function Wait(oM, nWait)
- **
- ** Syntax ..... WAIT(<A>[, <N>])
- **
- ** Purpose .... Wait for Mouse/Keyboard Activity/timeout
- **
- ** Argument ... <A> = Mouse Object
- ** <N> = Time to Wait [OPTIONAL]
- **
- ** Returns .... Nothing
- **
-
- local nSecs, nButton
-
- nSecs := seconds()
-
- if _Is_Mouse
- M_ClearButton(LEFT_BUTTON)
- M_ClearButton(RIGHT_BUTTON)
- M_ClearButton(BOTH_BUTTONS)
- pause(.1)
- endif
-
- nButton := 0
- keyboard ''
- do while .t.
- if _Is_Mouse
- SEND oM:Info()
- SEND oM:Button TO nButton
- endif
-
- if (nButton = 0) .and. ;
- (iif(nWait = nil, .t., StopWatch(nSecs, seconds()) < nWait))
- *|
- *| BUG !!!
- *|
- * if SOS_Inkey() # 0
- if inkey() # 0
- exit
- endif
- else
- exit
- endif
- enddo
-
- if _Is_Mouse
- M_ClearButton(LEFT_BUTTON)
- M_ClearButton(RIGHT_BUTTON)
- M_ClearButton(BOTH_BUTTONS)
- endif
- keyboard ''
-
- return (nil)
- *| EOF Wait
-
- *|----------------------------------------------------------------------------|*
-
- static function Goto(oM)
- **
- ** Syntax ..... GOTO(<A>)
- **
- ** Purpose .... Position Mouse Cursor
- **
- ** Argument ... <A> = Mouse Object
- **
- ** Returns .... Nothing
- **
-
- local nY, nX
-
- if _Is_Mouse
- SEND oM:YPos TO nY
- SEND oM:XPos TO nX
- m_Func4(((nY % 25) * 8), ((nX % 80) * 8))
- endif
-
- return (nil)
- *| EOF Goto
-
- *|----------------------------------------------------------------------------|*
-
- static function Show(oM)
- **
- ** Syntax ..... SHOW(<A>)
- **
- ** Purpose .... Display Mouse Cursor
- **
- ** Argument ... <A> = Mouse Object
- **
- ** Returns .... Nothing
- **
-
- return ( M_Cursor(oM, .t.) )
- *| EOF Show
-
- *|----------------------------------------------------------------------------|*
-
- static function Hide(oM)
- **
- ** Syntax ..... HIDE(<A>)
- **
- ** Purpose .... Display Mouse Cursor
- **
- ** Argument ... <A> = Mouse Object
- **
- ** Returns .... Nothing
- **
-
- return ( M_Cursor(oM, .f.) )
- *| EOF Hide
-
- *|----------------------------------------------------------------------------|*
-
- static function M_Cursor(oM, bShow)
- **
- ** Syntax ..... M_CURSOR(<A>, <L>)
- **
- ** Purpose .... Set Cursor ON/OFF for the MOUSE only
- **
- ** Argument ... <O> = Mouse object
- ** <L> = .T. for ON and .F. for OFF
- **
- ** Returns .... Nothing
- **
-
- local bCursor
-
- if _Is_Mouse
- SEND oM:Visible TO bCursor
-
- if bShow
- if ! bCursor
- SEND oM:Visible := .t.
- m_Func1()
- endif
- else
- if bCursor
- SEND oM:Visible := .f.
- m_Func2()
- endif
- endif
- endif
-
- return (nil)
- *| EOF M_Cursor
-
- *|----------------------------------------------------------------------------|*
-
- static function M_CursType(oM, nShape, cColor)
- **
- ** Syntax ..... M_CURSTYPE(<A>, <N>[, <C>])
- **
- ** Purpose .... Set the mouse Text cursor shape and colour
- **
- ** Argument ... <A> = Mouse Object
- ** <N> = ASCII code for Mouse cursor
- ** <C> = Colour for Mouse Cursor [OPTIONAL]
- **
- ** Returns .... Nothing
- **
- ** Usage ...... Colour is combined with Cursor character and passed down to
- ** MFUNC10() as an integer
- **
-
- if _Is_Mouse
- if cColor = nil
- cColor := strtran(setcolor(), ',')
- SEND oM:Color := cColor
- endif
-
- cColor := asc(Color2Bin(cColor))
- nShape := (cColor * 256) + nShape
- m_Func10(nShape)
- endif
-
- return (nil)
- *| EOF M_CursType
-
- *|----------------------------------------------------------------------------|*
-
- static function M_ButtonHold(nButton)
- **
- ** Syntax ..... M_BUTTONHOLD(<N>)
- **
- ** Purpose .... Check if Button is continuously Pressed
- **
- ** Argument ... <N> = Button No.
- **
- ** Returns .... Logical
- **
-
- return (m_Func3B() = nButton)
- *| EOF M_ButtonHold
-
- *|----------------------------------------------------------------------------|*
- *|----------------------------------------------------------------------------|*
- *|-------------------------- END OF OBJECT STUFF ---------------------------|*
- *|----------------------------------------------------------------------------|*
- *|----------------------------------------------------------------------------|*
-
- function M_ClearButton(nButton)
- **
- ** Syntax ..... M_CLEARBUTTON(<N>)
- **
- ** Purpose .... Clear Mouse Button Buffer
- **
- ** Argument ... <N> = Button No
- **
- ** Returns .... Nothing
- **
-
- if _Is_Mouse
- --nButton
- M_Func5C(nButton)
- SEND oMouse:Button := -1
- endif
-
- return (nil)
- *| EOF M_ClearButton
-
- *|----------------------------------------------------------------------------|*
-
- function M_OnHotSpot(oM, nY, nXMin, nXMax)
- **
- ** Syntax ..... M_ONHOTSPOT(<N1>, <N2>, <N3>, <N4>, <N5>)
- **
- ** Purpose .... Check if Mouse Positioned on a Hot Spot
- **
- ** Argument ... <A> = Mouse Object
- ** <N1> = Y Coordinate of Button
- ** <N2> = Minimum X Coordinate for Hot Spot
- ** <N3> = Maximum " " " " "
- **
- ** Returns .... Logical
- **
-
- local nM_Y, nM_X
-
- SEND oM:YPos TO nM_Y
- SEND oM:XPos TO nM_X
-
- return ( ((nM_Y = nY) .and. BUTTON_POS) )
- *| EOF M_OnHotSpot
-
- *|----------------------------------------------------------------------------|*
-
- function RadioButtonPress(oM, nY, nXMin, nXMax)
- **
- ** Syntax ..... RADIOBUTTONPRESS(<A>, <N1>, <N2>, <N3>)
- **
- ** Purpose .... Check if Mouse Clicked on a Button and Depress It
- **
- ** Argument ... <A> = Mouse Object
- ** <N1> = Y Coordinate of Button
- ** <N2> = Minimum X Coordinate for Button
- ** <N3> = Maximum " " " "
- **
- ** Returns .... Logical
- **
-
- local i, bOk, cMap, cButton, cAttrib, cNewAttrib, nDelay, ;
- nButton
-
- bOk := M_OnHotSpot(oM, nY, nXMin, nXMax)
- SEND oM:Button TO nButton
-
- if bOk .and. (nButton = LEFT_BUTTON)
- SEND oM:Hide()
- SEND oM:Delay TO nDelay
-
- cButton := cMap := MSaveScreen(nY, nXMin, nY, nXMax)
-
- cAttrib := substr(cMap, 2, 1)
- cNewAttrib := Color2Bin(ReverseColor(Bin2Color(cAttrib)))
-
- for i := 2 to len(cMap) step 2
- cButton := stuff(cButton, i, 1, cNewAttrib)
- next
-
- MRestScreen(nY, nXMin, nY, nXMax, cButton)
- Pause(nDelay * 1.5)
-
- MRestScreen(nY, nXMin, nY, nXMax, cMap)
-
- SEND oM:Show()
- endif
-
- return (bOk)
- *| EOF RadioButtonPress
-
- *|----------------------------------------------------------------------------|*
-
- function MSavescreen(nY1,nX1,nY2,nX2)
- **
- ** Syntax ..... MSAVESCREEN(<N1>, <N2>, <N3>, <N4>)
- **
- ** Purpose .... Save screen portion turning Mouse on and off
- **
- ** Argument ... <N1>..<N4> = screen coordinates
- **
- ** Returns .... Character
- **
-
- local cScn, bOff, bCursor, nM_X, nM_Y
-
- SEND oMouse:Info()
-
- SEND oMouse:YPos TO nM_Y
- SEND oMouse:XPos TO nM_X
-
- if (nM_Y >= nY1) .and. (nM_X >= nX1) .and. (nM_Y <= nY2) .and. (nM_X <= nX2)
- bOff := .t.
- SEND oMouse:Visible TO bCursor
- SEND oMouse:Hide()
- else
- bOff := .f.
- endif
-
- cScn := savescreen(ny1,nX1,nY2,nX2)
-
- if bOff .and. bCursor
- SEND oMouse:Show()
- endif
-
- return (cScn)
- *| EOF MSavescreen
-
- *|----------------------------------------------------------------------------|*
-
- function MRestscreen(nY1,nX1,nY2,nX2, cScn)
- **
- ** Syntax ..... MSAVESCREEN(<N1>, <N2>, <N3>, <N4>, <C>)
- **
- ** Purpose .... Restore screen portion turning Mouse on and off
- **
- ** Argument ... <N1>..<N4> = screen coordinates
- ** <C> = Screen map
- **
- ** Returns .... Nothing
- **
-
- local bOff, bCursor, nM_X, nM_Y
-
- SEND oMouse:Info()
-
- SEND oMouse:YPos TO nM_Y
- SEND oMouse:XPos TO nM_X
-
- if (nM_Y >= nY1) .and. (nM_X >= nX1) .and. (nM_Y <= nY2) .and. (nM_X <= nX2)
- bOff := .t.
- SEND oMouse:Visible TO bCursor
- SEND oMouse:Hide()
- else
- bOff := .f.
- endif
-
- restscreen(ny1,nX1,nY2,nX2, cScn)
-
- if bOff .and. bCursor
- SEND oMouse:Show()
- endif
-
- return (nil)
- *| EOF MRestscreen
-
- *|----------------------------------------------------------------------------|*
-
-
- *|----------------------------------------------------------------------------|*
- *|----------------------------------------------------------------------------|*
- *|----------------------------------------------------------------------------|*
- *|----------------- Non-Mouse User Defined Functions -----------------------|*
- *|----------------------------------------------------------------------------|*
- *|----------------------------------------------------------------------------|*
-
- function StopWatch(nStart, nStop)
- **
- ** Syntax ..... STOPWATCH<N1>, <N2>)
- **
- ** Purpose .... Give difference between 2 times in seconds and 1/100ths
- **
- ** Argument ... <N1> = Start time in seconds
- ** <N2> = Stop time in seconds
- **
- ** Returns .... Numeric
- **
-
- if nStart > nStop
- nStop := nStop + 86400
- endif
-
- return (nStop - nStart)
- *| EOF StopWatch
-
- *|----------------------------------------------------------------------------|*
-
- function Pause(nTime)
- **
- ** Syntax ..... PAUSE(<N>)
- **
- ** Purpose .... Uninterrupible time delay
- **
- ** Argument ... <N> = Time in seconds
- **
- ** Returns .... Nothing
- **
- ** See Also ... STOPWATCH()
- **
-
- local nSecs
-
- if nTime > 0
- nSecs := seconds()
- do while StopWatch(nSecs, seconds()) <= nTime
- enddo
- endif
-
- return (nil)
- *| EOF Pause
-
- *|----------------------------------------------------------------------------|*
-
- function ReverseColor(cColor)
- **
- ** Syntax ..... REVERSECOLOR(<C>)
- **
- ** Purpose .... Reverse a colour, ie "n/w" -> "w/n"
- **
- ** Argument ... <C> = Colour map
- **
- ** Returns .... Character
- **
-
- cColor := alltrim(left(cColor, at(',', cColor+',')-1))
- *|
- *| ^
- *| ensure at least 1 comma -+
- *|
-
- return ( strtran(cColor, left(cColor, at('/', cColor)-1) + '/' , '') + '/' + ;
- left(cColor, at('/', cColor)-1) )
- *| EOF ReverseColor
-
- *|----------------------------------------------------------------------------|*
-
- function Color2Num(cColor)
- **
- ** Syntax ..... COLOR2NUM(<C>)
- **
- ** Purpose .... Return number of Colour (0-15)
- **
- ** Argument ... <C> := Colour to convert
- **
- ** Returns .... Numeric
- **
-
- local nNo
-
- cColor := upper(trim(cColor))
-
- do case
- case cColor == 'N'
- nNo := 0
- case cColor == 'B'
- nNo := 1
- case cColor == 'G'
- nNo := 2
- case cColor == 'BG'
- nNo := 3
- case cColor == 'R'
- nNo := 4
- case cColor == 'RB'
- nNo := 5
- case cColor == 'GR'
- nNo := 6
- case cColor == 'W'
- nNo := 7
- case (cColor == 'N+') .or. (cColor == '+N')
- nNo := 8
- case cColor == ('B+') .or. (cColor == '+B')
- nNo := 9
- case cColor == ('G+') .or. (cColor == '+G')
- nNo := 10
- case cColor == ('BG+') .or. (cColor == '+BG')
- nNo := 11
- case cColor == ('R+') .or. (cColor == '+R')
- nNo := 12
- case cColor == ('RB+') .or. (cColor == '+RB')
- nNo := 13
- case cColor == ('GR+') .or. (cColor == '+GR')
- nNo := 14
- case cColor == ('W+') .or. (cColor == '+W')
- nNo := 15
- otherwise
- nNo := ''+.f. // create artificial error
- endcase
-
- return (nNo)
- *| EOF Color2Num
-
- *|----------------------------------------------------------------------------|*
-
- function Num2Color(nNo)
- **
- ** Syntax ..... NUM2COLOR(<N>)
- **
- ** Purpose .... Convert Colour No. to Colour String
- **
- ** Argument ... <N> := Colour No.
- **
- ** Returns .... Character
- **
-
- local cColor
-
- do case
- Case nNo == 0
- cColor := 'N'
- Case nNo == 1
- cColor := 'B'
- Case nNo == 2
- cColor := 'G'
- Case nNo == 3
- cColor := 'BG'
- Case nNo == 4
- cColor := 'R'
- Case nNo == 5
- cColor := 'RB'
- Case nNo == 6
- cColor := 'GR'
- Case nNo == 7
- cColor := 'W'
- Case nNo == 8
- cColor := '+N'
- Case nNo == 9
- cColor := '+B'
- Case nNo == 10
- cColor := '+G'
- Case nNo == 11
- cColor := '+BG'
- Case nNo == 12
- cColor := '+R'
- Case nNo == 13
- cColor := '+RB'
- Case nNo == 14
- cColor := '+GR'
- Case nNo == 15
- cColor := '+W'
- otherwise
- cColor := ''+.f. // create artificial error
- endcase
-
- return (cColor)
- *| EOF Num2Color
-
- *|----------------------------------------------------------------------------|*
-
- function Color2Bin(cColor)
- **
- ** Syntax ..... COLOR2BIN(<C>)
- **
- ** Purpose .... Convert Colour to Binary
- **
- ** Argument ... <C> := Colour to Convert
- **
- ** Returns .... Character
- **
- ** Usage ...... Binary := (background * 16) + foreground [+ 128 for Blinking]
- **
-
- local bBlink, cClr, nFore, nBack
-
- cColor := upper(alltrim(cColor))
- bBlink := at('*', cColor) # 0
- cColor := strtran(cColor, "*", "") && Remove blinking attribute
-
- *|
- *| Work out colour received, working from RIGHT to LEFT
- *|
- *|
- *| BACKGROUND COLOUR
- *|
- cClr := right(cColor, (len(cColor)-at('/',cColor)))
- cClr := strtran(cClr, '+')
-
- do case
- case "BR" $ cClr
- cClr := strtran(cClr, "BR", "RB")
- case "RG" $ cClr
- cClr := strtran(cClr, "RG", "GR")
- case "GB" $ cClr
- cClr := strtran(cClr, "GB", "BG")
- endcase
-
- nBack := Color2Num(cClr)
-
- *|
- *| FOREGROUND COLOUR
- *|
- cClr := alltrim(left(cColor, (at('/',cColor)-1)))
- if at('+', cClr) = 1
- cClr := stuff(cClr, 1, 1, '') + '+'
- endif
-
- do case
- case "BR" $ cClr
- cClr := strtran(cClr, "BR", "RB")
- case "RG" $ cClr
- cClr := strtran(cClr, "RG", "GR")
- case "GB" $ cClr
- cClr := strtran(cClr, "GB", "BG")
- endcase
-
- nFore := Color2Num(cClr)
-
- cClr := (nBack * 16) + nFore + iif(bBlink, 128, 0)
-
- return ( chr(cClr) )
- *| EOF Color2Bin
-
- *|----------------------------------------------------------------------------|*
-
- function Bin2Color(cBin)
- **
- ** Syntax ..... BIN2COLOR(<C>)
- **
- ** Purpose .... Convert Binary Number to Clipper Colour String
- **
- ** Argument ... <C> := Number to Convert
- **
- ** Returns .... Character
- **
- ** Usage ...... Binary := (background * 16) + foreground [+ 128 for Blinking]
- **
-
- local bBlink, nFore, nBack, nBin
-
- nBin := asc(cBin)
-
- *|
- *| Is colour blinking?
- *|
- bBlink := (nBin > 127)
- if bBlink
- nBin := nBin - 128
- endif
-
- *|
- *| Work out colour received, working from RIGHT to LEFT
- *|
- nBack := int(nBin / 16)
- nFore := (nBin % 16)
-
- return ( iif(bBlink, "*", "") + Num2Color(nFore) + "/" + Num2Color(nBack) )
- *| EOF Bin2Color
-
- *|----------------------------------------------------------------------------|*