[80] | 1 | /********************************************************************** <BR>
|
---|
| 2 | This file is part of Crack dot Com's free source code release of
|
---|
| 3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
| 4 | information about compiling & licensing issues visit this URL</a>
|
---|
| 5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
| 6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
| 7 | ***********************************************************************/
|
---|
| 8 |
|
---|
| 9 | #include "video/win32/dd_cursor.hh"
|
---|
| 10 | #include "video/win32/dx5_util.hh"
|
---|
| 11 | #include "video/win32/dx5_error.hh"
|
---|
| 12 | #include "image/context.hh"
|
---|
| 13 |
|
---|
| 14 | ddraw_thread_cursor_class::ddraw_thread_cursor_class(const i4_pal *screen_pal,
|
---|
| 15 | HWND window_handle,
|
---|
| 16 | sw32 clip_x1, sw32 clip_y1,
|
---|
| 17 | sw32 clip_x2, sw32 clip_y2)
|
---|
| 18 | : dx_threaded_mouse_class(screen_pal,window_handle,clip_x1,clip_y1,clip_x2,clip_y2)
|
---|
| 19 | {
|
---|
| 20 | cursor.pict = 0;
|
---|
| 21 | mouse_save = 0;
|
---|
| 22 |
|
---|
| 23 | current_mouse_x = 0;
|
---|
| 24 | current_mouse_y = 0;
|
---|
| 25 |
|
---|
| 26 | save_mouse_x = 0;
|
---|
| 27 | save_mouse_y = 0;
|
---|
| 28 |
|
---|
| 29 | visible = i4_F;
|
---|
| 30 |
|
---|
| 31 | use_back_buffer = i4_F;
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | void ddraw_thread_cursor_class::set_cursor(i4_cursor_class *c)
|
---|
| 35 | {
|
---|
| 36 | draw_lock.lock();
|
---|
| 37 |
|
---|
| 38 | remove();
|
---|
| 39 |
|
---|
| 40 | if (cursor.pict)
|
---|
| 41 | {
|
---|
| 42 | delete cursor.pict;
|
---|
| 43 | cursor.pict = 0;
|
---|
| 44 | }
|
---|
| 45 |
|
---|
| 46 | if (mouse_save)
|
---|
| 47 | {
|
---|
| 48 | delete mouse_save;
|
---|
| 49 | mouse_save = 0;
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | if (c && c->pict)
|
---|
| 53 | {
|
---|
| 54 | int cw=c->pict->width(), ch=c->pict->height();
|
---|
| 55 |
|
---|
| 56 | i4_draw_context_class context(0,0, cw-1, ch-1);
|
---|
| 57 |
|
---|
| 58 | i4_dx5_image_class *dx5_image = new i4_dx5_image_class(cw, ch, DX5_VRAM);
|
---|
| 59 |
|
---|
| 60 | //setup room for the mouse save
|
---|
| 61 | mouse_save = new i4_dx5_image_class(cw,ch,DX5_VRAM);
|
---|
| 62 |
|
---|
| 63 | //setup the color-key value for the mouse (black)
|
---|
| 64 | DDCOLORKEY colorkey;
|
---|
| 65 | memset(&colorkey,0,sizeof(DDCOLORKEY));
|
---|
| 66 |
|
---|
| 67 | colorkey.dwColorSpaceLowValue = c->trans;
|
---|
| 68 | colorkey.dwColorSpaceHighValue = c->trans;
|
---|
| 69 |
|
---|
| 70 | dx5_image->surface->SetColorKey(DDCKEY_SRCBLT,&colorkey);
|
---|
| 71 |
|
---|
| 72 | cursor = *c;
|
---|
| 73 | cursor.pict = dx5_image;
|
---|
| 74 |
|
---|
| 75 | dx5_image->lock();
|
---|
| 76 | c->pict->put_image(cursor.pict, 0,0, context);
|
---|
| 77 | dx5_image->unlock();
|
---|
| 78 |
|
---|
| 79 | display();
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 | draw_lock.unlock();
|
---|
| 83 | }
|
---|
| 84 |
|
---|
| 85 | void ddraw_thread_cursor_class::save()
|
---|
| 86 | {
|
---|
| 87 | if (!mouse_save)
|
---|
| 88 | {
|
---|
| 89 | return;
|
---|
| 90 | }
|
---|
| 91 |
|
---|
| 92 | RECT r;
|
---|
| 93 |
|
---|
| 94 | r.left = save_mouse_x;
|
---|
| 95 | r.top = save_mouse_y;
|
---|
| 96 | r.right = r.left + mouse_save->width();
|
---|
| 97 | r.bottom = r.top + mouse_save->height();
|
---|
| 98 |
|
---|
| 99 |
|
---|
| 100 |
|
---|
| 101 | IDirectDrawSurface3 *framebuffer = (use_back_buffer)?(dx5_common.back_surface):(dx5_common.primary_surface);
|
---|
| 102 |
|
---|
| 103 | HRESULT res =
|
---|
| 104 | mouse_save->surface->BltFast(0,
|
---|
| 105 | 0,
|
---|
| 106 | framebuffer,
|
---|
| 107 | &r,
|
---|
| 108 | DDBLTFAST_NOCOLORKEY |
|
---|
| 109 | DDBLTFAST_WAIT);
|
---|
| 110 | i4_dx5_check(res);
|
---|
| 111 |
|
---|
| 112 | }
|
---|
| 113 |
|
---|
| 114 | void ddraw_thread_cursor_class::remove()
|
---|
| 115 | {
|
---|
| 116 | if (!visible || !mouse_save || !mouse_save->surface)
|
---|
| 117 | {
|
---|
| 118 | return;
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 |
|
---|
| 122 | IDirectDrawSurface3 *framebuffer = (use_back_buffer)?(dx5_common.back_surface):(dx5_common.primary_surface);
|
---|
| 123 | HRESULT res =
|
---|
| 124 | framebuffer->BltFast(save_mouse_x,
|
---|
| 125 | save_mouse_y,
|
---|
| 126 | mouse_save->surface,
|
---|
| 127 | 0,
|
---|
| 128 | DDBLTFAST_NOCOLORKEY |
|
---|
| 129 | DDBLTFAST_WAIT);
|
---|
| 130 | i4_dx5_check(res);
|
---|
| 131 |
|
---|
| 132 | visible = i4_F;
|
---|
| 133 |
|
---|
| 134 | }
|
---|
| 135 |
|
---|
| 136 | void ddraw_thread_cursor_class::display()
|
---|
| 137 | {
|
---|
| 138 | if (!cursor.pict || !mouse_save || !mouse_save->surface)
|
---|
| 139 | {
|
---|
| 140 | return;
|
---|
| 141 | }
|
---|
| 142 |
|
---|
| 143 |
|
---|
| 144 |
|
---|
| 145 | save_mouse_x = current_mouse_x;
|
---|
| 146 | save_mouse_y = current_mouse_y;
|
---|
| 147 |
|
---|
| 148 | RECT r;
|
---|
| 149 |
|
---|
| 150 | r.left = save_mouse_x;
|
---|
| 151 | r.top = save_mouse_y;
|
---|
| 152 | r.right = r.left + mouse_save->width();
|
---|
| 153 | r.bottom = r.top + mouse_save->height();
|
---|
| 154 |
|
---|
| 155 |
|
---|
| 156 | IDirectDrawSurface3 *framebuffer = (use_back_buffer)?(dx5_common.back_surface):(dx5_common.primary_surface);
|
---|
| 157 | HRESULT res =
|
---|
| 158 | mouse_save->surface->BltFast(0,
|
---|
| 159 | 0,
|
---|
| 160 | framebuffer,
|
---|
| 161 | &r,
|
---|
| 162 | DDBLTFAST_NOCOLORKEY |
|
---|
| 163 | DDBLTFAST_WAIT);
|
---|
| 164 | i4_dx5_check(res);
|
---|
| 165 |
|
---|
| 166 | IDirectDrawSurface3 *mouse_draw_surface = ((i4_dx5_image_class *)cursor.pict)->surface;
|
---|
| 167 |
|
---|
| 168 | res =
|
---|
| 169 | framebuffer->BltFast(save_mouse_x,
|
---|
| 170 | save_mouse_y,
|
---|
| 171 | mouse_draw_surface,
|
---|
| 172 | 0,
|
---|
| 173 | DDBLTFAST_SRCCOLORKEY |
|
---|
| 174 | DDBLTFAST_WAIT);
|
---|
| 175 |
|
---|
| 176 | i4_dx5_check(res);
|
---|
| 177 |
|
---|
| 178 |
|
---|
| 179 | visible = i4_T;
|
---|
| 180 | }
|
---|
| 181 |
|
---|
| 182 | void ddraw_thread_cursor_class::use_backbuffer(i4_bool use)
|
---|
| 183 | {
|
---|
| 184 | use_back_buffer = use;
|
---|
| 185 | }
|
---|