⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 clrcntls.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
/****************************************************************************
*
*                            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 <string.h>
#include "ieclrpal.h"

static HWND             hColoursWnd;
static HWND             hScreenWnd;
static int              coloursHeight;
static int              screenHeight;
static palette_box      paletteBox[PALETTE_SIZE];
static palette_box      screenColour;
static palette_box      inverseColour;
static BOOL             fShowScreenClr = FALSE;
static HWND             hScreenTxt;
static HWND             hInverseTxt;
static short            numberOfColours;
static HBITMAP          hColourBitmap;
static HBITMAP          hMonoBitmap;
static int              prevRestoreState = FALSE;

/*
 * paintColours - paint the available colours on the colour palette.
 */
static void paintColours( HWND hwnd )
{
    WPI_PRES    pres;
    WPI_PRES    mempres;
    HDC         hdc;
    PAINTSTRUCT ps;
    HBITMAP     bitmap;
    HBITMAP     oldbitmap;

    pres = _wpi_beginpaint( hwnd, NULL, &ps );
#ifdef __OS2_PM__
   WinFillRect( pres, &ps, CLR_PALEGRAY );
#endif

    _wpi_torgbmode( pres );
    if (numberOfColours == 2) {
        bitmap = hMonoBitmap;
    } else {
        bitmap = hColourBitmap;
    }

    mempres = _wpi_createcompatiblepres( pres, Instance, &hdc );
    _wpi_torgbmode( mempres );
    oldbitmap = _wpi_selectbitmap( mempres, bitmap );

    _wpi_bitblt( pres, 0, 0, CUR_BMP_WIDTH, CUR_BMP_HEIGHT, mempres,
                                                            0, 0, SRCCOPY );
    _wpi_getoldbitmap( mempres, oldbitmap );
    _wpi_deletecompatiblepres( mempres, hdc );

    _wpi_endpaint( hwnd, pres, &ps );
} /* paintColours */

/*
 * paintScreen - paints the screen and inverse window
  */
void paintScreen( HWND hwnd )
{
    WPI_PRES    pres;
    PAINTSTRUCT ps;

    pres = _wpi_beginpaint( hwnd, NULL, &ps );
#ifdef __OS2_PM__
   WinFillRect( pres, &ps, CLR_PALEGRAY );
#endif
    _wpi_torgbmode( pres );
    if (fShowScreenClr) {
        DisplayColourBox(pres, &(screenColour));
        DisplayColourBox(pres, &(inverseColour));
    }
    _wpi_endpaint( hwnd, pres, &ps );

} /* paintScreen */

#ifdef __OS2_PM__
/*
 * convertToPMCoords - converts coordinates to PM (ie. origin at bottom left)
 */
static void convertToPMCoords( void )
{
    int         i;
    long        temp;

    for (i=0; i < PALETTE_SIZE; i+=2) {
        temp = paletteBox[i].box.top;
        paletteBox[i].box.top = paletteBox[i].box.bottom;
        paletteBox[i].box.bottom = temp;

        temp = paletteBox[i+1].box.top;
        paletteBox[i+1].box.top = paletteBox[i+1].box.bottom;
        paletteBox[i+1].box.bottom = temp;
    }
} /* convertToPMCoords */
#endif

/*
 * initPaletteBoxes - Assigns the values of the colours in the palette and
 *               initializes the palette boxes.
 */
static void initPaletteBoxes( BOOL firsttime )
{
    SetBoxColours(&screenColour, &inverseColour, numberOfColours, paletteBox );
    if (firsttime) {
        SetColour( LMOUSEBUTTON, BLACK, BLACK, NORMAL_CLR );
        SetColour( RMOUSEBUTTON, WHITE, WHITE, NORMAL_CLR );
        /*
         * screenColour has been set by profile information
         */
        inverseColour.colour = GetInverseColour( screenColour.colour );
        inverseColour.solid_colour = inverseColour.colour;
    } else {
        SetCurrentColours(fShowScreenClr);
    }
#ifdef __OS2_PM__
    convertToPMCoords();
#endif

} /* initPaletteBoxes */

