GetClassInfo should return global classes even if the hInstance
[wine] / graphics / dispdib.c
1 /*
2  * DISPDIB.dll
3  * 
4  * Copyright 1998 Ove Kåven (with some help from Marcus Meissner)
5  *
6  */
7
8 #include <string.h>
9 #include "windef.h"
10 #include "wingdi.h"
11 #include "wine/wingdi16.h"
12 #include "miscemu.h"
13 #include "dispdib.h"
14 #include "vga.h"
15 #include "debugtools.h"
16
17 DEFAULT_DEBUG_CHANNEL(ddraw);
18
19 static int dispdib_multi = 0;
20
21 static WORD DISPDIB_Begin(WORD wFlags)
22 {
23     unsigned Xres,Yres,Depth;
24
25     switch(wFlags&DISPLAYDIB_MODE) {
26         case DISPLAYDIB_MODE_DEFAULT:
27             /* FIXME: is this supposed to autodetect? */
28         case DISPLAYDIB_MODE_320x200x8:
29             Xres=320; Yres=200; Depth=8; break;
30         case DISPLAYDIB_MODE_320x240x8:
31             Xres=320; Yres=240; Depth=8; break;
32         default:
33             return DISPLAYDIB_NOTSUPPORTED;
34     }
35     /* more or less dummy calls to Death/Resurrection, for completeness */
36     /* FIXME: what arguments should they get? */
37     Death16(0);
38     if (VGA_SetMode(Xres,Yres,Depth)) {
39          Resurrection16(0,0,0,0,0,0,0);
40          return DISPLAYDIB_NOTSUPPORTED;
41     }
42     return DISPLAYDIB_NOERROR;
43 }
44
45 static void DISPDIB_End(void)
46 {
47     Resurrection16(0,0,0,0,0,0,0); /* FIXME: arguments */
48     VGA_Exit();
49 }
50
51 static void DISPDIB_Palette(LPBITMAPINFO lpbi)
52 {
53     VGA_SetQuadPalette(lpbi->bmiColors,0,256);
54 }
55
56 static void DISPDIB_Show(LPBITMAPINFOHEADER lpbi,LPSTR lpBits,WORD uFlags)
57 {
58     int Xofs,Yofs,Width=lpbi->biWidth,Height=lpbi->biHeight,Delta;
59     unsigned Pitch=(Width+3)&~3,sPitch,sWidth,sHeight;
60     LPSTR surf = DOSMEM_MapDosToLinear(0xa0000);
61
62     if (VGA_GetMode(&sHeight,&sWidth,NULL)) return;
63     sPitch=320;
64
65     Delta=(Height<0)*2-1;
66     Height*=-Delta; Pitch*=Delta;
67
68     if (uFlags&DISPLAYDIB_NOCENTER) {
69         Xofs=0; Yofs=0;
70     } else {
71         Xofs=(sWidth-Width)/2;
72         Yofs=(sHeight-Height)/2;
73     }
74     surf += (Yofs*sPitch)+Xofs;
75     if (Pitch<0) lpBits-=Pitch*(Height-1);
76     for (; Height; Height--,lpBits+=Pitch,surf+=sPitch) {
77         memcpy(surf,lpBits,Width);
78     }
79
80     VGA_Poll(0);
81 }
82
83 /*********************************************************************
84  *      DisplayDib      (DISPDIB.1)
85  *
86  *  Disables GDI and takes over the VGA screen to show DIBs in full screen.
87  *
88  * FLAGS
89  *
90  *  DISPLAYDIB_NOPALETTE: don't change palette
91  *  DISPLAYDIB_NOCENTER: don't center bitmap
92  *  DISPLAYDIB_NOWAIT: don't wait (for keypress) before returning
93  *  DISPLAYDIB_BEGIN: start of multiple calls (does not restore the screen)
94  *  DISPLAYDIB_END: end of multiple calls (restores the screen)
95  *  DISPLAYDIB_MODE_DEFAULT: default display mode
96  *  DISPLAYDIB_MODE_320x200x8: Standard VGA 320x200 256 colors
97  *  DISPLAYDIB_MODE_320x240x8: Tweaked VGA 320x240 256 colors
98  *
99  * RETURNS
100  *
101  *  DISPLAYDIB_NOERROR: success
102  *  DISPLAYDIB_NOTSUPPORTED: function not supported
103  *  DISPLAYDIB_INVALIDDIB: null or invalid DIB header
104  *  DISPLAYDIB_INVALIDFORMAT: invalid DIB format
105  *  DISPLAYDIB_INVALIDTASK: not called from current task
106  *
107  * BUGS
108  *
109  *  Waiting for keypresses is not implemented.
110  */
111 WORD WINAPI DisplayDib(
112                 LPBITMAPINFO lpbi, /* DIB header with resolution and palette */
113                 LPSTR lpBits, /* Bitmap bits to show */
114                 WORD wFlags
115         )
116 {
117     WORD ret;
118
119     if (wFlags&DISPLAYDIB_END) {
120         if (dispdib_multi) DISPDIB_End();
121         dispdib_multi = 0;
122         return DISPLAYDIB_NOERROR;
123     }
124     if (!dispdib_multi) {
125         ret=DISPDIB_Begin(wFlags);
126         if (ret) return ret;
127     }
128     if (wFlags&DISPLAYDIB_BEGIN) dispdib_multi = 1;
129     if (!(wFlags&DISPLAYDIB_NOPALETTE)) {
130         DISPDIB_Palette(lpbi);
131     }
132     /* FIXME: not sure if it's valid to draw images in DISPLAYDIB_BEGIN, so... */
133     if (lpBits) {
134         DISPDIB_Show(&(lpbi->bmiHeader),lpBits,wFlags);
135     }
136     if (!(wFlags&DISPLAYDIB_NOWAIT)) {
137         FIXME("wait not implemented\n");
138     }
139     if (!dispdib_multi) DISPDIB_End();
140     return DISPLAYDIB_NOERROR;
141 }