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