@@ -126,12 +126,17 @@ namespace MiniEngine
126126 h = H;
127127 }
128128
129+ Rect::Rect (const SDL_Rect& r):Rect(r.x,r.y,r.w,r.h)
130+ {
131+
132+ }
133+
129134 Rect::Rect ()
130135 {
131136 x = y = w = h = 0 ;
132137 }
133138
134- SDL_Rect Rect::toSDLRect ()
139+ SDL_Rect Rect::toSDLRect () const
135140 {
136141 SDL_Rect r;
137142 r.x = x;
@@ -141,6 +146,44 @@ namespace MiniEngine
141146 return r;
142147 }
143148
149+ bool Rect::isEmpty ()
150+ {
151+ SDL_Rect r=toSDLRect ();
152+ return SDL_RectEmpty (&r)==SDL_TRUE ;
153+ }
154+
155+ bool Rect::operator == (const Rect& r) const
156+ {
157+ SDL_Rect a=toSDLRect (),b=r.toSDLRect ();
158+ return SDL_RectEquals (&a,&b)==SDL_TRUE ;
159+ }
160+
161+ bool Rect::hasIntersection (const Rect& r)
162+ {
163+ SDL_Rect a=toSDLRect (),b=r.toSDLRect ();
164+ return SDL_HasIntersection (&a,&b)==SDL_TRUE ;
165+ }
166+
167+ Rect Rect::getIntersection (const Rect& r)
168+ {
169+ SDL_Rect a=toSDLRect (),b=r.toSDLRect (),c;
170+ if (SDL_IntersectRect (&a,&b,&c)==SDL_TRUE )
171+ {
172+ return Rect (c);
173+ }
174+ else
175+ {
176+ return Rect ();
177+ }
178+ }
179+
180+ Rect Rect::getUnion (const Rect& r)
181+ {
182+ SDL_Rect a=toSDLRect (),b=r.toSDLRect (),c;
183+ SDL_UnionRect (&a,&b,&c);// void
184+ return Rect (c);
185+ }
186+
144187 Point::Point (int X, int Y)
145188 {
146189 x = X;
@@ -1267,6 +1310,54 @@ namespace MiniEngine
12671310 va_end (ap);
12681311 }
12691312
1313+ SharedLibrary::SharedLibrary ()
1314+ {
1315+ _obj=nullptr ;
1316+ }
1317+
1318+ SharedLibrary::SharedLibrary (const std::string& Filename)
1319+ {
1320+ _obj=nullptr ;
1321+ load (Filename);
1322+ }
1323+
1324+ SharedLibrary::~SharedLibrary ()
1325+ {
1326+ if (_obj)
1327+ {
1328+ unload ();
1329+ }
1330+ }
1331+
1332+ int SharedLibrary::load (const std::string& Filename)
1333+ {
1334+ if (_obj) return -1 ;
1335+ else
1336+ {
1337+ _obj=SDL_LoadObject (Filename.c_str ());
1338+ if (_obj) return 0 ;
1339+ else return -2 ;
1340+ }
1341+ }
1342+
1343+ int SharedLibrary::unload ()
1344+ {
1345+ if (_obj)
1346+ {
1347+ SDL_UnloadObject (_obj);
1348+ _obj=nullptr ;
1349+ return 0 ;
1350+ }
1351+ else return -1 ;
1352+ }
1353+
1354+ void * SharedLibrary::get (const std::string& FunctionName)
1355+ {
1356+ if (!_obj) return nullptr ;
1357+ else return SDL_LoadFunction (_obj,FunctionName.c_str ());
1358+ }
1359+
1360+
12701361 int SDLSystem::SDLInit ()
12711362 {
12721363 return SDL_Init (SDL_INIT_EVERYTHING );
@@ -1404,7 +1495,6 @@ namespace MiniEngine
14041495 // / Global Executor For class Timer
14051496 Uint32 _global_timer_executor (Uint32 interval,void * param)
14061497 {
1407- printf (" DEBUG: Global Timer Executor.\n " );
14081498 auto p=reinterpret_cast <std::function<Uint32 (Uint32 interval)>*>(param);
14091499 return (*p)(interval);
14101500 }
0 commit comments