Ejemplo n.º 1
0
void Canvas::draw_gridlines(const CairoCtx &cr) {
    int spacing = VP_WIDTH / 20;
    int hlines_count = VP_HEIGHT / spacing;
    int vlines_count = VP_WIDTH / spacing;
    int pos = VP_YMIN + spacing;
    std::vector<double> dashes{5.0};

    cr->save();
    cr->set_dash(dashes, 0.0);

    // Draw horizontal grid lines
    for (int i = 0; i < hlines_count - 1; i++) {
        cr->move_to(VP_XMIN, pos);
        cr->line_to(VP_XMAX, pos);
        pos += spacing;
    }

    // Draw vertical grid lines
    pos = VP_XMIN + spacing;
    for (int i = 0; i < vlines_count - 1; i++) {
        cr->move_to(pos, VP_YMIN);
        cr->line_to(pos, VP_YMAX);
        pos += spacing;
    }

    cr->restore();
}
Ejemplo n.º 2
0
void Canvas::draw_center_lines(const CairoCtx &cr) {
    // Coordinates for the center of the window
    int xc = VP_XMIN + VP_WIDTH / 2;
    int yc = VP_YMIN + VP_HEIGHT / 2;

    // Set stroke properties for the centered axis
    cr->set_line_width(1.0);
    cr->set_source_rgba(0.0, 0.0, 0.0, 0.4);  // Light gray

    // Create horizontal and vertical axis centered on the screen
    cr->move_to(VP_XMIN, yc);
    cr->line_to(VP_XMAX, yc);
    cr->move_to(xc, VP_YMIN);
    cr->line_to(xc, VP_YMAX);

    cr->stroke();
}
void BackLayer::render_page_borders(const Rect &bounds) {
  CairoCtx *cr = _owner->cairoctx();
  bool use_gl = _owner->has_gl();

  double x, y;
  double left, top;
  double right, bottom;
  Size psize = _owner->get_page_size();

  double jitter = use_gl ? 0 : 0.5;
  left = jitter;
  right = bounds.right() + jitter;

  top = jitter;
  bottom = bounds.bottom() + jitter;

  if (use_gl) {
    glColor4d(0.75, 0.75, 0.75, 1);
    glBegin(GL_LINES);
    for (x = left; x <= right; x += psize.width) {
      glVertex2d(x, top);
      glVertex2d(x, bottom);
    }
    glEnd();
    glBegin(GL_LINES);
    for (y = top; y <= bottom; y += psize.height) {
      glVertex2d(left, y);
      glVertex2d(right, y);
    }
    glEnd();
  } else {
    cr->set_color(Color(0.75, 0.75, 0.75));
    cr->set_line_width(1.0);

    for (x = left; x <= right; x += psize.width) {
      cr->move_to(x, top);
      cr->line_to(x, bottom);
    }
    for (y = top; y <= bottom; y += psize.height) {
      cr->move_to(left, y);
      cr->line_to(right, y);
    }
    cr->stroke();
  }
}
Ejemplo n.º 4
0
void Canvas::draw_viewport(const CairoCtx &cr) {
    // Top horizontal line
    cr->move_to(VP_XMIN, VP_YMIN);
    cr->line_to(VP_XMAX, VP_YMIN);

    // Right vertical line
    cr->move_to(VP_XMAX, VP_YMIN);
    cr->line_to(VP_XMAX, VP_YMAX);

    // Bottom horizontal line
    cr->move_to(VP_XMAX, VP_YMAX);
    cr->line_to(VP_XMIN, VP_YMAX);

    // Left vertical line
    cr->move_to(VP_XMIN, VP_YMAX);
    cr->line_to(VP_XMIN, VP_YMIN);

    cr->stroke();
}
void BackLayer::render_grid(const Rect &bounds) {
  bool use_gl = _owner->has_gl();

  double gsize = _owner->_grid_size;
  double x, y;
  double left, top;
  double right, bottom;
  bool regen_display_lists = false;

  float jitter = 0.5f; // use_gl ? 0 : 0.5f; Also for GL it renders sharper lines with 0.5 offset.
  left = jitter;
  right = bounds.right() + jitter;

  top = jitter;
  bottom = bounds.bottom() + jitter;

  if (_grid1_dl == 0 || Point(left, top) != _grid_dl_start || _grid_dl_size != gsize || _grid_dl_area != bounds) {
    _grid_dl_start = Point(left, top);
    _grid_dl_size = gsize;
    _grid_dl_area = bounds;

    if (_grid1_dl == 0 && use_gl) {
      _grid1_dl = glGenLists(1);
      _grid2_dl = glGenLists(2);
    }
    regen_display_lists = true;
  }

  // Small grid.
  if (gsize * _owner->get_zoom() > 4) {
    if (use_gl) {
      if (regen_display_lists) {
        glNewList(_grid1_dl, GL_COMPILE);

        glDisable(GL_TEXTURE_2D);
        glColor4d(_line2_color.red, _line2_color.green, _line2_color.blue, _line2_color.alpha);

        glBegin(GL_LINES);
        for (x = left; x < right; x += gsize) {
          glVertex2d(x, top);
          glVertex2d(x, bottom);
        }
        glEnd();

        glBegin(GL_LINES);
        for (y = top; y < bottom; y += gsize) {
          glVertex2d(left, y);
          glVertex2d(right, y);
        }
        glEnd();

        glEndList();
      }

      glCallList(_grid1_dl);
    } else {
      CairoCtx *cr = _owner->cairoctx();

      cr->set_color(_line2_color);
      cr->set_line_width(1.0);

      for (x = left; x <= right; x += gsize) {
        cr->move_to(x, top);
        cr->line_to(x, bottom);
        cr->stroke();
      }

      for (y = top; y <= bottom; y += gsize) {
        cr->move_to(left, y);
        cr->line_to(right, y);
        cr->stroke();
      }
      cr->stroke();
    }
  }

  gsize *= 8;

  // Large grid.
  if (gsize * _owner->get_zoom() >= 10) {
    if (use_gl) {
      if (regen_display_lists) {
        glNewList(_grid2_dl, GL_COMPILE);

        glDisable(GL_TEXTURE_2D);
        glColor4d(_line1_color.red, _line1_color.green, _line1_color.blue, _line1_color.alpha);

        glBegin(GL_LINES);
        for (x = left; x < right; x += gsize) {
          glVertex2d(x, top);
          glVertex2d(x, bottom);
        }
        glEnd();
        glBegin(GL_LINES);
        for (y = top; y < bottom; y += gsize) {
          glVertex2d(left, y);
          glVertex2d(right, y);
        }
        glEnd();

        glEndList();
      }

      glCallList(_grid2_dl);
    } else {
      CairoCtx *cr = _owner->cairoctx();

      cr->set_color(_line1_color);

      for (x = left; x <= right; x += gsize) {
        cr->move_to(x, top);
        cr->line_to(x, bottom);
        cr->stroke();
      }
      for (y = top; y <= bottom; y += gsize) {
        cr->move_to(left, y);
        cr->line_to(right, y);
        cr->stroke();
      }
    }
  }
}