@@ -188,13 +188,6 @@ namespace dexpert
188188 }
189189
190190 bool ImagePanel::isSelecting () {
191- if (images_[image_type_paste]) {
192- selection_start_ = paste_coords_;
193- selection_end_ = paste_coords_;
194- selection_end_.x += images_[image_type_paste]->w ();
195- selection_end_.y += images_[image_type_paste]->h ();
196- return false ;
197- }
198191 return tool_ == image_tool_select && mouse_down_left_;
199192 }
200193
@@ -497,11 +490,19 @@ namespace dexpert
497490 scrollAgain ();
498491 }
499492
493+ void ImagePanel::setMaskPanel (ImagePanel *mask_panel) {
494+ mask_panel_ = mask_panel;
495+ }
496+
500497 RawImage* ImagePanel::get_cached_image (int layer) {
501498 /*
502499 Dim the image to fit the window. Don't draw a huge image in a smaller area...
503500 */
504501 RawImage *original = images_[layer].get ();
502+ if (mask_panel_ != NULL && layer == image_type_mask && mask_panel_->image_visible_ [layer]) {
503+ original = mask_panel_->images_ [layer].get ();
504+ }
505+
505506 if (layer == image_type_paste) {
506507 return NULL ;
507508 } else if (layer == image_type_image && original == NULL ) {
@@ -523,6 +524,7 @@ namespace dexpert
523524 }
524525
525526 image_ptr_t &cache = caches_[layer];
527+
526528 if (!cache.get () ||
527529 !valid_caches_[layer] ||
528530 cache_versions_[layer] != original->getVersion () ||
@@ -546,6 +548,8 @@ namespace dexpert
546548 s1.x -= xmove * zoom_;
547549 s1.y -= ymove * zoom_;
548550 cache->pasteAt (s1.x , s1.y , img->w () * zoom_, img->h () * zoom_, img);
551+ } else if (layer == image_type_mask && caches_[image_type_image].get () != NULL ) {
552+ cache->pasteInvertMask (caches_[image_type_image].get ());
549553 }
550554 }
551555
@@ -577,6 +581,7 @@ namespace dexpert
577581 draw_buffer (img);
578582 }
579583 }
584+
580585 blur_gl_contents (this ->w (), this ->h (), current_x_, current_y_);
581586 draw_tool ();
582587 }
@@ -607,6 +612,26 @@ namespace dexpert
607612 void ImagePanel::draw_tool () {
608613 float sx = 2.0 / this ->w ();
609614 float sy = 2.0 / this ->h ();
615+
616+ auto r = getReferenceImage ();
617+ if (r) {
618+ coordinate_t s1, s2;
619+ s1.x = -1 ;
620+ s1.y = -1 ;
621+ s2.x = r->w ()+2 ;
622+ s2.y = r->h ()+2 ;
623+ convertToScreenCoords (&s1.x , &s1.y );
624+ convertToScreenCoords (&s2.x , &s2.y );
625+ glBegin (GL_LINE_LOOP );
626+ glColor4f (0.5 , 0.5 , 0.5 , 0.3 );
627+ glVertex2f (s1.x * sx - 1.0 , 1.0 - s1.y * sy);
628+ glVertex2f (s2.x * sx - 1.0 , 1.0 - s1.y * sy);
629+ glVertex2f (s2.x * sx - 1.0 , 1.0 - s2.y * sy);
630+ glVertex2f (s1.x * sx - 1.0 , 1.0 - s2.y * sy);
631+ glVertex2f (s1.x * sx - 1.0 , 1.0 - s1.y * sy);
632+ glEnd ();
633+ }
634+
610635 if (tool_ == image_tool_brush) {
611636 glBegin (GL_LINE_LOOP );
612637 float theta;
@@ -767,7 +792,6 @@ namespace dexpert
767792 scrollAgain ();
768793 }
769794
770-
771795 void ImagePanel::setBrushSize (uint8_t size) {
772796 if (size > 128 )
773797 brush_size_ = 128 ;
@@ -1036,7 +1060,7 @@ namespace dexpert
10361060 }
10371061
10381062 void ImagePanel::selectAll () {
1039- if (images_[image_type_paste]) {
1063+ if (images_[image_type_paste]) {
10401064 return ;
10411065 }
10421066 auto r = getReferenceImage ();
0 commit comments