Panda3D
pnmPainter.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file pnmPainter.I
10  * @author drose
11  * @date 2007-02-02
12  */
13 
14 /**
15  *
16  */
17 INLINE PNMPainter::
18 ~PNMPainter() {
19 }
20 
21 /**
22  * Specifies a PNMBrush that will be used for drawing lines and edges. If the
23  * brush is a bitmap brush, its image will be smeared pixelwise along the
24  * line.
25  *
26  * Unlike the PNMImage passed to the constructor, the PNMPainter will take
27  * ownership of the pen. It is not necessary to keep a separate pointer to
28  * it.
29  */
30 INLINE void PNMPainter::
31 set_pen(PNMBrush *pen) {
32  _pen = pen;
33 }
34 
35 /**
36  * Returns the current pen. See set_pen().
37  */
38 INLINE PNMBrush *PNMPainter::
39 get_pen() const {
40  return _pen;
41 }
42 
43 /**
44  * Specifies a PNMBrush that will be used for filling in the interiors of
45  * objects. If the brush is a bitmap brush, its image will be tiled
46  * throughout the space.
47  *
48  * Unlike the PNMImage passed to the constructor, the PNMPainter will take
49  * ownership of the fill brush. It is not necessary to keep a separate
50  * pointer to it.
51  */
52 INLINE void PNMPainter::
53 set_fill(PNMBrush *fill) {
54  _fill = fill;
55 }
56 
57 /**
58  * Returns the current fill brush. See set_fill().
59  */
60 INLINE PNMBrush *PNMPainter::
61 get_fill() const {
62  return _fill;
63 }
64 
65 /**
66  * Draws an antialiased point on the PNMImage, using the current pen.
67  */
68 INLINE void PNMPainter::
69 draw_point(float x, float y) {
70  draw_line(x, y, x, y);
71 }
72 
73 /**
74  * Called within draw_line() to draw a single point of a mostly-horizontal
75  * line.
76  */
77 INLINE void PNMPainter::
78 draw_hline_point(int x, float xa, float ya, float xd, float yd,
79  float pixel_scale) {
80  float y = (yd * (x - xa) / xd) + ya;
81  int ymax = (int)cceil(y);
82  int ymin = (int)cfloor(y);
83  if (ymax == ymin) {
84  _pen->draw(_image, x, ymin, pixel_scale);
85  } else {
86  _pen->draw(_image, x, ymax, (y - ymin) * pixel_scale);
87  _pen->draw(_image, x, ymin, (ymax - y) * pixel_scale);
88  }
89 }
90 
91 /**
92  * Called within draw_line() to draw a single point of a mostly-vertical line.
93  */
94 INLINE void PNMPainter::
95 draw_vline_point(int y, float xa, float ya, float xd, float yd,
96  float pixel_scale) {
97  float x = (xd * (y - ya) / yd) + xa;
98  int xmax = (int)cceil(x);
99  int xmin = (int)cfloor(x);
100  if (xmax == xmin) {
101  _pen->draw(_image, xmin, y, pixel_scale);
102  } else {
103  _pen->draw(_image, xmax, y, (x - xmin) * pixel_scale);
104  _pen->draw(_image, xmin, y, (xmax - x) * pixel_scale);
105  }
106 }
set_pen
Specifies a PNMBrush that will be used for drawing lines and edges.
Definition: pnmPainter.h:40
void draw_point(float x, float y)
Draws an antialiased point on the PNMImage, using the current pen.
Definition: pnmPainter.I:69
set_fill
Specifies a PNMBrush that will be used for filling in the interiors of objects.
Definition: pnmPainter.h:41
void draw_line(float xa, float ya, float xb, float yb)
Draws an antialiased line on the PNMImage, using the current pen.
Definition: pnmPainter.cxx:39
This class is used to control the shape and color of the drawing operations performed by a PNMPainter...
Definition: pnmBrush.h:36