Author: manolo
Date: 2012-12-29 07:54:35 -0800 (Sat, 29 Dec 2012)
New Revision: 9783
Log:
Added fltk3::Widget::dragimage(fltk3::Image*) to control the image used as a 
cursor when dragging
from a widget on the Mac OS platform. The default image is built from the text 
present in the
selection buffer when dragging starts.
This also removes any use of dynamic_cast.

Modified:
   branches/branch-3.0/include/fltk3/Widget.h
   branches/branch-3.0/src/fltk3/Widget.cxx
   branches/branch-3.0/src/fltk3/cocoa.mm

Modified: branches/branch-3.0/include/fltk3/Widget.h
===================================================================
--- branches/branch-3.0/include/fltk3/Widget.h  2012-12-29 14:14:41 UTC (rev 
9782)
+++ branches/branch-3.0/include/fltk3/Widget.h  2012-12-29 15:54:35 UTC (rev 
9783)
@@ -90,6 +90,8 @@
     fltk3::Image* image_;
     /** optional image for a deactivated label */
     fltk3::Image* deimage_;
+    /** optional image when dragging */
+    fltk3::Image* dragimage_;
     
   public:
     
@@ -369,6 +371,17 @@
      */
     void deimage(fltk3::Image& img) {deimage_=&img;}
     
+    /** Sets the image to use when dragging from the widget. 
+     This image is used on the Mac OS platform as a cursor when dragging from
+     the widget. If no (or a NULL) dragging image is assigned to a widget, the 
text
+     data in the selection buffer is used to build an image.
+     \param[in] img the image used when dragging from the widget
+     */
+    void dragimage(fltk3::Image* img) {dragimage_=img;}
+    /** Gets the image that is used when dragging from the widget.  
+     */
+    fltk3::Image* dragimage() {return dragimage_;}
+    
   };
   
   

Modified: branches/branch-3.0/src/fltk3/Widget.cxx
===================================================================
--- branches/branch-3.0/src/fltk3/Widget.cxx    2012-12-29 14:14:41 UTC (rev 
9782)
+++ branches/branch-3.0/src/fltk3/Widget.cxx    2012-12-29 15:54:35 UTC (rev 
9783)
@@ -110,7 +110,8 @@
   labeltext_(L),
   flags_(0),
   image_(0),
-  deimage_(0)
+  deimage_(0),
+  dragimage_(0)
 {
 }
 

Modified: branches/branch-3.0/src/fltk3/cocoa.mm
===================================================================
--- branches/branch-3.0/src/fltk3/cocoa.mm      2012-12-29 14:14:41 UTC (rev 
9782)
+++ branches/branch-3.0/src/fltk3/cocoa.mm      2012-12-29 15:54:35 UTC (rev 
9783)
@@ -3027,21 +3027,16 @@
   return image;
 }
 
-static NSImage *defaultDragImage(int *pwidth, int *pheight)
+static NSImage *defaultDragImage(int *pwidth, int *pheight, fltk3::Image* img)
 {
-  const int width = 16, height = 16;
-  fltk3::Offscreen off = 
fltk3::QuartzGraphicsDriver::create_offscreen_with_alpha(width, height);
+  *pwidth = img->w();
+  *pheight = img->h();
+  fltk3::Offscreen off = 
fltk3::QuartzGraphicsDriver::create_offscreen_with_alpha(*pwidth, *pheight);
   fl_begin_offscreen(off);
-  CGContextSetRGBFillColor( (CGContextRef)off, 0,0,0,0);
-  fltk3::rectf(0,0,width,height);
-  CGContextSetRGBStrokeColor( (CGContextRef)off, 0,0,0,0.6);
-  fltk3::rect(0,0,width,height);
-  fltk3::rect(2,2,width-4,height-4);
+  img->draw(0,0);
   fl_end_offscreen();
   NSImage* image = CGBitmapContextToNSImage( (CGContextRef)off );
   fl_delete_offscreen( off );
-  *pwidth = width;
-  *pheight = height;
   return image;
 }
 
@@ -3064,19 +3059,18 @@
   }
   NSView *myview = [Fl_X::i(win)->xid contentView];
   NSEvent *theEvent = [NSApp currentEvent];
-  
+ 
   int width, height;
   NSImage *image;
-  if ( dynamic_cast<fltk3::Input_*>(w) != NULL ||  
dynamic_cast<fltk3::TextDisplay*>(w) != NULL) {
+  if ( !w->dragimage() ) {
     fl_selection_buffer[0][ fl_selection_length[0] ] = 0;
     image = imageFromText(fl_selection_buffer[0], &width, &height);
   } else {
-    image = defaultDragImage(&width, &height);
+    image = defaultDragImage(&width, &height, w->dragimage());
   }
   
   static NSSize offset={0,0};
   NSPoint pt = [theEvent locationInWindow];
-  pt.x -= width/2;
   pt.y -= height/2;
   [myview dragImage:image  at:pt  offset:offset 
               event:theEvent  pasteboard:mypasteboard  

_______________________________________________
fltk-commit mailing list
[email protected]
http://lists.easysw.com/mailman/listinfo/fltk-commit

Reply via email to