]> git.eshelyaron.com Git - emacs.git/commitdiff
Draw outermost line using black relief and erase corners also for cairo.
authorYAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
Tue, 17 Feb 2015 01:14:56 +0000 (10:14 +0900)
committerYAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
Tue, 17 Feb 2015 01:14:56 +0000 (10:14 +0900)
* xterm.c [USE_CAIRO]: Include math.h.
(enum corners) [USE_CAIRO]: New enum.
(x_erase_corners_for_relief) [USE_CAIRO]: New function.
(x_draw_relief_rect) [USE_CAIRO]: Use it.  If box width is larger
than 1, draw the outermost line using the black relief.

src/ChangeLog
src/xterm.c

index 052bf6985c0024e18984757d556640a9a2538b9d..fea9e379d7317d5999040e7d5dba7acdc4064ff6 100644 (file)
@@ -1,3 +1,11 @@
+2015-02-17  YAMAMOTO Mitsuharu  <mituharu@math.s.chiba-u.ac.jp>
+
+       * xterm.c [USE_CAIRO]: Include math.h.
+       (enum corners) [USE_CAIRO]: New enum.
+       (x_erase_corners_for_relief) [USE_CAIRO]: New function.
+       (x_draw_relief_rect) [USE_CAIRO]: Use it.  If box width is larger
+       than 1, draw the outermost line using the black relief.
+
 2015-02-16  YAMAMOTO Mitsuharu  <mituharu@math.s.chiba-u.ac.jp>
 
        * gtkutil.c (xg_page_setup_dialog, xg_get_page_setup, draw_page)
index c1970cc4334e9dd51f959b57104b79c1b62f1855..99ebaad4715ef410a9da4a969279dcb67e75d1d0 100644 (file)
@@ -22,6 +22,9 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #include <config.h>
 #include <stdio.h>
+#ifdef USE_CAIRO
+#include <math.h>
+#endif
 
 #include "lisp.h"
 #include "blockinput.h"
@@ -824,6 +827,48 @@ x_fill_trapezoid_for_relief (struct frame *f, GC gc, int x, int y,
   x_end_cr_clip (f);
 }
 
+enum corners
+  {
+    CORNER_BOTTOM_RIGHT,       /* 0 -> pi/2 */
+    CORNER_BOTTOM_LEFT,                /* pi/2 -> pi */
+    CORNER_TOP_LEFT,           /* pi -> 3pi/2 */
+    CORNER_TOP_RIGHT,          /* 3pi/2 -> 2pi */
+    CORNER_LAST
+  };
+
+static void
+x_erase_corners_for_relief (struct frame *f, GC gc, int x, int y,
+                           int width, int height,
+                           double radius, double margin, int corners)
+{
+  cairo_t *cr;
+  int i;
+
+  cr = x_begin_cr_clip (f, gc);
+  x_set_cr_source_with_gc_background (f, gc);
+  for (i = 0; i < CORNER_LAST; i++)
+    if (corners & (1 << i))
+      {
+       double xm, ym, xc, yc;
+
+       if (i == CORNER_TOP_LEFT || i == CORNER_BOTTOM_LEFT)
+         xm = x - margin, xc = xm + radius;
+       else
+         xm = x + width + margin, xc = xm - radius;
+       if (i == CORNER_TOP_LEFT || i == CORNER_TOP_RIGHT)
+         ym = y - margin, yc = ym + radius;
+       else
+         ym = y + height + margin, yc = ym - radius;
+
+       cairo_move_to (cr, xm, ym);
+       cairo_arc (cr, xc, yc, radius, i * M_PI_2, (i + 1) * M_PI_2);
+      }
+  cairo_clip (cr);
+  cairo_rectangle (cr, x, y, width, height);
+  cairo_fill (cr);
+  x_end_cr_clip (f);
+}
+
 static void
 x_draw_horizontal_wave (struct frame *f, GC gc, int x, int y,
                        int width, int height, int wave_length)
@@ -2505,6 +2550,7 @@ x_draw_relief_rect (struct frame *f,
 {
 #ifdef USE_CAIRO
   GC top_left_gc, bottom_right_gc;
+  int corners = 0;
 
   if (raised_p)
     {
@@ -2521,11 +2567,23 @@ x_draw_relief_rect (struct frame *f,
   x_set_clip_rectangles (f, bottom_right_gc, clip_rect, 1);
 
   if (left_p)
-    x_fill_rectangle (f, top_left_gc, left_x, top_y,
-                     width, bottom_y + 1 - top_y);
+    {
+      x_fill_rectangle (f, top_left_gc, left_x, top_y,
+                       width, bottom_y + 1 - top_y);
+      if (top_p)
+       corners |= 1 << CORNER_TOP_LEFT;
+      if (bot_p)
+       corners |= 1 << CORNER_BOTTOM_LEFT;
+    }
   if (right_p)
-    x_fill_rectangle (f, bottom_right_gc, right_x + 1 - width, top_y,
-                     width, bottom_y + 1 - top_y);
+    {
+      x_fill_rectangle (f, bottom_right_gc, right_x + 1 - width, top_y,
+                       width, bottom_y + 1 - top_y);
+      if (top_p)
+       corners |= 1 << CORNER_TOP_RIGHT;
+      if (bot_p)
+       corners |= 1 << CORNER_BOTTOM_RIGHT;
+    }
   if (top_p)
     {
       if (!right_p)
@@ -2545,6 +2603,20 @@ x_draw_relief_rect (struct frame *f,
                                     left_x, bottom_y + 1 - width,
                                     right_x + 1 - left_x, width, 0);
     }
+  if (left_p && width != 1)
+    x_fill_rectangle (f, bottom_right_gc, left_x, top_y,
+                     1, bottom_y + 1 - top_y);
+  if (top_p && width != 1)
+    x_fill_rectangle (f, bottom_right_gc, left_x, top_y,
+                     right_x + 1 - left_x, 1);
+  if (corners)
+    {
+      XSetBackground (FRAME_X_DISPLAY (f), top_left_gc,
+                     FRAME_BACKGROUND_PIXEL (f));
+      x_erase_corners_for_relief (f, top_left_gc, left_x, top_y,
+                                 right_x - left_x + 1, bottom_y - top_y + 1,
+                                 6, 1, corners);
+    }
 
   x_reset_clip_rectangles (f, top_left_gc);
   x_reset_clip_rectangles (f, bottom_right_gc);