bool platform_support::load_img_from_dc(unsigned idx, HDC hdc)
    {
        if(idx < max_images) 
        {
#ifndef _MG_MINIMALGRAF
            if(m_specific->m_surf_img[idx]) 
                UnloadBitmap(m_specific->m_surf_img[idx]);
            else
                m_specific->m_surf_img[idx] = (PBITMAP)calloc(1, sizeof(BITMAP)); 
#endif

#if 0
            if (LoadBitmapFromMem(m_specific->m_surf_window, 
                                m_specific->m_surf_img[idx], 
                                (const void *)LockDC(hdc, NULL, NULL, NULL, NULL), 
                                0,
                                "bmp") != 0)
#else
            HDC tmpdc = CreateCompatibleDC(m_specific->m_surf_window);
            if(tmpdc == HDC_INVALID)
                return false;

            BitBlt(hdc, 0, 0, 0, 0, tmpdc, 0, 0, 0);
            if ( !GetBitmapFromDC(tmpdc, 
                            0, 0, 240, 320, 
                            m_specific->m_surf_img[idx]) )
#endif
            {
                DeleteCompatibleDC(tmpdc);
                return false;
            }

            DeleteCompatibleDC(tmpdc);
#if 0
            FillBoxWithBitmap(HDC_SCREEN, 350, 0, 0, 0, 
                    m_specific->m_surf_img[idx]);
            //BitBlt(hdc, 0, 0, 0, 0, HDC_SCREEN, 500, 0, true);
#endif

#if 0
            printf("load img: w=%d, h=%d, pitch=%d, pixels=%x\n", 
                    m_specific->m_surf_img[idx]->bmWidth, 
                    m_specific->m_surf_img[idx]->bmHeight, 
                    m_specific->m_surf_img[idx]->bmPitch, 
                    m_specific->m_surf_img[idx]->bmBits);
#endif
            m_rbuf_img[idx].attach(m_specific->m_surf_img[idx]->bmBits, 
                    m_specific->m_surf_img[idx]->bmWidth, 
                    m_specific->m_surf_img[idx]->bmHeight, 
                    m_flip_y?(-m_specific->m_surf_img[idx]->bmPitch):
                            m_specific->m_surf_img[idx]->bmPitch);
            return true;
        }
        return false;
    }
    bool platform_support::load_img_from_bitmap(unsigned idx, PBITMAP pbmp)
    {
        if(idx < max_images) 
        {
            int ret = FALSE;

#ifndef _MG_MINIMALGRAF
            if(m_specific->m_surf_img[idx]) 
                UnloadBitmap(m_specific->m_surf_img[idx]);
            else
                m_specific->m_surf_img[idx] = (PBITMAP)calloc(1, sizeof(BITMAP)); 
#endif

            HDC tmpdc = CreateCompatibleDC(m_specific->m_surf_window);
            HDC tmpdc2 = CreateCompatibleDC(HDC_SCREEN);

            if(tmpdc == HDC_INVALID)
                return false;

            FillBoxWithBitmap(tmpdc2, 0, 0, pbmp->bmWidth, pbmp->bmHeight, 
                    pbmp);

            BitBlt(tmpdc2, 0, 0, 0, 0, tmpdc, 0, 0, 0);
            do {
                if (!GetBitmapFromDC(tmpdc, 
                            0, 0, 240, 320, 
                            m_specific->m_surf_img[idx]))
                {
                    ret = FALSE;
                    break;
                }
                m_rbuf_img[idx].attach(m_specific->m_surf_img[idx]->bmBits, 
                        m_specific->m_surf_img[idx]->bmWidth, 
                        m_specific->m_surf_img[idx]->bmHeight, 
                        m_flip_y?(-m_specific->m_surf_img[idx]->bmPitch):
                        m_specific->m_surf_img[idx]->bmPitch);

                ret = TRUE;

            } while(FALSE);

            DeleteCompatibleDC(tmpdc);
            DeleteCompatibleDC(tmpdc2);

            return ret;
        }
        return false;
    }
