FLTK sandbox

Check-in [c7f085e1da]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Mac OS: improved the Fl_Image_Surface class so it returns an RGBA image allowing to draw exactly windows with rounded corners. git-svn-id: http://seriss.com/public/fltk/fltk/branches/branch-1.3@10999 ea41ed52-d2ee-0310-a9c1-e6b18d33e121
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1:c7f085e1da8fd45726f02fd8ba0670526d2f2b51
User & Date: manolo@ea41ed52-d2ee-0310-a9c1-e6b18d33e121 2016-01-06 20:47:39
Context
2016-01-07
05:09
Mention new method Fl_Image_Surface::draw_decorated_window(). git-svn-id: http://seriss.com/public/fltk/fltk/branches/branch-1.3@11000 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 check-in: 2d724a4016 user: manolo@ea41ed52-d2ee-0310-a9c1-e6b18d33e121 tags: trunk
2016-01-06
20:47
Mac OS: improved the Fl_Image_Surface class so it returns an RGBA image allowing to draw exactly windows with rounded corners. git-svn-id: http://seriss.com/public/fltk/fltk/branches/branch-1.3@10999 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 check-in: c7f085e1da user: manolo@ea41ed52-d2ee-0310-a9c1-e6b18d33e121 tags: trunk
20:41
Fixed typo. git-svn-id: http://seriss.com/public/fltk/fltk/branches/branch-1.3@10998 ea41ed52-d2ee-0310-a9c1-e6b18d33e121 check-in: d798ebc92a user: manolo@ea41ed52-d2ee-0310-a9c1-e6b18d33e121 tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to src/Fl_Image_Surface.cxx.

25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41

42
43
44
45
46
47

48
49
50







51
52
53
54
55
56
57
58
59
60



61
62

63
64

65
66
67
68
69
70
71
72
73
74
75

76
77
78




79
80
81
82
83
84
85
..
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
...
186
187
188
189
190
191
192


193
194
195
196
197
198
199
200
201

/** The constructor.
 \param w and \param h give the size in pixels of the resulting image.
 */
Fl_Image_Surface::Fl_Image_Surface(int w, int h) : Fl_Surface_Device(NULL) {
  width = w;
  height = h;
#if !(defined(__APPLE__) || defined(WIN32))
  gc = 0;
  if (!fl_gc) { // allows use of this class before any window is shown
    fl_open_display();
    gc = XCreateGC(fl_display, RootWindow(fl_display, fl_screen), 0, 0);
    fl_gc = gc;
    }
#endif
  offscreen = fl_create_offscreen(w, h);
#ifdef __APPLE__

  helper = new Fl_Quartz_Flipped_Surface_(width, height);
  driver(helper->driver());
  CGContextSaveGState(offscreen);
  CGContextTranslateCTM(offscreen, 0, height);
  CGContextScaleCTM(offscreen, 1.0f, -1.0f);
#elif defined(WIN32)

  helper = new Fl_GDI_Surface_();
  driver(helper->driver());
#else







  helper = new Fl_Xlib_Surface_();
  driver(helper->driver());
#endif
}

/** The destructor.
 */
Fl_Image_Surface::~Fl_Image_Surface() {
  fl_delete_offscreen(offscreen);
#ifdef __APPLE__



  delete (Fl_Quartz_Flipped_Surface_*)helper;
#elif defined(WIN32)

  delete (Fl_GDI_Surface_*)helper;
#else

  if (gc) { XFreeGC(fl_display, gc); fl_gc = 0; }
  delete (Fl_Xlib_Surface_*)helper;
#endif
}

/** Returns an image made of all drawings sent to the Fl_Image_Surface object.
 The returned object contains its own copy of the RGB data.
 */
Fl_RGB_Image* Fl_Image_Surface::image()
{
  unsigned char *data;

#ifdef __APPLE__
  CGContextFlush(offscreen);
  data = fl_read_image(NULL, 0, 0, width, height, 0);




  fl_gc = 0;
#elif defined(WIN32)
  fl_pop_clip(); 
  data = fl_read_image(NULL, 0, 0, width, height, 0);
  RestoreDC(fl_gc, _savedc); 
  DeleteDC(fl_gc); 
  _ss->set_current(); 
................................................................................
  fl_gc = _sgc;
#else
  fl_pop_clip(); 
  data = fl_read_image(NULL, 0, 0, width, height, 0);
  fl_window = pre_window; 
  previous->set_current();
#endif
  Fl_RGB_Image *image = new Fl_RGB_Image(data, width, height);
  image->alloc_array = 1;
  return image;
}

