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

Commit a5808d9

Browse files
committed
[[ MyColors ]] Remove dependence on MCContext from MCObject::getforecolor
The only dependencies on MCContext the implementation of getforecolor() had was the context's depth, and the context's type. Caller's of getforecolor() must now pass a MCContextType rather than an MCContext, and the never-used code path which checks a context's depth has been removed (getdepth() returns 32 for both MCGraphicsContext and MCMetaContext).
1 parent b4fd32f commit a5808d9

File tree

6 files changed

+81
-77
lines changed

6 files changed

+81
-77
lines changed

engine/src/block.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1338,8 +1338,8 @@ void MCBlock::draw(MCDC *dc, coord_t x, coord_t lx, coord_t cx, int2 y, findex_t
13381338
MCPatternRef t_pattern;
13391339
int2 x, y;
13401340
MCColor fc, hc;
1341-
f->getforecolor(DI_FORE, False, True, fc, t_pattern, x, y, dc, f);
1342-
f->getforecolor(DI_HILITE, False, True, hc, t_pattern, x, y, dc, f);
1341+
f->getforecolor(DI_FORE, False, True, fc, t_pattern, x, y, dc -> gettype(), f);
1342+
f->getforecolor(DI_HILITE, False, True, hc, t_pattern, x, y, dc -> gettype(), f);
13431343
if (hc.pixel == fc.pixel)
13441344
f->setforeground(dc, DI_BACK, False, True);
13451345
else

engine/src/card.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3329,12 +3329,12 @@ void MCCard::drawbackground(MCContext *p_context, const MCRectangle &p_dirty)
33293329
t_hilite = MClook == LF_WIN95 && (wm == WM_COMBO || wm == WM_OPTION);
33303330

33313331
bool t_opaque;
3332-
t_opaque = getforecolor(DI_BACK, False, t_hilite, color, t_pattern, x, y, p_context, this) || MCPatternIsOpaque(t_pattern);
3332+
t_opaque = getforecolor(DI_BACK, False, t_hilite, color, t_pattern, x, y, p_context -> gettype(), this) || MCPatternIsOpaque(t_pattern);
33333333

33343334
// If the card background is a pattern with transparency, then draw the stack background first
33353335
if (!t_opaque)
33363336
{
3337-
t_opaque = parent->getforecolor(DI_BACK, False, t_hilite, color, t_stack_pattern, t_stack_x, t_stack_y, p_context, parent) || MCPatternIsOpaque(t_stack_pattern);
3337+
t_opaque = parent->getforecolor(DI_BACK, False, t_hilite, color, t_stack_pattern, t_stack_x, t_stack_y, p_context -> gettype(), parent) || MCPatternIsOpaque(t_stack_pattern);
33383338

33393339
// And if the stack background is a pattern with transparency, then fill with black first
33403340
if (!t_opaque)

engine/src/object.cpp

Lines changed: 67 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,7 +1413,8 @@ Boolean MCObject::resizeparent()
14131413

14141414
Boolean MCObject::getforecolor(uint2 p_di, Boolean rev, Boolean hilite,
14151415
MCColor &c, MCPatternRef &r_pattern,
1416-
int2 &x, int2 &y, MCDC *dc, MCObject *o, bool selected)
1416+
int2 &x, int2 &y, MCContextType dc_type,
1417+
MCObject *o, bool selected)
14171418
{
14181419
uint2 di;
14191420
switch (p_di)
@@ -1440,69 +1441,65 @@ Boolean MCObject::getforecolor(uint2 p_di, Boolean rev, Boolean hilite,
14401441
}
14411442

14421443
uint2 i;
1443-
if (dc->getdepth() > 1)
1444-
{
1445-
Boolean hasindex = getcindex(di, i);
1446-
// MM-2013-08-28: [[ RefactorGraphics ]] We now pack alpha values into pixels meaning checking against MAXUNIT4 means white will always be ignored. Not sure why this check was here previously.
1447-
if (hasindex) // && colors[i].pixel != MAXUINT4)
1448-
{
1449-
c = colors[i];
1450-
return True;
1451-
}
1452-
else
1453-
if (getpindex(di, i))
1454-
{
1455-
r_pattern = patterns[i].pattern;
1444+
Boolean hasindex = getcindex(di, i);
1445+
// MM-2013-08-28: [[ RefactorGraphics ]] We now pack alpha values into pixels meaning checking against MAXUNIT4 means white will always be ignored. Not sure why this check was here previously.
1446+
if (hasindex) // && colors[i].pixel != MAXUINT4)
1447+
{
1448+
c = colors[i];
1449+
return True;
1450+
}
1451+
else if (getpindex(di, i))
1452+
{
1453+
r_pattern = patterns[i].pattern;
14561454

1457-
if (gettype() == CT_STACK)
1458-
x = y = 0;
1459-
else
1460-
{
1461-
x = rect.x;
1462-
y = rect.y;
1463-
}
1464-
return False;
1465-
}
1466-
else
1467-
{
1468-
if (di == DI_FORE && flags & F_DISABLED)
1469-
{
1470-
c = dc->getgray();
1471-
return True;
1472-
}
1473-
if (MClook != LF_MOTIF && hilite && flags & F_OPAQUE
1474-
&& !(flags & F_DISABLED))
1475-
{
1476-
if (p_di == DI_BACK)
1477-
{
1478-
// Use the themed colours and ignore inheritance. We do
1479-
// this so that controls always have the appropriate
1480-
// background colour (particularly fields).
1481-
MCPlatformControlType t_control_type;
1482-
MCPlatformControlPart t_control_part;
1483-
MCPlatformControlState t_control_state;
1484-
MCPlatformThemeProperty t_theme_prop;
1485-
MCPlatformThemePropertyType t_theme_prop_type;
1486-
if (o->getthemeselectorsforprop(P_BACK_COLOR, t_control_type, t_control_part, t_control_state, t_theme_prop, t_theme_prop_type))
1487-
{
1488-
if (selected)
1489-
t_control_state |= kMCPlatformControlStateSelected;
1490-
1491-
if (MCPlatformGetControlThemePropColor(t_control_type, t_control_part, t_control_state, t_theme_prop, c))
1492-
return True;
1493-
}
1494-
1495-
// No themed colour available; fall back to white
1496-
c = dc->getwhite();
1497-
}
1498-
else
1499-
parent->getforecolor(p_di, rev, hilite, c, r_pattern, x, y, dc, o, selected);
1500-
return True;
1501-
}
1502-
if (parent && parent != MCdispatcher)
1503-
return parent->getforecolor(p_di, rev, hilite, c, r_pattern, x, y, dc, o, selected);
1504-
}
1505-
}
1455+
if (gettype() == CT_STACK)
1456+
x = y = 0;
1457+
else
1458+
{
1459+
x = rect.x;
1460+
y = rect.y;
1461+
}
1462+
return False;
1463+
}
1464+
else
1465+
{
1466+
if (di == DI_FORE && flags & F_DISABLED)
1467+
{
1468+
c = MCscreen->getgray();
1469+
return True;
1470+
}
1471+
if (MClook != LF_MOTIF && hilite && flags & F_OPAQUE
1472+
&& !(flags & F_DISABLED))
1473+
{
1474+
if (p_di == DI_BACK)
1475+
{
1476+
// Use the themed colours and ignore inheritance. We do
1477+
// this so that controls always have the appropriate
1478+
// background colour (particularly fields).
1479+
MCPlatformControlType t_control_type;
1480+
MCPlatformControlPart t_control_part;
1481+
MCPlatformControlState t_control_state;
1482+
MCPlatformThemeProperty t_theme_prop;
1483+
MCPlatformThemePropertyType t_theme_prop_type;
1484+
if (o->getthemeselectorsforprop(P_BACK_COLOR, t_control_type, t_control_part, t_control_state, t_theme_prop, t_theme_prop_type))
1485+
{
1486+
if (selected)
1487+
t_control_state |= kMCPlatformControlStateSelected;
1488+
1489+
if (MCPlatformGetControlThemePropColor(t_control_type, t_control_part, t_control_state, t_theme_prop, c))
1490+
return True;
1491+
}
1492+
1493+
// No themed colour available; fall back to white
1494+
c = MCscreen->getwhite();
1495+
}
1496+
else
1497+
parent->getforecolor(p_di, rev, hilite, c, r_pattern, x, y, dc_type, o, selected);
1498+
return True;
1499+
}
1500+
if (parent && parent != MCdispatcher)
1501+
return parent->getforecolor(p_di, rev, hilite, c, r_pattern, x, y, dc_type, o, selected);
1502+
}
15061503

15071504
// Try to get the colour from the system theme rather than these hard-coded values
15081505
MCPlatformControlType t_control_type;
@@ -1573,13 +1570,13 @@ Boolean MCObject::getforecolor(uint2 p_di, Boolean rev, Boolean hilite,
15731570
case DI_BOTTOM:
15741571
case DI_FORE:
15751572
if (rev)
1576-
c = dc->getwhite();
1573+
c = MCscreen->getwhite();
15771574
else
1578-
c = dc->getblack();
1575+
c = MCscreen->getblack();
15791576
break;
15801577
case DI_BACK:
15811578
#ifdef _MACOSX
1582-
if (IsMacLFAM() && dc -> gettype() != CONTEXT_TYPE_PRINTER)
1579+
if (IsMacLFAM() && dc_type)
15831580
{
15841581
extern bool MCMacThemeGetBackgroundPattern(Window_mode p_mode, bool p_active, MCPatternRef &r_pattern);
15851582
x = 0;
@@ -1589,7 +1586,7 @@ Boolean MCObject::getforecolor(uint2 p_di, Boolean rev, Boolean hilite,
15891586
return False;
15901587
}
15911588
#endif
1592-
c = dc->getbg();
1589+
c = MCscreen->getbg();
15931590
break;
15941591
case DI_HILITE:
15951592
c = o->gettype() == CT_BUTTON ? MCaccentcolor : MChilitecolor;
@@ -1604,7 +1601,7 @@ Boolean MCObject::getforecolor(uint2 p_di, Boolean rev, Boolean hilite,
16041601
}
16051602
break;
16061603
default:
1607-
c = dc->getblack();
1604+
c = MCscreen->getblack();
16081605
break;
16091606
}
16101607
return True;
@@ -1636,13 +1633,13 @@ void MCObject::setforeground(MCDC *dc, uint2 di, Boolean rev, Boolean hilite, bo
16361633
MCColor color;
16371634
MCPatternRef t_pattern = nil;
16381635
int2 x, y;
1639-
if (getforecolor(idi, rev, hilite, color, t_pattern, x, y, dc, this, selected))
1636+
if (getforecolor(idi, rev, hilite, color, t_pattern, x, y, dc -> gettype(), this, selected))
16401637
{
16411638
MCColor fcolor;
16421639
if (dc->getdepth() == 1 && di != DI_BACK
16431640
&& getforecolor((state & CS_HILITED && flags & F_OPAQUE)
16441641
? DI_HILITE : DI_BACK, False, False, fcolor,
1645-
t_pattern, x, y, dc, this)
1642+
t_pattern, x, y, dc -> gettype(), this)
16461643
&& color.pixel == fcolor.pixel)
16471644
color.pixel ^= 1;
16481645
dc->setforeground(color);

engine/src/object.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ along with LiveCode. If not see <http://www.gnu.org/licenses/>. */
2626
#include "objdefs.h"
2727
#include "parsedef.h"
2828
#include "platform.h"
29+
#include "context.h"
2930

3031
#include "native-layer.h"
3132

@@ -669,7 +670,8 @@ class MCObject : public MCDLlist
669670

670671
Boolean resizeparent();
671672
Boolean getforecolor(uint2 di, Boolean reversed, Boolean hilite, MCColor &c,
672-
MCPatternRef &r_pattern, int2 &x, int2 &y, MCDC *dc, MCObject *o, bool selected = false);
673+
MCPatternRef &r_pattern, int2 &x, int2 &y, MCContextType dc_type,
674+
MCObject *o, bool selected = false);
673675
void setforeground(MCDC *dc, uint2 di, Boolean rev, Boolean hilite = False, bool selected = false);
674676
Boolean setcolor(uint2 index, const MCString &eptr);
675677
Boolean setcolors(const MCString &data);

engine/src/paragraf.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,8 +1571,8 @@ void MCParagraph::draw(MCDC *dc, int2 x, int2 y, uint2 fixeda,
15711571
MCPatternRef t_pattern;
15721572
int2 x, y;
15731573
MCColor fc, hc;
1574-
parent->getforecolor(DI_FORE, False, True, fc, t_pattern, x, y, dc, parent);
1575-
parent->getforecolor(DI_HILITE, False, True, hc, t_pattern, x, y, dc, parent);
1574+
parent->getforecolor(DI_FORE, False, True, fc, t_pattern, x, y, dc -> gettype(), parent);
1575+
parent->getforecolor(DI_HILITE, False, True, hc, t_pattern, x, y, dc -> gettype(), parent);
15761576
if (hc.pixel == fc.pixel)
15771577
parent->setforeground(dc, DI_BACK, False, True);
15781578
}

engine/src/uidc.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,11 @@ class MCUIDC
663663
{
664664
return gray_pixel;
665665
}
666+
667+
const MCColor& getbg(void) const
668+
{
669+
return background_pixel;
670+
}
666671
};
667672

668673
#endif

0 commit comments

Comments
 (0)