forked from KolibriOS/kolibrios
SDL: now window is always centered.
git-svn-id: svn://kolibrios.org@9769 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
parent
635fbac815
commit
bfe9af6494
@ -26,6 +26,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/ksys.h>
|
||||
|
||||
#include "SDL.h"
|
||||
#include "SDL_error.h"
|
||||
@ -113,32 +114,6 @@ static SDL_GrabMode SDL_WM_GrabInputOff(void);
|
||||
static int lock_count = 0;
|
||||
#endif
|
||||
|
||||
|
||||
typedef union{
|
||||
unsigned val;
|
||||
struct{
|
||||
short x;
|
||||
short y;
|
||||
};
|
||||
}ksys_pos_t;
|
||||
|
||||
static inline
|
||||
ksys_pos_t _ksys_screen_size()
|
||||
{
|
||||
ksys_pos_t size;
|
||||
ksys_pos_t size_tmp;
|
||||
__asm__ __volatile__(
|
||||
"int $0x40"
|
||||
:"=a"(size_tmp)
|
||||
:"a"(14)
|
||||
:"memory"
|
||||
);
|
||||
size.x = size_tmp.y;
|
||||
size.y = size_tmp.x;
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Initialize the video and event subsystems -- determine native pixel format
|
||||
*/
|
||||
|
@ -1,5 +1,6 @@
|
||||
#include <menuet/os.h>
|
||||
#include <kos32sys.h>
|
||||
#include <sys/ksys.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "SDL.h"
|
||||
@ -200,7 +201,10 @@ void MenuetOS_PumpEvents(_THIS)
|
||||
SDL_PrivateKeyboard(code,&key);
|
||||
break;
|
||||
case 3:
|
||||
if(get_os_button()==1) exit(0);
|
||||
if (_ksys_get_button()==1) {
|
||||
SDL_CloseAudio();
|
||||
exit(0);
|
||||
}
|
||||
break;
|
||||
case 6: {
|
||||
int __tmp,mx,my;
|
||||
|
@ -11,7 +11,8 @@
|
||||
#include <string.h>
|
||||
|
||||
static SDL_VideoDevice * vm_suf=NULL;
|
||||
static int was_initialized=0;
|
||||
static int was_initialized = 0;
|
||||
static int scrn_size_defined = 0;
|
||||
|
||||
static int has_null_cursor=0;
|
||||
static void* null_cursor;
|
||||
@ -19,16 +20,26 @@ static void* null_cursor;
|
||||
#define WINDOW_BORDER_H 4
|
||||
#define WINDOW_BORDER_W 9
|
||||
|
||||
ksys_pos_t screen_size = {0};
|
||||
|
||||
void kos_SDL_RepaintWnd(void)
|
||||
{
|
||||
_ksys_start_draw();
|
||||
_ksys_create_window(1, 1, vm_suf->hidden->win_size_x+WINDOW_BORDER_W,
|
||||
vm_suf->hidden->win_size_y+_ksys_get_skin_height()+ WINDOW_BORDER_H,
|
||||
vm_suf->hidden->__title, 0, 0x34);
|
||||
int win_pos_x, win_pos_y;
|
||||
int win_size_w = vm_suf->hidden->win_size_x+WINDOW_BORDER_W;
|
||||
int win_size_h = vm_suf->hidden->win_size_y+_ksys_get_skin_height()+WINDOW_BORDER_H;
|
||||
|
||||
if (vm_suf && vm_suf->hidden->__video_buffer) {
|
||||
_ksys_draw_bitmap(vm_suf->hidden->__video_buffer, 0, 0,
|
||||
vm_suf->hidden->win_size_x, vm_suf->hidden->win_size_y);
|
||||
if (!screen_size.val) {
|
||||
screen_size = _ksys_screen_size();
|
||||
win_pos_x = screen_size.x/2-win_size_w/2;
|
||||
win_pos_y = screen_size.y/2-win_size_h/2;
|
||||
}
|
||||
|
||||
_ksys_start_draw();
|
||||
_ksys_create_window(win_pos_x, win_pos_y, win_size_w, win_size_h, vm_suf->hidden->__title, 0, 0x34);
|
||||
|
||||
if (vm_suf && vm_suf->hidden->__video_buffer) {
|
||||
_ksys_draw_bitmap(vm_suf->hidden->__video_buffer, 0, 0,
|
||||
vm_suf->hidden->win_size_x, vm_suf->hidden->win_size_y);
|
||||
}
|
||||
_ksys_end_draw();
|
||||
}
|
||||
@ -50,9 +61,9 @@ static void kos_UnlockHWSurface(_THIS,SDL_Surface * surface) {/*STUB*/}
|
||||
static void kos_DirectUpdate(_THIS,int numrects,SDL_Rect * rects)
|
||||
{
|
||||
if (numrects) {
|
||||
_ksys_draw_bitmap(this->hidden->__video_buffer, 0,0,
|
||||
vm_suf->hidden->win_size_x,vm_suf->hidden->win_size_y);
|
||||
}
|
||||
_ksys_draw_bitmap(this->hidden->__video_buffer, 0,0,
|
||||
vm_suf->hidden->win_size_x,vm_suf->hidden->win_size_y);
|
||||
}
|
||||
}
|
||||
|
||||
int kos_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors)
|
||||
@ -72,46 +83,48 @@ void kos_FinalQuit(void) {/*STUB*/}
|
||||
|
||||
void kos_SetCaption(_THIS,const char * title, const char * icon)
|
||||
{
|
||||
this->hidden->__title=(char *)title;
|
||||
if (was_initialized) _ksys_set_window_title(title);
|
||||
this->hidden->__title=(char *)title;
|
||||
if (was_initialized) _ksys_set_window_title(title);
|
||||
}
|
||||
|
||||
SDL_Surface *kos_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags)
|
||||
{
|
||||
int ly;
|
||||
unsigned char* lx;
|
||||
if (bpp!=24) return NULL;
|
||||
unsigned char* lx;
|
||||
if (bpp!=24) return NULL;
|
||||
|
||||
current->flags=flags;
|
||||
current->w=width;
|
||||
current->h=height;
|
||||
current->pitch=width*(bpp>>3);
|
||||
current->flags=flags;
|
||||
current->w=width;
|
||||
current->h=height;
|
||||
current->pitch=width*(bpp>>3);
|
||||
|
||||
char info[100];
|
||||
sprintf(info, "width = %d, height = %d, pitch = %d, bpp = %d\n", current->w, current->h, current->pitch, bpp);
|
||||
char info[100];
|
||||
sprintf(info, "width = %d, height = %d, pitch = %d, bpp = %d\n", current->w, current->h, current->pitch, bpp);
|
||||
_ksys_debug_puts(info);
|
||||
|
||||
current->pixels=this->hidden->__video_buffer=realloc(this->hidden->__video_buffer, current->pitch*current->h);
|
||||
this->hidden->__lines=(unsigned char **)realloc(this->hidden->__lines, sizeof(unsigned char *)*current->h);
|
||||
this->hidden->__lines=(unsigned char **)realloc(this->hidden->__lines, sizeof(unsigned char *)*current->h);
|
||||
|
||||
for (ly=0, lx=current->pixels; ly<current->h; ly++, lx+=current->pitch)
|
||||
this->hidden->__lines[ly]=lx;
|
||||
for (ly=0, lx=current->pixels; ly<current->h; ly++, lx+=current->pitch)
|
||||
this->hidden->__lines[ly]=lx;
|
||||
|
||||
this->UpdateRects=kos_DirectUpdate;
|
||||
this->hidden->win_size_x=width;
|
||||
this->hidden->win_size_y=height;
|
||||
vm_suf=this;
|
||||
this->UpdateRects=kos_DirectUpdate;
|
||||
this->hidden->win_size_x=width;
|
||||
this->hidden->win_size_y=height;
|
||||
vm_suf=this;
|
||||
|
||||
if (was_initialized) {
|
||||
unsigned newheight = height+_ksys_get_skin_height()+WINDOW_BORDER_H;
|
||||
unsigned newwidth = width+WINDOW_BORDER_W;
|
||||
_ksys_change_window(-1, -1, newwidth, newheight);
|
||||
} else {
|
||||
if (was_initialized) {
|
||||
unsigned newheight = height+_ksys_get_skin_height()+WINDOW_BORDER_H;
|
||||
unsigned newwidth = width+WINDOW_BORDER_W;
|
||||
int win_pos_x = screen_size.x/2-newwidth/2;
|
||||
int win_pos_y = screen_size.y/2-newheight/2;
|
||||
_ksys_change_window(win_pos_x, win_pos_y, newwidth, newheight);
|
||||
} else {
|
||||
_ksys_set_event_mask(0x27);
|
||||
was_initialized=1;
|
||||
kos_SDL_RepaintWnd();
|
||||
}
|
||||
return current;
|
||||
was_initialized=1;
|
||||
kos_SDL_RepaintWnd();
|
||||
}
|
||||
return current;
|
||||
}
|
||||
|
||||
/*static SDL_Rect video_mode[4];
|
||||
@ -128,29 +141,29 @@ static SDL_Rect** kos_ListModes(_THIS,SDL_PixelFormat * fmt,Uint32 flags)
|
||||
|
||||
static int kos_Available(void)
|
||||
{
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void kos_DeleteDevice(_THIS)
|
||||
{
|
||||
// free(this->hidden->__video_buffer); // it will be freed as current->pixels
|
||||
free(this->hidden->__lines);
|
||||
free(this->hidden->__lines);
|
||||
}
|
||||
|
||||
static int kos_VideoInit(_THIS,SDL_PixelFormat * vformat)
|
||||
{
|
||||
vformat->BitsPerPixel = 24;
|
||||
vformat->BytesPerPixel = 3;
|
||||
this->info.wm_available = 1;
|
||||
this->info.hw_available = 0;
|
||||
this->info.video_mem = 0x200000;
|
||||
return 0;
|
||||
vformat->BytesPerPixel = 3;
|
||||
this->info.wm_available = 1;
|
||||
this->info.hw_available = 0;
|
||||
this->info.video_mem = 0x200000;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int kos_FlipHWSurface(_THIS,SDL_Surface * surface)
|
||||
{
|
||||
_ksys_draw_bitmap(surface->pixels, 0, 0, surface->w,surface->h);
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
WMcursor* kos_CreateWMCursor(_THIS, Uint8* data, Uint8* mask, int w, int h, int hot_x, int hot_y)
|
||||
@ -200,6 +213,7 @@ void kos_FreeWMCursor(_THIS, WMcursor* cursor)
|
||||
{
|
||||
_ksys_delete_cursor(cursor);
|
||||
}
|
||||
|
||||
void kos_CheckMouseMode(_THIS)
|
||||
{
|
||||
if (this->input_grab == SDL_GRAB_OFF)
|
||||
@ -218,44 +232,45 @@ char def_title[] = "KolibriOS SDL App";
|
||||
static SDL_VideoDevice *kos_CreateDevice(int indx)
|
||||
{
|
||||
SDL_VideoDevice * dev;
|
||||
dev = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
|
||||
if (dev) {
|
||||
memset(dev,0,(sizeof *dev));
|
||||
dev->hidden = (struct SDL_PrivateVideoData*)malloc((sizeof *dev->hidden));
|
||||
}
|
||||
if ((dev==NULL) || (dev->hidden==NULL)) {
|
||||
SDL_OutOfMemory();
|
||||
if(dev) {
|
||||
free(dev);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
dev = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
|
||||
if (dev) {
|
||||
memset(dev,0,(sizeof *dev));
|
||||
dev->hidden = (struct SDL_PrivateVideoData*)malloc((sizeof *dev->hidden));
|
||||
}
|
||||
|
||||
if ((dev==NULL) || (dev->hidden==NULL)) {
|
||||
SDL_OutOfMemory();
|
||||
if(dev) {
|
||||
free(dev);
|
||||
}
|
||||
return(0);
|
||||
}
|
||||
|
||||
memset(dev->hidden, 0, (sizeof *dev->hidden));
|
||||
dev->hidden->__title = def_title;
|
||||
dev->VideoInit = kos_VideoInit;
|
||||
dev->ListModes = kos_ListModes;
|
||||
dev->ListModes = kos_ListModes;
|
||||
dev->SetVideoMode = kos_SetVideoMode;
|
||||
dev->SetColors = kos_SetColors;
|
||||
dev->UpdateRects = NULL;
|
||||
dev->VideoQuit = kos_VideoQuit;
|
||||
dev->AllocHWSurface=kos_AllocHWSurface;
|
||||
dev->CheckHWBlit = NULL;
|
||||
dev->FillHWRect = NULL;
|
||||
dev->SetHWColorKey = NULL;
|
||||
dev->SetHWAlpha = NULL;
|
||||
dev->LockHWSurface = kos_LockHWSurface;
|
||||
dev->UnlockHWSurface = kos_UnlockHWSurface;
|
||||
dev->FlipHWSurface = kos_FlipHWSurface;
|
||||
dev->FreeHWSurface = kos_FreeHWSurface;
|
||||
dev->SetCaption = kos_SetCaption;
|
||||
dev->SetIcon = NULL;
|
||||
dev->IconifyWindow = NULL;
|
||||
dev->GrabInput = NULL;
|
||||
dev->GetWMInfo = NULL;
|
||||
dev->InitOSKeymap = MenuetOS_InitOSKeymap;
|
||||
dev->PumpEvents = MenuetOS_PumpEvents;
|
||||
dev->free = kos_DeleteDevice;
|
||||
dev->UpdateRects = NULL;
|
||||
dev->VideoQuit = kos_VideoQuit;
|
||||
dev->AllocHWSurface=kos_AllocHWSurface;
|
||||
dev->CheckHWBlit = NULL;
|
||||
dev->FillHWRect = NULL;
|
||||
dev->SetHWColorKey = NULL;
|
||||
dev->SetHWAlpha = NULL;
|
||||
dev->LockHWSurface = kos_LockHWSurface;
|
||||
dev->UnlockHWSurface = kos_UnlockHWSurface;
|
||||
dev->FlipHWSurface = kos_FlipHWSurface;
|
||||
dev->FreeHWSurface = kos_FreeHWSurface;
|
||||
dev->SetCaption = kos_SetCaption;
|
||||
dev->SetIcon = NULL;
|
||||
dev->IconifyWindow = NULL;
|
||||
dev->GrabInput = NULL;
|
||||
dev->GetWMInfo = NULL;
|
||||
dev->InitOSKeymap = MenuetOS_InitOSKeymap;
|
||||
dev->PumpEvents = MenuetOS_PumpEvents;
|
||||
dev->free = kos_DeleteDevice;
|
||||
dev->CreateWMCursor = kos_CreateWMCursor;
|
||||
dev->FreeWMCursor = kos_FreeWMCursor;
|
||||
dev->ShowWMCursor = kos_ShowWMCursor;
|
||||
@ -263,7 +278,7 @@ static SDL_VideoDevice *kos_CreateDevice(int indx)
|
||||
return dev;
|
||||
}
|
||||
|
||||
VideoBootStrap mosvideo_bootstrab={
|
||||
"kolibrios", "KolibriOS Device Driver",
|
||||
kos_Available, kos_CreateDevice,
|
||||
VideoBootStrap mosvideo_bootstrab = {
|
||||
"kolibrios", "KolibriOS Device Driver",
|
||||
kos_Available, kos_CreateDevice,
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user