Skip to content

Commit 1601313

Browse files
committed
Refactored array properties
1 parent 57d2e20 commit 1601313

15 files changed

Lines changed: 1033 additions & 12 deletions

engine/src/bitmapeffect.cpp

Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -446,6 +446,7 @@ static Exec_stat MCBitmapEffectGetProperty(MCBitmapEffect *effect, MCBitmapEffec
446446
return ES_NORMAL;
447447
}
448448

449+
449450
Exec_stat MCBitmapEffectsGetProperties(MCBitmapEffectsRef& self, Properties which_type, MCExecPoint& ep, MCNameRef prop)
450451
{
451452
// Reset ep to empty, the default value.
@@ -508,6 +509,88 @@ Exec_stat MCBitmapEffectsGetProperties(MCBitmapEffectsRef& self, Properties whic
508509
return ES_NORMAL;
509510
}
510511

512+
513+
bool MCBitmapEffectsGetPropertyElement(MCBitmapEffectsRef& self, Properties which_type, MCNameRef p_prop, MCValueRef& r_setting)
514+
{
515+
MCExecPoint ep(nil, nil, nil);
516+
517+
// First map the property type
518+
MCBitmapEffectType t_type;
519+
t_type = (MCBitmapEffectType)(which_type - P_BITMAP_EFFECT_DROP_SHADOW);
520+
521+
// Now fetch the bitmap effect we are processing - note that if this is
522+
// NULL it means it isn't set. In this case we still carry on since we
523+
// need to report a invalid key error (if applicable).
524+
MCBitmapEffect *t_effect;
525+
if (self != nil && (self -> mask & (1 << t_type)) != 0)
526+
t_effect = &self -> effects[t_type];
527+
else
528+
t_effect = nil;
529+
530+
MCBitmapEffectProperty t_property;
531+
if (MCBitmapEffectLookupProperty(t_type, p_prop, t_property) != ES_NORMAL)
532+
return false;
533+
534+
// If there is no effect set for this type, then we are done.
535+
if (t_effect == nil)
536+
return true;
537+
538+
// Otherwise fetch for the appropriate effect.
539+
if (MCBitmapEffectGetProperty(&self -> effects[t_type], t_property, ep) == ES_NORMAL)
540+
{
541+
/* UNCHECKED */ ep . copyasvalueref(r_setting);
542+
return true;
543+
}
544+
545+
return false;
546+
}
547+
548+
bool MCBitmapEffectsGetProperties(MCBitmapEffectsRef& self, Properties which_type, MCArrayRef& r_props)
549+
{
550+
MCExecPoint ep(nil, nil, nil);
551+
552+
// First map the property type
553+
MCBitmapEffectType t_type;
554+
t_type = (MCBitmapEffectType)(which_type - P_BITMAP_EFFECT_DROP_SHADOW);
555+
556+
// Now fetch the bitmap effect we are processing - note that if this is
557+
// NULL it means it isn't set. In this case we still carry on since we
558+
// need to report a invalid key error (if applicable).
559+
MCBitmapEffect *t_effect;
560+
if (self != nil && (self -> mask & (1 << t_type)) != 0)
561+
t_effect = &self -> effects[t_type];
562+
else
563+
t_effect = nil;
564+
565+
// If there is no effect set for this type, then we are done.
566+
if (t_effect == nil)
567+
return true;
568+
569+
// Otherwise we have an array get, so first create a new value
570+
MCAutoArrayRef v;
571+
if (!MCArrayCreateMutable(&v))
572+
return false;
573+
574+
// Now loop through all the properties, getting the ones applicable to this type.
575+
for(uint32_t i = 0; i < ELEMENTS(s_bitmap_effect_properties); i++)
576+
if ((s_bitmap_effect_properties[i] . mask & (1 << t_type)) != 0)
577+
{
578+
MCValueRef t_prop_value;
579+
MCNewAutoNameRef t_key;
580+
581+
/* UNCHECKED */ MCNameCreateWithCString(s_bitmap_effect_properties[i] . token, &t_key);
582+
// Attempt to fetch the property, then store it into the array.
583+
if (MCBitmapEffectGetProperty(t_effect, s_bitmap_effect_properties[i] . value, ep) != ES_NORMAL)
584+
return false;
585+
586+
/* UNCHECKED */ ep . copyasvalueref(t_prop_value);
587+
MCArrayStoreValue(*v, kMCCompareExact, *t_key, t_prop_value);
588+
}
589+
590+
// Give the array to the ep
591+
r_props = MCValueRetain(*v);
592+
}
593+
511594
// Set the given effect to default values for its type.
512595
static void MCBitmapEffectDefault(MCBitmapEffect *p_effect, MCBitmapEffectType p_type)
513596
{
@@ -777,6 +860,7 @@ Exec_stat MCBitmapEffectSetProperty(MCBitmapEffect *self, MCBitmapEffectProperty
777860
return ES_NORMAL;
778861
}
779862

863+
780864
Exec_stat MCBitmapEffectsSetProperties(MCBitmapEffectsRef& self, Properties which_type, MCExecPoint& ep, MCNameRef prop, Boolean& r_dirty)
781865
{
782866
// First map the property type
@@ -892,6 +976,183 @@ Exec_stat MCBitmapEffectsSetProperties(MCBitmapEffectsRef& self, Properties whic
892976
return ES_NORMAL;
893977
}
894978

979+
980+
bool MCBitmapEffectsSetPropertyElement(MCBitmapEffectsRef& self, Properties which_type, MCValueRef p_setting, MCNameRef p_prop, bool& r_dirty)
981+
{
982+
MCExecPoint ep(nil, nil, nil);
983+
984+
// First map the property type
985+
MCBitmapEffectType t_type;
986+
t_type = (MCBitmapEffectType)(which_type - P_BITMAP_EFFECT_DROP_SHADOW);
987+
988+
// A temporary bool to store the dirtiness
989+
bool t_dirty;
990+
991+
// Fetch (a copy of) the bitmap effect we are processing, otherwise
992+
// initialize one with defaults for the type.
993+
MCBitmapEffect t_effect;
994+
if (self != nil && (self -> mask & (1 << t_type)) != 0)
995+
{
996+
t_effect = self -> effects[t_type];
997+
998+
// At this point we have made no changes.
999+
t_dirty = false;
1000+
}
1001+
else
1002+
{
1003+
MCBitmapEffectDefault(&t_effect, t_type);
1004+
1005+
// If the effect doesn't yet exist, it means we will dirty the object
1006+
// regardless.
1007+
t_dirty = true;
1008+
}
1009+
1010+
Boolean t_dirty_boolean;
1011+
t_dirty_boolean = False;
1012+
// Now update the copy of the effect with any newly set properties
1013+
1014+
// Lookup the property and ensure it is appropriate for our type.
1015+
MCBitmapEffectProperty t_property;
1016+
if (MCBitmapEffectLookupProperty(t_type, p_prop, t_property) != ES_NORMAL)
1017+
return false;
1018+
1019+
// Set the property in our (copy of the) bitmap effect.
1020+
/* UNCHECKED */ ep . setvalueref(p_setting);
1021+
1022+
if (MCBitmapEffectSetProperty(&t_effect, t_property, ep, t_dirty_boolean) != ES_NORMAL)
1023+
return false;
1024+
1025+
if (t_dirty_boolean != False)
1026+
t_dirty = true;
1027+
1028+
// If no changes have been made, we have nothing to do.
1029+
if (!t_dirty)
1030+
return true;
1031+
1032+
// Otherwise we must commit the changes
1033+
1034+
// If we are currently empty, then allocate a new object
1035+
if (self == NULL)
1036+
{
1037+
self = new MCBitmapEffects;
1038+
if (self == NULL)
1039+
return false;
1040+
1041+
// Only need to initialize the mask.
1042+
self -> mask = 0;
1043+
}
1044+
1045+
// Now copy in the updated effect.
1046+
self -> mask |= (1 << t_type);
1047+
self -> effects[t_type] = t_effect;
1048+
1049+
r_dirty = t_dirty;
1050+
return true;
1051+
}
1052+
1053+
1054+
bool MCBitmapEffectsSetProperties(MCBitmapEffectsRef& self, Properties which_type, MCArrayRef p_setting, bool& r_dirty)
1055+
{
1056+
MCExecPoint ep(nil, nil, nil);
1057+
1058+
// First map the property type
1059+
MCBitmapEffectType t_type;
1060+
t_type = (MCBitmapEffectType)(which_type - P_BITMAP_EFFECT_DROP_SHADOW);
1061+
1062+
// First handle the 'clear' action (i.e. carray is empty and ep is 'empty')
1063+
if (MCArrayIsEmpty(p_setting))
1064+
{
1065+
if (self == nil || (self -> mask & (1 << t_type)) == 0)
1066+
return true;
1067+
1068+
// We are set, so just unset our bit in the mask
1069+
self -> mask &= ~(1 << t_type);
1070+
1071+
// If we are now empty, then clear.
1072+
if (self -> mask == 0)
1073+
MCBitmapEffectsClear(self);
1074+
1075+
// Mark the object as dirty
1076+
r_dirty = true;
1077+
1078+
return true;
1079+
}
1080+
1081+
// A temporary boolean to store the dirtiness
1082+
bool t_dirty;
1083+
1084+
// Fetch (a copy of) the bitmap effect we are processing, otherwise
1085+
// initialize one with defaults for the type.
1086+
MCBitmapEffect t_effect;
1087+
if (self != nil && (self -> mask & (1 << t_type)) != 0)
1088+
{
1089+
t_effect = self -> effects[t_type];
1090+
1091+
// At this point we have made no changes.
1092+
t_dirty = false;
1093+
}
1094+
else
1095+
{
1096+
MCBitmapEffectDefault(&t_effect, t_type);
1097+
1098+
// If the effect doesn't yet exist, it means we will dirty the object
1099+
// regardless.
1100+
t_dirty = true;
1101+
}
1102+
1103+
Boolean t_dirty_boolean;
1104+
t_dirty_boolean = False;
1105+
1106+
// Loop through all the properties in the table and apply the relevant
1107+
// ones.
1108+
for(uint32_t i = 0; i < ELEMENTS(s_bitmap_effect_properties); i++)
1109+
if ((s_bitmap_effect_properties[i] . mask & (1 << t_type)) != 0)
1110+
{
1111+
MCValueRef t_prop_value;
1112+
MCNewAutoNameRef t_key;
1113+
1114+
/* UNCHECKED */ MCNameCreateWithCString(s_bitmap_effect_properties[i] . token, &t_key);
1115+
// If we don't have the given element, then move to the next one
1116+
if (!MCArrayFetchValue((MCArrayRef)p_setting, kMCCompareExact, *t_key, t_prop_value))
1117+
continue;
1118+
1119+
// Otherwise, fetch the keys value and attempt to set the property
1120+
/* UNCHECKED */ ep . setvalueref(t_prop_value);
1121+
if (!MCBitmapEffectSetProperty(&t_effect, s_bitmap_effect_properties[i] . value, ep, t_dirty_boolean))
1122+
return false;
1123+
1124+
if (t_dirty_boolean != False)
1125+
t_dirty = true;
1126+
}
1127+
1128+
// If no changes have been made, we have nothing to do.
1129+
if (!t_dirty)
1130+
return true;
1131+
1132+
// Otherwise we must commit the changes
1133+
1134+
// If we are currently empty, then allocate a new object
1135+
if (self == NULL)
1136+
{
1137+
self = new MCBitmapEffects;
1138+
if (self == NULL)
1139+
return false;
1140+
1141+
// Only need to initialize the mask.
1142+
self -> mask = 0;
1143+
}
1144+
1145+
// Now copy in the updated effect.
1146+
self -> mask |= (1 << t_type);
1147+
self -> effects[t_type] = t_effect;
1148+
1149+
// Return the dirtiness.
1150+
r_dirty = t_dirty;
1151+
1152+
return true;
1153+
}
1154+
1155+
8951156
uint32_t MCBitmapEffectsWeigh(MCBitmapEffectsRef self)
8961157
{
8971158
uint32_t t_size;

engine/src/bitmapeffect.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ bool MCBitmapEffectsScale(MCBitmapEffectsRef& x_dst, int32_t scale);
3434

3535
Exec_stat MCBitmapEffectsSetProperties(MCBitmapEffectsRef& self, Properties which_type, MCExecPoint& ep, MCNameRef prop, Boolean& r_dirty);
3636
Exec_stat MCBitmapEffectsGetProperties(MCBitmapEffectsRef& self, Properties which_type, MCExecPoint& ep, MCNameRef prop);
37+
bool MCBitmapEffectsSetPropertyElement(MCBitmapEffectsRef& self, Properties which_type, MCValueRef p_setting, MCNameRef p_prop, bool& r_dirty);
38+
bool MCBitmapEffectsSetProperties(MCBitmapEffectsRef& self, Properties which_type, MCArrayRef p_setting, bool& r_dirty);
39+
bool MCBitmapEffectsGetPropertyElement(MCBitmapEffectsRef& self, Properties which_type, MCNameRef p_prop, MCValueRef& r_setting);
40+
bool MCBitmapEffectsGetProperties(MCBitmapEffectsRef& self, Properties which_type, MCArrayRef& r_props);
3741

3842
uint32_t MCBitmapEffectsWeigh(MCBitmapEffectsRef self);
3943
IO_stat MCBitmapEffectsPickle(MCBitmapEffectsRef self, MCObjectOutputStream& p_stream);

engine/src/control.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,17 @@ MCPropertyInfo MCControl::kProperties[] =
6565

6666
DEFINE_RW_OBJ_NON_EFFECTIVE_ENUM_PROPERTY(P_LAYER_MODE, InterfaceLayerMode, MCControl, LayerMode)
6767
DEFINE_RO_OBJ_EFFECTIVE_ENUM_PROPERTY(P_LAYER_MODE, InterfaceLayerMode, MCControl, LayerMode)
68+
69+
DEFINE_RW_OBJ_ARRAY_PROPERTY(P_BITMAP_EFFECT_DROP_SHADOW, Any, MCControl, DropShadowElement)
70+
DEFINE_RW_OBJ_PROPERTY(P_BITMAP_EFFECT_DROP_SHADOW, Array, MCControl, DropShadow)
71+
DEFINE_RW_OBJ_ARRAY_PROPERTY(P_BITMAP_EFFECT_INNER_SHADOW, Any, MCControl, InnerShadowElement)
72+
DEFINE_RW_OBJ_PROPERTY(P_BITMAP_EFFECT_INNER_SHADOW, Array, MCControl, InnerShadow)
73+
DEFINE_RW_OBJ_ARRAY_PROPERTY(P_BITMAP_EFFECT_OUTER_GLOW, Any, MCControl, OuterGlowElement)
74+
DEFINE_RW_OBJ_PROPERTY(P_BITMAP_EFFECT_OUTER_GLOW, Array, MCControl, OuterGlow)
75+
DEFINE_RW_OBJ_ARRAY_PROPERTY(P_BITMAP_EFFECT_INNER_GLOW, Any, MCControl, InnerGlowElement)
76+
DEFINE_RW_OBJ_PROPERTY(P_BITMAP_EFFECT_INNER_GLOW, Array, MCControl, InnerGlow)
77+
DEFINE_RW_OBJ_ARRAY_PROPERTY(P_BITMAP_EFFECT_COLOR_OVERLAY, Any, MCControl, ColorOverlayElement)
78+
DEFINE_RW_OBJ_PROPERTY(P_BITMAP_EFFECT_COLOR_OVERLAY, Array, MCControl, ColorOverlay)
6879
};
6980

7081
MCObjectPropertyTable MCControl::kPropertyTable =
@@ -681,7 +692,6 @@ Exec_stat MCControl::setarrayprop_legacy(uint4 parid, Properties which, MCExecPo
681692
default:
682693
break;
683694
}
684-
685695
return MCObject::setarrayprop_legacy(parid, which, ep, key, effective);
686696
}
687697

engine/src/control.h

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,11 @@ class MCControl : public MCObject
330330
void DoSetHScrollbar(MCExecContext& ctxt, MCScrollbar*& hsb, uint2& sbw);
331331
void DoSetVScrollbar(MCExecContext& ctxt, MCScrollbar*& vsb, uint2& sbw);
332332
void DoSetScrollbarWidth(MCExecContext& ctxt, uint2& sbw, uinteger_t p_width);
333-
333+
334+
void DoGetBitmapEffectArray(MCExecContext& ctxt, Properties which, MCArrayRef& r_array);
335+
void DoSetBitmapEffectArray(MCExecContext& ctxt, Properties which, MCArrayRef p_array);
336+
void DoGetBitmapEffectElement(MCExecContext& ctxt, Properties which, MCNameRef p_prop, MCValueRef& r_value);
337+
void DoSetBitmapEffectElement(MCExecContext& ctxt, Properties which, MCNameRef p_prop, MCValueRef p_value);
334338

335339
////////// PROPERTY ACCESSORS
336340

@@ -357,6 +361,27 @@ class MCControl : public MCObject
357361
virtual void SetShowFocusBorder(MCExecContext& ctxt, bool setting);
358362
virtual void SetOpaque(MCExecContext& ctxt, bool setting);
359363
virtual void SetShadow(MCExecContext& ctxt, const MCInterfaceShadow& p_shadow);
364+
365+
void GetDropShadow(MCExecContext& ctxt, MCArrayRef& r_array);
366+
void SetDropShadow(MCExecContext& ctxt, MCArrayRef p_array);
367+
void GetDropShadowElement(MCExecContext& ctxt, MCNameRef p_prop, MCValueRef& r_value);
368+
void SetDropShadowElement(MCExecContext& ctxt, MCNameRef p_prop, MCValueRef p_value);
369+
void GetInnerShadow(MCExecContext& ctxt, MCArrayRef& r_array);
370+
void SetInnerShadow(MCExecContext& ctxt, MCArrayRef p_array);
371+
void GetInnerShadowElement(MCExecContext& ctxt, MCNameRef p_prop, MCValueRef& r_value);
372+
void SetInnerShadowElement(MCExecContext& ctxt, MCNameRef p_prop, MCValueRef p_value);
373+
void GetOuterGlow(MCExecContext& ctxt, MCArrayRef& r_array);
374+
void SetOuterGlow(MCExecContext& ctxt, MCArrayRef p_array);
375+
void GetOuterGlowElement(MCExecContext& ctxt, MCNameRef p_prop, MCValueRef& r_value);
376+
void SetOuterGlowElement(MCExecContext& ctxt, MCNameRef p_prop, MCValueRef p_value);
377+
void GetInnerGlow(MCExecContext& ctxt, MCArrayRef& r_array);
378+
void SetInnerGlow(MCExecContext& ctxt, MCArrayRef p_array);
379+
void GetInnerGlowElement(MCExecContext& ctxt, MCNameRef p_prop, MCValueRef& r_value);
380+
void SetInnerGlowElement(MCExecContext& ctxt, MCNameRef p_prop, MCValueRef p_value);
381+
void GetColorOverlay(MCExecContext& ctxt, MCArrayRef& r_array);
382+
void SetColorOverlay(MCExecContext& ctxt, MCArrayRef p_array);
383+
void GetColorOverlayElement(MCExecContext& ctxt, MCNameRef p_prop, MCValueRef& r_value);
384+
void SetColorOverlayElement(MCExecContext& ctxt, MCNameRef p_prop, MCValueRef p_value);
360385

361386
};
362387
#endif

0 commit comments

Comments
 (0)