Skip to content

Commit aae49be

Browse files
committed
[[ Bug 11300 ]] Reinstated old behavior of 'flip' working on referenced images until we can do it properly.
1 parent 6bd4655 commit aae49be

5 files changed

Lines changed: 98 additions & 10 deletions

File tree

docs/notes/bug-11300.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Flip does not work on referenced images.
2+
The flip command will now work on referenced images.
3+
Note that at the moment this behavior is the same as pre-6.0 where doing 'flip' on a referenced image would work, but would not be persistent and not interact well with other operations. This behavior will be improved in a subsequent release when image transformation abilities are improved.

engine/src/cmdsc.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1325,12 +1325,21 @@ Exec_stat MCFlip::exec(MCExecPoint &ep)
13251325
return ES_ERROR;
13261326
}
13271327
// MW-2013-07-01: [[ Bug 10999 ]] Throw an error if the image is not editable.
1328-
if (optr->gettype() != CT_IMAGE || optr->getflag(F_HAS_FILENAME))
1328+
if (optr->gettype() != CT_IMAGE)
13291329
{
13301330
MCeerror->add(EE_FLIP_NOTIMAGE, line, pos);
13311331
return ES_ERROR;
13321332
}
1333+
1334+
// MW-2013-10-25: [[ Bug 11300 ]] If this is a reference image, then flip using
1335+
// transient flags in the image object.
13331336
MCImage *iptr = (MCImage *)optr;
1337+
if (optr->getflag(F_HAS_FILENAME))
1338+
{
1339+
iptr -> flip(direction == FL_HORIZONTAL);
1340+
return ES_NORMAL;
1341+
}
1342+
13341343
iptr->selimage();
13351344
t_created_selection = true;
13361345
}

engine/src/image.cpp

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,11 @@ MCImage::MCImage()
8080
m_transformed_bitmap = nil;
8181
m_image_opened = false;
8282
m_has_transform = false;
83+
84+
// MW-2013-10-25: [[ Bug 11300 ]] Images start off unflipped.
85+
m_flip_x = false;
86+
m_flip_y = false;
87+
8388
m_scale_factor = 1.0;
8489

8590
m_locked_frame = nil;
@@ -99,6 +104,11 @@ MCImage::MCImage(const MCImage &iref) : MCControl(iref)
99104
m_transformed_bitmap = nil;
100105
m_image_opened = false;
101106
m_has_transform = false;
107+
108+
// MW-2013-10-25: [[ Bug 11300 ]] Images start off unflipped.
109+
m_flip_x = false;
110+
m_flip_y = false;
111+
102112
m_scale_factor = 1.0;
103113

104114
m_locked_frame = nil;
@@ -2031,16 +2041,36 @@ MCSharedString *MCImage::getclipboardtext(void)
20312041

20322042
///////////////////////////////////////////////////////////////////////////////
20332043

2044+
void MCImage::flip(bool p_horz)
2045+
{
2046+
// Invert the flip states.
2047+
if (p_horz)
2048+
m_flip_x = !m_flip_x;
2049+
else
2050+
m_flip_y = !m_flip_y;
2051+
2052+
// Update the transform.
2053+
apply_transform();
2054+
2055+
// Ensure we redraw.
2056+
layer_redrawall();
2057+
notifyneeds(false);
2058+
}
2059+
20342060
void MCImage::apply_transform()
20352061
{
20362062
uindex_t t_width = rect.width;
20372063
uindex_t t_height = rect.height;
20382064
/* UNCHECKED */ getsourcegeometry(t_width, t_height);
20392065

2066+
// MW-2013-10-25: [[ Bug 11300 ]] Make sure we apply a flip transform if
2067+
// required and there are no other transforms to apply.
20402068
if (angle != 0)
20412069
rotate_transform(angle);
20422070
else if (rect.width != t_width || rect.height != t_height)
20432071
resize_transform();
2072+
else if (m_flip_x || m_flip_y)
2073+
flip_transform();
20442074
else
20452075
m_has_transform = false;
20462076
}

engine/src/image.h

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,12 @@ class MCImage : public MCControl
299299

300300
bool m_has_transform;
301301
MCGAffineTransform m_transform;
302+
303+
// MW-2013-10-25: [[ Bug 11300 ]] These control whether a horz/vert flip is
304+
// applied to the transform on referenced images (set by the flip cmd).
305+
bool m_flip_x : 1;
306+
bool m_flip_y : 1;
307+
302308
// IM-2013-07-19: [[ ResIndependence ]] added scale factor for hi-res images
303309
MCGFloat m_scale_factor;
304310

@@ -408,9 +414,11 @@ class MCImage : public MCControl
408414

409415
void resetimage();
410416

417+
void flip(bool horz);
418+
411419
void rotate_transform(int32_t p_angle);
412420
void resize_transform();
413-
421+
void flip_transform();
414422
void apply_transform();
415423

416424
uint8_t getresizequality()

