Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Do we want numeric grid?
- #define NUM_GRID
- // Set options based on which grid was selected
- #ifdef NUM_GRID
- #define GRID_ZOOMMAX2 1.00000001504746624E30
- // Property formatX in the first class has one zero more than in the second class
- #define GRID_FORMAT_X2 00
- #define GRID_FORMAT_X1 GRID_FORMAT_X2##0
- // These properties don't change so just copy from previous
- #define GRID_FORMAT_Y1 GRID_FORMAT_X1
- #define GRID_FORMAT_Y2 GRID_FORMAT_X2
- #define GRID_STEP 100
- // This is a multiplier, -1 will result in a negative number
- #define GRID_STEP_Y -1
- #else
- #define GRID_ZOOMMAX2 1.00000001504747E+30
- // Property formatX in the first class has one letter more than in the second class
- #define GRID_FORMAT_X2 A
- #define GRID_FORMAT_X1 GRID_FORMAT_X2##a
- // Property formatY in the first class has one zero more than in the second class
- #define GRID_FORMAT_Y2 0
- #define GRID_FORMAT_Y1 GRID_FORMAT_Y2##0
- #define GRID_STEP 128
- // This is a multiplier, 1 means no change
- #define GRID_STEP_Y 1
- #endif
- class Grid
- {
- offsetX = 0;
- offsetY =
- #ifdef NUM_GRID 12800
- #else 0
- #endif ;
- // Zoom classes are similar so create a function-like macro
- #define GRID_ZOOM(NUM, ZOOMMAX, FORMATX, FORMATY, STEP, STEP_Y, MULTIPLIER) \
- class Zoom##NUM { \
- zoomMax = ZOOMMAX; \
- format = "XY"; \
- formatX = #FORMATX; \
- formatY = #FORMATY; \
- stepX = __EVAL(STEP * MULTIPLIER); \
- stepY = __EVAL(STEP * MULTIPLIER * STEP_Y); \
- };
- // NUM - class name appendix
- // #FORMATX, #FORMATY - will wrap macro in quotation marks
- // __EVAL() - calculates formula
- // STEP_Y, MULTIPLIER - multipliers, in the second class the value needs to be larger
- // Now call this function and pass to it options defined on the beginning
- GRID_ZOOM(1, 0.2 ,GRID_FORMAT_X1,GRID_FORMAT_Y1, GRID_STEP, GRID_STEP_Y, 1)
- GRID_ZOOM(2, GRID_ZOOMMAX2 ,GRID_FORMAT_X2,GRID_FORMAT_Y2, GRID_STEP, GRID_STEP_Y, 10)
- // This will create classes Zoom1 and Zoom2
- // Be careful with whitespaces as they are not ignored in the function-like macros
- };
- /*
- After preprocessing with NUM_GRID macro
- Cleaned for readability
- class Grid
- {
- offsetX = 0;
- offsetY = 12800;
- class Zoom1 {
- zoomMax = 0.2;
- format = "XY";
- formatX = "000";
- formatY = "000";
- stepX = __EVAL( 100 * 1);
- stepY = __EVAL( 100 * 1 * -1);
- };
- class Zoom2 {
- zoomMax = 1.00000001504746624E30;
- format = "XY";
- formatX = "00";
- formatY = "00";
- stepX = __EVAL( 100 * 10);
- stepY = __EVAL( 100 * 10 * -1);
- };
- };
- After preprocessing without NUM_GRID macro
- Cleaned for readability
- class Grid
- {
- offsetX = 0;
- offsetY = 0;
- class Zoom1 {
- zoomMax = 0.2;
- format = "XY";
- formatX = "Aa";
- formatY = "00";
- stepX = __EVAL( 128 * 1);
- stepY = __EVAL( 128 * 1 * 1);
- };
- class Zoom2 {
- zoomMax = 1.00000001504747E+30;
- format = "XY";
- formatX = "A";
- formatY = "0";
- stepX = __EVAL( 128 * 10);
- stepY = __EVAL( 128 * 10 * 1);
- };
- };
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement