Anda di halaman 1dari 5

COLORSET

/* COLORSET.PRG Tom Groeger 1993


Sound & Vision for Clipper (c) Demonstration Code

*/

#include "SOUNDVIS.CH"
#include "INKEY.CH"
#define
#define
#define
#define
#define
#define
#define

F_WBLUE
F_NHB
F_NW
F_RW
F_WBROWN
F_NBEIGE
F_RBEIGE

31
48
112
116
191
208
212

//
//
//
//
//
//
//

LiteWhite on Blue
Black on LiteBlue
Black on White
Red on White
LiteWhite on Brown (converted)
black on Beige
(converted)
red on Beige
(converted)

/*
VgaMenu () -> nil

Demo using SETDAC(), A_RED(),

A_BLUE() and A_GREEN()

With the help if these you can read and write

the Vga-Palette. It's also a good example of

'How to add a Mouse'

*/
FUNCTION VgaMenu ()
// Array for the 3 main colors
LOCAL aColorCon := { a_Red(0), a_Green(0), a_Blue(0) }
// Control and UpdateFlags
LOCAL lNewColorCon := .f., lNewDAC := .f.
// WorkVars
LOCAL nPalette := 0, nControl := 1
LOCAL nX, nKey, oWin, oR, oG, oB, nEvent := 0
// MousePosition and first ControlRow
LOCAL nMouseCol, nConRow
// declare ColorSave-Array
LOCAL aOrgColor [ 16, 3], nOrgButt
// save original values
FOR nX := 0 TO 15
aOrgColor [nX+1] := { a_Red(nX), a_Green(nX), a_Blue(nX) }
NEXT
MSE_SHOW(.f.)
// Here comes the surrounding 'move-loop'
// -------------------------------------DO WHILE nKey # K_ESC
// build screen
// -------------CREATE WINDOW oWin ;
Page 1

COLORSET
FROM 7, 1 TO 18, 76
TITLE 'ColorSet' ;
TYP WIN_MESSAGE ;
TOPCOLOR F_WBROWN ;
WINCOLOR F_NBEIGE

DISPBEGIN()
// Calculate first ControlRow
nConRow := 4
// draw ColorFields
// ----------------FOR nX := 0 TO 15
OutLine ( 2, 7+( nX*4 ), ' ', 1, INT((nx+1)*15))
NEXT
// draw field
// -----------@ 10, 3 SAY 'Color:'
@ 10, 44 SAY 'F3'
@ 10, 56 SAY 'F4'
nOrgButt := SetPref (C_BUTTLOWER, 208 )
OutLine ( 10, 47, 'Reset'
, 1,
OutLine ( 10, 59, 'Reset all'
, 1,
OutLine ( 10, 11, STR( nPalette, 3), 1,
OutLine ( 10, 18, SPACE(22)
, 1,
SetPref (C_BUTTLOWER, nOrgButt )
//
//
oR
oG
oB

Setup ScrollbarObjects
---------------------:= ScrollBar():New ( 4,
:= ScrollBar():New ( 6,
:= ScrollBar():New ( 8,

5,
5,
5,

F_NW )
F_NW )
F_NW )
15 )

72,.t., 0 ):Show()
72,.t., 0 ):Show()
72,.t., 0 ):Show()

// What to do if Mouse hits Left ICON


// --------------------------------oR:UpAction
:= {||nControl := 1, nEvent := 1 }
oG:UpAction
:= {||nControl := 2, nEvent := 1 }
oB:UpAction
:= {||nControl := 3, nEvent := 1 }
// and Right Icon
// -------------oR:DownAction := {||nControl := 1, nEvent := 2 }
oG:DownAction := {||nControl := 2, nEvent := 2 }
oB:DownAction := {||nControl := 3, nEvent := 2 }
DISPEND()
//
//
//
DO

============
Input-Loop
-----------WHILE .t.
DISPBEGIN()
SETCOLOR("N/W")
Page 2

COLORSET
// draw description
// ----------------@ 10, 12 SAY STR( nPalette, 3)
@ 10, 18 SAY SPACE(24)
// Adjust Slider
// ------------oR:SetOffPos ( aColorCon[1]+1 )
oG:SetOffPos ( aColorCon[2]+1 )
oB:SetOffPos ( aColorCon[3]+1 )
// Show Value of RGB
// ----------------@ 10,20 SAY STR( aColorCon [1], 2)
@ 10,28 SAY STR( aColorCon [2], 2)
@ 10,36 SAY STR( aColorCon [3], 2)
SETCOLOR( 'N/*RB')
@ 3, 7+( nPalette*4 ) SAY "  "
// Set new ColorControl
// -------------------@ nConRow, 2 SAY ' '
@ (nConRow := 2+(2*nControl)),

