📄 colours.c
字号:
/****************************************************************************
*
* Open Watcom Project
*
* Portions Copyright (c) 1983-2002 Sybase, Inc. All Rights Reserved.
*
* ========================================================================
*
* This file contains Original Code and/or Modifications of Original
* Code as defined in and that are subject to the Sybase Open Watcom
* Public License version 1.0 (the 'License'). You may not use this file
* except in compliance with the License. BY USING THIS FILE YOU AGREE TO
* ALL TERMS AND CONDITIONS OF THE LICENSE. A copy of the License is
* provided with the Original Code and Modifications, and is also
* available at www.sybase.com/developer/opensource.
*
* The Original Code and all software distributed under the License are
* distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
* EXPRESS OR IMPLIED, AND SYBASE AND ALL CONTRIBUTORS HEREBY DISCLAIM
* ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR
* NON-INFRINGEMENT. Please see the License for the specific language
* governing rights and limitations under the License.
*
* ========================================================================
*
* Description: WHEN YOU FIGURE OUT WHAT THIS FILE DOES, PLEASE
* DESCRIBE IT HERE!
*
****************************************************************************/
#include "imgedit.h"
#include "ieclrpal.h"
#include "colours.h"
static RGBQUAD Palette[NUM_PALETTES][PALETTE_SIZE];
static RGBQUAD restorePalette[PALETTE_SIZE];
static RGBQUAD Solids[ 16 ]; // maybe vary this later
static int currentPalIndex = 0;
static int leftColourIndex;
static int rightColourIndex;
/*
* chooseThePalette - checks the number of colours and decides which palette
* we need.
*/
void chooseThePalette( int num_of_colours )
{
switch (num_of_colours)
{
case 2:
currentPalIndex = COLOUR_2;
break;
case 16:
currentPalIndex = COLOUR_16;
break;
case 256:
currentPalIndex = COLOUR_256;
break;
}
} /* chooseThePalette */
/*
* getColourIndex - given a colour, this routine returns the index of that
* colour in the current palette. It returns -1 if the
* colour is not found in the palette.
*/
int getColourIndex( COLORREF colour )
{
int i;
for (i=0; i < PALETTE_SIZE; ++i) {
if ( colour == RGB( Palette[currentPalIndex][i].rgbRed,
Palette[currentPalIndex][i].rgbGreen,
Palette[currentPalIndex][i].rgbBlue ) ) {
return( i );
}
}
return ( -1 );
} /* getColourIndex */
/*
* InitPalette - Initializes the colour palette.
* Palette[0] is the 16 colour palette
* Palette[1] is the 2 colour palette
* Palette[2] is the 256 colour palette
*/
void InitPalette( void )
{
short i;
RGBQUAD quads[PALETTE_SIZE];
for (i=0; i < PALETTE_SIZE; ++i) {
quads[i].rgbReserved = (BYTE)0;
}
// white
quads[0].rgbRed = 0xFF;
quads[0].rgbGreen = 0xFF;
quads[0].rgbBlue = 0xFF;
// black
quads[1].rgbRed = 0x00;
quads[1].rgbGreen = 0x00;
quads[1].rgbBlue = 0x00;
#ifdef __OS2_PM__
quads[2].rgbRed = 0xCC;
quads[2].rgbGreen = 0xCC;
quads[2].rgbBlue = 0xCC;
#else
quads[2].rgbRed = 0xC0;
quads[2].rgbGreen = 0xC0;
quads[2].rgbBlue = 0xC0;
#endif
quads[3].rgbRed = 0x80;
quads[3].rgbGreen = 0x80;
quads[3].rgbBlue = 0x80;
// red
quads[4].rgbRed = 0xFF;
quads[4].rgbGreen = 0x00;
quads[4].rgbBlue = 0x00;
quads[5].rgbRed = 0x80;
quads[5].rgbGreen = 0x00;
quads[5].rgbBlue = 0x00;
quads[6].rgbRed = 0xFF;
quads[6].rgbGreen = 0xFF;
quads[6].rgbBlue = 0x00;
quads[7].rgbRed = 0x80;
quads[7].rgbGreen = 0x80;
quads[7].rgbBlue = 0x00;
quads[8].rgbRed = 0x00;
quads[8].rgbGreen = 0xFF;
quads[8].rgbBlue = 0x00;
quads[9].rgbRed = 0x00;
quads[9].rgbGreen = 0x80;
quads[9].rgbBlue = 0x00;
quads[10].rgbRed = 0x00;
quads[10].rgbGreen = 0xFF;
quads[10].rgbBlue = 0xFF;
quads[11].rgbRed = 0x00;
quads[11].rgbGreen = 0x80;
quads[11].rgbBlue = 0x80;
quads[12].rgbRed = 0x00;
quads[12].rgbGreen = 0x00;
quads[12].rgbBlue = 0xFF;
quads[13].rgbRed = 0x00;
quads[13].rgbGreen = 0x00;
quads[13].rgbBlue = 0x80;
quads[14].rgbRed = 0xFF;
quads[14].rgbGreen = 0x00;
quads[14].rgbBlue = 0xFF;
quads[15].rgbRed = 0x80;
quads[15].rgbGreen = 0x00;
quads[15].rgbBlue = 0x80;
quads[16].rgbRed = 0xFF;
quads[16].rgbGreen = 0xFF;
quads[16].rgbBlue = 0x80;
quads[17].rgbRed = 0x80;
quads[17].rgbGreen = 0x80;
quads[17].rgbBlue = 0x40;
quads[18].rgbRed = 0x80;
quads[18].rgbGreen = 0xFF;
quads[18].rgbBlue = 0x80;
quads[19].rgbRed = 0x00;
quads[19].rgbGreen = 0x40;
quads[19].rgbBlue = 0x40;
quads[20].rgbRed = 0x80;
quads[20].rgbGreen = 0xFF;
quads[20].rgbBlue = 0xFF;
quads[21].rgbRed = 0x00;
quads[21].rgbGreen = 0x80;
quads[21].rgbBlue = 0xFF;
quads[22].rgbRed = 0x80;
quads[22].rgbGreen = 0x80;
quads[22].rgbBlue = 0xFF;
quads[23].rgbRed = 0x00;
quads[23].rgbGreen = 0x40;
quads[23].rgbBlue = 0x80;
quads[24].rgbRed = 0xFF;
quads[24].rgbGreen = 0x00;
quads[24].rgbBlue = 0x80;
quads[25].rgbRed = 0x40;
quads[25].rgbGreen = 0x00;
quads[25].rgbBlue = 0x80;
quads[26].rgbRed = 0xFF;
quads[26].rgbGreen = 0x80;
quads[26].rgbBlue = 0x40;
quads[27].rgbRed = 0x80;
quads[27].rgbGreen = 0x40;
quads[27].rgbBlue = 0x00;
for (i=0; i < PALETTE_SIZE; ++i) {
Palette[COLOUR_16][i] = quads[i];
restorePalette[i] = quads[i];
}
/*
* initialize the 256 colour palette the same as the 16 colour
*/
for (i=0; i < PALETTE_SIZE; ++i) {
Palette[COLOUR_256][i] = quads[i];
restorePalette[i] = quads[i];
}
/*
* Brain dead method ... but the most convenient right now!
*/
Solids[0] = quads[0];
Solids[1] = quads[1];
Solids[2] = quads[2];
Solids[3] = quads[3];
Solids[4] = quads[4];
Solids[5] = quads[11];
Solids[6] = quads[6];
Solids[7] = quads[13];
Solids[8] = quads[8];
Solids[9] = quads[15];
Solids[10] = quads[10];
Solids[11] = quads[5];
Solids[12] = quads[12];
Solids[13] = quads[7];
Solids[14] = quads[14];
Solids[15] = quads[9];
quads[0].rgbRed = 255;
quads[1].rgbRed = 0;
quads[2].rgbRed = 250;
quads[3].rgbRed = 9;
quads[4].rgbRed = 242;
quads[5].rgbRed = 18;
quads[6].rgbRed = 226;
quads[7].rgbRed = 33;
quads[8].rgbRed = 208;
quads[9].rgbRed = 50;
quads[10].rgbRed = 194;
quads[11].rgbRed = 64;
quads[12].rgbRed = 176;
quads[13].rgbRed = 82;
quads[14].rgbRed = 159;
quads[15].rgbRed = 97;
quads[16].rgbRed = 130;
quads[17].rgbRed = 72;
quads[18].rgbRed = 174;
quads[19].rgbRed = 81;
quads[20].rgbRed = 165;
quads[21].rgbRed = 90;
quads[22].rgbRed = 156;
quads[23].rgbRed = 99;
quads[24].rgbRed = 147;
quads[25].rgbRed = 108;
quads[26].rgbRed = 138;
quads[27].rgbRed = 117;
for (i=0; i < PALETTE_SIZE; i += 1) {
Palette[COLOUR_2][i].rgbRed = quads[i].rgbRed;
Palette[COLOUR_2][i].rgbBlue = quads[i].rgbRed;
Palette[COLOUR_2][i].rgbGreen = quads[i].rgbRed;
}
} /* InitPalette */
/*
* SetBoxColours - Sets the values of the colour boxes. NOTE that all
* coordinates are using the windows convention of the
* top left as the origin.
*/
void SetBoxColours( palette_box *screen, palette_box *inverse,
int num_colours, palette_box *avail_colours )
{
short i;
wie_clrtype type;
WPI_PRES pres;
COLORREF rgbcolour;
leftColourIndex = getColourIndex(GetSelectedColour(LMOUSEBUTTON, NULL, &type));
rightColourIndex = getColourIndex(GetSelectedColour(RMOUSEBUTTON, NULL, &type));
chooseThePalette( num_colours );
/*
* First initialize the screen colour boxes.
*/
screen->box.left = SCRN_COL_X;
screen->box.right = SCRN_COL_X + SQR_SIZE + 1;
screen->box.top = SCRN_COL_Y;
screen->box.bottom = SCRN_COL_Y + SQR_SIZE + 1;
inverse->box.left = SCRN_COL_X;
inverse->box.right = SCRN_COL_X + SQR_SIZE + 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -