SDL: now window is always centered.

git-svn-id: svn://kolibrios.org@9769 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
turbocat 2022-04-15 22:15:59 +00:00
parent 635fbac815
commit bfe9af6494
3 changed files with 101 additions and 107 deletions

View File

@ -26,6 +26,7 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/ksys.h>
#include "SDL.h" #include "SDL.h"
#include "SDL_error.h" #include "SDL_error.h"
@ -113,32 +114,6 @@ static SDL_GrabMode SDL_WM_GrabInputOff(void);
static int lock_count = 0; static int lock_count = 0;
#endif #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 * Initialize the video and event subsystems -- determine native pixel format
*/ */

View File

@ -1,5 +1,6 @@
#include <menuet/os.h> #include <menuet/os.h>
#include <kos32sys.h> #include <kos32sys.h>
#include <sys/ksys.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include "SDL.h" #include "SDL.h"
@ -200,7 +201,10 @@ void MenuetOS_PumpEvents(_THIS)
SDL_PrivateKeyboard(code,&key); SDL_PrivateKeyboard(code,&key);
break; break;
case 3: case 3:
if(get_os_button()==1) exit(0); if (_ksys_get_button()==1) {
SDL_CloseAudio();
exit(0);
}
break; break;
case 6: { case 6: {
int __tmp,mx,my; int __tmp,mx,my;

View File

@ -11,7 +11,8 @@
#include <string.h> #include <string.h>
static SDL_VideoDevice * vm_suf=NULL; 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 int has_null_cursor=0;
static void* null_cursor; static void* null_cursor;
@ -19,16 +20,26 @@ static void* null_cursor;
#define WINDOW_BORDER_H 4 #define WINDOW_BORDER_H 4
#define WINDOW_BORDER_W 9 #define WINDOW_BORDER_W 9
ksys_pos_t screen_size = {0};
void kos_SDL_RepaintWnd(void) void kos_SDL_RepaintWnd(void)
{ {
_ksys_start_draw(); int win_pos_x, win_pos_y;
_ksys_create_window(1, 1, vm_suf->hidden->win_size_x+WINDOW_BORDER_W, int win_size_w = vm_suf->hidden->win_size_x+WINDOW_BORDER_W;
vm_suf->hidden->win_size_y+_ksys_get_skin_height()+ WINDOW_BORDER_H, int win_size_h = vm_suf->hidden->win_size_y+_ksys_get_skin_height()+WINDOW_BORDER_H;
vm_suf->hidden->__title, 0, 0x34);
if (vm_suf && vm_suf->hidden->__video_buffer) { if (!screen_size.val) {
_ksys_draw_bitmap(vm_suf->hidden->__video_buffer, 0, 0, screen_size = _ksys_screen_size();
vm_suf->hidden->win_size_x, vm_suf->hidden->win_size_y); 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(); _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) static void kos_DirectUpdate(_THIS,int numrects,SDL_Rect * rects)
{ {
if (numrects) { if (numrects) {
_ksys_draw_bitmap(this->hidden->__video_buffer, 0,0, _ksys_draw_bitmap(this->hidden->__video_buffer, 0,0,
vm_suf->hidden->win_size_x,vm_suf->hidden->win_size_y); vm_suf->hidden->win_size_x,vm_suf->hidden->win_size_y);
} }
} }
int kos_SetColors(_THIS, int firstcolor, int ncolors, SDL_Color *colors) 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) void kos_SetCaption(_THIS,const char * title, const char * icon)
{ {
this->hidden->__title=(char *)title; this->hidden->__title=(char *)title;
if (was_initialized) _ksys_set_window_title(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) SDL_Surface *kos_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags)
{ {
int ly; int ly;
unsigned char* lx; unsigned char* lx;
if (bpp!=24) return NULL; if (bpp!=24) return NULL;
current->flags=flags; current->flags=flags;
current->w=width; current->w=width;
current->h=height; current->h=height;
current->pitch=width*(bpp>>3); current->pitch=width*(bpp>>3);
char info[100]; char info[100];
sprintf(info, "width = %d, height = %d, pitch = %d, bpp = %d\n", current->w, current->h, current->pitch, bpp); sprintf(info, "width = %d, height = %d, pitch = %d, bpp = %d\n", current->w, current->h, current->pitch, bpp);
_ksys_debug_puts(info); _ksys_debug_puts(info);
current->pixels=this->hidden->__video_buffer=realloc(this->hidden->__video_buffer, current->pitch*current->h); 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) for (ly=0, lx=current->pixels; ly<current->h; ly++, lx+=current->pitch)
this->hidden->__lines[ly]=lx; this->hidden->__lines[ly]=lx;
this->UpdateRects=kos_DirectUpdate; this->UpdateRects=kos_DirectUpdate;
this->hidden->win_size_x=width; this->hidden->win_size_x=width;
this->hidden->win_size_y=height; this->hidden->win_size_y=height;
vm_suf=this; vm_suf=this;
if (was_initialized) { if (was_initialized) {
unsigned newheight = height+_ksys_get_skin_height()+WINDOW_BORDER_H; unsigned newheight = height+_ksys_get_skin_height()+WINDOW_BORDER_H;
unsigned newwidth = width+WINDOW_BORDER_W; unsigned newwidth = width+WINDOW_BORDER_W;
_ksys_change_window(-1, -1, newwidth, newheight); int win_pos_x = screen_size.x/2-newwidth/2;
} else { 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); _ksys_set_event_mask(0x27);
was_initialized=1; was_initialized=1;
kos_SDL_RepaintWnd(); kos_SDL_RepaintWnd();
} }
return current; return current;
} }
/*static SDL_Rect video_mode[4]; /*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) static int kos_Available(void)
{ {
return 1; return 1;
} }
static void kos_DeleteDevice(_THIS) static void kos_DeleteDevice(_THIS)
{ {
// free(this->hidden->__video_buffer); // it will be freed as current->pixels // 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) static int kos_VideoInit(_THIS,SDL_PixelFormat * vformat)
{ {
vformat->BitsPerPixel = 24; vformat->BitsPerPixel = 24;
vformat->BytesPerPixel = 3; vformat->BytesPerPixel = 3;
this->info.wm_available = 1; this->info.wm_available = 1;
this->info.hw_available = 0; this->info.hw_available = 0;
this->info.video_mem = 0x200000; this->info.video_mem = 0x200000;
return 0; return 0;
} }
static int kos_FlipHWSurface(_THIS,SDL_Surface * surface) static int kos_FlipHWSurface(_THIS,SDL_Surface * surface)
{ {
_ksys_draw_bitmap(surface->pixels, 0, 0, surface->w,surface->h); _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) 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); _ksys_delete_cursor(cursor);
} }
void kos_CheckMouseMode(_THIS) void kos_CheckMouseMode(_THIS)
{ {
if (this->input_grab == SDL_GRAB_OFF) if (this->input_grab == SDL_GRAB_OFF)
@ -218,44 +232,45 @@ char def_title[] = "KolibriOS SDL App";
static SDL_VideoDevice *kos_CreateDevice(int indx) static SDL_VideoDevice *kos_CreateDevice(int indx)
{ {
SDL_VideoDevice * dev; SDL_VideoDevice * dev;
dev = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice)); dev = (SDL_VideoDevice *)malloc(sizeof(SDL_VideoDevice));
if (dev) { if (dev) {
memset(dev,0,(sizeof *dev)); memset(dev,0,(sizeof *dev));
dev->hidden = (struct SDL_PrivateVideoData*)malloc((sizeof *dev->hidden)); dev->hidden = (struct SDL_PrivateVideoData*)malloc((sizeof *dev->hidden));
} }
if ((dev==NULL) || (dev->hidden==NULL)) {
SDL_OutOfMemory(); if ((dev==NULL) || (dev->hidden==NULL)) {
if(dev) { SDL_OutOfMemory();
free(dev); if(dev) {
} free(dev);
return(0); }
} return(0);
}
memset(dev->hidden, 0, (sizeof *dev->hidden)); memset(dev->hidden, 0, (sizeof *dev->hidden));
dev->hidden->__title = def_title; dev->hidden->__title = def_title;
dev->VideoInit = kos_VideoInit; dev->VideoInit = kos_VideoInit;
dev->ListModes = kos_ListModes; dev->ListModes = kos_ListModes;
dev->SetVideoMode = kos_SetVideoMode; dev->SetVideoMode = kos_SetVideoMode;
dev->SetColors = kos_SetColors; dev->SetColors = kos_SetColors;
dev->UpdateRects = NULL; dev->UpdateRects = NULL;
dev->VideoQuit = kos_VideoQuit; dev->VideoQuit = kos_VideoQuit;
dev->AllocHWSurface=kos_AllocHWSurface; dev->AllocHWSurface=kos_AllocHWSurface;
dev->CheckHWBlit = NULL; dev->CheckHWBlit = NULL;
dev->FillHWRect = NULL; dev->FillHWRect = NULL;
dev->SetHWColorKey = NULL; dev->SetHWColorKey = NULL;
dev->SetHWAlpha = NULL; dev->SetHWAlpha = NULL;
dev->LockHWSurface = kos_LockHWSurface; dev->LockHWSurface = kos_LockHWSurface;
dev->UnlockHWSurface = kos_UnlockHWSurface; dev->UnlockHWSurface = kos_UnlockHWSurface;
dev->FlipHWSurface = kos_FlipHWSurface; dev->FlipHWSurface = kos_FlipHWSurface;
dev->FreeHWSurface = kos_FreeHWSurface; dev->FreeHWSurface = kos_FreeHWSurface;
dev->SetCaption = kos_SetCaption; dev->SetCaption = kos_SetCaption;
dev->SetIcon = NULL; dev->SetIcon = NULL;
dev->IconifyWindow = NULL; dev->IconifyWindow = NULL;
dev->GrabInput = NULL; dev->GrabInput = NULL;
dev->GetWMInfo = NULL; dev->GetWMInfo = NULL;
dev->InitOSKeymap = MenuetOS_InitOSKeymap; dev->InitOSKeymap = MenuetOS_InitOSKeymap;
dev->PumpEvents = MenuetOS_PumpEvents; dev->PumpEvents = MenuetOS_PumpEvents;
dev->free = kos_DeleteDevice; dev->free = kos_DeleteDevice;
dev->CreateWMCursor = kos_CreateWMCursor; dev->CreateWMCursor = kos_CreateWMCursor;
dev->FreeWMCursor = kos_FreeWMCursor; dev->FreeWMCursor = kos_FreeWMCursor;
dev->ShowWMCursor = kos_ShowWMCursor; dev->ShowWMCursor = kos_ShowWMCursor;
@ -263,7 +278,7 @@ static SDL_VideoDevice *kos_CreateDevice(int indx)
return dev; return dev;
} }
VideoBootStrap mosvideo_bootstrab={ VideoBootStrap mosvideo_bootstrab = {
"kolibrios", "KolibriOS Device Driver", "kolibrios", "KolibriOS Device Driver",
kos_Available, kos_CreateDevice, kos_Available, kos_CreateDevice,
}; };