/*
 * editCurrentColour - edits the colour under the cursor.
  */
static void editCurrentColour( WPI_POINT *pt )
{
    int         i;
    WPI_RECT    wrect;
    int         top;
    int         bottom;

    for (i=0; i < PALETTE_SIZE; ++i) {
        top = _wpi_cvth_y( paletteBox[i].box.top, coloursHeight );
        bottom = _wpi_cvth_y( paletteBox[i].box.bottom, coloursHeight );

        _wpi_setintwrectvalues( &wrect, paletteBox[i].box.left, top,
                                            paletteBox[i].box.right, bottom );
        if ( _wpi_ptinrect(&wrect, *pt) ) {
            if (numberOfColours == 2) {
                return;
            } else {
#ifndef __OS2_PM__
                EditColours();
#endif
                return;
            }
        }
    }
} /* editCurrentColour */

/*
 * selectColour - Select the colour under the cursor
 */
static void selectColour( WPI_POINT *pt, int mousebutton )
{
    short       i;
    WPI_RECT    wrect;
    int         top;
    int         bottom;

    for (i=0; i < PALETTE_SIZE; ++i) {
        top = _wpi_cvth_y( paletteBox[i].box.top, coloursHeight );
        bottom = _wpi_cvth_y( paletteBox[i].box.bottom, coloursHeight );

        _wpi_setintrectvalues( &wrect, paletteBox[i].box.left, top,
                                            paletteBox[i].box.right, bottom );
        if ( _wpi_ptinrect(&wrect, *pt) ) {
            SetColour( mousebutton, paletteBox[i].colour,
                                    paletteBox[i].solid_colour, NORMAL_CLR );
            return;
        }
    }
} /* selectColour */

/*
 * selectScreen - selects the screen colour.
 */
void selectScreen( WPI_POINT *pt, int mousebutton )
{
    WPI_RECT    wrect;
    int         top;
    int         bottom;

    if (!fShowScreenClr) {
        return;
    }
    top = _wpi_cvth_y( screenColour.box.top, screenHeight );
    bottom = _wpi_cvth_y( screenColour.box.bottom, screenHeight );

    _wpi_setintwrectvalues( &wrect, screenColour.box.left, top,
                                        screenColour.box.right, bottom );

    if ( _wpi_ptinrect(&wrect, *pt) ) {
        SetColour( mousebutton, screenColour.colour, screenColour.colour,
                                                                SCREEN_CLR );
        return;
    }

    top = _wpi_cvth_y( inverseColour.box.top, screenHeight );
    bottom = _wpi_cvth_y( inverseColour.box.bottom, screenHeight );

    _wpi_setintwrectvalues( &wrect, inverseColour.box.left, top,
                                        inverseColour.box.right, bottom );
    if ( _wpi_ptinrect(&wrect, *pt) ) {
        SetColour( mousebutton, inverseColour.colour, inverseColour.colour,
                                                                INVERSE_CLR );
        return;
    }
} /* selectScreen */

/*
 * ColoursWndProc - handle messages for the available colour selection window.
 */
MRESULT CALLBACK ColoursWndProc( HWND hwnd, WPI_MSG msg, WPI_PARAM1 wparam,
                                                          WPI_PARAM2 lparam )
{
    static WPI_POINT            pt;

    switch ( msg ) {
    case WM_CREATE:
        numberOfColours = 16;
        initPaletteBoxes(TRUE);
        InitPaletteBitmaps( hwnd, &hColourBitmap, &hMonoBitmap );
        break;

    case WM_PAINT:
        paintColours( hwnd );
        break;

    case WM_LBUTTONDOWN:
        IMGED_MAKEPOINT( wparam, lparam, pt );
        selectColour(&pt, LMOUSEBUTTON);
        break;

    case WM_LBUTTONDBLCLK:
        IMGED_MAKEPOINT( wparam, lparam, pt );
        editCurrentColour( &pt );
        break;

    case WM_RBUTTONDOWN:
        IMGED_MAKEPOINT( wparam, lparam, pt );

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -