~ubuntu-branches/debian/wheezy/vlc/wheezy

« back to all changes in this revision

Viewing changes to modules/gui/skins/win32/win32_bitmap.cpp

Tags: upstream-0.7.2.final
Import upstream version 0.7.2.final

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*****************************************************************************
 
2
 * win32_bitmap.cpp: Win32 implementation of the Bitmap class
 
3
 *****************************************************************************
 
4
 * Copyright (C) 2003 VideoLAN
 
5
 * $Id: win32_bitmap.cpp 6961 2004-03-05 17:34:23Z sam $
 
6
 *
 
7
 * Authors: Olivier Teuli�re <ipkiss@via.ecp.fr>
 
8
 *          Emmanuel Puig    <karibu@via.ecp.fr>
 
9
 *
 
10
 * This program is free software; you can redistribute it and/or modify
 
11
 * it under the terms of the GNU General Public License as published by
 
12
 * the Free Software Foundation; either version 2 of the License, or
 
13
 * (at your option) any later version.
 
14
 *
 
15
 * This program is distributed in the hope that it will be useful,
 
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
18
 * GNU General Public License for more details.
 
19
 *
 
20
 * You should have received a copy of the GNU General Public License
 
21
 * along with this program; if not, write to the Free Software
 
22
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111,
 
23
 * USA.
 
24
 *****************************************************************************/
 
25
 
 
26
#ifdef WIN32
 
27
 
 
28
//--- WIN32 -----------------------------------------------------------------
 
29
#define WINVER  0x0500
 
30
#include <windows.h>
 
31
 
 
32
//--- VLC -------------------------------------------------------------------
 
33
#include <vlc/intf.h>
 
34
 
 
35
//--- SKIN ------------------------------------------------------------------
 
36
#include "../os_api.h"
 
37
#include "../src/graphics.h"
 
38
#include "win32_graphics.h"
 
39
#include "../src/bitmap.h"
 
40
#include "win32_bitmap.h"
 
41
#include "../src/skin_common.h"
 
42
 
 
43
 
 
44
 
 
45
//---------------------------------------------------------------------------
 
46
//   Win32Bitmap
 
47
//---------------------------------------------------------------------------
 
48
Win32Bitmap::Win32Bitmap( intf_thread_t *p_intf, string FileName, int AColor )
 
49
    : Bitmap( p_intf, FileName, AColor )
 
50
{
 
51
    HBITMAP HBitmap;
 
52
    HBITMAP HBuf;
 
53
    BITMAP  Bmp;
 
54
    HDC     bufDC;
 
55
 
 
56
    // Create image from file if it exists
 
57
    HBitmap = (HBITMAP) LoadImage( NULL, FileName.c_str(), IMAGE_BITMAP,
 
58
                                   0, 0, LR_LOADFROMFILE );
 
59
    if( HBitmap == NULL )
 
60
    {
 
61
        if( FileName != "" )
 
62
            msg_Warn( p_intf, "Couldn't load bitmap: %s", FileName.c_str() );
 
63
 
 
64
        HBitmap = CreateBitmap( 0, 0, 1, 32, NULL );
 
65
    }
 
66
 
 
67
    // Create device context
 
68
    bmpDC   = CreateCompatibleDC( NULL );
 
69
    SelectObject( bmpDC, HBitmap );
 
70
 
 
71
    // Get size of image
 
72
    GetObject( HBitmap, sizeof( Bmp ), &Bmp );
 
73
    Width  = Bmp.bmWidth;
 
74
    Height = Bmp.bmHeight;
 
75
 
 
76
    // If alpha color is not 0, then change 0 color to non black color to avoid
 
77
    // window transparency
 
78
    if( (int)AlphaColor != OSAPI_GetNonTransparentColor( 0 ) )
 
79
    {
 
80
        bufDC = CreateCompatibleDC( bmpDC );
 
81
        HBuf = CreateCompatibleBitmap( bmpDC, Width, Height );
 
82
        SelectObject( bufDC, HBuf );
 
83
 
 
84
        LPRECT r = new RECT;
 
85
        HBRUSH Brush = CreateSolidBrush( OSAPI_GetNonTransparentColor( 0 ) );
 
86
        r->left   = 0;
 
87
        r->top    = 0;
 
88
        r->right  = Width;
 
89
        r->bottom = Height;
 
90
        FillRect( bufDC, r, Brush );
 
91
        DeleteObject( Brush );
 
92
        delete r;
 
93
 
 
94
        if( p_intf->p_sys->TransparentBlt && IS_WINNT )
 
95
        {
 
96
            // This function contains a memory leak on win95/win98
 
97
            p_intf->p_sys->TransparentBlt( bufDC, 0, 0, Width, Height,
 
98
                                           bmpDC, 0, 0, Width, Height, 0 );
 
99
        }
 
100
        else
 
101
        {
 
102
            BitBlt( bufDC, 0, 0, Width, Height, bmpDC, 0, 0, SRCCOPY );
 
103
        }
 
104
 
 
105
        BitBlt( bmpDC, 0, 0, Width, Height, bufDC, 0, 0, SRCCOPY );
 
106
        DeleteDC( bufDC );
 
107
        DeleteObject( HBuf );
 
108
    }
 
109
 
 
110
    // Delete objects
 
111
    DeleteObject( HBitmap );
 
112
}
 
113
//---------------------------------------------------------------------------
 
114
Win32Bitmap::Win32Bitmap( intf_thread_t *p_intf, Graphics *from, int x, int y,
 
115
    int w, int h, int AColor ) : Bitmap( p_intf, from, x, y, w, h, AColor )
 
116
{
 
117
    Width  = w;
 
118
    Height = h;
 
119
    AlphaColor = AColor;
 
120
    HBITMAP HBmp;
 
121
    HDC fromDC = ( (Win32Graphics *)from )->GetImageHandle();
 
122
 
 
123
    // Create image
 
124
    bmpDC = CreateCompatibleDC( fromDC );
 
125
    HBmp  = CreateCompatibleBitmap( fromDC, Width, Height );
 
126
    SelectObject( bmpDC, HBmp );
 
127
    DeleteObject( HBmp );
 
128
    BitBlt( bmpDC, 0, 0, Width, Height, fromDC, x, y, SRCCOPY );
 
129
}
 
130
//---------------------------------------------------------------------------
 
131
Win32Bitmap::Win32Bitmap( intf_thread_t *p_intf, Bitmap *c )
 
132
    : Bitmap( p_intf, c )
 
133
{
 
134
    HBITMAP HBuf;
 
135
 
 
136
    // Copy attibutes
 
137
    c->GetSize( Width, Height );
 
138
    AlphaColor = c->GetAlphaColor();
 
139
 
 
140
    // Copy bmpDC
 
141
    bmpDC = CreateCompatibleDC( NULL );
 
142
    HBuf  = CreateCompatibleBitmap( bmpDC, Width, Height );
 
143
    SelectObject( bmpDC, HBuf );
 
144
 
 
145
    BitBlt( bmpDC, 0, 0, Width, Height, ( (Win32Bitmap *)c )->GetBmpDC(),
 
146
            0, 0, SRCCOPY );
 
147
    DeleteObject( HBuf );
 
148
}
 
149
//---------------------------------------------------------------------------
 
150
Win32Bitmap::~Win32Bitmap()
 
151
{
 
152
    DeleteDC( bmpDC );
 
153
}
 
154
//---------------------------------------------------------------------------
 
155
void Win32Bitmap::DrawBitmap( int x, int y, int w, int h, int xRef, int yRef,
 
156
                              Graphics *dest )
 
157
{
 
158
    HDC destDC = ( (Win32Graphics *)dest )->GetImageHandle();
 
159
 
 
160
    if( p_intf->p_sys->TransparentBlt && IS_WINNT )
 
161
    {
 
162
        // This function contains a memory leak on win95/win98
 
163
        p_intf->p_sys->TransparentBlt( destDC, xRef, yRef, w, h,
 
164
                                       bmpDC, x, y, w, h, AlphaColor );
 
165
    }
 
166
    else
 
167
    {
 
168
        BitBlt( destDC, xRef, yRef, w, h, bmpDC, x, y, SRCCOPY );
 
169
    }
 
170
}
 
171
//---------------------------------------------------------------------------
 
172
bool Win32Bitmap::Hit( int x, int y)
 
173
{
 
174
    unsigned int c = GetPixel( bmpDC, x, y );
 
175
    if( c == AlphaColor || c == CLR_INVALID )
 
176
        return false;
 
177
    else
 
178
        return true;
 
179
 
 
180
}
 
181
//---------------------------------------------------------------------------
 
182
int Win32Bitmap::GetBmpPixel( int x, int y )
 
183
{
 
184
    return GetPixel( bmpDC, x, y );
 
185
}
 
186
//---------------------------------------------------------------------------
 
187
void Win32Bitmap::SetBmpPixel( int x, int y, int color )
 
188
{
 
189
    SetPixelV( bmpDC, x, y, color );
 
190
}
 
191
//---------------------------------------------------------------------------
 
192
 
 
193
#endif