📄 colours.c
字号:
inverse->box.top = SCRN_COL_Y + SQR_SIZE;
inverse->box.bottom = SCRN_COL_Y + 2*SQR_SIZE + 1;
pres = _wpi_getpres( HWND_DESKTOP );
_wpi_torgbmode( pres );
for (i=0; i < PALETTE_SIZE; i += 2) {
rgbcolour = RGB( Palette[currentPalIndex][i].rgbRed,
Palette[currentPalIndex][i].rgbGreen,
Palette[currentPalIndex][i].rgbBlue );
avail_colours[i].colour = _wpi_getcolourindex( pres, rgbcolour );
if (num_colours == 2) {
avail_colours[i].solid_colour = WHITE;
} else {
avail_colours[i].solid_colour = _wpi_getnearestcolor( pres, rgbcolour );
}
avail_colours[i].box.left = (i/2)*SQR_SIZE;
avail_colours[i].box.top = 0;
avail_colours[i].box.right = SQR_SIZE+(i/2)*SQR_SIZE+1;
avail_colours[i].box.bottom = SQR_SIZE+1;
rgbcolour = RGB( Palette[currentPalIndex][i+1].rgbRed,
Palette[currentPalIndex][i+1].rgbGreen,
Palette[currentPalIndex][i+1].rgbBlue );
avail_colours[i+1].colour = _wpi_getcolourindex( pres, rgbcolour );
if (num_colours == 2) {
avail_colours[i+1].solid_colour = BLACK;
} else {
avail_colours[i+1].solid_colour = _wpi_getnearestcolor(pres, rgbcolour);
}
avail_colours[i+1].box.left = avail_colours[i].box.left;
avail_colours[i+1].box.top = SQR_SIZE;
avail_colours[i+1].box.right = avail_colours[i].box.right;
avail_colours[i+1].box.bottom = SQR_SIZE*2 + 1;
}
_wpi_releasepres( HWND_DESKTOP, pres );
} /* SetBoxColours */
/*
* DisplayColourBox - display the colours on the given DC.
* PM Note: we assume the presentation space is already
* in rgb mode
*/
void DisplayColourBox( WPI_PRES pres, palette_box *box )
{
int top;
int bottom;
HBRUSH hcolourbrush;
HBRUSH holdbrush;
HPEN holdpen;
HPEN blackpen;
int height;
blackpen = _wpi_createpen( PS_SOLID, 0, BLACK );
holdpen = _wpi_selectobject( pres, blackpen );
hcolourbrush = _wpi_createsolidbrush( box->colour );
holdbrush = _wpi_selectobject( pres, hcolourbrush );
height = 2* SQR_SIZE + 1;
top = _wpi_cvth_y( box->box.top, height );
bottom = _wpi_cvth_y( box->box.bottom, height );
_wpi_rectangle( pres, box->box.left, top, box->box.right, bottom );
_wpi_selectobject( pres, holdbrush );
_wpi_deleteobject( hcolourbrush );
_wpi_selectobject( pres, holdpen );
_wpi_deleteobject( blackpen );
} /* DisplayColourBox */
/*
* GetInverseColour - Returns the inverse colour. Simply performing a bitwise
* NOT doesn't do the trick so this method is employed.
*/
COLORREF GetInverseColour( COLORREF colour )
{
int i;
int num_colours;
COLORREF solidcolour;
COLORREF newcolour;
WPI_PRES pres;
pres = _wpi_getpres( HWND_DESKTOP );
_wpi_torgbmode( pres );
/*
* change this so that we check the number of colours the machine has
*/
num_colours = 16;
solidcolour = _wpi_getnearestcolor( pres, colour );
_wpi_releasepres( HWND_DESKTOP, pres );
for (i=0; i < num_colours; ++i) {
if ( solidcolour == RGB( Solids[i].rgbRed, Solids[i].rgbBlue,
Solids[i].rgbGreen ) ) {
break;
}
}
switch (i) {
case 0:
case 2:
case 4:
case 6:
case 8:
case 10:
case 12:
case 14:
newcolour = RGB(Solids[i+1].rgbRed, Solids[i+1].rgbBlue, Solids[i+1].rgbGreen);
return( RGB(Solids[i+1].rgbRed, Solids[i+1].rgbBlue, Solids[i+1].rgbGreen) );
case 1:
case 3:
case 5:
case 7:
case 9:
case 11:
case 13:
case 15:
newcolour = RGB(Solids[i-1].rgbRed, Solids[i-1].rgbBlue, Solids[i-1].rgbGreen);
return( RGB(Solids[i-1].rgbRed, Solids[i-1].rgbBlue, Solids[i-1].rgbGreen) );
default:
return (WHITE);
}
} /* GetInverseColour */
/*
* ReplacePaletteEntry - replace the current entry with the given RGB value
*/
void ReplacePaletteEntry( COLORREF newcolour )
{
COLORREF cur_colour;
COLORREF nearestcolour;
COLORREF screencolour;
COLORREF rightcolour;
wie_clrtype lefttype;
wie_clrtype righttype;
int index;
int rightindex;
WPI_PRES pres;
if (currentPalIndex != COLOUR_16 && currentPalIndex != COLOUR_256) {
return;
}
cur_colour = GetSelectedColour( LMOUSEBUTTON, NULL, &lefttype );
if (lefttype == NORMAL_CLR) {
index = getColourIndex( cur_colour );
rightcolour = GetSelectedColour( RMOUSEBUTTON, NULL, &righttype );
rightindex = getColourIndex( rightcolour );
Palette[currentPalIndex][index].rgbRed = GetRValue( newcolour );
Palette[currentPalIndex][index].rgbGreen = GetGValue( newcolour );
Palette[currentPalIndex][index].rgbBlue = GetBValue( newcolour );
Palette[currentPalIndex][index].rgbReserved = 0;
ShowNewColour( index, newcolour, TRUE );
pres = _wpi_getpres( HWND_DESKTOP );
_wpi_torgbmode( pres );
SetColour( LMOUSEBUTTON, newcolour, _wpi_getnearestcolor(pres, newcolour), NORMAL_CLR );
if (index == rightindex) {
SetColour( RMOUSEBUTTON, newcolour,
_wpi_getnearestcolor(pres, newcolour), NORMAL_CLR );
}
_wpi_releasepres( HWND_DESKTOP, pres );
} else if (lefttype == SCREEN_CLR) {
pres = _wpi_getpres( HWND_DESKTOP );
_wpi_torgbmode( pres );
nearestcolour = _wpi_getnearestcolor(pres, newcolour);
_wpi_releasepres( HWND_DESKTOP, pres );
SetScreenClr( nearestcolour );
} else {
pres = _wpi_getpres( HWND_DESKTOP );
_wpi_torgbmode( pres );
nearestcolour = _wpi_getnearestcolor(pres, newcolour);
_wpi_releasepres( HWND_DESKTOP, pres );
screencolour = GetInverseColour( nearestcolour );
SetScreenClr( screencolour );
}
} /* ReplacePaletteEntry */
/*
* ResetColourPalette - Resets the colour palette to it's original form (ie
* the way it is when the program is first executed or
* the way it was most recently loaded). IE, in response
* to hitting the Restore button.
*/
void ResetColourPalette( void )
{
int i;
COLORREF leftcolour;
COLORREF rightcolour;
COLORREF colour;
WPI_PRES pres;
int leftindex;
int rightindex;
wie_clrtype lefttype;
wie_clrtype righttype;
if (currentPalIndex != COLOUR_16 && currentPalIndex != COLOUR_256) {
return;
}
leftcolour = GetSelectedColour( LMOUSEBUTTON, NULL, &lefttype );
rightcolour = GetSelectedColour( RMOUSEBUTTON, NULL, &righttype );
leftindex = getColourIndex( leftcolour );
rightindex = getColourIndex( rightcolour );
for (i=0; i < PALETTE_SIZE-1; ++i) {
Palette[currentPalIndex][i] = restorePalette[i];
ShowNewColour( i, RGB(Palette[currentPalIndex][i].rgbRed,
Palette[currentPalIndex][i].rgbGreen,
Palette[currentPalIndex][i].rgbBlue), FALSE );
}
/*
* We do the last one separately to invalidate the window.
*/
Palette[currentPalIndex][i] = restorePalette[i];
ShowNewColour( i, RGB(Palette[currentPalIndex][i].rgbRed,
Palette[currentPalIndex][i].rgbGreen,
Palette[currentPalIndex][i].rgbBlue), TRUE );
if (lefttype == NORMAL_CLR) {
colour = RGB(Palette[currentPalIndex][leftindex].rgbRed,
Palette[currentPalIndex][leftindex].rgbGreen,
Palette[currentPalIndex][leftindex].rgbBlue);
pres = _wpi_getpres( HWND_DESKTOP );
_wpi_torgbmode( pres );
SetColour(LMOUSEBUTTON, colour, _wpi_getnearestcolor(pres, colour),
NORMAL_CLR);
_wpi_releasepres( HWND_DESKTOP, pres );
}
if (righttype == NORMAL_CLR) {
colour = RGB(Palette[currentPalIndex][rightindex].rgbRed,
Palette[currentPalIndex][rightindex].rgbGreen,
Palette[currentPalIndex][rightindex].rgbBlue);
pres = _wpi_getpres( HWND_DESKTOP );
_wpi_torgbmode( pres );
SetColour(RMOUSEBUTTON, colour, _wpi_getnearestcolor(pres, colour),
NORMAL_CLR);
_wpi_releasepres( HWND_DESKTOP, pres );
}
} /* ResetColourPalette */
/*
* SetCurrentColours - sets the current colour selection (we need to be
* careful that the image supports the current palette).
*/
void SetCurrentColours( BOOL fshowscreenclrs )
{
COLORREF leftcolour;
COLORREF rightcolour;
COLORREF solid;
wie_clrtype type;
WPI_PRES pres;
leftcolour = GetSelectedColour(LMOUSEBUTTON, NULL, &type);
if (type == NORMAL_CLR) {
leftcolour = GetPaletteColour( leftColourIndex );
if (currentPalIndex == COLOUR_16 || currentPalIndex == COLOUR_256) {
pres = _wpi_getpres( HWND_DESKTOP );
_wpi_torgbmode( pres );
solid = _wpi_getnearestcolor(pres, leftcolour);
_wpi_releasepres( HWND_DESKTOP, pres );
} else if ( (currentPalIndex == COLOUR_2) &&
((leftColourIndex/2) == (leftColourIndex+1)/2) ) {
solid = WHITE;
} else {
solid = BLACK;
}
SetColour( LMOUSEBUTTON, leftcolour, solid, NORMAL_CLR );
} else if (!fshowscreenclrs) {
leftcolour = GetPaletteColour( 1 );
if (currentPalIndex == COLOUR_16 || currentPalIndex == COLOUR_256) {
pres = _wpi_getpres( HWND_DESKTOP );
_wpi_torgbmode( pres );
solid = _wpi_getnearestcolor(pres, leftcolour);
_wpi_releasepres( HWND_DESKTOP, pres );
} else if (currentPalIndex == COLOUR_2) {
solid = BLACK;
}
SetColour( LMOUSEBUTTON, leftcolour, solid, NORMAL_CLR );
} else {
SetColour( LMOUSEBUTTON, leftcolour, leftcolour, type );
}
rightcolour = GetSelectedColour(RMOUSEBUTTON, NULL, &type);
if (type == NORMAL_CLR) {
rightcolour = GetPaletteColour( rightColourIndex );
if (currentPalIndex == COLOUR_16 || currentPalIndex == COLOUR_256) {
pres = _wpi_getpres( HWND_DESKTOP );
_wpi_torgbmode( pres );
solid = _wpi_getnearestcolor(pres, rightcolour);
_wpi_releasepres( HWND_DESKTOP, pres );
} else if ( (currentPalIndex == COLOUR_2) &&
((rightColourIndex/2) == (rightColourIndex+1)/2) ) {
solid = WHITE;
} else {
solid = BLACK;
}
SetColour( RMOUSEBUTTON, rightcolour, solid, NORMAL_CLR );
} else if (!fshowscreenclrs) {
rightcolour = GetPaletteColour( 0 );
if (currentPalIndex == COLOUR_16 || currentPalIndex == COLOUR_256) {
pres = _wpi_getpres( HWND_DESKTOP );
_wpi_torgbmode( pres );
solid = _wpi_getnearestcolor(pres, rightcolour);
_wpi_releasepres( HWND_DESKTOP, pres );
} else if (currentPalIndex == COLOUR_2) {
solid = WHITE;
}
SetColour( RMOUSEBUTTON, rightcolour, solid, NORMAL_CLR );
} else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -