Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit e832053

Browse files
author
Ali Lloyd
committed
fixed bitmap effects
1 parent 7934ab2 commit e832053

File tree

8 files changed

+147
-145
lines changed

8 files changed

+147
-145
lines changed

engine/src/bitmapeffect.cpp

Lines changed: 111 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,65 +1300,6 @@ void MCBitmapEffectsComputeBounds(MCBitmapEffectsRef self, const MCRectangle& p_
13001300

13011301
////////////////////////////////////////////////////////////////////////////////
13021302

1303-
static bool MCBitmapEffectLookup(MCBitmapEffectsRef& self, MCNameRef p_prop, MCBitmapEffectType p_type, MCBitmapEffectProperty& r_prop, MCBitmapEffect*& r_effect)
1304-
{
1305-
// Now fetch the bitmap effect we are processing - note that if this is
1306-
// NULL it means it isn't set. In this case we still carry on since we
1307-
// need to report a invalid key error (if applicable).
1308-
MCBitmapEffect *t_effect;
1309-
if (self != nil && (self -> mask & (1 << p_type)) != 0)
1310-
r_effect = &self -> effects[p_type];
1311-
else
1312-
r_effect = nil;
1313-
1314-
if (MCBitmapEffectLookupProperty(p_type, p_prop, r_prop) != ES_NORMAL)
1315-
return false;
1316-
1317-
return true;
1318-
}
1319-
1320-
1321-
static bool MCBitmapEffectLookupForSet(MCBitmapEffectsRef& self, MCNameRef p_prop, MCBitmapEffectType p_type, MCBitmapEffectProperty& r_prop, MCBitmapEffect& r_effect, bool& r_dirty)
1322-
{
1323-
// Now fetch the bitmap effect we are processing - note that if this is
1324-
// NULL it means it isn't set. In this case we still carry on since we
1325-
// need to report a invalid key error (if applicable).
1326-
if (self != nil && (self -> mask & (1 << p_type)) != 0)
1327-
{
1328-
r_effect = self -> effects[p_type];
1329-
r_dirty = false;
1330-
}
1331-
else
1332-
{
1333-
MCBitmapEffectDefault(&r_effect, p_type);
1334-
// If the effect doesn't yet exist, it means we will dirty the object
1335-
// regardless.
1336-
r_dirty = true;
1337-
}
1338-
1339-
// Lookup the property and ensure it is appropriate for our type.
1340-
if (MCBitmapEffectLookupProperty(p_type, p_prop, r_prop) != ES_NORMAL)
1341-
return false;
1342-
}
1343-
1344-
static bool MCBitmapEffectCommitChanges(MCBitmapEffectsRef& self, MCBitmapEffectType p_type, MCBitmapEffect p_new_effect)
1345-
{
1346-
// If we are currently empty, then allocate a new object
1347-
if (self == nil)
1348-
{
1349-
self = new MCBitmapEffects;
1350-
if (self == nil)
1351-
return false;
1352-
1353-
// Only need to initialize the mask.
1354-
self -> mask = 0;
1355-
}
1356-
1357-
// Now copy in the updated effect.
1358-
self -> mask |= (1 << p_type);
1359-
self -> effects[p_type] = p_new_effect;
1360-
}
1361-
13621303
static void MCBitmapEffectFetchProperty(MCExecContext& ctxt, MCBitmapEffect *effect, MCBitmapEffectProperty p_prop, MCExecValue& r_value)
13631304
{
13641305
if (effect == nil)
@@ -1428,9 +1369,6 @@ static void MCBitmapEffectFetchProperty(MCExecContext& ctxt, MCBitmapEffect *eff
14281369

14291370
bool MCBitmapEffectsGetProperty(MCExecContext& ctxt, MCBitmapEffectsRef& self, MCNameRef p_index, Properties which, MCExecValue& r_value)
14301371
{
1431-
MCBitmapEffectProperty t_prop;
1432-
MCBitmapEffect* effect;
1433-
14341372
// First map the property type
14351373
MCBitmapEffectType t_type;
14361374
t_type = (MCBitmapEffectType)(which - P_BITMAP_EFFECT_DROP_SHADOW);
@@ -1439,45 +1377,56 @@ bool MCBitmapEffectsGetProperty(MCExecContext& ctxt, MCBitmapEffectsRef& self, M
14391377
bool t_is_array;
14401378
t_is_array = MCNameIsEqualTo(p_index, kMCEmptyName, kMCCompareCaseless);
14411379

1442-
if (MCBitmapEffectLookup(self, p_index, t_type, t_prop, effect))
1380+
// Now fetch the bitmap effect we are processing - note that if this is
1381+
// NULL it means it isn't set. In this case we still carry on since we
1382+
// need to report a invalid key error (if applicable).
1383+
MCBitmapEffect *t_effect;
1384+
if (self != nil && (self -> mask & (1 << t_type)) != 0)
1385+
t_effect = &self -> effects[t_type];
1386+
else
1387+
t_effect = nil;
1388+
1389+
MCBitmapEffectProperty t_prop;
1390+
if (!MCNameIsEmpty(p_index) && MCBitmapEffectLookupProperty(t_type, p_index, t_prop) != ES_NORMAL)
1391+
return false;
1392+
1393+
if (t_is_array)
14431394
{
1444-
if (t_is_array)
1395+
if (t_effect == nil)
14451396
{
1446-
if (effect == nil)
1447-
{
1448-
r_value . arrayref_value = MCValueRetain(kMCEmptyArray);
1449-
r_value . type = kMCExecValueTypeArrayRef;
1450-
return true;
1451-
}
1452-
1453-
// Otherwise we have an array get, so first create a new value
1454-
MCAutoArrayRef v;
1455-
if (MCArrayCreateMutable(&v))
1397+
r_value . stringref_value = MCValueRetain(kMCEmptyString);
1398+
r_value . type = kMCExecValueTypeStringRef;
1399+
return true;
1400+
}
1401+
1402+
// Otherwise we have an array get, so first create a new value
1403+
MCAutoArrayRef v;
1404+
if (MCArrayCreateMutable(&v))
1405+
{
1406+
// Now loop through all the properties, getting the ones applicable to this type.
1407+
for(uint32_t i = 0; i < ELEMENTS(s_bitmap_effect_properties); i++)
14561408
{
1457-
// Now loop through all the properties, getting the ones applicable to this type.
1458-
for(uint32_t i = 0; i < ELEMENTS(s_bitmap_effect_properties); i++)
1409+
if ((s_bitmap_effect_properties[i] . mask & (1 << t_type)) != 0)
14591410
{
1460-
if ((s_bitmap_effect_properties[i] . mask & (1 << t_type)) != 0)
1461-
{
1462-
MCExecValue t_value;
1463-
MCAutoValueRef t_valueref;
1464-
// Fetch the property, then store it into the array.
1465-
MCBitmapEffectFetchProperty(ctxt, effect, s_bitmap_effect_properties[i] . value, t_value);
1466-
MCExecTypeConvertAndReleaseAlways(ctxt, t_value . type, &t_value . type + 1, kMCExecValueTypeValueRef, &(&t_valueref));
1467-
MCArrayStoreValue(*v, ctxt . GetCaseSensitive(), MCNAME(s_bitmap_effect_properties[i] . token), *t_valueref);
1468-
}
1411+
MCExecValue t_value;
1412+
MCAutoValueRef t_valueref;
1413+
// Fetch the property, then store it into the array.
1414+
MCBitmapEffectFetchProperty(ctxt, t_effect, s_bitmap_effect_properties[i] . value, t_value);
1415+
MCExecTypeConvertAndReleaseAlways(ctxt, t_value . type, &t_value . type + 1, kMCExecValueTypeValueRef, &(&t_valueref));
1416+
MCArrayStoreValue(*v, ctxt . GetCaseSensitive(), MCNAME(s_bitmap_effect_properties[i] . token), *t_valueref);
14691417
}
1470-
r_value . arrayref_value = MCValueRetain(*v);
1471-
r_value . type = kMCExecValueTypeArrayRef;
1472-
return true;
14731418
}
1474-
}
1475-
else
1476-
{
1477-
MCBitmapEffectFetchProperty(ctxt, effect, t_prop, r_value);
1419+
r_value . arrayref_value = MCValueRetain(*v);
1420+
r_value . type = kMCExecValueTypeArrayRef;
14781421
return true;
14791422
}
14801423
}
1424+
else
1425+
{
1426+
MCBitmapEffectFetchProperty(ctxt, t_effect, t_prop, r_value);
1427+
return true;
1428+
}
1429+
14811430
return false;
14821431
}
14831432

@@ -1654,9 +1603,6 @@ bool MCBitmapEffectsSetProperty(MCExecContext& ctxt, MCBitmapEffectsRef& self, M
16541603
// First map the property type
16551604
MCBitmapEffectType t_type;
16561605
t_type = (MCBitmapEffectType)(which - P_BITMAP_EFFECT_DROP_SHADOW);
1657-
1658-
MCBitmapEffectProperty t_prop;
1659-
MCBitmapEffect effect;
16601606

16611607
// If 'p_index' is the empty name, this is a whole array op.
16621608
bool t_is_array;
@@ -1680,48 +1626,82 @@ bool MCBitmapEffectsSetProperty(MCExecContext& ctxt, MCBitmapEffectsRef& self, M
16801626
return true;
16811627
}
16821628

1629+
MCBitmapEffectProperty t_prop;
1630+
MCBitmapEffect effect;
16831631
bool t_dirty;
1684-
if (MCBitmapEffectLookupForSet(self, p_index, t_type, t_prop, effect, t_dirty))
1632+
1633+
// Now fetch the bitmap effect we are processing - note that if this is
1634+
// NULL it means it isn't set. In this case we still carry on since we
1635+
// need to report a invalid key error (if applicable).
1636+
if (self != nil && (self -> mask & (1 << t_type)) != 0)
16851637
{
1686-
if (t_is_array)
1687-
{
1688-
bool t_dirty_array;
1689-
t_dirty_array = false;
1690-
MCAutoArrayRef t_array;
1691-
MCExecTypeConvertAndReleaseAlways(ctxt, p_value . type, &p_value . type + 1, kMCExecValueTypeArrayRef, &(&t_array));
1692-
// Loop through all the properties in the table and apply the relevant
1693-
// ones.
1694-
for(uint32_t i = 0; i < ELEMENTS(s_bitmap_effect_properties); i++)
1695-
if ((s_bitmap_effect_properties[i] . mask & (1 << t_type)) != 0)
1696-
{
1697-
MCValueRef t_prop_value;
1698-
MCNewAutoNameRef t_key;
1699-
1700-
/* UNCHECKED */ MCNameCreateWithCString(s_bitmap_effect_properties[i] . token, &t_key);
1701-
// If we don't have the given element, then move to the next one
1702-
if (!MCArrayFetchValue(*t_array, kMCCompareExact, *t_key, t_prop_value))
1703-
continue;
1704-
1705-
// Otherwise, fetch the keys value and attempt to set the property
1706-
MCExecValue t_value;
1707-
t_value . valueref_value = MCValueRetain(t_prop_value);
1708-
t_value . type = kMCExecValueTypeValueRef;
1709-
MCBitmapEffectStoreProperty(ctxt, effect, s_bitmap_effect_properties[i] . value, t_value, t_dirty_array);
1710-
}
1711-
if (t_dirty_array)
1712-
t_dirty = true;
1713-
1714-
}
1715-
else
1716-
MCBitmapEffectStoreProperty(ctxt, effect, t_prop, p_value, t_dirty);
1638+
effect = self -> effects[t_type];
1639+
t_dirty = false;
1640+
}
1641+
else
1642+
{
1643+
MCBitmapEffectDefault(&effect, t_type);
1644+
// If the effect doesn't yet exist, it means we will dirty the object
1645+
// regardless.
1646+
t_dirty = true;
1647+
}
1648+
1649+
// Lookup the property and ensure it is appropriate for our type.
1650+
if (!MCNameIsEmpty(p_index) && MCBitmapEffectLookupProperty(t_type, p_index, t_prop) != ES_NORMAL)
1651+
return false;
1652+
1653+
if (t_is_array)
1654+
{
1655+
bool t_dirty_array;
1656+
t_dirty_array = false;
1657+
MCAutoArrayRef t_array;
1658+
MCExecTypeConvertAndReleaseAlways(ctxt, p_value . type, &p_value . type + 1, kMCExecValueTypeArrayRef, &(&t_array));
1659+
// Loop through all the properties in the table and apply the relevant
1660+
// ones.
1661+
for(uint32_t i = 0; i < ELEMENTS(s_bitmap_effect_properties); i++)
1662+
if ((s_bitmap_effect_properties[i] . mask & (1 << t_type)) != 0)
1663+
{
1664+
MCValueRef t_prop_value;
1665+
MCNewAutoNameRef t_key;
1666+
1667+
/* UNCHECKED */ MCNameCreateWithCString(s_bitmap_effect_properties[i] . token, &t_key);
1668+
// If we don't have the given element, then move to the next one
1669+
if (!MCArrayFetchValue(*t_array, kMCCompareExact, *t_key, t_prop_value))
1670+
continue;
1671+
1672+
// Otherwise, fetch the keys value and attempt to set the property
1673+
MCExecValue t_value;
1674+
t_value . valueref_value = MCValueRetain(t_prop_value);
1675+
t_value . type = kMCExecValueTypeValueRef;
1676+
MCBitmapEffectStoreProperty(ctxt, effect, s_bitmap_effect_properties[i] . value, t_value, t_dirty_array);
1677+
}
1678+
if (t_dirty_array)
1679+
t_dirty = true;
17171680

1718-
if (!t_dirty || MCBitmapEffectCommitChanges(self, t_type, effect))
1681+
}
1682+
else
1683+
MCBitmapEffectStoreProperty(ctxt, effect, t_prop, p_value, t_dirty);
1684+
1685+
if (t_dirty)
1686+
{
1687+
// If we are currently empty, then allocate a new object
1688+
if (self == nil)
17191689
{
1720-
r_dirty = t_dirty;
1721-
return true;
1690+
self = new MCBitmapEffects;
1691+
if (self == nil)
1692+
return false;
1693+
1694+
// Only need to initialize the mask.
1695+
self -> mask = 0;
17221696
}
1697+
1698+
// Now copy in the updated effect.
1699+
self -> mask |= (1 << t_type);
1700+
self -> effects[t_type] = effect;
17231701
}
1724-
return false;
1702+
1703+
r_dirty = t_dirty;
1704+
return true;
17251705
}
17261706

17271707
////////////////////////////////////////////////////////////////////////////////

engine/src/exec-interface-stack.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2177,3 +2177,10 @@ void MCStack::SetTextStyle(MCExecContext& ctxt, const MCInterfaceTextStyle& p_st
21772177
MCObject::SetTextStyle(ctxt, p_style);
21782178
MCRedrawDirtyScreen();
21792179
}
2180+
2181+
void MCStack::GetKey(MCExecContext& ctxt, bool& r_value)
2182+
{
2183+
// OK-2010-02-11: [[Bug 8610]] - Passkey property more useful if it returns
2184+
// whether or not the script is available.
2185+
r_value = iskeyed();
2186+
}

engine/src/exec.cpp

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1326,7 +1326,14 @@ void MCExecFetchProperty(MCExecContext& ctxt, const MCPropertyInfo *prop, void *
13261326

13271327
case kMCPropertyTypeString:
13281328
{
1329-
((void(*)(MCExecContext&, void *, MCStringRef&))prop -> getter)(ctxt, mark, r_value . stringref_value);
1329+
MCAutoStringRef t_string;
1330+
((void(*)(MCExecContext&, void *, MCStringRef&))prop -> getter)(ctxt, mark, &t_string);
1331+
if (*t_string == nil)
1332+
{
1333+
MCAutoStringRef t_new;
1334+
((void(*)(MCExecContext&, void *, MCStringRef&))prop -> getter)(ctxt, mark, &t_new);
1335+
}
1336+
r_value . stringref_value = MCValueRetain(*t_string);
13301337
if (!ctxt . HasError())
13311338
{
13321339
r_value . type = kMCExecValueTypeStringRef;
@@ -1923,8 +1930,7 @@ void MCExecFetchProperty(MCExecContext& ctxt, const MCPropertyInfo *prop, void *
19231930

19241931
case kMCPropertyTypeRecord:
19251932
{
1926-
MCObjectIndexPtr* t_index = (MCObjectIndexPtr *)mark;
1927-
((void(*)(MCExecContext&, MCObjectIndexPtr *, MCExecValue&))prop -> getter)(ctxt, t_index, r_value);
1933+
((void(*)(MCExecContext&, void *, MCExecValue&))prop -> getter)(ctxt, mark, r_value);
19281934
}
19291935
break;
19301936

@@ -2381,8 +2387,7 @@ void MCExecStoreProperty(MCExecContext& ctxt, const MCPropertyInfo *prop, void *
23812387

23822388
case kMCPropertyTypeRecord:
23832389
{
2384-
MCObjectIndexPtr* t_index = (MCObjectIndexPtr *)mark;
2385-
((void(*)(MCExecContext&, MCObjectIndexPtr *, MCExecValue))prop -> setter)(ctxt, t_index, p_value);
2390+
((void(*)(MCExecContext&, void *, MCExecValue))prop -> setter)(ctxt, mark, p_value);
23862391
}
23872392
break;
23882393

engine/src/exec.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -928,19 +928,26 @@ template<typename A, typename B, void Method(MCExecContext&, B, A)> inline void
928928

929929
////
930930

931-
template<typename O, typename A, void (O::*Method)(MCExecContext&, MCNameRef, A)> inline void MCPropertyObjectRecordThunk(MCExecContext& ctxt, MCObjectIndexPtr *obj, A arg)
931+
template<typename O, typename A, void (O::*Method)(MCExecContext&, MCNameRef, A)> inline void MCPropertyObjectRecordPropThunk(MCExecContext& ctxt, MCObjectIndexPtr *obj, A arg)
932932
{
933933
if (obj -> index == nil)
934934
(static_cast<O *>(obj -> object) ->*Method)(ctxt, kMCEmptyName, arg);
935935
else
936936
(static_cast<O *>(obj -> object) ->*Method)(ctxt, obj -> index, arg);
937937
}
938-
939-
#define MCPropertyObjectGetRecordThunkImp(obj, mth) (void(*)(MCExecContext&,MCObjectIndexPtr*,MCExecValue&))MCPropertyObjectRecordThunk<obj,MCExecValue&, &obj::mth>
940-
#define MCPropertyObjectSetRecordThunkImp(obj,mth) (void(*)(MCExecContext&,MCObjectIndexPtr*,MCExecValue))MCPropertyObjectRecordThunk<obj,MCExecValue, &obj::mth>
938+
939+
template<typename O, typename A, void (O::*Method)(MCExecContext&, MCNameRef, A)> inline void MCPropertyObjectRecordThunk(MCExecContext& ctxt, MCObjectPtr *obj, A arg)
940+
{
941+
(static_cast<O *>(obj -> object) ->*Method)(ctxt, kMCEmptyName, arg);
942+
}
943+
944+
#define MCPropertyObjectGetRecordPropThunkImp(obj, mth) (void(*)(MCExecContext&,MCObjectIndexPtr*,MCExecValue&))MCPropertyObjectRecordPropThunk<obj,MCExecValue&, &obj::mth>
945+
#define MCPropertyObjectSetRecordPropThunkImp(obj,mth) (void(*)(MCExecContext&,MCObjectIndexPtr*,MCExecValue))MCPropertyObjectRecordPropThunk<obj,MCExecValue, &obj::mth>
946+
#define MCPropertyObjectGetRecordThunkImp(obj, mth) (void(*)(MCExecContext&,MCObjectPtr*,MCExecValue&))MCPropertyObjectRecordThunk<obj,MCExecValue&, &obj::mth>
947+
#define MCPropertyObjectSetRecordThunkImp(obj,mth) (void(*)(MCExecContext&,MCObjectPtr*,MCExecValue))MCPropertyObjectRecordThunk<obj,MCExecValue, &obj::mth>
941948

942949
#define DEFINE_RW_OBJ_RECORD_PROPERTY(prop, obj, tag) \
943-
{ prop, false, kMCPropertyTypeRecord, nil, (void *)MCPropertyObjectGetRecordThunkImp(obj, Get##tag##Property), (void *)MCPropertyObjectSetRecordThunkImp(obj, Set##tag##Property), false, true, false, kMCPropertyInfoChunkTypeNone }, { prop, false, kMCPropertyTypeRecord, nil, (void *)MCPropertyObjectGetRecordThunkImp(obj, Get##tag##Property), (void *)MCPropertyObjectSetRecordThunkImp(obj, Set##tag##Property), false, false, false, kMCPropertyInfoChunkTypeNone },
950+
{ prop, false, kMCPropertyTypeRecord, nil, (void *)MCPropertyObjectGetRecordPropThunkImp(obj, Get##tag##Property), (void *)MCPropertyObjectSetRecordPropThunkImp(obj, Set##tag##Property), false, true, false, kMCPropertyInfoChunkTypeNone }, { prop, false, kMCPropertyTypeRecord, nil, (void *)MCPropertyObjectGetRecordThunkImp(obj, Get##tag##Property), (void *)MCPropertyObjectSetRecordThunkImp(obj, Set##tag##Property), false, false, false, kMCPropertyInfoChunkTypeNone },
944951

945952
////////////////////////////////////////////////////////////////////////////////
946953

engine/src/object.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2095,8 +2095,7 @@ Exec_stat MCObject::names_old(Properties which, MCExecPoint& ep, uint32_t parid)
20952095

20962096
bool MCObject::names(Properties which, MCValueRef& r_name_val)
20972097
{
2098-
MCStringRef &r_name = (MCStringRef&)
2099-
r_name_val;
2098+
MCStringRef &r_name = (MCStringRef&)r_name_val;
21002099

21012100
const char *itypestring = gettypestring();
21022101
MCAutoPointer<char> tmptypestring;

engine/src/objectprops.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2664,7 +2664,7 @@ void MCObject::getstringprop(MCExecContext& ctxt, uint32_t p_part_id, Properties
26642664
void MCObject::setstringprop(MCExecContext& ctxt, uint32_t p_part_id, Properties p_which, Boolean p_effective, MCStringRef p_value)
26652665
{
26662666
MCExecValue t_value;
2667-
t_value . stringref_value = p_value;
2667+
t_value . stringref_value = MCValueRetain(p_value);
26682668
t_value . type = kMCExecValueTypeStringRef;
26692669
if (setprop(ctxt, p_part_id, p_which, p_effective, t_value))
26702670
return;
@@ -2693,7 +2693,7 @@ void MCObject::getvariantprop(MCExecContext& ctxt, uint32_t p_part_id, Propertie
26932693
void MCObject::setvariantprop(MCExecContext& ctxt, uint32_t p_part_id, Properties p_which, Boolean p_effective, MCValueRef p_value)
26942694
{
26952695
MCExecValue t_value;
2696-
t_value . valueref_value = p_value;
2696+
t_value . valueref_value = MCValueRetain(p_value);
26972697
t_value . type = kMCExecValueTypeValueRef;
26982698
if (setprop(ctxt, p_part_id, p_which, p_effective, t_value))
26992699
return;

0 commit comments

Comments
 (0)