Esempio n. 1
0
static int DrawYSpace ( HDC hdc, int x, int y, int w, int h, PSCOLORDIA scld)
{
    int i;
    Uint8 r, g, b;
    HDC mdc;
    
    mdc = CreateCompatibleDCEx (hdc, scld->ysp_w, 256);
    for (i = 0; i < 256; i ++) {
        HSV2RGB (scld->clrh, scld->clrs, i, &r, &g, &b );
        SetPenColor (mdc, RGB2Pixel(mdc, r, g, b));
        MoveTo (mdc, 0, i);
        LineTo (mdc, 20 * scld->SCALE_W, i);
    }
    SetBrushColor (mdc, PIXEL_lightgray);
    FillBox (mdc, 21 * scld->SCALE_W, 0, scld->ysp_w * scld->SCALE_W, 256);
    scld->pz = scld->clrv ;
    SetPenColor (mdc, RGB2Pixel(mdc, 0, 0, 0));
    MoveTo ( mdc, 21 * scld->SCALE_W, scld->pz);
    LineTo ( mdc, 28 * scld->SCALE_W, scld->pz-3);
    MoveTo ( mdc, 21 * scld->SCALE_W, scld->pz);
    LineTo ( mdc, 28 * scld->SCALE_W, scld->pz+3);
    StretchBlt (mdc, 0, 0, scld->ysp_w, 256, hdc, x, y, w, h, 0);
    DeleteMemDC (mdc);
    return 0;
}
Esempio n. 2
0
static gal_pixel anim_get_color_key (ANIMATIONINFO* anim_info)
{
    int i;
    gal_pixel pixel;
    struct gal_pixel_table table;
    GAL_Color* colors;
    ANIMATIONFRAME* f;

    if (anim_info == NULL)
        return PIXEL_black;
    if (anim_info->anim == NULL)
        return PIXEL_black;

    table.size = 256;
    table.count = 0;
    table.colors = NULL;
    f = anim_info->anim->frames;
    colors = calloc(256, sizeof(GAL_Color));
    while(f)
    {
        int colornum = GetGDCapability(f->mem_dc, GDCAP_COLORNUM);
        if(colornum > 256)
            colornum = 256;
        GetPalette(f->mem_dc, 0, colornum, colors);
        for(i=0; i< colornum; i++)
        {
            pixel = RGB2Pixel(anim_info->mem_dc,
                            colors[i].r, colors[i].g, colors[i].b);
            add_pixel_to_gal_colors(&table, pixel);
        }
        f = f->next;
    }
    free (colors);
    for(i=0; i<256; i++) // we try 256 times.
    {
        int r, g, b;
        r = rand()/(RAND_MAX/256);
        g = rand()/(RAND_MAX/256);
        b = rand()/(RAND_MAX/256);
        pixel = RGB2Pixel(anim_info->mem_dc, r, g, b);
        if(!is_pixel_in_gal_colors(&table, pixel)) {
            free (table.colors);
            return pixel;
        }
    }
    free (table.colors);
    return PIXEL_lightwhite;
}
Esempio n. 3
0
static int DrawIndication (HDC hdc, PSCOLORDIA scld)
{
    scld->px = scld->clrh * scld->sp_w/360;
    scld->py = scld->sp_h - scld->clrs * scld->sp_h/255;
    SetBrushColor (hdc, RGB2Pixel (hdc, 0, 0, 0));
    Circle(hdc, scld->px, scld->py, 5);
    return 0;
}
Esempio n. 4
0
static int DrawSelSpace (HDC hdc, int x, int y, int w, int h, PSCOLORDIA scld)
{
    Uint8 r, g, b;
    HDC mdc;
    
    mdc = CreateCompatibleDCEx (hdc, w, h);
    HSV2RGB (scld->clrh, scld->clrs, scld->clrv, &r, &g, &b);
    SetBrushColor (mdc, RGB2Pixel(mdc, r, g, b));
    FillBox (mdc, 0, 0, w, h);
    BitBlt (mdc, 0, 0, w, h, hdc, x, y, 0);
    DeleteMemDC (mdc);
    return 0;
}
static void setup_palette(void)
{
    int i;

    use_putbox = 0;

    if (GetGDCapability (HDC_SCREEN, GDCAP_DEPTH) == 8)
        use_putbox = 1;

    for (i=0; i < 256; i++) {

        GAL_Color col;

        col.r = ((i >> 5) & 7) * 0xffff / 7;
        col.g = ((i >> 2) & 7) * 0xffff / 7;
        col.b = ((i)      & 3) * 0xffff / 3;

        lookup[i] = RGB2Pixel (HDC_SCREEN, col.r, col.g, col.b);
    }
}
static int PaletteWndProc(HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
	
	switch ( message ) {
	case MSG_SETCURSOR:
        SetCursorEx(0, FALSE);
        return 0;
 case MSG_CREATE:
        /* fill our palette with a gradually altering sequence of colors */
        for (c=0; c<64; c++) {
            palette[c].r = c*4;
            palette[c].g = 0;
            palette[c].b = 0;
        }
        for (c=64; c<128; c++) {
            palette[c].r = (127-c)*4;
            palette[c].g = (c-64)*4;
            palette[c].b = 0;
        }
        for (c=128; c<192; c++) {
            palette[c].r = 0;
            palette[c].g = (191-c)*4;
            palette[c].b = (c-128)*4;
        }
        for (c=192; c<256; c++) {
            palette[c].r = 0;
            palette[c].g = 0;
            palette[c].b = (255-c)*4;
        }
        SetTimer(hWnd, IDT_PAL, 1); 
        mem_dc = CreateCompatibleDC (hdc);
	break;
	case MSG_TIMER:
		switch(wParam){
            case IDT_PAL:
		temp = palette[255];
		for (c =255; c>0; c--)
		palette[c] = palette [c-1];
		palette[0] = temp;
		SetPalette(mem_dc, 0, 255, palette);

                for (c=255; c>0; c--){
                    pix = RGB2Pixel (mem_dc, palette[c].r, palette[c].g, palette[c].b);
                    SetBrushColor (mem_dc, pix);
                    FillCircle (mem_dc, SCREEN_W/2, SCREEN_H/2, c);
                }
		InvalidateRect (hWnd , NULL , FALSE);
                break;
        }
        break;
	case MSG_PAINT:
		hdc = BeginPaint(hWnd);	
		BitBlt (mem_dc, 0, 0, SCREEN_W, SCREEN_H, hdc, 0, 0, 0);
                
		EndPaint(hWnd, hdc);
	break;
	case MSG_CLOSE:
		KillTimer(hWnd , IDT_PAL);
		DeleteCompatibleDC(mem_dc);
		DestroyMainWindow (hWnd);
		PostQuitMessage (hWnd);
		break;
	}
		

	return DefaultMainWinProc(hWnd, message, wParam, lParam);
}
Esempio n. 7
0
static int HelloWinProc (HWND hWnd, int message, WPARAM wParam, LPARAM lParam)
{
HDC hdc;
static HWND hwnd;
static int i = 0;
switch (message) {
case MSG_PAINT:
hdc = BeginPaint (hWnd);
TextOut (hdc, 60, 60, "Hello world!");
EndPaint (hWnd, hdc);
return 0;
case 888888888888888888:
        {

            HDC hdc2 = (HDC)wParam;
            const RECT* clip = (const RECT*) lParam;
            BOOL fGetDC = FALSE;
            RECT rcTemp;

            if (hdc2 == 0) {
                hdc2 = GetClientDC (hWnd);
                fGetDC = TRUE;
            }

            if (clip) {
                rcTemp = *clip;
                ScreenToClient (hWnd, &rcTemp.left, &rcTemp.top);
                ScreenToClient (hWnd, &rcTemp.right, &rcTemp.bottom);
                IncludeClipRect (hdc2, &rcTemp);
            }

            FillBoxWithBitmap (HDC_SCREEN, 0, 0, 0, 0, &bmp_bkgnd);

            if (fGetDC)
                ReleaseDC (hdc2);
            return 0;
        }
        break;
case MSG_CREATE:
	hwnd = CreateWindowEx("static", "",
			WS_CHILD | WS_VISIBLE,
			WS_EX_NONE,
			123,
			0, 0, 50, 50,
			hWnd, NULL);
	SetWindowBkColor(hwnd, RGBA2Pixel(HDC_SCREEN, 0x00, 0x00, 0xff, 0x10));
break;
case MSG_KEYDOWN:
	if (i) {
	SetWindowBkColor(hwnd, RGBA2Pixel(HDC_SCREEN, 0x00, 0x00, 0xff, 0x10));
	} else {
	SetWindowBkColor(hwnd, RGB2Pixel(HDC_SCREEN, 0x00, 0xff, 0xff));
	}
	i = 1-i;
break;
case MSG_CLOSE:
DestroyMainWindow (hWnd);
PostQuitMessage (hWnd);
return 0;

}
return DefaultMainWinProc (hWnd, message, wParam, lParam);
}
Esempio n. 8
0
static int ColorDlgProc (HWND hDlg, int message, WPARAM wParam, LPARAM lParam)
{
    PSCOLORDIA scld;

    switch (message) {
    case MSG_INITDIALOG:
        {
            int i, j;
            Uint8 r, g, b;
            HDC hdc, mdc;
            
            scld = (PSCOLORDIA)lParam;
            SetWindowAdditionalData (hDlg, (LPARAM)scld);

            hdc = GetClientDC (hDlg);
            scld->SpaceDC = CreateCompatibleDCEx(hdc, scld->sp_w, scld->sp_h);
            mdc = CreateCompatibleDCEx (hdc, 360, 256);
            for (i =  0; i < 360; i ++) {
                for (j = 0; j < 256; j ++) {
                    HSV2RGB (i, j, 200, &r, &g, &b);
                    SetPixelRGB(mdc, i, 256-j, r, g, b);
                }
            }
            
            StretchBlt(mdc, 0, 0, 360, 256, scld->SpaceDC, 0, 0, scld->sp_w, scld->sp_h, 0);
            DeleteMemDC(mdc);
            ReleaseDC(hdc);
        }        
        break;

    case MSG_CLOSE:
        EndDialog (hDlg, SELCOLOR_CANCEL);
        break;

    case MSG_DESTROY:
        scld = (PSCOLORDIA)GetWindowAdditionalData (hDlg);
        DeleteMemDC (scld->SpaceDC);
        break;

    case MSG_PAINT:
    {
        HDC hdc;

        scld = (PSCOLORDIA)GetWindowAdditionalData (hDlg);
        hdc = BeginPaint (hDlg);
        DrawAllSpace (hdc, scld);
        EndPaint (hDlg, hdc);
        return 0;
    }

    case MSG_COMMAND:
    {
        int msg = HIWORD(wParam);
        int id = LOWORD(wParam);

        scld = (PSCOLORDIA)GetWindowAdditionalData (hDlg);

        if (msg == EN_CONTCHANGED) {
            UpdateValue (hDlg, id, scld);
        }

        switch(id) {
        case IDC_CANCEL:
            EndDialog (hDlg, SELCOLOR_CANCEL);
            break;
        case IDC_OK:
            scld->H = scld->clrh;
            scld->S = scld->clrs;
            scld->V = scld->clrv;
            HSV2RGB (scld->clrh, scld->clrs, scld->clrv, &scld->R, &scld->G, &scld->B);
            scld->PIXEL = RGB2Pixel (HDC_SCREEN, scld->R, scld->G, scld->B);
            EndDialog (hDlg, SELCOLOR_OK);
            break;
        }
        break;
    }

    case MSG_LBUTTONDOWN:
    {
        int x = LOSWORD (lParam);
        int y = HISWORD (lParam);

        scld = (PSCOLORDIA)GetWindowAdditionalData (hDlg);

        if (PtInRect (&scld->rcSpace, x, y)) {
            HDC dc = GetClientDC (hDlg);
            scld->clrh = (x-scld->rcSpace.left)*360/RECTW(scld->rcSpace);
            scld->clrs = 256-(y-scld->rcSpace.top)*256/RECTH(scld->rcSpace);
            DrawAllSpace (dc, scld);
            SetValue (hDlg, scld);
            ReleaseDC (dc);
        }

        if (PtInRect(&scld->rcYSpace, x,y)) {
            HDC dc = GetClientDC (hDlg);
            scld->clrv = (y-scld->rcYSpace.top)*256 / RECTH(scld->rcYSpace);
            DrawAllSpace (dc, scld);
            SetValue (hDlg, scld);
            ReleaseDC (dc);
        }
    }
    }
    return DefaultDialogProc (hDlg, message, wParam, lParam);
}