2 SAY

''

DISPEND()
// ------------// Poll Keyboard
// ------------nKey := KeyReader(nil,0)
// =================
// Process keystroke
// =================
DO CASE
// Increase or Decrease ColorIntensity ?
// -------------------------------------CASE nKey == K_LEFT .OR. nEvent == 1
aColorCon[nControl] := MAX( aColorCon[nControl]-1, 0)
lNewDAC := .t.
nEvent := 0
CASE nKey == K_RIGHT .OR. nEvent == 2
aColorCon[nControl] := MIN( aColorCon[nControl]+1, 63)
lNewDAC := .t.
nEvent := 0
// Beginning or End of Control-line ?
// ----------------------------------CASE nKey == K_HOME .OR. nKey == K_END
aColorCon[nControl] := IIF( nKey == K_HOME, 0, 63 )
lNewDAC := .t.
// Up or Down, change MainColor
// ----------------------------CASE nKey == K_UP .OR. nKey == K_DOWN
Page 3

COLORSET
// get new ColorNo
nControl := WrapWert( nKey == K_DOWN, nControl, 1, 3)
// Next Palette
// ------------CASE nKey == K_PGDN .OR. nKey == K_PGUP
@ 3, 7+( nPalette*4 ) SAY REPLI( CHR(13),3)
nPalette := WrapWert( nKey == K_PGUP, nPalette, 0, 15)
aColorCon := { a_red (nPalette),;
a_green (nPalette),;
a_blue (nPalette) }

// Restore all DAC-Registers


// -------------------------CASE nKey == K_F4 .OR. Mse_Check ( 10,
FOR nX := 1 TO 16
SetDac ( nX-1, aOrgColor [nX,
aOrgColor [nX,
aOrgColor [nX,
NEXT

59,, 66)
1],;
2],;
3] )

lNewColorCon := .t.
// Restore active DAC-Register
// ---------------------------CASE nKey == K_F3 .OR. Mse_Check ( 10, 47,, 51)
lNewDAC := .t.
aColorCon := { aOrgColor [nPalette+1, 1],;
aOrgColor [nPalette+1, 2],;
aOrgColor [nPalette+1, 3] }
/* Exit the easy way (without Eventhandler)
------------------------------------------ */
CASE LASTKEY() == K_ESC
nKey := K_ESC
EXIT
// Mouse on ColorField ?
// ---------------------CASE Mse_Check ( 2, 7,, 70)
nMouseCol := Mse_Col()
// on which one, please ?
FOR nX := 1 TO 16
// I see.. get ColorValues
IF nMouseCol < 7 + (nX * 4)
@ 3, 7+( nPalette*4 ) SAY REPLI( CHR(13),3)
nPalette := --nX
aColorCon := { a_red
(nPalette),;
a_green (nPalette),;
a_blue (nPalette) }
EXIT
ENDIF
NEXT
Page 4

COLORSET
// Mouse on RED ?
// -------------CASE (nX := oR:GetMouse()) # 0
nControl := 1
lNewDAC := .t.
aColorCon [nControl] := --nX
// hum, maybe on GREEN ?
// --------------------CASE (nX := oG:GetMouse()) # 0
nControl := 2
lNewDAC := .t.
aColorCon [nControl] := --nX
// or BLUE
// -------CASE (nX := oB:GetMouse()) # 0
nControl := 3
lNewDAC := .t.
aColorCon [nControl] := --nX
ENDCASE

// Read new ColorRegister ?


// =========================
IF lNewColorCon
// Flag reset
lNewColorCon := .f.
// Read ColorRegister
aColorCon := { a_red
a_green
a_blue
ENDIF

and save to array


(nPalette),;
(nPalette),;
(nPalette) }

// DAC new ?
// ==========
IF lNewDAC
lNewDAC := .f.
SetDAC ( nPalette, aColorCon[1], aColorCon[2], aColorCon[3] )
ENDIF
ENDDO
CLOSE WINDOW oWin
ENDDO
RETURN ( nil )


Page 5

Anda mungkin juga menyukai