@@ -250,40 +250,65 @@ typedef uint32_t MCGColor;
250250
251251struct MCGPoint
252252{
253- public:
254- /* TODO[C++11] Use member initialisers and remove these constructors */
255- MCGPoint () : x(0 ), y(0 ) {}
256- MCGPoint (MCGFloat p_x, MCGFloat p_y) : x(p_x), y(p_y) {}
257- MCGFloat x, y;
253+ /* TODO[C++14] In C++11, aggregate initialisation of object types
254+ * with member variables that have static initialisers is
255+ * forbidden. In C++14, this restriction is relaxed (so these
256+ * constructors can be removed). */
257+ constexpr MCGPoint () = default;
258+ constexpr MCGPoint (MCGFloat p_x, MCGFloat p_y) : x(p_x), y(p_y) {}
259+
260+ MCGFloat x = 0 ;
261+ MCGFloat y = 0 ;
258262};
259263
260264struct MCGSize
261265{
262- MCGFloat width, height;
266+ /* TODO[C++14] In C++11, aggregate initialisation of object types
267+ * with member variables that have static initialisers is
268+ * forbidden. In C++14, this restriction is relaxed (so these
269+ * constructors can be removed). */
270+ constexpr MCGSize () = default;
271+ constexpr MCGSize (MCGFloat p_width, MCGFloat p_height)
272+ : width(p_width), height(p_height) {}
273+
274+ MCGFloat width = 0 ;
275+ MCGFloat height = 0 ;
263276};
264277
265278struct MCGRectangle
266279{
267- MCGPoint origin;
268- MCGSize size;
280+ /* TODO[C++14] In C++11, aggregate initialisation of object types
281+ * with member variables that have static initialisers is
282+ * forbidden. In C++14, this restriction is relaxed (so these
283+ * constructors can be removed). */
284+ constexpr MCGRectangle () = default;
285+ constexpr MCGRectangle (MCGPoint p_origin, MCGSize p_size)
286+ : origin(p_origin), size(p_size) {}
287+
288+ MCGPoint origin;
289+ MCGSize size;
269290};
270291
271292struct MCGAffineTransform
272293{
273- MCGFloat a, b, c, d;
274- MCGFloat tx, ty;
294+ MCGFloat a = 0 ;
295+ MCGFloat b = 0 ;
296+ MCGFloat c = 0 ;
297+ MCGFloat d = 0 ;
298+ MCGFloat tx = 0 ;
299+ MCGFloat ty = 0 ;
275300};
276301
277302struct MCGIntegerPoint
278303{
279- int32_t x;
280- int32_t y;
304+ int32_t x = 0 ;
305+ int32_t y = 0 ;
281306};
282307
283308struct MCGIntegerSize
284309{
285- uint32_t width;
286- uint32_t height;
310+ uint32_t width = 0 ;
311+ uint32_t height = 0 ;
287312};
288313
289314struct MCGIntegerRectangle
@@ -443,50 +468,61 @@ enum MCGMaskFormat
443468
444469struct MCGRaster
445470{
446- MCGRasterFormat format;
447- uint32_t width;
448- uint32_t height;
449- uint32_t stride;
450- void *pixels;
471+ MCGRasterFormat format = kMCGRasterFormat_xRGB ;
472+ uint32_t width = 0 ;
473+ uint32_t height = 0 ;
474+ uint32_t stride = 0 ;
475+ void *pixels = nullptr ;
451476};
452477
453478struct MCGStrokeAttr
454479{
455- MCGFloat width;
456- MCGJoinStyle join_style;
457- MCGCapStyle cap_style;
458- MCGFloat miter_limit;
459- MCGDashesRef dashes;
480+ MCGFloat width = 0 ;
481+ MCGJoinStyle join_style = kMCGJoinStyleBevel ;
482+ MCGCapStyle cap_style = kMCGCapStyleButt ;
483+ MCGFloat miter_limit = 0 ;
484+ MCGDashesRef dashes = nullptr ;
460485};
461486
462487struct MCGLayerEffect
463488{
464- MCGColor color;
465- MCGBlendMode blend_mode;
489+ MCGColor color = 0 ;
490+ MCGBlendMode blend_mode = kMCGBlendModeClear ;
466491};
467492
468493struct MCGShadowEffect
469494{
470- MCGColor color;
471- MCGBlendMode blend_mode;
472- MCGFloat size;
473- MCGFloat spread;
474- MCGFloat x_offset;
475- MCGFloat y_offset;
495+ constexpr MCGShadowEffect () : knockout(false ) {}
496+ MCGColor color = 0 ;
497+ MCGBlendMode blend_mode = kMCGBlendModeClear ;
498+ MCGFloat size = 0 ;
499+ MCGFloat spread = 0 ;
500+ MCGFloat x_offset = 0 ;
501+ MCGFloat y_offset = 0 ;
476502 bool knockout : 1 ;
477503};
478504
479505struct MCGGlowEffect
480506{
481- MCGColor color;
482- MCGBlendMode blend_mode;
483- MCGFloat size;
484- MCGFloat spread;
507+ constexpr MCGGlowEffect () : inverted(false ) {}
508+ MCGColor color = 9 ;
509+ MCGBlendMode blend_mode = kMCGBlendModeClear ;
510+ MCGFloat size = 0 ;
511+ MCGFloat spread = 0 ;
485512 bool inverted : 1 ;
486513};
487514
488515struct MCGBitmapEffects
489516{
517+ /* bitfield struct members can't have static initializers, so we have
518+ to write a constexpr constructor for them. */
519+ constexpr MCGBitmapEffects ()
520+ : has_color_overlay(false ),
521+ has_inner_glow(false ),
522+ has_inner_shadow(false ),
523+ has_outer_glow(false ),
524+ has_drop_shadow(false ) {}
525+
490526 bool has_color_overlay : 1 ;
491527 bool has_inner_glow : 1 ;
492528 bool has_inner_shadow : 1 ;
@@ -502,23 +538,23 @@ struct MCGBitmapEffects
502538
503539struct MCGDeviceMaskInfo
504540{
505- MCGMaskFormat format;
506- int32_t x, y, width, height;
507- void *data;
541+ MCGMaskFormat format = kMCGMaskFormat_A1 ;
542+ int32_t x = 0 ;
543+ int32_t y = 0 ;
544+ int32_t width = 0 ;
545+ int32_t height = 0 ;
546+ void *data = nullptr ;
508547};
509548
510549struct MCGFont
511550{
512- MCGFont ()
513- : fid(nullptr ), size(0 ), fixed_advance(0 ),
514- m_ascent (0 ), m_descent(0 ), m_leading(0 ), ideal(false ) {}
515-
516- void *fid;
517- uint16_t size;
518- uint16_t fixed_advance;
519- MCGFloat m_ascent;
520- MCGFloat m_descent;
521- MCGFloat m_leading;
551+ constexpr MCGFont () : ideal(false ) {}
552+ void *fid = nullptr ;
553+ uint16_t size = 0 ;
554+ uint16_t fixed_advance = 0 ;
555+ MCGFloat m_ascent = 0 ;
556+ MCGFloat m_descent = 0 ;
557+ MCGFloat m_leading = 0 ;
522558 bool ideal : 1 ;
523559};
524560
0 commit comments