engine/src/iutil.cpp

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,9 @@ void MCImage::rotate_transform(int32_t p_angle)
492492

493493
// IM-2013-04-22: [[ BZ 10858 ]] A transformed rep is needed if the angle is non-zero,
494494
// or the rect is locked and doesn't match the source dimensions.
495-
if (p_angle == 0 && !(getflag(F_LOCK_LOCATION) && (t_src_width != rect.width || t_src_height != rect.height)))
495+
// MW-2013-10-25: [[ Bug 11300 ]] Additionally a transform is needed if flipped on
496+
// either axis.
497+
if (p_angle == 0 && !(getflag(F_LOCK_LOCATION) && (t_src_width != rect.width || t_src_height != rect.height)) && !m_flip_x && !m_flip_y)
496498
m_has_transform = false;
497499
else
498500
{
@@ -502,8 +504,13 @@ void MCImage::rotate_transform(int32_t p_angle)
502504

503505
MCGAffineTransform t_transform = MCGAffineTransformMakeTranslation(-(int32_t)t_src_width / 2.0, -(int32_t)t_src_height / 2.0);
504506
t_transform = MCGAffineTransformRotate(t_transform, -p_angle);
507+
508+
// MW-2013-10-25: [[ Bug 11300 ]] If needed, flip the transform appropriately.
509+
if (m_flip_x || m_flip_y)
510+
t_transform = MCGAffineTransformScale(t_transform, m_flip_x ? -1.0f : 1.0f, m_flip_y ? -1.0f : 1.0f);
511+
505512
t_transform = MCGAffineTransformTranslate(t_transform, t_trans_width / 2.0, t_trans_height / 2.0);
506-
513+
507514
if (getflag(F_LOCK_LOCATION))
508515
{
509516
t_transform = MCGAffineTransformScale(t_transform, rect.width / (MCGFloat)t_trans_width, rect.height / (MCGFloat)t_trans_height);
@@ -530,18 +537,49 @@ void MCImage::resize_transform()
530537
{
531538
uint32_t t_src_width = rect.width, t_src_height = rect.height;
532539
/* UNCHECKED */ getsourcegeometry(t_src_width, t_src_height);
533-
534-
if (rect.width == t_src_width && rect.height == t_src_height)
535-
m_has_transform = nil;
540+
541+
// MW-2013-10-25: [[ Bug 11300 ]] Additionally a transform is needed if flipped on
542+
// either axis.
543+
if (rect.width == t_src_width && rect.height == t_src_height && !m_flip_x && !m_flip_y)
544+
m_has_transform = false;
536545
else
537546
{
538547
m_has_transform = true;
539-
MCGFloat t_mid_x = (MCGFloat)t_src_width / 2.0;
540-
MCGFloat t_mid_y = (MCGFloat)t_src_height / 2.0;
541-
m_transform = MCGAffineTransformMakeScale(rect.width / (MCGFloat)t_src_width, rect.height / (MCGFloat)t_src_height);
548+
549+
MCGAffineTransform t_transform;
550+
551+
// MW-2013-10-25: [[ Bug 11300 ]] If needed, flip the transform appropriately.
552+
if (m_flip_x || m_flip_y)
553+
{
554+
t_transform = MCGAffineTransformMakeTranslation(-(signed)t_src_width / 2.0f, -(signed)t_src_height / 2.0f);
555+
t_transform = MCGAffineTransformScale(t_transform, m_flip_x ? -1.0f : 1.0f, m_flip_y ? -1.0f : 1.0f);
556+
t_transform = MCGAffineTransformTranslate(t_transform, t_src_width / 2.0, t_src_height / 2.0);
557+
}
558+
else
559+
t_transform = MCGAffineTransformMakeIdentity();
560+
561+
m_transform = MCGAffineTransformScale(t_transform, rect.width / (MCGFloat)t_src_width, rect.height / (MCGFloat)t_src_height);
542562
}
543563
}
544564

565+
// MW-2013-05-25: [[ Bug 11300 ]] This applies the flip transform if needed.
566+
void MCImage::flip_transform()
567+
{
568+
uint32_t t_src_width = rect.width, t_src_height = rect.height;
569+
/* UNCHECKED */ getsourcegeometry(t_src_width, t_src_height);
570+
571+
if (!m_flip_x && !m_flip_y)
572+
m_has_transform = false;
573+
else
574+
{
575+
m_has_transform = true;
576+
577+
m_transform = MCGAffineTransformMakeTranslation(-(signed)t_src_width / 2.0, -(signed)t_src_height / 2.0);
578+
m_transform = MCGAffineTransformScale(m_transform, m_flip_x ? -1.0f : 1.0f, m_flip_y ? -1.0f : 1.0f);
579+
m_transform = MCGAffineTransformTranslate(m_transform, t_src_width / 2.0, t_src_height / 2.0);
580+
}
581+
}
582+
545583
void MCImage::createbrush(Properties which)
546584
{
547585
MCGImageRef t_image = nil;

0 commit comments

Comments
 (0)