emacs-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: C equivalent for: (face-attribute 'region :background (selected-fram


From: YAMAMOTO Mitsuharu
Subject: Re: C equivalent for: (face-attribute 'region :background (selected-frame) 'default)
Date: Wed, 27 Sep 2017 08:19:29 +0900
User-agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.8 (Shij┼Ź) APEL/10.6 Emacs/22.3 (sparc-sun-solaris2.8) MULE/5.0 (SAKAKI)

>>>>> On Mon, 25 Sep 2017 21:38:07 -0700, Keith David Bershatsky 
>>>>> <address@hidden> said:

> I am working on implementing my own feature requests to draw crosshairs 
> (#17684) using multiple fake cursors (#22873), and I am trying to quickly 
> convert (in C) the :background of the region face into a string -- e.g., 
> "blue" or "#0000FF".  My goal is to do all of this in C, and I would like to 
> avoid porting (rewriting) several Lisp functions to give me the result of:
>     (face-attribute 'region :background (selected-frame) 'default)

> Is there anything built-in into the Emacs C code base that already does this, 
> or *almost* does this ...?

> BACKGROUND:  I already have a function written in C that converts a color 
> string (e.g., "blue" or "#0000FF") into an LSL color vector, which is used by 
> the new multiple fake cursors (#22873) feature.  I erase glyphless (floating) 
> fake cursors by drawing new ones that match the background face.  When a 
> region is active, I need the LSL color vector of the region :background.

Do you need xterm.c-level drawing functions?  Then perhaps you want
GCs rather than the color strings.  In the Mac port, I use the
following function.

/* Return GC for the face with FACE_ID on frame F.  If the face is not
   available, return DEFAULT_GC.  */

GC
mac_gc_for_face_id (struct frame *f, int face_id, GC default_gc)
{
  struct face *face = FACE_FROM_ID_OR_NULL (f, face_id);

  if (face)
    {
      prepare_face_for_display (f, face);
      return face->gc;
    }
  else
    return default_gc;
}


Here's an example:

/* Draw a window divider from (x0,y0) to (x1,y1)  */

static void
mac_draw_window_divider (struct window *w, int x0, int x1, int y0, int y1)
{
  struct frame *f = XFRAME (WINDOW_FRAME (w));
  GC gc = mac_gc_for_face_id (f, WINDOW_DIVIDER_FACE_ID,
                              f->output_data.mac->normal_gc);

  if ((y1 - y0 > x1 - x0 && x1 - x0 > 2)
      || (x1 - x0 > y1 - y0 && y1 - y0 > 3))
    {
      GC gc_first = mac_gc_for_face_id (f, WINDOW_DIVIDER_FIRST_PIXEL_FACE_ID,
                                        f->output_data.mac->normal_gc);
      GC gc_last = mac_gc_for_face_id (f, WINDOW_DIVIDER_LAST_PIXEL_FACE_ID,
                                       f->output_data.mac->normal_gc);

      if (y1 - y0 > x1 - x0)
        /* Vertical.  */
        {
          mac_fill_rectangle (f, gc_first, x0, y0, 1, y1 - y0);
          mac_fill_rectangle (f, gc, x0 + 1, y0, x1 - x0 - 2, y1 - y0);
          mac_fill_rectangle (f, gc_last, x1 - 1, y0, 1, y1 - y0);
        }
      else
        /* Horizontal.  */
        {
          mac_fill_rectangle (f, gc_first, x0, y0, x1 - x0, 1);
          mac_fill_rectangle (f, gc, x0, y0 + 1, x1 - x0, y1 - y0 - 2);
          mac_fill_rectangle (f, gc_last, x0, y1 - 1, x1 - x0, 1);
        }
    }
  else
    mac_fill_rectangle (f, gc, x0, y0, x1 - x0, y1 - y0);
}

                                     YAMAMOTO Mitsuharu
                                address@hidden



reply via email to

[Prev in Thread] Current Thread [Next in Thread]