Simple macros for init code

Post those lines of code you feel like sharing or find what you require for your project here; or simply use them as tutorials.
Post Reply
Dreadstew
Posts: 23
Joined: Wed Apr 01, 2015 5:18 pm

Simple macros for init code

Post by Dreadstew »

I have some macros I made for my init code. Very simple but make code cleaner, especially QuickScene

Code: Select all

 
#define MessageBoxAndQuit(lstr) MessageBox(0, (lstr), 0, MB_OK | MB_ICONERROR); \
                                return 1
 
//allows you to draw any number of components by putting them between begin and end scene
#define QuickScene(drawcalls)   driver->beginScene(); \
                                (drawcalls) \
                                driver->endScene()
 
#define LoadValidate(pointer, errormessage) if (!(pointer)) { MessageBoxAndQuit((errormessage)); }
 
use quick scene by putting drawcalls ended with a semicolon. Like this.

Code: Select all

 
QuickScene(guiobject->draw(); otherobject->draw(); thing->draw(););
 
You have to name your driver variable "driver" for this to work

Also, MessageBox is in Windows.h. I planned on supporting Linux, but after finding that it takes hundreds of crazy lines to make a message box that isn't even standard, I dropped support for it lol (aka deleted 10 lines of preprocessor addled code) 8)
hendu
Posts: 2600
Joined: Sat Dec 18, 2010 12:53 pm

Re: Simple macros for init code

Post by hendu »

FLTK lets you have OS-independent things like that easily. fl_alert("Something happened");
Dreadstew
Posts: 23
Joined: Wed Apr 01, 2015 5:18 pm

Re: Simple macros for init code

Post by Dreadstew »

I'll look into that! Thanks for letting me know!
Post Reply