mirror of
https://github.com/ultimatepp/ultimatepp.git
synced 2026-08-15 22:02:51 -06:00
SDL: Changed internal structure
git-svn-id: svn://ultimatepp.org/upp/trunk@2869 f0d560ea-af0d-0410-9eb7-867de7ffcac7
This commit is contained in:
parent
3048ad3eb2
commit
3ce488aa42
3 changed files with 109 additions and 61 deletions
|
|
@ -33,8 +33,9 @@ SDL_Cursor *CursorFromImage(const Image &image)
|
|||
return SDL_CreateCursor(data, mask, width, height, image.GetHotSpot().x, image.GetHotSpot().y);
|
||||
}
|
||||
|
||||
SDLCtrl::SDLCtrl() {
|
||||
SDLCtrl::SDLCtrlIn::SDLCtrlIn() {
|
||||
surface = 0;
|
||||
delIn = false;
|
||||
cursor = 0;
|
||||
|
||||
int flags = SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_TIMER;
|
||||
|
|
@ -57,7 +58,7 @@ SDLCtrl::SDLCtrl() {
|
|||
init = true;
|
||||
|
||||
videoflags = SDL_NOFRAME | SDL_HWSURFACE | SDL_DOUBLEBUF | SDL_RESIZABLE;
|
||||
bpp = 8;
|
||||
bpp = 24;
|
||||
|
||||
SDL_SysWMinfo wmInfo;
|
||||
SDL_VERSION(&wmInfo.version);
|
||||
|
|
@ -77,7 +78,7 @@ SDLCtrl::SDLCtrl() {
|
|||
#endif
|
||||
}
|
||||
|
||||
SDLCtrl::~SDLCtrl() {
|
||||
SDLCtrl::SDLCtrlIn::~SDLCtrlIn() {
|
||||
if (cursor)
|
||||
SDL_FreeCursor(cursor);
|
||||
if (surface)
|
||||
|
|
@ -86,19 +87,15 @@ SDLCtrl::~SDLCtrl() {
|
|||
SDL_Quit();
|
||||
}
|
||||
|
||||
bool SDLCtrl::CreateScreen() {
|
||||
bool SDLCtrl::SDLCtrlIn::CreateScreen() {
|
||||
#ifdef PLATFORM_POSIX
|
||||
if (!isInitialized)
|
||||
return false;
|
||||
#endif
|
||||
if (surface)
|
||||
SDL_FreeSurface(surface);
|
||||
Rect r = GetRect();
|
||||
#ifndef __APPLE__
|
||||
surface = SDL_SetVideoMode(r.GetWidth(), r.GetHeight(), 0, videoflags);
|
||||
#else
|
||||
Rect r = GetView();
|
||||
surface = SDL_SetVideoMode(r.GetWidth(), r.GetHeight(), bpp, videoflags);
|
||||
#endif
|
||||
if(!surface) {
|
||||
SetError(SDL_GetError());
|
||||
return false;
|
||||
|
|
@ -106,14 +103,14 @@ bool SDLCtrl::CreateScreen() {
|
|||
return true;
|
||||
}
|
||||
|
||||
void SDLCtrl::Layout() {
|
||||
void SDLCtrl::SDLCtrlIn::Layout() {
|
||||
#ifdef PLATFORM_WIN32
|
||||
if (!hwndSDL || !hwnd)
|
||||
return;
|
||||
GuiLock __;
|
||||
HWND phwnd = GetTopCtrl()->GetHWND();
|
||||
if(phwnd) {
|
||||
Rect r = GetScreenRect();
|
||||
Rect r = GetScreenView();
|
||||
SetWindowPos(hwnd, NULL, r.left, r.top,
|
||||
r.GetWidth(), r.GetHeight(), SWP_NOACTIVATE|SWP_NOZORDER);
|
||||
}
|
||||
|
|
@ -124,7 +121,7 @@ void SDLCtrl::Layout() {
|
|||
}
|
||||
|
||||
#ifdef PLATFORM_WIN32
|
||||
void SDLCtrl::State(int reason)
|
||||
void SDLCtrl::SDLCtrlIn::State(int reason)
|
||||
{
|
||||
if (!hwndSDL)
|
||||
return;
|
||||
|
|
@ -146,7 +143,7 @@ void SDLCtrl::State(int reason)
|
|||
}
|
||||
#endif
|
||||
|
||||
void SDLCtrl::SetError(String str) {
|
||||
void SDLCtrl::SDLCtrlIn::SetError(String str) {
|
||||
if (!strError.IsEmpty())
|
||||
strError << "\n";
|
||||
strError << ToUpper(str[0]) + DeQtfLf(str.Mid(1));
|
||||
|
|
|
|||
|
|
@ -11,6 +11,9 @@ public:
|
|||
SDLSurface(int width, int height, int bpp = 0);
|
||||
SDLSurface(SDL_Surface *_surface, bool _del = false);
|
||||
~SDLSurface();
|
||||
bool Resize(int width, int height);
|
||||
bool LoadBMP(const char *filename);
|
||||
bool CreateRGB(int width, int height, int bpp);
|
||||
void Lock();
|
||||
void Unlock();
|
||||
bool Blit(SDLSurface &surf, Rect source = Null, Rect dest = Null);
|
||||
|
|
@ -25,59 +28,70 @@ public:
|
|||
void DrawPixel(int x, int y, Color color);
|
||||
void DrawPixel(int x, int y, Uint32 scolor);
|
||||
Color GetPixel(int x, int y);
|
||||
byte GetPixelByte(int x, int y);
|
||||
byte *GetPixelPos(int x, int y);
|
||||
Uint32 GetColor(Color color);
|
||||
int GetBpp() {return surface->format->BitsPerPixel;};
|
||||
int GetWidth() {return surface->w;};
|
||||
int GetHeight() {return surface->h;};
|
||||
const char *GetError() {return SDL_GetError();};
|
||||
bool IsReady() {return surface;};
|
||||
SDL_Surface *GetSurface() {return surface;};
|
||||
|
||||
protected:
|
||||
SDL_Surface *surface;
|
||||
bool del;
|
||||
bool delIn;
|
||||
};
|
||||
|
||||
class SDLCtrl : public DHCtrl, public SDLSurface {
|
||||
class SDLCtrl : public Ctrl {
|
||||
typedef SDLCtrl CLASSNAME;
|
||||
public:
|
||||
SDLCtrl();
|
||||
~SDLCtrl();
|
||||
|
||||
SDLCtrl &SetBpp(int _bpp) {bpp = _bpp; return *this;};
|
||||
SDLCtrl &SetVideoflags(int _vf) {videoflags = _vf; return *this;};
|
||||
String GetError() {
|
||||
const char *err = SDLSurface::GetError();
|
||||
if (*err)
|
||||
return err;
|
||||
else
|
||||
return strError;};
|
||||
void SetError(String str);
|
||||
void ResetError() {strError = "";};
|
||||
bool IsReady() {return surface;};
|
||||
int GetWidth() {return surface->w;};
|
||||
int GetHeight() {return surface->h;};
|
||||
class SDLCtrlIn : public DHCtrl, public SDLSurface {
|
||||
typedef SDLCtrl CLASSNAME;
|
||||
public:
|
||||
SDLCtrlIn();
|
||||
~SDLCtrlIn();
|
||||
|
||||
virtual void Layout();
|
||||
//virtual void Paint(Draw& w);
|
||||
bool CreateScreen();
|
||||
|
||||
#ifdef PLATFORM_POSIX
|
||||
XDisplay *display;
|
||||
#else
|
||||
long hwndSDL;
|
||||
#endif
|
||||
int videoflags;
|
||||
int bpp;
|
||||
|
||||
protected:
|
||||
virtual void Layout();
|
||||
//virtual void Paint(Draw& w);
|
||||
bool CreateScreen();
|
||||
|
||||
#ifdef PLATFORM_POSIX
|
||||
XDisplay *display;
|
||||
#else
|
||||
long hwndSDL;
|
||||
#endif
|
||||
int videoflags;
|
||||
int bpp;
|
||||
|
||||
bool init;
|
||||
|
||||
private:
|
||||
#ifdef PLATFORM_WIN32
|
||||
virtual void State(int reason);
|
||||
#endif
|
||||
SDL_Cursor *cursor;
|
||||
String strError;
|
||||
bool init;
|
||||
|
||||
#ifdef PLATFORM_WIN32
|
||||
virtual void State(int reason);
|
||||
#endif
|
||||
SDL_Cursor *cursor;
|
||||
String strError;
|
||||
String GetError() {return strError;};
|
||||
void SetError(String str);
|
||||
void ResetError() {strError = "";};
|
||||
};
|
||||
SDLCtrlIn ctrlIn;
|
||||
|
||||
public:
|
||||
SDLCtrl() {
|
||||
Add(ctrlIn.SizePos());
|
||||
}
|
||||
SDLCtrl &SetBpp(int bpp) {ctrlIn.bpp = bpp; return *this;};
|
||||
int GetBpp() {return ctrlIn.GetBpp();};
|
||||
SDLCtrl &SetVideoflags(int vf) {ctrlIn.videoflags = vf; return *this;};
|
||||
bool IsReady() {return ctrlIn.IsReady();};
|
||||
int GetWidth() {return ctrlIn.GetWidth();};
|
||||
int GetHeight() {return ctrlIn.GetHeight();};
|
||||
String GetError() {return ctrlIn.GetError();};
|
||||
void SetError(String str) {ctrlIn.SetError(str);};
|
||||
void ResetError() {ctrlIn.ResetError();};
|
||||
SDL_Surface *GetSurface() {return ctrlIn.GetSurface();};
|
||||
bool Blit(SDLSurface &surf, Rect source = Null, Rect dest = Null) {
|
||||
return ctrlIn.Blit(surf, source, dest);};
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -6,23 +6,49 @@ using namespace Upp;
|
|||
|
||||
SDLSurface::SDLSurface() {
|
||||
surface = 0;
|
||||
del = false;
|
||||
delIn = true;
|
||||
}
|
||||
|
||||
SDLSurface::SDLSurface(SDL_Surface *_surface, bool _del) {
|
||||
surface = _surface;
|
||||
del = _del;
|
||||
delIn = _del;
|
||||
}
|
||||
|
||||
SDLSurface::SDLSurface(int width, int height, int bpp) {
|
||||
if (surface = SDL_CreateRGBSurface(0, width, height, bpp, 0x0000FF, 0x00FF00, 0xFF0000, 0))
|
||||
del = true;
|
||||
else
|
||||
del = false;
|
||||
surface = SDL_CreateRGBSurface(0, width, height, bpp, 0x0000FF, 0x00FF00, 0xFF0000, 0);
|
||||
delIn = true;
|
||||
}
|
||||
|
||||
bool SDLSurface::CreateRGB(int width, int height, int bpp) {
|
||||
if (!delIn)
|
||||
return false;
|
||||
if (surface)
|
||||
SDL_FreeSurface(surface);
|
||||
return surface = SDL_CreateRGBSurface(0, width, height, bpp, 0x0000FF, 0x00FF00, 0xFF0000, 0);
|
||||
}
|
||||
|
||||
bool SDLSurface::LoadBMP(const char *filename) {
|
||||
if (!delIn)
|
||||
return false;
|
||||
if (surface)
|
||||
SDL_FreeSurface(surface);
|
||||
return surface = SDL_LoadBMP(filename);
|
||||
}
|
||||
|
||||
bool SDLSurface::Resize(int width, int height) {
|
||||
if (!delIn)
|
||||
return false;
|
||||
int bpp;
|
||||
if (surface) {
|
||||
bpp = GetBpp();
|
||||
SDL_FreeSurface(surface);
|
||||
} else
|
||||
bpp = 0;
|
||||
return surface = SDL_CreateRGBSurface(0, width, height, bpp, 0x0000FF, 0x00FF00, 0xFF0000, 0);
|
||||
}
|
||||
|
||||
SDLSurface::~SDLSurface() {
|
||||
if (del)
|
||||
if (delIn && surface)
|
||||
SDL_FreeSurface(surface);
|
||||
}
|
||||
|
||||
|
|
@ -82,7 +108,11 @@ void SDLSurface::DrawPixel(int x, int y, Color color) {
|
|||
|
||||
inline void SDLSurface::DrawPixel(int x, int y, Uint32 scolor) {
|
||||
byte *pixelpos = GetPixelPos(x, y);
|
||||
if (pixelpos)
|
||||
if (!pixelpos)
|
||||
return;
|
||||
if (surface->format->BytesPerPixel == 1)
|
||||
*pixelpos = (byte)scolor;
|
||||
else
|
||||
memcpy(pixelpos, &scolor, surface->format->BytesPerPixel);
|
||||
}
|
||||
|
||||
|
|
@ -97,6 +127,13 @@ Color SDLSurface::GetPixel(int x, int y) {
|
|||
return Color(r, g, b);
|
||||
}
|
||||
|
||||
byte SDLSurface::GetPixelByte(int x, int y) {
|
||||
byte *pixelpos = GetPixelPos(x, y);
|
||||
if (!pixelpos)
|
||||
return 0;
|
||||
return *pixelpos;
|
||||
}
|
||||
|
||||
void SDLSurface::DrawImage(Image img, int x0, int y0, Color transparent) {
|
||||
for(int y = 0; y < img.GetHeight(); y++) {
|
||||
for(int x = 0; x < img.GetWidth(); x++) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue