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

📄 colours.c

📁 开放源码的编译器open watcom 1.6.0版的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
        SetColour( RMOUSEBUTTON, rightcolour, rightcolour, type );
    }
} /* SetCurrentColours */

/*
 * GetPaletteColour - Returns the COLORREF associated with the given index.
 */
COLORREF GetPaletteColour( int index )
{
    COLORREF    colour;

    colour = RGB( Palette[currentPalIndex][index].rgbRed,
                  Palette[currentPalIndex][index].rgbGreen,
                  Palette[currentPalIndex][index].rgbBlue );
    return( colour );
} /* GetPaletteColour */

/*
 * InitFromColourPalette - Sets the values of the colour boxes in the dialog
 *                              box.
 */
void InitFromColourPalette( palette_box *screen, palette_box *inverse,
                                palette_box *avail_colours )
{
    short               i;
    short               left;

    /*
     * For now we assume they can choose from only 16 colours!
     * First initialize the screen colour boxes.
     */
    left = 76;
    screen->box.left = 3;
    screen->box.right = SQR_SIZE + 4;
    screen->box.top = 3;
    screen->box.bottom = SQR_SIZE + 4;

    inverse->box.left = 3;
    inverse->box.right = SQR_SIZE + 4;
    inverse->box.top = SQR_SIZE + 3;
    inverse->box.bottom = 2*SQR_SIZE + 4;

    for (i=0; i < 16; i += 2) {
        avail_colours[i].colour = RGB( Solids[i].rgbRed,
                                       Solids[i].rgbGreen,
                                       Solids[i].rgbBlue );
        avail_colours[i].box.left = left + (i/2)*SQR_SIZE;
        avail_colours[i].box.top = screen->box.top;
        avail_colours[i].box.right = left + SQR_SIZE+(i/2)*SQR_SIZE+1;
        avail_colours[i].box.bottom = screen->box.bottom;

        avail_colours[i+1].colour = RGB( Solids[i+1].rgbRed,
                                         Solids[i+1].rgbGreen,
                                         Solids[i+1].rgbBlue );
        avail_colours[i+1].box.left = avail_colours[i].box.left;
        avail_colours[i+1].box.top = avail_colours[i].box.bottom-1;
        avail_colours[i+1].box.right = avail_colours[i].box.right;
        avail_colours[i+1].box.bottom = avail_colours[i].box.bottom+SQR_SIZE+1;
    }
}

/*
 * GetPaletteFile - This routine sets up the palette file.  Since it isn't
 *                  documented (?!), I got this from a hex dump of a file
 *                  created by other image editors (MS).
 */
BOOL GetPaletteFile( a_pal_file *pal_file )
{
    int                 i;

    if (currentPalIndex != COLOUR_16 && currentPalIndex != COLOUR_256) {
        return(FALSE);
    }

    pal_file->file_id = PALETTE_FILE;
    for (i=0; i < 12; ++i) {
        pal_file->reserved[i] = 0;
    }

    for (i=0; i < PALETTE_SIZE; ++i) {
        /*
         * I don't know why they do this but it seems to work ?!
         */
        pal_file->rgbqs[i].rgbBlue = Palette[currentPalIndex][i].rgbRed;
        pal_file->rgbqs[i].rgbRed = Palette[currentPalIndex][i].rgbBlue;
        pal_file->rgbqs[i].rgbGreen = Palette[currentPalIndex][i].rgbGreen;
        pal_file->rgbqs[i].rgbReserved = 0;
    }

    return(TRUE);
} /* GetPaletteFile */

/*
 * SetNewPalette - Sets a new palette from a loaded file.
 */
