Browse Source

Platform: macros for easier creation of application entry points.

pull/7/head
Vladimír Vondruš 14 years ago
parent
commit
8789c31dec
  1. 28
      src/Platform/AbstractXApplication.h
  2. 37
      src/Platform/GlutApplication.h
  3. 9
      src/Platform/GlxApplication.h
  4. 12
      src/Platform/NaClApplication.h
  5. 37
      src/Platform/Sdl2Application.h
  6. 9
      src/Platform/XEglApplication.h

28
src/Platform/AbstractXApplication.h

@ -296,6 +296,34 @@ class AbstractXApplication {
Flags flags; Flags flags;
}; };
/** @hideinitializer
@param className Class name
Can be used as equivalent to the following code to achieve better portability,
see @ref portability-applications for more information.
@code
int main(int argc, char** argv) {
className app(argc, argv);
return app.exec();
}
@endcode
When no other application header is included this macro is also aliased to
`MAGNUM_APPLICATION_MAIN()`.
*/
#define MAGNUM_XAPPLICATION_MAIN(className) \
int main(int argc, char** argv) { \
className app(argc, argv); \
return app.exec(); \
}
#ifndef DOXYGEN_GENERATING_OUTPUT
#ifndef MAGNUM_APPLICATION_MAIN
#define MAGNUM_APPLICATION_MAIN(className) MAGNUM_XAPPLICATION_MAIN(className)
#else
#undef MAGNUM_APPLICATION_MAIN
#endif
#endif
CORRADE_ENUMSET_OPERATORS(AbstractXApplication::Modifiers) CORRADE_ENUMSET_OPERATORS(AbstractXApplication::Modifiers)
CORRADE_ENUMSET_OPERATORS(AbstractXApplication::Flags) CORRADE_ENUMSET_OPERATORS(AbstractXApplication::Flags)

37
src/Platform/GlutApplication.h

@ -43,16 +43,13 @@ support for changing cursor and mouse tracking and warping.
@section GlutApplication-usage Usage @section GlutApplication-usage Usage
You need to implement at least drawEvent() and viewportEvent() to be able to You need to implement at least drawEvent() and viewportEvent() to be able to
draw on the screen. The subclass can be then used directly in `main()`, for draw on the screen. The subclass can be then used directly in `main()` - see
example: convenience macro MAGNUM_GLUTAPPLICATION_MAIN().
@code @code
class MyApplication: public Magnum::Platform::GlutApplication { class MyApplication: public Magnum::Platform::GlutApplication {
// implement required methods... // implement required methods...
}; };
int main(int argc, char** argv) { MAGNUM_GLUTAPPLICATION_MAIN(MyApplication)
MyApplication c(argc, argv);
return c.exec();
}
@endcode @endcode
*/ */
class GlutApplication { class GlutApplication {
@ -269,6 +266,34 @@ class GlutApplication {
Context* c; Context* c;
}; };
/** @hideinitializer
@param className Class name
Can be used as equivalent to the following code to achieve better portability,
see @ref portability-applications for more information.
@code
int main(int argc, char** argv) {
className app(argc, argv);
return app.exec();
}
@endcode
When no other application header is included this macro is also aliased to
`MAGNUM_APPLICATION_MAIN()`.
*/
#define MAGNUM_GLUTAPPLICATION_MAIN(className) \
int main(int argc, char** argv) { \
className app(argc, argv); \
return app.exec(); \
}
#ifndef DOXYGEN_GENERATING_OUTPUT
#ifndef MAGNUM_APPLICATION_MAIN
#define MAGNUM_APPLICATION_MAIN(className) MAGNUM_GLUTAPPLICATION_MAIN(className)
#else
#undef MAGNUM_APPLICATION_MAIN
#endif
#endif
/* Implementations for inline functions with unused parameters */ /* Implementations for inline functions with unused parameters */
inline void GlutApplication::keyPressEvent(Key, const Math::Vector2<int>&) {} inline void GlutApplication::keyPressEvent(Key, const Math::Vector2<int>&) {}
inline void GlutApplication::mousePressEvent(MouseButton, const Math::Vector2<int>&) {} inline void GlutApplication::mousePressEvent(MouseButton, const Math::Vector2<int>&) {}

9
src/Platform/GlxApplication.h

@ -32,16 +32,13 @@ Uses GlxContextHandler.
@section GlxApplication-usage Usage @section GlxApplication-usage Usage
You need to implement at least drawEvent() and viewportEvent() to be able to You need to implement at least drawEvent() and viewportEvent() to be able to
draw on the screen. The subclass can be then used directly in `main()`, for draw on the screen. The subclass can be then used directly in `main()` - see
example: convenience macro MAGNUM_XAPPLICATION_MAIN().
@code @code
class MyApplication: public Magnum::Platform::GlxApplication { class MyApplication: public Magnum::Platform::GlxApplication {
// implement required methods... // implement required methods...
}; };
int main(int argc, char** argv) { MAGNUM_XAPPLICATION_MAIN(MyApplication)
MyApplication c(argc, argv);
return c.exec();
}
@endcode @endcode
*/ */
class GlxApplication: public AbstractXApplication { class GlxApplication: public AbstractXApplication {

12
src/Platform/NaClApplication.h

@ -160,7 +160,9 @@ namespace Implementation {
@brief Entry point for NaCl application @brief Entry point for NaCl application
@param application Application class name @param application Application class name
See NaClApplication for more information. See NaClApplication and @ref portability-applications for more information.
When no other application header is included this macro is also aliased to
`MAGNUM_APPLICATION_MAIN()`.
*/ */
/* look at that insane placement of __attribute__. WTF. */ /* look at that insane placement of __attribute__. WTF. */
#define MAGNUM_NACLAPPLICATION_MAIN(application) \ #define MAGNUM_NACLAPPLICATION_MAIN(application) \
@ -170,6 +172,14 @@ See NaClApplication for more information.
} \ } \
} }
#ifndef DOXYGEN_GENERATING_OUTPUT
#ifndef MAGNUM_APPLICATION_MAIN
#define MAGNUM_APPLICATION_MAIN(className) MAGNUM_NACLAPPLICATION_MAIN(className)
#else
#undef MAGNUM_APPLICATION_MAIN
#endif
#endif
}} }}
#endif #endif