/** Draws a widget in the image surface
 
 \param widget any FLTK widget (e.g., standard, custom, window, GL view) to draw in the image
................................................................................
{
#ifdef WIN32
  // draw_decorated_window() will change the current drawing surface, and set it
  // back to us; it's necessary to do some cleaning before
  fl_pop_clip();
  RestoreDC(fl_gc, _savedc);
  DeleteDC(fl_gc);


#endif
  helper->draw_decorated_window(win, delta_x, delta_y, this);
}
#endif


//
// End of "$Id$".
//







<
<
<
<
<
<
<
<
<

>






>



>
>
>
>
>
>
>








<

>
>
>


>


>











>


<
>
>
>
>







 







|







 







>
>









25
26
27
28
29
30
31









32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58

59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82

83
84
85
86
87
88
89
90
91
92
93
..
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
...
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211

/** The constructor.
 \param w and \param h give the size in pixels of the resulting image.
 */
Fl_Image_Surface::Fl_Image_Surface(int w, int h) : Fl_Surface_Device(NULL) {
  width = w;
  height = h;









#ifdef __APPLE__
  offscreen = Fl_Quartz_Graphics_Driver::create_offscreen_with_alpha(w, h);
  helper = new Fl_Quartz_Flipped_Surface_(width, height);
  driver(helper->driver());
  CGContextSaveGState(offscreen);
  CGContextTranslateCTM(offscreen, 0, height);
  CGContextScaleCTM(offscreen, 1.0f, -1.0f);
#elif defined(WIN32)
  offscreen = fl_create_offscreen(w, h);
  helper = new Fl_GDI_Surface_();
  driver(helper->driver());
#else
  gc = 0;
  if (!fl_gc) { // allows use of this class before any window is shown
    fl_open_display();
    gc = XCreateGC(fl_display, RootWindow(fl_display, fl_screen), 0, 0);
    fl_gc = gc;
  }
  offscreen = fl_create_offscreen(w, h);
  helper = new Fl_Xlib_Surface_();
  driver(helper->driver());
#endif
}

/** The destructor.
 */
Fl_Image_Surface::~Fl_Image_Surface() {

#ifdef __APPLE__
  void *data = CGBitmapContextGetData((CGContextRef)offscreen);
  free(data);
  CGContextRelease((CGContextRef)offscreen);
  delete (Fl_Quartz_Flipped_Surface_*)helper;
#elif defined(WIN32)
  fl_delete_offscreen(offscreen);
  delete (Fl_GDI_Surface_*)helper;
#else
  fl_delete_offscreen(offscreen);
  if (gc) { XFreeGC(fl_display, gc); fl_gc = 0; }
  delete (Fl_Xlib_Surface_*)helper;
#endif
}

/** Returns an image made of all drawings sent to the Fl_Image_Surface object.
 The returned object contains its own copy of the RGB data.
 */
Fl_RGB_Image* Fl_Image_Surface::image()
{
  unsigned char *data;
  int depth = 3, ld = 0;
#ifdef __APPLE__
  CGContextFlush(offscreen);

  ld = CGBitmapContextGetBytesPerRow(offscreen);
  data = (uchar*)malloc(ld * height);
  memcpy(data, (uchar *)CGBitmapContextGetData(offscreen), ld * height);
  depth = 4;
  fl_gc = 0;
#elif defined(WIN32)
  fl_pop_clip(); 
  data = fl_read_image(NULL, 0, 0, width, height, 0);
  RestoreDC(fl_gc, _savedc); 
  DeleteDC(fl_gc); 
  _ss->set_current(); 
................................................................................
  fl_gc = _sgc;
#else
  fl_pop_clip(); 
  data = fl_read_image(NULL, 0, 0, width, height, 0);
  fl_window = pre_window; 
  previous->set_current();
#endif
  Fl_RGB_Image *image = new Fl_RGB_Image(data, width, height, depth, ld);
  image->alloc_array = 1;
  return image;
}

/** Draws a widget in the image surface
 
 \param widget any FLTK widget (e.g., standard, custom, window, GL view) to draw in the image
................................................................................
{
#ifdef WIN32
  // draw_decorated_window() will change the current drawing surface, and set it
  // back to us; it's necessary to do some cleaning before
  fl_pop_clip();
  RestoreDC(fl_gc, _savedc);
  DeleteDC(fl_gc);
#elif !defined(__APPLE__)
  fl_pop_clip();
#endif
  helper->draw_decorated_window(win, delta_x, delta_y, this);
}
#endif


//
// End of "$Id$".
//