31 _pen = PNMBrush::make_pixel(LColorf(0, 0, 0, 1));
32 _fill = PNMBrush::make_pixel(LColorf(1, 1, 1, 1));
41 xa -= (_pen->get_xc() - 0.5);
42 xb -= (_pen->get_xc() - 0.5);
43 ya -= (_pen->get_yc() - 0.5);
44 yb -= (_pen->get_yc() - 0.5);
50 if (xa == xb && ya == yb) {
55 if (cabs(xd) > cabs(yd)) {
59 int x_min = (int)cfloor(xa);
60 int x_max = (int)cceil(xb);
63 draw_hline_point(x_min, xa, ya, xd, yd, 1.0 - (xa - x_min));
66 for (
int x = x_min + 1; x < x_max; ++x) {
67 draw_hline_point(x, xa, ya, xd, yd, 1.0);
72 draw_hline_point(x_max, xa, ya, xd, yd, 1.0 - (x_max - xb));
77 int x_min = (int)cfloor(xb);
78 int x_max = (int)cceil(xa);
81 draw_hline_point(x_max, xa, ya, xd, yd, 1.0 - (x_max - xa));
84 for (
int x = x_max - 1; x > x_min; --x) {
85 draw_hline_point(x, xa, ya, xd, yd, 1.0);
90 draw_hline_point(x_min, xa, ya, xd, yd, 1.0 - (xb - x_min));
98 int y_min = (int)cfloor(ya);
99 int y_max = (int)cceil(yb);
102 draw_vline_point(y_min, xa, ya, xd, yd, 1.0 - (ya - y_min));
105 for (
int y = y_min + 1; y < y_max; ++y) {
106 draw_vline_point(y, xa, ya, xd, yd, 1.0);
109 if (y_max != y_min) {
111 draw_vline_point(y_max, xa, ya, xd, yd, 1.0 - (y_max - yb));
116 int y_min = (int)cfloor(yb);
117 int y_max = (int)cceil(ya);
120 draw_vline_point(y_max, xa, ya, xd, yd, 1.0 - (y_max - ya));
123 for (
int y = y_max - 1; y > y_min; --y) {
124 draw_vline_point(y, xa, ya, xd, yd, 1.0);
127 if (y_max != y_min) {
129 draw_vline_point(y_min, xa, ya, xd, yd, 1.0 - (yb - y_min));
156 int x_min = (int)cceil(xa);
157 int x_max = (int)cfloor(xb);
158 int y_min = (int)cceil(ya);
159 int y_max = (int)cfloor(yb);
160 for (
int y = y_min; y <= y_max; ++y) {
161 _fill->fill(_image, x_min, x_max, y, _xo, _yo);
The name of this class derives from the fact that we originally implemented it as a layer on top of t...
PNMPainter(PNMImage &image, int xo=0, int yo=0)
The constructor stores a pointer to the PNMImage you pass it, but it does not take ownership of the o...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
void draw_line(float xa, float ya, float xb, float yb)
Draws an antialiased line on the PNMImage, using the current pen.
void draw_rectangle(float xa, float ya, float xb, float yb)
Draws a filled rectangule on the PNMImage, using the current pen for the outline, and the current fil...