Panda3D
|
00001 // Filename: pnmPainter.I 00002 // Created by: drose (02Feb07) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 00012 // 00013 //////////////////////////////////////////////////////////////////// 00014 00015 00016 //////////////////////////////////////////////////////////////////// 00017 // Function: PNMPainter::Destructor 00018 // Access: Published 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE PNMPainter:: 00022 ~PNMPainter() { 00023 } 00024 00025 //////////////////////////////////////////////////////////////////// 00026 // Function: PNMPainter::set_pen 00027 // Access: Published 00028 // Description: Specifies a PNMBrush that will be used for drawing 00029 // lines and edges. If the brush is a bitmap brush, its 00030 // image will be smeared pixelwise along the line. 00031 // 00032 // Unlike the PNMImage passed to the constructor, the 00033 // PNMPainter will take ownership of the pen. It is not 00034 // necessary to keep a separate pointer to it. 00035 //////////////////////////////////////////////////////////////////// 00036 INLINE void PNMPainter:: 00037 set_pen(PNMBrush *pen) { 00038 _pen = pen; 00039 } 00040 00041 //////////////////////////////////////////////////////////////////// 00042 // Function: PNMPainter::get_pen 00043 // Access: Published 00044 // Description: Returns the current pen. See set_pen(). 00045 //////////////////////////////////////////////////////////////////// 00046 INLINE PNMBrush *PNMPainter:: 00047 get_pen() const { 00048 return _pen; 00049 } 00050 00051 //////////////////////////////////////////////////////////////////// 00052 // Function: PNMPainter::set_fill 00053 // Access: Published 00054 // Description: Specifies a PNMBrush that will be used for filling 00055 // in the interiors of objects. If the brush is a 00056 // bitmap brush, its image will be tiled throughout the 00057 // space. 00058 // 00059 // Unlike the PNMImage passed to the constructor, the 00060 // PNMPainter will take ownership of the fill brush. It 00061 // is not necessary to keep a separate pointer to it. 00062 //////////////////////////////////////////////////////////////////// 00063 INLINE void PNMPainter:: 00064 set_fill(PNMBrush *fill) { 00065 _fill = fill; 00066 } 00067 00068 //////////////////////////////////////////////////////////////////// 00069 // Function: PNMPainter::get_fill 00070 // Access: Published 00071 // Description: Returns the current fill brush. See set_fill(). 00072 //////////////////////////////////////////////////////////////////// 00073 INLINE PNMBrush *PNMPainter:: 00074 get_fill() const { 00075 return _fill; 00076 } 00077 00078 //////////////////////////////////////////////////////////////////// 00079 // Function: PNMPainter::draw_point 00080 // Access: Published 00081 // Description: Draws an antialiased point on the PNMImage, using the 00082 // current pen. 00083 //////////////////////////////////////////////////////////////////// 00084 INLINE void PNMPainter:: 00085 draw_point(double x, double y) { 00086 draw_line(x, y, x, y); 00087 } 00088 00089 //////////////////////////////////////////////////////////////////// 00090 // Function: PNMPainter::draw_hline_point 00091 // Access: Private 00092 // Description: Called within draw_line() to draw a single point of a 00093 // mostly-horizontal line. 00094 //////////////////////////////////////////////////////////////////// 00095 INLINE void PNMPainter:: 00096 draw_hline_point(int x, double xa, double ya, double xd, double yd, 00097 double pixel_scale) { 00098 double y = (yd * (x - xa) / xd) + ya; 00099 int ymax = (int)cceil(y); 00100 int ymin = (int)cfloor(y); 00101 if (ymax == ymin) { 00102 _pen->draw(_image, x, ymin, pixel_scale); 00103 } else { 00104 _pen->draw(_image, x, ymax, (y - ymin) * pixel_scale); 00105 _pen->draw(_image, x, ymin, (ymax - y) * pixel_scale); 00106 } 00107 } 00108 00109 //////////////////////////////////////////////////////////////////// 00110 // Function: PNMPainter::draw_vline_point 00111 // Access: Private 00112 // Description: Called within draw_line() to draw a single point of a 00113 // mostly-vertical line. 00114 //////////////////////////////////////////////////////////////////// 00115 INLINE void PNMPainter:: 00116 draw_vline_point(int y, double xa, double ya, double xd, double yd, 00117 double pixel_scale) { 00118 double x = (xd * (y - ya) / yd) + xa; 00119 int xmax = (int)cceil(x); 00120 int xmin = (int)cfloor(x); 00121 if (xmax == xmin) { 00122 _pen->draw(_image, xmin, y, pixel_scale); 00123 } else { 00124 _pen->draw(_image, xmax, y, (x - xmin) * pixel_scale); 00125 _pen->draw(_image, xmin, y, (xmax - x) * pixel_scale); 00126 } 00127 }