Rev 9785 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
8211 | maxcodehac | 1 | #include |
2 | #include |
||
9768 | turbocat | 3 | #include |
8211 | maxcodehac | 4 | #include "SDL.h" |
5 | #include "SDL_error.h" |
||
6 | #include "SDL_video.h" |
||
7 | #include "SDL_mouse.h" |
||
8 | #include "SDL_sysvideo.h" |
||
9 | #include "SDL_pixels_c.h" |
||
9787 | turbocat | 10 | #include "SDL_kolibri_video.h" |
8211 | maxcodehac | 11 | #include |
12 | |||
13 | static SDL_VideoDevice * vm_suf=NULL; |
||
9769 | turbocat | 14 | static int was_initialized = 0; |
15 | static int scrn_size_defined = 0; |
||
8211 | maxcodehac | 16 | |
17 | static int has_null_cursor=0; |
||
9768 | turbocat | 18 | static void* null_cursor; |
8211 | maxcodehac | 19 | |
9768 | turbocat | 20 | #define WINDOW_BORDER_H 4 |
21 | #define WINDOW_BORDER_W 9 |
||
8211 | maxcodehac | 22 | |
9769 | turbocat | 23 | ksys_pos_t screen_size = {0}; |
24 | |||
9768 | turbocat | 25 | void kos_SDL_RepaintWnd(void) |
9288 | turbocat | 26 | { |
9769 | turbocat | 27 | int win_pos_x, win_pos_y; |
28 | int win_size_w = vm_suf->hidden->win_size_x+WINDOW_BORDER_W; |
||
29 | int win_size_h = vm_suf->hidden->win_size_y+_ksys_get_skin_height()+WINDOW_BORDER_H; |
||
30 | |||
31 | if (!screen_size.val) { |
||
32 | screen_size = _ksys_screen_size(); |
||
33 | win_pos_x = screen_size.x/2-win_size_w/2; |
||
34 | win_pos_y = screen_size.y/2-win_size_h/2; |
||
35 | } |
||
36 | |||
9768 | turbocat | 37 | _ksys_start_draw(); |
9769 | turbocat | 38 | _ksys_create_window(win_pos_x, win_pos_y, win_size_w, win_size_h, vm_suf->hidden->__title, 0, 0x34); |
9288 | turbocat | 39 | |
9769 | turbocat | 40 | if (vm_suf && vm_suf->hidden->__video_buffer) { |
41 | _ksys_draw_bitmap(vm_suf->hidden->__video_buffer, 0, 0, |
||
42 | vm_suf->hidden->win_size_x, vm_suf->hidden->win_size_y); |
||
9768 | turbocat | 43 | } |
44 | _ksys_end_draw(); |
||
8211 | maxcodehac | 45 | } |
46 | |||
9768 | turbocat | 47 | static int kos_AllocHWSurface(_THIS,SDL_Surface * surface) |
8211 | maxcodehac | 48 | { |
9768 | turbocat | 49 | return -1; |
8211 | maxcodehac | 50 | } |
51 | |||
9768 | turbocat | 52 | static void kos_FreeHWSurface(_THIS,SDL_Surface * surface) {/*STUB*/} |
8211 | maxcodehac | 53 | |
9768 | turbocat | 54 | static int kos_LockHWSurface(_THIS,SDL_Surface * surface) |
8211 | maxcodehac | 55 | { |
9768 | turbocat | 56 | return 0; |
8211 | maxcodehac | 57 | } |
58 | |||
9768 | turbocat | 59 | static void kos_UnlockHWSurface(_THIS,SDL_Surface * surface) {/*STUB*/} |
8211 | maxcodehac | 60 | |
9768 | turbocat | 61 | static void kos_DirectUpdate(_THIS,int numrects,SDL_Rect * rects) |
8211 | maxcodehac | 62 | { |
9768 | turbocat | 63 | if (numrects) { |
9769 | turbocat | 64 | _ksys_draw_bitmap(this->hidden->__video_buffer, 0,0, |
65 | vm_suf->hidden->win_size_x,vm_suf->hidden->win_size_y); |
||
66 | } |
||
8211 | maxcodehac | 67 | } |
68 | |||
9768 | turbocat | 69 | int kos_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) |
8211 | maxcodehac | 70 | { |
9768 | turbocat | 71 | return 0; |
8211 | maxcodehac | 72 | } |
73 | |||
9768 | turbocat | 74 | void kos_VideoQuit(_THIS) |
8211 | maxcodehac | 75 | { |
9768 | turbocat | 76 | if (has_null_cursor) { |
77 | _ksys_delete_cursor(null_cursor); |
||
78 | has_null_cursor = 0; |
||
79 | } |
||
8211 | maxcodehac | 80 | } |
81 | |||
9768 | turbocat | 82 | void kos_FinalQuit(void) {/*STUB*/} |
8211 | maxcodehac | 83 | |
9768 | turbocat | 84 | void kos_SetCaption(_THIS,const char * title, const char * icon) |
8211 | maxcodehac | 85 | { |
9769 | turbocat | 86 | this->hidden->__title=(char *)title; |
87 | if (was_initialized) _ksys_set_window_title(title); |
||
8211 | maxcodehac | 88 | } |
89 | |||
9768 | turbocat | 90 | SDL_Surface *kos_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) |
8211 | maxcodehac | 91 | { |
9768 | turbocat | 92 | int ly; |
9769 | turbocat | 93 | unsigned char* lx; |
94 | if (bpp!=24) return NULL; |
||
9211 | turbocat | 95 | |
9769 | turbocat | 96 | current->flags=flags; |
97 | current->w=width; |
||
98 | current->h=height; |
||
99 | current->pitch=width*(bpp>>3); |
||
8211 | maxcodehac | 100 | |
9769 | turbocat | 101 | char info[100]; |
102 | sprintf(info, "width = %d, height = %d, pitch = %d, bpp = %d\n", current->w, current->h, current->pitch, bpp); |
||
9768 | turbocat | 103 | _ksys_debug_puts(info); |
8211 | maxcodehac | 104 | |
9768 | turbocat | 105 | current->pixels=this->hidden->__video_buffer=realloc(this->hidden->__video_buffer, current->pitch*current->h); |
9769 | turbocat | 106 | this->hidden->__lines=(unsigned char **)realloc(this->hidden->__lines, sizeof(unsigned char *)*current->h); |
8211 | maxcodehac | 107 | |
9769 | turbocat | 108 | for (ly=0, lx=current->pixels; ly |
109 | this->hidden->__lines[ly]=lx; |
||
9211 | turbocat | 110 | |
9769 | turbocat | 111 | this->UpdateRects=kos_DirectUpdate; |
112 | this->hidden->win_size_x=width; |
||
113 | this->hidden->win_size_y=height; |
||
114 | vm_suf=this; |
||
9211 | turbocat | 115 | |
9769 | turbocat | 116 | if (was_initialized) { |
117 | unsigned newheight = height+_ksys_get_skin_height()+WINDOW_BORDER_H; |
||
118 | unsigned newwidth = width+WINDOW_BORDER_W; |
||
119 | int win_pos_x = screen_size.x/2-newwidth/2; |
||
120 | int win_pos_y = screen_size.y/2-newheight/2; |
||
121 | _ksys_change_window(win_pos_x, win_pos_y, newwidth, newheight); |
||
122 | } else { |
||
9768 | turbocat | 123 | _ksys_set_event_mask(0x27); |
9769 | turbocat | 124 | was_initialized=1; |
125 | kos_SDL_RepaintWnd(); |
||
126 | } |
||
127 | return current; |
||
8211 | maxcodehac | 128 | } |
129 | |||
130 | /*static SDL_Rect video_mode[4]; |
||
131 | static SDL_Rect * SDL_modelist[4]={NULL,NULL,NULL,NULL};*/ |
||
132 | |||
9768 | turbocat | 133 | static SDL_Rect** kos_ListModes(_THIS,SDL_PixelFormat * fmt,Uint32 flags) |
8211 | maxcodehac | 134 | { |
135 | // return (&SDL_modelist[((fmt->BitsPerPixel+7)/8)-1]); |
||
9768 | turbocat | 136 | if (fmt->BitsPerPixel==24) |
137 | return (SDL_Rect**)-1; |
||
138 | else |
||
139 | return NULL; |
||
8211 | maxcodehac | 140 | } |
141 | |||
9768 | turbocat | 142 | static int kos_Available(void) |
8211 | maxcodehac | 143 | { |
9769 | turbocat | 144 | return 1; |
8211 | maxcodehac | 145 | } |
146 | |||
9768 | turbocat | 147 | static void kos_DeleteDevice(_THIS) |
8211 | maxcodehac | 148 | { |
9768 | turbocat | 149 | // free(this->hidden->__video_buffer); // it will be freed as current->pixels |
9769 | turbocat | 150 | free(this->hidden->__lines); |
8211 | maxcodehac | 151 | } |
152 | |||
9768 | turbocat | 153 | static int kos_VideoInit(_THIS,SDL_PixelFormat * vformat) |
8211 | maxcodehac | 154 | { |
9768 | turbocat | 155 | vformat->BitsPerPixel = 24; |
9769 | turbocat | 156 | vformat->BytesPerPixel = 3; |
157 | this->info.wm_available = 1; |
||
158 | this->info.hw_available = 0; |
||
159 | this->info.video_mem = 0x200000; |
||
160 | return 0; |
||
8211 | maxcodehac | 161 | } |
162 | |||
9768 | turbocat | 163 | static int kos_FlipHWSurface(_THIS,SDL_Surface * surface) |
8211 | maxcodehac | 164 | { |
9768 | turbocat | 165 | _ksys_draw_bitmap(surface->pixels, 0, 0, surface->w,surface->h); |
9769 | turbocat | 166 | return 0; |
8211 | maxcodehac | 167 | } |
168 | |||
9768 | turbocat | 169 | WMcursor* kos_CreateWMCursor(_THIS, Uint8* data, Uint8* mask, int w, int h, int hot_x, int hot_y) |
8211 | maxcodehac | 170 | { |
9768 | turbocat | 171 | int i,j; |
172 | Uint32* cursor; |
||
173 | WMcursor* res; |
||
8211 | maxcodehac | 174 | |
9768 | turbocat | 175 | if (w>32 || h>32) return NULL; |
176 | if (w%8 || h%8) return NULL; |
||
177 | cursor = (Uint32*)malloc(32*32*4); |
||
178 | if (!cursor) return NULL; |
||
179 | for (i=0;i<32;i++) { |
||
180 | for (j=0;j<32;j++) { |
||
181 | if (i>=h || j>=w) { |
||
182 | cursor[i*32+j] = 0x00000000; |
||
183 | continue; |
||
184 | } |
||
185 | if (mask[i*w/8+j/8] & (0x80>>(j&7))) |
||
186 | cursor[i*32+j] = (data[i*w/8+j/8] & (0x80>>(j&7)))?0xFF000000:0xFFFFFFFF; |
||
187 | else |
||
188 | cursor[i*32+j] = 0x00000000; |
||
189 | } |
||
190 | } |
||
191 | res = _ksys_load_cursor(cursor, (hot_x<<24)+(hot_y<<16)+KSYS_CURSOR_INDIRECT); |
||
192 | free(cursor); |
||
193 | return res; |
||
8211 | maxcodehac | 194 | } |
9768 | turbocat | 195 | |
196 | int kos_ShowWMCursor(_THIS, WMcursor* cursor) |
||
8211 | maxcodehac | 197 | { |
9768 | turbocat | 198 | if (!cursor) { |
199 | if (!has_null_cursor) { |
||
200 | unsigned* u = malloc(32*32*4); |
||
201 | if (!u) return 1; |
||
9785 | turbocat | 202 | memset(u, 0, 32*32*4); |
9768 | turbocat | 203 | null_cursor = _ksys_load_cursor(u, KSYS_CURSOR_INDIRECT); |
204 | free(u); |
||
205 | has_null_cursor = 1; |
||
206 | } |
||
207 | cursor = (WMcursor*)null_cursor; |
||
208 | } |
||
209 | _ksys_set_cursor(cursor); |
||
210 | return 1; |
||
8211 | maxcodehac | 211 | } |
9768 | turbocat | 212 | void kos_FreeWMCursor(_THIS, WMcursor* cursor) |
8211 | maxcodehac | 213 | { |
9768 | turbocat | 214 | _ksys_delete_cursor(cursor); |
8211 | maxcodehac | 215 | } |
9769 | turbocat | 216 | |
9768 | turbocat | 217 | void kos_CheckMouseMode(_THIS) |
8211 | maxcodehac | 218 | { |
9768 | turbocat | 219 | if (this->input_grab == SDL_GRAB_OFF) |
220 | return; |
||
221 | ksys_thread_t thread_info; |
||
9785 | turbocat | 222 | int top = _ksys_thread_info(&thread_info, -1); |
223 | |||
224 | if (top == thread_info.pos_in_window_stack) { |
||
9768 | turbocat | 225 | int x = thread_info.winx_start + thread_info.clientx + this->hidden->win_size_x/2; |
226 | int y = thread_info.winy_start + thread_info.clienty + this->hidden->win_size_y/2; |
||
227 | _ksys_set_mouse_pos(x, y); |
||
228 | } |
||
8211 | maxcodehac | 229 | } |
230 | |||
231 | char def_title[] = "KolibriOS SDL App"; |
||
9768 | turbocat | 232 | |
233 | static SDL_VideoDevice *kos_CreateDevice(int indx) |
||
8211 | maxcodehac | 234 | { |
9768 | turbocat | 235 | SDL_VideoDevice * dev; |
9769 | turbocat | 236 | dev = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice)); |
237 | if (dev) { |
||
238 | memset(dev,0,(sizeof *dev)); |
||
239 | dev->hidden = (struct SDL_PrivateVideoData*)malloc((sizeof *dev->hidden)); |
||
240 | } |
||
9768 | turbocat | 241 | |
9769 | turbocat | 242 | if ((dev==NULL) || (dev->hidden==NULL)) { |
243 | SDL_OutOfMemory(); |
||
244 | if(dev) { |
||
245 | free(dev); |
||
246 | } |
||
247 | return(0); |
||
248 | } |
||
249 | |||
9768 | turbocat | 250 | memset(dev->hidden, 0, (sizeof *dev->hidden)); |
251 | dev->hidden->__title = def_title; |
||
252 | dev->VideoInit = kos_VideoInit; |
||
9769 | turbocat | 253 | dev->ListModes = kos_ListModes; |
9768 | turbocat | 254 | dev->SetVideoMode = kos_SetVideoMode; |
255 | dev->SetColors = kos_SetColors; |
||
9769 | turbocat | 256 | dev->UpdateRects = NULL; |
257 | dev->VideoQuit = kos_VideoQuit; |
||
258 | dev->AllocHWSurface=kos_AllocHWSurface; |
||
259 | dev->CheckHWBlit = NULL; |
||
260 | dev->FillHWRect = NULL; |
||
261 | dev->SetHWColorKey = NULL; |
||
262 | dev->SetHWAlpha = NULL; |
||
263 | dev->LockHWSurface = kos_LockHWSurface; |
||
264 | dev->UnlockHWSurface = kos_UnlockHWSurface; |
||
265 | dev->FlipHWSurface = kos_FlipHWSurface; |
||
266 | dev->FreeHWSurface = kos_FreeHWSurface; |
||
267 | dev->SetCaption = kos_SetCaption; |
||
268 | dev->SetIcon = NULL; |
||
269 | dev->IconifyWindow = NULL; |
||
270 | dev->GrabInput = NULL; |
||
271 | dev->GetWMInfo = NULL; |
||
9785 | turbocat | 272 | dev->InitOSKeymap = kos_InitOSKeymap; |
273 | dev->PumpEvents = kos_PumpEvents; |
||
9769 | turbocat | 274 | dev->free = kos_DeleteDevice; |
9768 | turbocat | 275 | dev->CreateWMCursor = kos_CreateWMCursor; |
276 | dev->FreeWMCursor = kos_FreeWMCursor; |
||
277 | dev->ShowWMCursor = kos_ShowWMCursor; |
||
278 | dev->CheckMouseMode = kos_CheckMouseMode; |
||
279 | return dev; |
||
8211 | maxcodehac | 280 | } |
281 | |||
9787 | turbocat | 282 | VideoBootStrap kos_video_bootstrab = { |
9769 | turbocat | 283 | "kolibrios", "KolibriOS Device Driver", |
284 | kos_Available, kos_CreateDevice, |
||
8211 | maxcodehac | 285 | };16)+KSYS_CURSOR_INDIRECT); |