void SetNewPalette( a_pal_file *pal_file )
{
    int         i;
    wie_clrtype type;
    HMENU       hmenu;

    if (currentPalIndex != COLOUR_16 && currentPalIndex != COLOUR_256) {
        return;
    }

    leftColourIndex = getColourIndex(GetSelectedColour(LMOUSEBUTTON, NULL, &type));
    rightColourIndex = getColourIndex(GetSelectedColour(RMOUSEBUTTON, NULL, &type));

    for (i=0; i < PALETTE_SIZE-1; ++i) {
        Palette[currentPalIndex][i].rgbRed = pal_file->rgbqs[i].rgbBlue;
        Palette[currentPalIndex][i].rgbGreen = pal_file->rgbqs[i].rgbGreen;
        Palette[currentPalIndex][i].rgbBlue = pal_file->rgbqs[i].rgbRed;
        ShowNewColour( i, RGB(Palette[currentPalIndex][i].rgbRed,
                                Palette[currentPalIndex][i].rgbGreen,
                                Palette[currentPalIndex][i].rgbBlue), FALSE );
        restorePalette[i] = Palette[currentPalIndex][i];
    }
    Palette[currentPalIndex][i].rgbRed = pal_file->rgbqs[i].rgbBlue;
    Palette[currentPalIndex][i].rgbGreen = pal_file->rgbqs[i].rgbGreen;
    Palette[currentPalIndex][i].rgbBlue = pal_file->rgbqs[i].rgbRed;
    restorePalette[i] = Palette[currentPalIndex][i];

    ShowNewColour( i, RGB(Palette[currentPalIndex][i].rgbRed,
                        Palette[currentPalIndex][i].rgbGreen,
                        Palette[currentPalIndex][i].rgbBlue), TRUE );
    SetCurrentColours( TRUE );

    if (HMainWindow) {
        hmenu = GetMenu( _wpi_getframe(HMainWindow) );
        _wpi_enablemenuitem( hmenu, IMGED_RCOLOUR, TRUE, FALSE );
    }
} /* SetNewPalette */

/*
 * RestoreColourPalette - Restores the colour palette to the hard coded
 *                        colours in the init routine.
 */
void RestoreColourPalette( void )
{
    int         i;
    COLORREF    leftcolour;
    COLORREF    rightcolour;
    COLORREF    colour;
    WPI_PRES    pres;
    int         leftindex;
    int         rightindex;
    wie_clrtype lefttype;
    wie_clrtype righttype;
    HMENU       hmenu;
    HWND        frame;

    if (currentPalIndex != COLOUR_16 && currentPalIndex != COLOUR_256) {
        return;
    }
    leftcolour = GetSelectedColour( LMOUSEBUTTON, NULL, &lefttype );
    rightcolour = GetSelectedColour( RMOUSEBUTTON, NULL, &righttype );

    leftindex = getColourIndex( leftcolour );
    rightindex = getColourIndex( rightcolour );

    InitPalette();
    for (i=0; i < PALETTE_SIZE-1; ++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.
     */
    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 );
    }

    PrintHintTextByID( WIE_PALETTERESTORED, NULL );

    if (HMainWindow) {
        frame = _wpi_getframe( _wpi_getframe(HMainWindow) );
        hmenu = GetMenu( frame );
        _wpi_enablemenuitem( hmenu, IMGED_RCOLOUR, FALSE, FALSE );
    }

} /* RestoreColourPalette */

/*
 * InitPaletteBitmaps - Initializes the available colour bitmaps
 */