Esempio n. 3
0
static void setup_anim_mem_dc (HWND hwnd, ANIMATIONINFO* anim_info)
{
    gal_pixel bk_pixel;
    HDC hdc;

    if (!anim_info->anim)
        return;

    if (anim_info->mem_dc)
        DeleteCompatibleDC (anim_info->mem_dc);
    hdc = GetClientDC (hwnd);
#ifdef _USE_NEWGAL
    anim_info->mem_dc = CreateCompatibleDCEx (hdc,
                    anim_info->anim->width, anim_info->anim->height);
#else
    anim_info->mem_dc = CreateCompatibleDC (hdc);
#endif

    if (GetWindowExStyle (hwnd) & WS_EX_TRANSPARENT)
        bk_pixel = GetWindowBkColor (GetParent (hwnd));
    else
        bk_pixel = GetWindowBkColor (hwnd);

    SetBkColor (anim_info->mem_dc, bk_pixel);
    SetBrushColor (anim_info->mem_dc, bk_pixel);
    FillBox (anim_info->mem_dc, 0, 0,
            GetGDCapability (hdc, GDCAP_MAXX)+1,
            GetGDCapability (hdc, GDCAP_MAXY)+1);

    ReleaseDC (hdc);
}
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. 5
0
static int AnimationCtrlProc (HWND hwnd, int message, WPARAM wParam, LPARAM lParam)
{
    ANIMATIONINFO* anim_info = (ANIMATIONINFO*)GetWindowAdditionalData2 (hwnd);

    switch (message) {
    case MSG_CREATE:
        if (!HaveFreeTimer ()) {
            fprintf (stderr,
                     "Animation error : no free timer is available!\n");
            return -1;
        }
        anim_info = (ANIMATIONINFO*) calloc (1, sizeof (ANIMATIONINFO));
        if (anim_info == NULL)
            return -1;

        SetWindowAdditionalData2 (hwnd, (DWORD)anim_info);
        if(lParam)
            SendMessage (hwnd, ANM_SETANIMATION, 0, lParam);
        break;

    case MSG_DESTROY:
        if (anim_info->mem_dc)
                DeleteCompatibleDC (anim_info->mem_dc);
        free (anim_info);
        /* timer will be freed automatically */
        //KillTimer (hwnd, ID_TIMER);
        break;

    case MSG_TIMER:
        if(anim_info->anim == NULL)
            return 0;
        if (anim_info->status == ANIM_STATUS_PLAY) {
            int delay_time = -1;
            if(anim_info->current) {
                delay_time = anim_info->current->delay_time;
            }
            anim_info->elapsed_10ms++;
            if (delay_time > 0 && anim_info->elapsed_10ms >= delay_time) {
                next_frame (hwnd, anim_info);
                anim_info->elapsed_10ms = 0;
            }
        }
        return 0;

    case MSG_PAINT: {

        HDC hdc;
        HDC src_dc;
        RECT rc_anim;

        if (!anim_info->mem_dc)
            break;

        hdc = BeginPaint (hwnd);
        src_dc = anim_info->mem_dc;

        if (GetWindowStyle (hwnd) & ANS_SCALED) {
            GetClientRect (hwnd, &rc_anim);
        } else {
            SetRect (&rc_anim, 0, 0, anim_info->anim->width,
                     anim_info->anim->height);
        }

        if (RECTW (rc_anim) == anim_info->anim->width
            && RECTH (rc_anim) == anim_info->anim->height) {
            BitBlt (anim_info->mem_dc, 0, 0, 0, 0, hdc, 0, 0, 0);
        } else {
            StretchBlt (anim_info->mem_dc, 0, 0,
                        anim_info->anim->width, anim_info->anim->height,
                        hdc,
                        0, 0,
                        RECTW (rc_anim), RECTH (rc_anim), 0);
        }

        EndPaint (hwnd, hdc);
        return 0;
    }

    case ANM_SETANIMATION: {

          ANIMATION* old = anim_info->anim;
          anim_info->anim = (ANIMATION*)lParam;
          anim_info->current = NULL;
          if (anim_info->anim) {
              KillTimer (hwnd, ID_TIMER);
              if (GetWindowStyle (hwnd) & ANS_FITTOANI) {
                  RECT rc;
                  GetWindowRect(hwnd, &rc);
                  MoveWindow(hwnd, rc.left, rc.top,
                             anim_info->anim->width,
                             anim_info->anim->height, FALSE);
              }
              anim_info->current = NULL;
              setup_anim_mem_dc(hwnd, anim_info);
              next_frame(hwnd, anim_info);
              anim_info->elapsed_10ms = 0;
              //SetTimer (hwnd, ID_TIMER, anim_info->anim->time_unit);
              SetTimer (hwnd, ID_TIMER, 10);
          }
          return (int)old;
      }

    case ANM_GETANIMATION:
        return (int)anim_info->anim;

    case ANM_STARTPLAY: {

        if (anim_info->anim) {
            anim_info->current = NULL;
            anim_info->status = ANIM_STATUS_PLAY;
            next_frame(hwnd, anim_info);
            anim_info->elapsed_10ms = 0;
        }
        return 0;
    }
    case ANM_PAUSE_RESUME:
        if(anim_info->anim)
        {
            if (anim_info->status == ANIM_STATUS_PLAY)
                anim_info->status = ANIM_STATUS_STOP;
            else
                anim_info->status = ANIM_STATUS_PLAY;
        }
        return 0;

    case ANM_STOPPLAY:
        if(anim_info->anim)
        {
            anim_info->current = NULL;
            anim_info->status = ANIM_STATUS_STOP;
            next_frame (hwnd, anim_info); //back to the first frame
            anim_info->elapsed_10ms = 0;
            InvalidateRect (hwnd, NULL, FALSE);
            }
        return 0;

    case MSG_LBUTTONDBLCLK:
        NotifyParent (hwnd, GetDlgCtrlID (hwnd), ANNC_DBLCLK);
        break;

    case MSG_LBUTTONDOWN:
        NotifyParent (hwnd, GetDlgCtrlID (hwnd), ANNC_CLICKED);
        break;

        default:
            break;
    }

    return DefaultControlProc (hwnd, message, wParam, lParam);
}