bug-gnu-emacs
[Top][All Lists]
Advanced

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

bug#35468: [PATCH] Refactor draw_glyph_string on X and w32


From: Alex Gramiak
Subject: bug#35468: [PATCH] Refactor draw_glyph_string on X and w32
Date: Mon, 29 Apr 2019 11:43:23 -0600
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/26.2 (gnu/linux)

>> The result of this refactoring should be more low-level and more
>> primitive interfaces, and they should each one make sense, not be
>> ad-hoc.  It means the job becomes more complex, and you will probably
>> need to ask questions regarding the GUI systems you are less familiar
>> with.  But the result will IMO much better and future-proof.
>
> I'll see what I can do.

Alright, for the first question may I ask if you're okay with the
following abstraction (which may be the start of a pattern)?

I'm in {x,w32}_draw_box_rect right now, trying to generalize both
versions. The issue is that the fill command in each accepts different
arguments; specifically the w32 version takes in the color explicitly
and uses s->hdc instead of s->gc. So I think there will have to be 2
different fill_rectangle interface procedures: one for glyph strings (so
that the w32 version can access s->hdc), and another for other
procedures like *_draw_bar_cursor.

  void
  gui_draw_glyph_string_box (struct glyph_string *s)
  {
    int width, left_x, right_x, top_y, bottom_y, last_x;
    bool raised_p, left_p, right_p;
    struct glyph *last_glyph;

    last_x = ((s->row->full_width_p && !s->w->pseudo_window_p)
              ? WINDOW_RIGHT_EDGE_X (s->w)
              : window_box_right (s->w, s->area));

    /* The glyph that may have a right box line.  */
    last_glyph = (s->cmp || s->img
                  ? s->first_glyph
                  : s->first_glyph + s->nchars - 1);

    width = eabs (s->face->box_line_width);
    raised_p = s->face->box == FACE_RAISED_BOX;
    left_x = s->x;
    right_x = (s->row->full_width_p && s->extends_to_end_of_line_p
               ? last_x - 1
               : min (last_x, s->x + s->background_width) - 1);
    top_y = s->y;
    bottom_y = top_y + s->height - 1;

    left_p = (s->first_glyph->left_box_line_p
              || (s->hl == DRAW_MOUSE_FACE
                  && (s->prev == NULL
                      || s->prev->hl != s->hl)));
    right_p = (last_glyph->right_box_line_p
               || (s->hl == DRAW_MOUSE_FACE
                   && (s->next == NULL
                       || s->next->hl != s->hl)));

    if (s->face->box == FACE_SIMPLE_BOX)
      FRAME_GDIF (s->f)->draw_box_rect (s,
                                        left_x,
                                        top_y,
                                        right_x,
                                        bottom_y,
                                        width,
                                        left_p,
                                        right_p);
    else
      {
        FRAME_GDIF (s->f)->setup_relief_colors (s);
        FRAME_GDIF (s->f)->draw_relief_rect (s->f,
                                             left_x,
                                             top_y,
                                             right_x,
                                             bottom_y,
                                             width,
                                             raised_p,
                                             true,
                                             true,
                                             left_p,
                                             right_p);
      }
  }

  void
  gui_draw_box_rect (struct glyph_string *s,
                     int left_x, int top_y, int right_x, int bottom_y, int 
width,
                     bool left_p, bool right_p)
  {
    struct graphical_drawing_interface *gdif = FRAME_GDIF (s->f);

    gdif->save_context (s);

    gdif->set_context_clip (s);
    gdif->set_context_foreground (s, s->face->box_color);

    /* Top.  */
    gdif->fill_rectangle (s, s->gc, left_x, top_y, right_x - left_x + 1, width);

    /* Left.  */
    if (left_p)
      {
        gdif->fill_rectangle (s, s->gc,
                              left_x, top_y,
                              width, bottom_y - top_y + 1);
      }

    /* Bottom.  */
    gdif->fill_rectangle (s, s->gc,
                          left_x, bottom_y - width + 1,
                          right_x - left_x + 1, width);

    /* Right.  */
    if (right_p)
      {
        gdif->fill_rectangle (s, s->gc,
                              right_x - width + 1, top_y,
                              width, bottom_y - top_y + 1);
      }

    gdif->reset_context (s);
  }

It doesn't work for NS partially because of the following section only
present in the NS equivalent of gui_draw_glyph_string_box. Would you be
okay with putting this in the generic version inside a FRAME_NS_P (s->f)
check? I don't know why only NS has this, though...

  if (s->hl == DRAW_MOUSE_FACE)
    {
      face = FACE_FROM_ID_OR_NULL (s->f,
                                   MOUSE_HL_INFO (s->f)->mouse_face_face_id);
      if (!face)
        face = FACE_FROM_ID (s->f, MOUSE_FACE_ID);
    }
  else
    face = s->face;





reply via email to

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