void InitPaletteBitmaps( HWND hwnd, HBITMAP *colourbitmap,
                                                        HBITMAP *monobitmap )
{
    WPI_PRES    pres;
    WPI_PRES    mempres;
    HDC         hdc;
    HBITMAP     oldbitmap;
    COLORREF    colour;
    int         i;
    int         left_sqr;
    HBRUSH      colourbrush;
    HBRUSH      oldbrush;
    HPEN        blackpen;
    HPEN        oldpen;
    int         top;
    int         bottom;
    int         height;

    pres = _wpi_getpres( hwnd );

    *colourbitmap = _wpi_createcompatiblebitmap( pres, CUR_BMP_WIDTH, CUR_BMP_HEIGHT );
    *monobitmap = _wpi_createbitmap( CUR_BMP_WIDTH, CUR_BMP_HEIGHT, 1, 1, NULL );
    mempres = _wpi_createcompatiblepres( pres, Instance, &hdc );

    _wpi_releasepres( hwnd, pres );
    _wpi_torgbmode( mempres );

    blackpen = _wpi_createpen( PS_SOLID, 0, BLACK );
    oldpen = _wpi_selectobject( mempres, blackpen );
    oldbitmap = _wpi_selectobject( mempres, *colourbitmap );

    /*
     * PM NOTE:  all box coordinates are relative to the windows origin
     * of top left.  so we convert the height for PM.
     */
    left_sqr = 0;
    height = 2 * SQR_SIZE + 1;
    for (i = 0; i < PALETTE_SIZE; i+=2) {
        colour = RGB(Palette[COLOUR_16][i].rgbRed,
                     Palette[COLOUR_16][i].rgbGreen,
                     Palette[COLOUR_16][i].rgbBlue);
        colourbrush = _wpi_createsolidbrush( colour );
        oldbrush = _wpi_selectobject( mempres, colourbrush );

        top = _wpi_cvth_y( 0, height );
        bottom = _wpi_cvth_y( SQR_SIZE + 1, height );

        _wpi_rectangle( mempres, left_sqr, top, left_sqr+SQR_SIZE+1, bottom );
        _wpi_selectobject( mempres, oldbrush );
        _wpi_deleteobject( colourbrush );
        colour = RGB(Palette[COLOUR_16][i+1].rgbRed,
                     Palette[COLOUR_16][i+1].rgbGreen,
                     Palette[COLOUR_16][i+1].rgbBlue);
        colourbrush = _wpi_createsolidbrush( colour );
        oldbrush = _wpi_selectobject( mempres, colourbrush );

        top = _wpi_cvth_y( SQR_SIZE, height );
        bottom = _wpi_cvth_y( 2*SQR_SIZE + 1, height );

        _wpi_rectangle( mempres, left_sqr, top, left_sqr+SQR_SIZE+1, bottom );
        _wpi_selectobject( mempres, oldbrush );
        _wpi_deleteobject( colourbrush );

        left_sqr += SQR_SIZE;
    }

    _wpi_selectobject( mempres, oldbitmap );
    oldbitmap = _wpi_selectobject( mempres, *monobitmap );

    left_sqr = 0;
    for (i = 0; i < PALETTE_SIZE; i+=2) {
        colour = RGB(Palette[COLOUR_2][i].rgbRed,
                     Palette[COLOUR_2][i].rgbGreen,
                     Palette[COLOUR_2][i].rgbBlue);
        colourbrush = _wpi_createsolidbrush( colour );
        oldbrush = _wpi_selectobject( mempres, colourbrush );

        top = _wpi_cvth_y( 0, height );
        bottom = _wpi_cvth_y( SQR_SIZE + 1, height );

        _wpi_rectangle( mempres, left_sqr, top, left_sqr+SQR_SIZE+1, bottom );
        _wpi_selectobject( mempres, oldbrush );
        _wpi_deleteobject( colourbrush );

        colour = RGB(Palette[COLOUR_2][i+1].rgbRed,
                     Palette[COLOUR_2][i+1].rgbGreen,
                     Palette[COLOUR_2][i+1].rgbBlue);
        colourbrush = _wpi_createsolidbrush( colour );
        oldbrush = _wpi_selectobject( mempres, colourbrush );

        top = _wpi_cvth_y( SQR_SIZE, height );
        bottom = _wpi_cvth_y( 2*SQR_SIZE + 1, height );

        _wpi_rectangle( mempres, left_sqr, top, left_sqr+SQR_SIZE+1, bottom );
        _wpi_selectobject( mempres, oldbrush );
        _wpi_deleteobject( colourbrush );

        left_sqr += SQR_SIZE;
    }
    _wpi_selectobject( mempres, oldbitmap );
    _wpi_selectobject( mempres, oldpen );
    _wpi_deletecompatiblepres( mempres, hdc );
    _wpi_deleteobject( blackpen );

} /* InitPaletteBitmaps */

⌨️ 快捷键说明

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