37
src/Platform/Sdl2Application.h

@ -42,16 +42,13 @@ Supports keyboard and mouse handling.
@section Sdl2Application-usage Usage @section Sdl2Application-usage Usage
You need to implement at least drawEvent() and viewportEvent() to be able to You need to implement at least drawEvent() and viewportEvent() to be able to
draw on the screen. The subclass can be then used directly in `main()`, for draw on the screen. The subclass can be then used directly in `main()` - see
example: convenience macro MAGNUM_SDL2APPLICATION_MAIN().
@code @code
class MyApplication: public Magnum::Platform::Sdl2Application { class MyApplication: public Magnum::Platform::Sdl2Application {
// implement required methods... // implement required methods...
}; };
int main(int argc, char** argv) { MAGNUM_SDL2APPLICATION_MAIN(MyApplication)
MyApplication c(argc, argv);
return c.exec();
}
@endcode @endcode
*/ */
class Sdl2Application { class Sdl2Application {
@ -217,6 +214,34 @@ class Sdl2Application {
bool _redraw; bool _redraw;
}; };
/** @hideinitializer
@param className Class name
Can be used as equivalent to the following code to achieve better portability,
see @ref portability-applications for more information.
@code
int main(int argc, char** argv) {
className app(argc, argv);
return app.exec();
}
@endcode
When no other application header is included this macro is also aliased to
`MAGNUM_APPLICATION_MAIN()`.
*/
#define MAGNUM_SDL2APPLICATION_MAIN(className) \
int main(int argc, char** argv) { \
className app(argc, argv); \
return app.exec(); \
}
#ifndef DOXYGEN_GENERATING_OUTPUT
#ifndef MAGNUM_APPLICATION_MAIN
#define MAGNUM_APPLICATION_MAIN(className) MAGNUM_SDL2APPLICATION_MAIN(className)
#else
#undef MAGNUM_APPLICATION_MAIN
#endif
#endif
CORRADE_ENUMSET_OPERATORS(Sdl2Application::Modifiers) CORRADE_ENUMSET_OPERATORS(Sdl2Application::Modifiers)
/* Implementations for inline functions with unused parameters */ /* Implementations for inline functions with unused parameters */

9
src/Platform/XEglApplication.h

@ -32,16 +32,13 @@ Uses EglContextHandler.
@section XEglApplication-usage Usage @section XEglApplication-usage Usage
You need to implement at least drawEvent() and viewportEvent() to be able to You need to implement at least drawEvent() and viewportEvent() to be able to
draw on the screen. The subclass can be then used directly in `main()`, for draw on the screen. The subclass can be then used directly in `main()` - see
example: convenience macro MAGNUM_XAPPLICATION_MAIN().
@code @code
class MyApplication: public Magnum::Platform::XEglApplication { class MyApplication: public Magnum::Platform::XEglApplication {
// implement required methods... // implement required methods...
}; };
int main(int argc, char** argv) { MAGNUM_XAPPLICATION_MAIN(MyApplication)
MyApplication c(argc, argv);
return c.exec();
}
@endcode @endcode
*/ */
class XEglApplication: public AbstractXApplication { class XEglApplication: public AbstractXApplication {

Loading…
Cancel
Save