Esempio n. 1
0
QGraphicsItem* CGraphicsRoundRectItem::createItem()
{
	QGraphicsPathItem* pItem = new QGraphicsPathItem(m_Parent);
	drawPen(pItem);
	drawBrush(pItem);
	QPainterPath path;
	qreal x = GET_VALUE(x).toFloat();
	qreal y = GET_VALUE(y).toFloat();
	qreal w = GET_VALUE(w).toFloat();
	qreal h = GET_VALUE(h).toFloat();
	qreal cx = GET_VALUE(cx).toFloat();
	qreal cy = GET_VALUE(cy).toFloat();

	path.addRoundedRect(x,y,w,h,cx,cy);
	pItem->setPath(path);
	return pItem;
}
Esempio n. 2
0
QGraphicsItem* CGraphicsCircleArcItem::createItem()
{
	QGraphicsPathItem* pItem = new QGraphicsPathItem(m_Parent);
	drawPen(pItem);
	drawBrush(pItem);
	QPainterPath path;
	qreal cx = GET_VALUE(cx).toFloat();
	qreal cy = GET_VALUE(cy).toFloat();
	qreal r  = GET_VALUE(r).toFloat();
	qreal a1 = GET_VALUE(a1).toFloat();
	qreal a2 = GET_VALUE(a2).toFloat();

	QRectF round(cx-r,cy-r,2*r,2*r);
	qreal  span = a2 - a1;
	path.arcTo(round,a1*16,span*16);
	pItem->setPath(path);
	return pItem;
}
Esempio n. 3
0
QGraphicsItem* CGraphicsPolygonItem::createItem()
{
	QGraphicsPolygonItem* pItem = new QGraphicsPolygonItem(m_Parent);

	drawPen(pItem);
	drawBrush(pItem);

	QPolygonF d;
	QStringList lstPath = GET_VALUE(d).split(' ');
	int iCount = lstPath.size();
	for (int j = 0; j < iCount; j++)
	{
		QStringList lstPoint = lstPath[j].split(',');
		d.append(QPointF(lstPoint[0].toDouble(), lstPoint[1].toDouble()));
		lstPoint.clear();
	}
	pItem->setPolygon(d);

	return pItem;
}
Esempio n. 4
0
int process(char *fname, int components, int z_lookup, unsigned char *startbuf, unsigned char *endbuf, int z_draw, int x_draw, int y_draw, struct graphics *gc, int mapbits, int metabits, int dump, int gps, struct color_range *colors, int xoff, int yoff) {
	int bytes = bytesfor(mapbits, metabits, components, z_lookup);
	int ret = 0;

	char fn[strlen(fname) + 1 + 5 + 1 + 5 + 1];

	struct tilecontext tc;
	tc.z = z_draw;
	tc.x = x_draw;
	tc.y = y_draw;
	tc.xoff = xoff;
	tc.yoff = yoff;

	if (components == 1) {
		sprintf(fn, "%s/1,0", fname);
	} else {
		sprintf(fn, "%s/%d,%d", fname, components, z_lookup);
	}

	int fd = open(fn, O_RDONLY);
	if (fd < 0) {
		// perror(fn);
		return ret;
	}

	struct stat st;
	if (fstat(fd, &st) < 0) {
		perror("stat");
		exit(EXIT_FAILURE);
	}

	unsigned char *map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
	if (map == MAP_FAILED) {
		perror("mmap");
		exit(EXIT_FAILURE);
	}

	gSortBytes = bytes;
	unsigned char *start = search(startbuf, map, st.st_size / bytes, bytes, bufcmp);
	unsigned char *end = search(endbuf, map, st.st_size / bytes, bytes, bufcmp);

	end += bytes; // points to the last value in range; need the one after that

	if (memcmp(start, startbuf, bytes) < 0) {
		start += bytes; // if not exact match, points to element before match
	}

	int step = 1;
	double brush = 1;
	double thick = line_thick;
	double bright1;
	if (components == 1) {
		bright1 = dot_bright;

		if (z_draw > dot_base) {
			step = 1;
			brush = exp(log(2.0) * (z_draw - dot_base));
			bright1 *= exp(log(dot_ramp) * (z_draw - dot_base));
		} else {
			step = floor(exp(log(exponent) * (dot_base - z_draw)) + .5);
			bright1 *= exp(log(dot_ramp) * (z_draw - dot_base));
			bright1 = bright1 * step / (1 << (dot_base - z_draw));
		}

		bright1 /= point_size;
		brush *= point_size;
	} else {
		bright1 = dot_bright * line_per_dot / line_thick;

		if (line_ramp >= 1) {
			thick *= exp(log(line_ramp) * (z_draw - dot_base));
			bright1 *= exp(log(dot_ramp / line_ramp) * (z_draw - dot_base));
		} else {
			bright1 *= exp(log(dot_ramp) * (z_draw - dot_base));
		}
	}

	if (mercator >= 0) {
		double lat, lon;
		tile2latlon((x_draw + .5) * (1LL << (32 - z_draw)),
			    (y_draw + .5) * (1LL << (32 - z_draw)),
			    32, &lat, &lon);
		double rat = cos(lat * M_PI / 180);

		double base = cos(mercator * M_PI / 180);
		brush /= rat * rat / (base * base);
	}

	if (dump) {
		step = 1;
	} else {
		// Align to step size so each zoom is a superset of the previous
		start = (start - map + (step * bytes - 1)) / (step * bytes) * (step * bytes) + map;
	}

	double size = cloudsize(z_draw, x_draw, y_draw);
	int innerstep = 1;
	long long todo = 0;

	size *= tilesize;                  // convert to pixels

	if (circle > 0) {
		// An additional 4 zoom levels without skipping
		// XXX Why 4?
		if (step > 1 && size > .0625) {
			innerstep = step;
			step = 1;
		}
	}

	const double b = brush * (tilesize / 256.0) * (tilesize / 256.0);

	for (; start < end; start += step * bytes) {
		unsigned int x[components], y[components];
		double xd[components], yd[components];
		int k;
		unsigned long long meta = 0;

		buf2xys(start, mapbits, metabits, z_lookup, components, x, y, &meta);

		if (meta > maxmeta) {
			continue;
		}

		if (!dump && z_draw >= mapbits / 2 - 8) {
			// Add noise below the bottom of the file resolution
			// so that it looks less gridded when overzoomed

			int j;
			for (j = 0; j < components; j++) {
				int noisebits = 32 - mapbits / 2;
				int i;

				for (i = 0; i < noisebits; i++) {
					x[j] |= ((y[j] >> (2 * noisebits - 1 - i)) & 1) << i;
					y[j] |= ((x[j] >> (2 * noisebits - 1 - i)) & 1) << i;
				}
			}
		}

		double hue = -1;
		if (metabits > 0 && colors->active) {
			hue = (((double) meta - colors->meta1) / (colors->meta2 - colors->meta1) * (colors->hue2 - colors->hue1) + colors->hue1) / 360;

			if (hue < -2) {
				hue = -1;
			} else {
				while (hue < 0) {
					hue++;
				}
				while (hue > 1) {
					hue--;
				}
			}
		}

		double bright = bright1;
		double bb = b;

		if (metabright) {
			bright *= meta;
		}
		if (metabrush) {
			bb = bb * meta;
		}

		for (k = 0; k < components; k++) {
			wxy2fxy(x[k], y[k], &xd[k], &yd[k], z_draw, x_draw, y_draw);
		}

		if (dump) {
			int should = 0;

			if (components == 1) {
				should = 1;
			} else {
				for (k = 1; k < components; k++) {
					double x1 = xd[k - 1];
					double y1 = yd[k - 1];
					double x2 = xd[k];
					double y2 = yd[k];

					if (clip(&x1, &y1, &x2, &y2, 0, 0, 1, 1)) {
						should = 1;
						break;
					}
				}
			}

			if (should) {
				dump_out(dump, x, y, components, metabits, meta);
			}
		} else if (components == 1) {
			if (!antialias) {
				xd[0] = ((int) (xd[0] * tilesize) + .5) / tilesize;
				yd[0] = ((int) (yd[0] * tilesize) + .5) / tilesize;
			}

			if (circle > 0) {
				if (size < .5) {
					if (bb <= 1) {
						drawPixel((xd[0] * tilesize - .5) + xoff, (yd[0] * tilesize - .5) + yoff, gc, bright * bb * meta / innerstep, hue, meta, &tc);
					} else {
						drawBrush((xd[0] * tilesize) + xoff, (yd[0] * tilesize) + yoff, gc, bright * meta / innerstep, bb, hue, meta, gaussian, &tc);
						ret = 1;
					}
				} else {
					double xc = (xd[0] * tilesize) + xoff;
					double yc = (yd[0] * tilesize) + yoff;

					if (xc + size >= 0 &&
					    yc + size >= 0 &&
					    xc - size <= tilesize &&
					    yc - size <= tilesize) {
						srand(x[0] * 37 + y[0]);

						for (todo += meta; todo > 0; todo -= innerstep) {
							double r = sqrt(((double) (rand() & (INT_MAX - 1))) / (INT_MAX));
							double ang = ((double) (rand() & (INT_MAX - 1))) / (INT_MAX) * 2 * M_PI;

							double xp = xc + size * r * cos(ang);
							double yp = yc + size * r * sin(ang);

							if (bb <= 1) {
								drawPixel(xp - .5, yp - .5, gc, bright * bb, hue, meta, &tc);
							} else {
								drawBrush(xp, yp, gc, bright, bb, hue, meta, gaussian, &tc);
								ret = 1;
							}
						}
					}
				}
			} else {
				if (bb <= 1) {
					drawPixel((xd[0] * tilesize - .5) + xoff, (yd[0] * tilesize - .5) + yoff, gc, bright * bb, hue, meta, &tc);
				} else {
					drawBrush((xd[0] * tilesize) + xoff, (yd[0] * tilesize) + yoff, gc, bright, bb, hue, meta, gaussian, &tc);
					ret = 1;
				}
			}
		} else {
			for (k = 1; k < components; k++) {
				double bright1 = bright;

				long long xk1 = x[k - 1];
				long long xk = x[k];

				if (gps) {
					double xdist = (long long) x[k] - (long long) x[k - 1];
					double ydist = (long long) y[k] - (long long) y[k - 1];
					double dist = sqrt(xdist * xdist + ydist * ydist);

					double min = gps_dist;
					min = min * exp(log(gps_ramp) * (gps_base - z_draw));

					if (dist > min) {
						bright1 /= (dist / min);
					}

					if (bright1 < .0025) {
						continue;
					}
				}

				double thick1 = thick * tilesize / 256.0;

				if (xk - xk1 >= (1LL << 31)) {
					wxy2fxy(xk - (1LL << 32), y[k], &xd[k], &yd[k], z_draw, x_draw, y_draw);
					drawClip(xd[k - 1] * tilesize + xoff, yd[k - 1] * tilesize + yoff, xd[k] * tilesize + xoff, yd[k] * tilesize + yoff, gc, bright1, hue, meta, antialias, thick1, &tc);

					wxy2fxy(x[k], y[k], &xd[k], &yd[k], z_draw, x_draw, y_draw);
					wxy2fxy(xk1 + (1LL << 32), y[k - 1], &xd[k - 1], &yd[k - 1], z_draw, x_draw, y_draw);
					drawClip(xd[k - 1] * tilesize + xoff, yd[k - 1] * tilesize + yoff, xd[k] * tilesize + xoff, yd[k] * tilesize + yoff, gc, bright1, hue, meta, antialias, thick1, &tc);

					wxy2fxy(x[k - 1], y[k - 1], &xd[k - 1], &yd[k - 1], z_draw, x_draw, y_draw);
				} else if (xk1 - xk >= (1LL << 31)) {
					wxy2fxy(xk1 - (1LL << 32), y[k - 1], &xd[k - 1], &yd[k - 1], z_draw, x_draw, y_draw);
					drawClip(xd[k - 1] * tilesize + xoff, yd[k - 1] * tilesize + yoff, xd[k] * tilesize + xoff, yd[k] * tilesize + yoff, gc, bright1, hue, meta, antialias, thick1, &tc);

					wxy2fxy(x[k - 1], y[k - 1], &xd[k - 1], &yd[k - 1], z_draw, x_draw, y_draw);
					wxy2fxy(xk + (1LL << 32), y[k], &xd[k], &yd[k], z_draw, x_draw, y_draw);
					drawClip(xd[k - 1] * tilesize + xoff, yd[k - 1] * tilesize + yoff, xd[k] * tilesize + xoff, yd[k] * tilesize + yoff, gc, bright1, hue, meta, antialias, thick1, &tc);

					wxy2fxy(x[k], y[k], &xd[k], &yd[k], z_draw, x_draw, y_draw);
				} else {
					drawClip(xd[k - 1] * tilesize + xoff, yd[k - 1] * tilesize + yoff, xd[k] * tilesize + xoff, yd[k] * tilesize + yoff, gc, bright1, hue, meta, antialias, thick1, &tc);
				}
			}
		}
	}
Esempio n. 5
0
int process(char *fname, int components, int z_lookup, unsigned char *startbuf, unsigned char *endbuf, int z_draw, int x_draw, int y_draw, double *image, double *cx, double *cy, int mapbits, int metabits, int dump, int gps, int colors) {
	int bytes = bytesfor(mapbits, metabits, components, z_lookup);
	int ret = 0;

	char fn[strlen(fname) + 1 + 5 + 1 + 5 + 1];

	if (components == 1) {
		sprintf(fn, "%s/1,0", fname);
	} else {
		sprintf(fn, "%s/%d,%d", fname, components, z_lookup);
	}

	int fd = open(fn, O_RDONLY);
	if (fd < 0) {
		perror(fn);
		return ret;
	}

	struct stat st;
	if (fstat(fd, &st) < 0) {
		perror("stat");
		exit(EXIT_FAILURE);
	}

	unsigned char *map = mmap(NULL, st.st_size, PROT_READ, MAP_SHARED, fd, 0);
	if (map == MAP_FAILED) {
		perror("mmap");
		exit(EXIT_FAILURE);
	}

	gSortBytes = bytes;
	unsigned char *start = search(startbuf, map, st.st_size / bytes, bytes, bufcmp);
	unsigned char *end = search(endbuf, map, st.st_size / bytes, bytes, bufcmp);

	end += bytes; // points to the last value in range; need the one after that

	if (memcmp(start, startbuf, bytes) < 0) {
		start += bytes; // if not exact match, points to element before match
	}

	int step = 1;
	double brush = 1;
	double bright1;
	if (components == 1) {
		bright1 = dot_bright;

		if (z_draw > dot_base) {
			step = 1;
			brush = 1 << (multiplier * (z_draw - dot_base));
		} else {
			step = 1 << (multiplier * (dot_base - z_draw));
		}

		bright1 *= exp(log(dot_ramp) * (z_draw - dot_base));
	} else {
		bright1 = dot_bright * line_per_dot;
		bright1 *= exp(log(dot_ramp) * (z_draw - dot_base));
	}

	if (dump) {
		step = 1;
	} else {
		// Align to step size so each zoom is a superset of the previous
		start = (start - map) / (step * bytes) * (step * bytes) + map;
	}

	for (; start < end; start += step * bytes) {
		unsigned int x[components], y[components];
		double xd[components], yd[components];
		int k;
		unsigned int meta = 0;

		buf2xys(start, mapbits, metabits, z_lookup, components, x, y, &meta);

		if (!dump && z_draw >= mapbits / 2 - 8) {
			// Add noise below the bottom of the file resolution
			// so that it looks less gridded when overzoomed

			int j;
			for (j = 0; j < components; j++) {
				int noisebits = 32 - mapbits / 2;
				int i;

				for (i = 0; i < noisebits; i++) {
					x[j] |= ((y[j] >> (2 * noisebits - 1 - i)) & 1) << i;
					y[j] |= ((x[j] >> (2 * noisebits - 1 - i)) & 1) << i;
				}
			}
		}

		double hue = -1;
		if (metabits > 0 && colors > 0) {
			hue = (double) meta / colors;
		}

		double bright = bright1;
		if (mercator >= 0) {
			double lat, lon;
			tile2latlon(x[0], y[0], 32, &lat, &lon);
			double rat = cos(lat * M_PI / 180);
			double base = cos(mercator * M_PI / 180);
			bright /= rat * rat / (base * base);
		}

		for (k = 0; k < components; k++) {
			wxy2fxy(x[k], y[k], &xd[k], &yd[k], z_draw, x_draw, y_draw);
		}

		if (dump) {
			int should = 0;

			if (components == 1) {
				should = 1;
			} else {
				for (k = 1; k < components; k++) {
					if (drawClip(xd[k - 1], yd[k - 1], xd[k], yd[k], NULL, NULL, NULL, 0, 0, 0)) {
						should = 1;
						break;
					}
				}
			}

			if (should) {
				for (k = 0; k < components; k++) {
					double lat, lon;
					tile2latlon(x[k], y[k], 32, &lat, &lon);

					printf("%lf,%lf ", lat, lon);
				}

				if (metabits != 0) {
					printf("%d:%d ", metabits, meta);
				}

				printf("// ");

				for (k = 0; k < components; k++) {
					printf("%08x %08x ", x[k], y[k]);
				}

				printf("\n");
			}
		} else if (components == 1) {
			if (!antialias) {
				xd[0] = (int) xd[0] + .5;
				yd[0] = (int) yd[0] + .5;
			}

			if (brush <= 1) {
				drawPixel(xd[0] - .5, yd[0] - .5, image, cx, cy, bright * brush, hue);
			} else {
				drawBrush(xd[0], yd[0], image, cx, cy, bright, brush, hue);
				ret = 1;
			}
		} else {
			for (k = 1; k < components; k++) {
				double bright1 = bright;

				long long xk1 = x[k - 1];
				long long xk = x[k];

				if (gps) {
					double xdist = (long long) x[k] - (long long) x[k - 1];
					double ydist = (long long) y[k] - (long long) y[k - 1];
					double dist = sqrt(xdist * xdist + ydist * ydist);

					double min = gps_dist;
					min = min * exp(log(gps_ramp) * (gps_base - z_draw));

					if (dist > min) {
						bright1 /= (dist / min);
					}

					if (bright1 < .0025) {
						continue;
					}
				}

				if (xk - xk1 >= (1LL << 31)) {
					wxy2fxy(xk - (1LL << 32), y[k], &xd[k], &yd[k], z_draw, x_draw, y_draw);
					drawClip(xd[k - 1], yd[k - 1], xd[k], yd[k], image, cx, cy, bright1, hue, antialias);

					wxy2fxy(x[k], y[k], &xd[k], &yd[k], z_draw, x_draw, y_draw);
					wxy2fxy(xk1 + (1LL << 32), y[k - 1], &xd[k - 1], &yd[k - 1], z_draw, x_draw, y_draw);
					drawClip(xd[k - 1], yd[k - 1], xd[k], yd[k], image, cx, cy, bright1, hue, antialias);

					wxy2fxy(x[k - 1], y[k - 1], &xd[k - 1], &yd[k - 1], z_draw, x_draw, y_draw);
				} else if (xk1 - xk >= (1LL << 31)) {
					wxy2fxy(xk1 - (1LL << 32), y[k - 1], &xd[k - 1], &yd[k - 1], z_draw, x_draw, y_draw);
					drawClip(xd[k - 1], yd[k - 1], xd[k], yd[k], image, cx, cy, bright1, hue, antialias);

					wxy2fxy(x[k - 1], y[k - 1], &xd[k - 1], &yd[k - 1], z_draw, x_draw, y_draw);
					wxy2fxy(xk + (1LL << 32), y[k], &xd[k], &yd[k], z_draw, x_draw, y_draw);
					drawClip(xd[k - 1], yd[k - 1], xd[k], yd[k], image, cx, cy, bright1, hue, antialias);

					wxy2fxy(x[k], y[k], &xd[k], &yd[k], z_draw, x_draw, y_draw);
				} else {
					drawClip(xd[k - 1], yd[k - 1], xd[k], yd[k], image, cx, cy, bright1, hue, antialias);
				}
			}
		}
	}
Esempio n. 6
0
void ProxyViz::draw( M3dView & view, const MDagPath & path, 
							 M3dView::DisplayStyle style,
							 M3dView::DisplayStatus status )
{
	if(!m_enableCompute) return;
	MObject thisNode = thisMObject();
	updateWorldSpace(thisNode);
	
	MPlug mutxplug( thisNode, axmultiplier);
	MPlug mutyplug( thisNode, aymultiplier);
	MPlug mutzplug( thisNode, azmultiplier);
	setScaleMuliplier(mutxplug.asFloat(), 
						mutyplug.asFloat(),
						mutzplug.asFloat() );	
                        
    MPlug svtPlug(thisNode, adisplayVox);
    setShowVoxLodThresold(svtPlug.asFloat() );
	
	MDagPath cameraPath;
	view.getCamera(cameraPath);
	if(hasView() ) updateViewFrustum(thisNode);
	else updateViewFrustum(cameraPath);
	
	setViewportAspect(view.portWidth(), view.portHeight() );
	
	MPlug actp(thisNode, aactivated);
	if(actp.asBool()) setWireColor(.125f, .1925f, .1725f);
    else setWireColor(.0675f, .0675f, .0675f);

	_viewport = view;
	fHasView = 1;
	
	view.beginGL();
	
	double mm[16];
	matrix_as_array(_worldInverseSpace, mm);
	
	glPushMatrix();
	glMultMatrixd(mm);	
	
	ExampVox * defBox = plantExample(0);
	updateGeomBox(defBox, thisNode);
	drawWireBox(defBox->geomCenterV(), defBox->geomScale() );
	Matrix44F mat;
	mat.setFrontOrientation(Vector3F::YAxis);
	mat.scaleBy(defBox->geomSize() );
    mat.glMatrix(m_transBuf);
	
	drawCircle(m_transBuf);
	
	drawGridBounding();
	// drawGrid();

	if ( style == M3dView::kFlatShaded || 
		    style == M3dView::kGouraudShaded ) {		
		drawPlants();
	}
	else 
		drawWiredPlants();
	
    if(hasView() ) drawViewFrustum();
    
	drawBrush(view);
	drawActivePlants();
	drawGround();
	glPopMatrix();
	view.endGL();
	std::cout<<" viz node draw end";
}
Esempio n. 7
0
void Paint::loop()
{
	sf::Event e;
	int t[2];
	t[0] = t[1] = -1;
	drawBrush(_App, _colors);
	while (1)
	{
		if (_App->GetEvent(e))
		{
			if (e.Type == sf::Event::MouseButtonPressed || _pressed == true)
			{
				const sf::Input &input = _App->GetInput();
				int x = input.GetMouseX();
				int y = input.GetMouseY();
				
				if (y > 100)
				{
					if (_type == PAINT)
						_App->Draw(sf::Sprite(sf::Image(5, 5, _currentColor), sf::Vector2f(x, y)));
					else if ((_type == CARRE || _type == CERCLE) && _pressed == false)
					{
						t[0] = x;
						t[1] = y;					
					}
					_pressed = true;
				}
				else
				{
					if (x >= 220 && x <= 333)
					{
						if (y >= 10 && y <= 65)
						{
							_type = CARRE;
						}
					}
					else if (x >= 350 && 429)
					{
						if (y >= 10 && y <= 65)
							_type = CERCLE;
					}
						else
						_currentColor = checkColor(x, y, _colors, _currentColor, _App);
					_pressed = false;
				}
			}
			if (e.Type == sf::Event::MouseButtonReleased)
			{
				
				if ((_type == CARRE || _type == CERCLE) && _pressed == true)
				{
				const sf::Input &input = _App->GetInput();
				int x = input.GetMouseX();
				int y = input.GetMouseY();
				if (_type == CARRE)
				{
						sf::Shape p(sf::Shape::Rectangle(t[0], t[1], x, y, _currentColor));
						_App->Draw(p);
				}
				else
				{
					int r = ABS((t[1] - y));
					if (t[1] - r > 100)
					{
						sf::Shape p(sf::Shape::Circle(t[0], t[1], (t[1] - y), _currentColor));
						_App->Draw(p);
					}
				}
					t[0] = t[1] = -1;
					_type = PAINT;
				}
				_pressed = false;
			}
		}
		
		_App->Display();
	}

	
}
Esempio n. 8
0
	void CGDIPracticeView::OnDraw(CDC* pDC)
	{
		CClientDC dc(this);			//Client DC를 얻는다.

		// Client Rect를 얻는다.
		CRect rClientRect;
		GetClientRect(&rClientRect);

		// Bitmap 생성
		Bitmap mBitmap(rClientRect.Width(), rClientRect.Height());

		// Graphics를 얻는다.
		Graphics graphics(dc);

		// 비트맵을 메모리 내에서 그릴 그래픽 생성
		Graphics memGraphics(&mBitmap);

		// 화면을 흰색 바탕으로 그리기 위한 브러쉬
		SolidBrush drawBrush(Color(255,255,255));

		// 검은색 컬러 지정
		Color drawColor(255,0,0,0);

		// 팬 생성
		Pen drawPen(drawColor, 1);
		drawPen.SetStartCap(LineCapRound);
		drawPen.SetEndCap(LineCapRound);

		// bitmap을 흰색으로 칠한다(line같은 경우 이미지가 남기 때문에)
		memGraphics.FillRectangle(&drawBrush, 0,0,rClientRect.Width(), rClientRect.Height());

		int componentSize = m_components.GetSize();
		CString str;
		str.Format(_T("size : %d\n"), componentSize);
		TRACE(str);
		for (int i = 0; i < componentSize; i++)
		{
			// 컴포넌트의 팬 설정
			drawColor.SetFromCOLORREF(m_components.GetAt(i)->m_colorPen);
			drawPen.SetColor(drawColor);
			drawPen.SetWidth((float)m_components.GetAt(i)->m_nPenSize);

			// 얕은 복사
			CDrawComponent *component = m_components.GetAt(i);

			switch (component->m_nDrawMode)
			{
				// 지우개인 경우
			case DRAW_NONE:
				{
					// 팬의 브러쉬 색을 흰색으로 변경
					drawBrush.SetColor(drawColor);

					// 지우개를 사용한 좌표를 순차적으로 다시 그린다.
					int pointSize = component->m_points.GetSize();
					for (int j = 0; j < pointSize; j++)
					{
						// 흰색의 지우개 사각형을 그린다. 
						memGraphics.FillRectangle(&drawBrush, component->m_points.GetAt(j).X, component->m_points.GetAt(j).Y,
							component->m_nEraserSize * 2, component->m_nEraserSize * 2);
					}
					break;
				}
			case LINE_MODE:
				memGraphics.DrawLine(&drawPen, component->m_ptStart.x, component->m_ptStart.y,
					component->m_ptEnd.x, component->m_ptEnd.y);
				break;
			case RECT_MODE:
			{
				// 우측 아래
				if(component->m_ptStart.x < component->m_ptEnd.x && component->m_ptStart.y < component->m_ptEnd.y)
					memGraphics.DrawRectangle(&drawPen, component->m_ptStart.x, component->m_ptStart.y,
					component->m_ptEnd.x - component->m_ptStart.x, component->m_ptEnd.y - component->m_ptStart.y);
				// 우측 위
				else if(component->m_ptStart.x < component->m_ptEnd.x && component->m_ptStart.y > component->m_ptEnd.y)
					memGraphics.DrawRectangle(&drawPen, component->m_ptStart.x, component->m_ptEnd.y,
					component->m_ptEnd.x - component->m_ptStart.x, component->m_ptStart.y - component->m_ptEnd.y);
				// 좌측 아래
				else if(component->m_ptStart.x > component->m_ptEnd.x && component->m_ptStart.y < component->m_ptEnd.y)
					memGraphics.DrawRectangle(&drawPen, component->m_ptEnd.x, component->m_ptStart.y,
					component->m_ptStart.x - component->m_ptEnd.x, component->m_ptEnd.y - component->m_ptStart.y);
				// 좌측 위
				else
					memGraphics.DrawRectangle(&drawPen, component->m_ptEnd.x, component->m_ptEnd.y,
					component->m_ptStart.x - component->m_ptEnd.x, component->m_ptStart.y - component->m_ptEnd.y);

				break;
			}
			case CIRCLE_MODE:
				memGraphics.DrawEllipse(&drawPen, component->m_ptStart.x, component->m_ptStart.y,
					component->m_ptEnd.x - component->m_ptStart.x, component->m_ptEnd.y - component->m_ptStart.y);
				break;
			case FREE_MODE:
				if (component->m_points.GetSize() > 1)
				{
					// 자유선의 작은 선들을을 순차적으로 하나씩 그린다.
					int pointSize = component->m_points.GetSize();
					for (int j = 1; j < pointSize; j++)
						memGraphics.DrawLine(&drawPen, component->m_points.GetAt(j - 1).X, component->m_points.GetAt(j - 1).Y,
						component->m_points.GetAt(j).X, component->m_points.GetAt(j).Y);
				}
				break;
			case POLY_MODE:
			{
				int pointSize = component->m_points.GetSize();
				for (int j = 1; j < pointSize; j++)
					memGraphics.DrawLine(&drawPen, component->m_points.GetAt(j-1).X, component->m_points.GetAt(j-1).Y,
					component->m_points.GetAt(j).X, component->m_points.GetAt(j).Y);

				// 처음 점과 마지막점을 이어준다.
				memGraphics.DrawLine(&drawPen, component->m_points.GetAt(component->m_points.GetSize() - 1).X,
					component->m_points.GetAt(component->m_points.GetSize() - 1).Y,
					component->m_points.GetAt(0).X, component->m_points.GetAt(0).Y);

				break;
			}
			default:
				break;
			}
		}

		//현재 그리고 있는 것

		drawColor.SetFromCOLORREF(m_colorPen);
		drawPen.SetColor(drawColor);
		drawPen.SetWidth(m_nPenSize);

		// 왼쪽 버튼 클릭시 || 지우개인경우 | 다각형인 경우(삭제)
		if (m_nDrawMode == DRAW_NONE || m_nDrawMode == POLY_MODE || m_bLButtonDown)
		{
			switch (m_nDrawMode)
			{
			case DRAW_NONE:
				{
					// 브러쉬 흰색 설정
					drawColor.SetFromCOLORREF(RGB(255, 255, 255));
					drawBrush.SetColor(drawColor);
					// 팬 컬러 검정색 설정
					drawColor.SetFromCOLORREF(RGB(0, 0, 0));
					drawPen.SetColor(drawColor);
					drawPen.SetWidth(1);

					int pointSize = m_points.GetSize()-1;
					for (int i = 0; i < pointSize; i++)
					{
						memGraphics.FillRectangle(&drawBrush, m_points.GetAt(i).X, m_points.GetAt(i).Y,
							m_nEraserSize * 2, m_nEraserSize * 2);
					}
					memGraphics.FillRectangle(&drawBrush, m_points.GetAt(m_points.GetSize() - 1).X, m_points.GetAt(m_points.GetSize() - 1).Y,
						m_nEraserSize * 2, m_nEraserSize * 2);
					memGraphics.DrawRectangle(&drawPen, m_points.GetAt(m_points.GetSize() - 1).X, m_points.GetAt(m_points.GetSize() - 1).Y,
						m_nEraserSize * 2, m_nEraserSize * 2);

					break;
				}
			case LINE_MODE:
				memGraphics.DrawLine(&drawPen, m_ptPrev.x, m_ptPrev.y,
					m_ptDrawing.x, m_ptDrawing.y);
				break;
			case RECT_MODE:
			{
				memGraphics.DrawRectangle(&drawPen, m_ptPrev.x, m_ptPrev.y,
					m_ptDrawing.x - m_ptPrev.x, m_ptDrawing.y - m_ptPrev.y);

				// 우측 아래
				if(m_ptPrev.x < m_ptDrawing.x && m_ptPrev.y < m_ptDrawing.y)
					memGraphics.DrawRectangle(&drawPen, m_ptPrev.x, m_ptPrev.y,
					m_ptDrawing.x - m_ptPrev.x, m_ptDrawing.y - m_ptPrev.y);
				// 우측 위
				else if(m_ptPrev.x < m_ptDrawing.x && m_ptPrev.y > m_ptDrawing.y)
					memGraphics.DrawRectangle(&drawPen, m_ptPrev.x, m_ptDrawing.y,
					m_ptDrawing.x - m_ptPrev.x, m_ptPrev.y - m_ptDrawing.y);
				// 좌측 아래
				else if(m_ptPrev.x > m_ptDrawing.x && m_ptPrev.y < m_ptDrawing.y)
					memGraphics.DrawRectangle(&drawPen, m_ptDrawing.x, m_ptPrev.y,
					m_ptPrev.x - m_ptDrawing.x, m_ptDrawing.y - m_ptPrev.y);
				// 좌측 위
				else
					memGraphics.DrawRectangle(&drawPen, m_ptDrawing.x, m_ptDrawing.y,
					m_ptPrev.x - m_ptDrawing.x, m_ptPrev.y - m_ptDrawing.y);

				break;
			}
			case CIRCLE_MODE:
				memGraphics.DrawEllipse(&drawPen, m_ptPrev.x, m_ptPrev.y,
					m_ptDrawing.x - m_ptPrev.x, m_ptDrawing.y - m_ptPrev.y);
				break;
			case FREE_MODE:
				if (m_points.GetSize() > 1)
				{
					for (int i = 1; i < m_points.GetSize(); i++)
						memGraphics.DrawLine(&drawPen, m_points.GetAt(i - 1).X, m_points.GetAt(i - 1).Y,
						m_points.GetAt(i).X, m_points.GetAt(i).Y);
				}
				break;
			case POLY_MODE:
				if (m_points.GetSize() > 1)
				{
					for (int i = 1; i < m_points.GetSize(); i++)
						memGraphics.DrawLine(&drawPen, m_points.GetAt(i-1).X, m_points.GetAt(i-1).Y,
						m_points.GetAt(i).X, m_points.GetAt(i).Y);

					// 처음 점과 마지막점을 이어준다.
					memGraphics.DrawLine(&drawPen, m_points.GetAt(m_points.GetSize() - 1).X, m_points.GetAt(m_points.GetSize() - 1).Y,
						m_ptDrawing.x, m_ptDrawing.y);
				}
				else if (m_points.GetSize() == 1)
					memGraphics.DrawLine(&drawPen, m_points.GetAt(0).X, m_points.GetAt(0).Y, m_ptDrawing.x, m_ptDrawing.y);
				break;
			default:
				break;
			}
		}
		graphics.DrawImage(&mBitmap, 0, 0);
	}
void VoxelEditor::handleClick(){
	glm::vec3 tempV = _currentIntersect;
	Voxel *tempVox = _voxelGrid->getVoxel((int)tempV.x, (int)tempV.y, (int)tempV.z);

	printf("Intersect at <%f,%f,%f>\n", (float)tempV.x, (float)tempV.y, (float)tempV.z);

	switch (_state) {
	case 's':
		if (_currentIntersect.y < 0) {
			tempV -= (_clickDirection * _step);
			tempVox = _voxelGrid->getVoxel((int)tempV.x, (int)tempV.y, (int)tempV.z);
			if (tempVox != NULL) {
				if (!_selectedFirstBlock) {
					_selectedFirstBlock = true;
					_selectedX1 = (int)tempV.x;
					_selectedY1 = (int)tempV.y;
					_selectedZ1 = (int)tempV.z;
					std::cout << "X1: " << _selectedX1 << " Y1: " << _selectedY1 << " Z1: " << _selectedZ1 << std::endl;
				}
				else if (!_selectedSecondBlock) {
					_selectedSecondBlock = true;
					_selectedX2 = (int)tempV.x;
					_selectedY2 = (int)tempV.y;
					_selectedZ2 = (int)tempV.z;
					std::cout << "X2: " << _selectedX2 << " Y2: " << _selectedY2 << " Z2: " << _selectedZ2 << std::endl;
				}
				else {
					_selectedFirstBlock = false;
					_selectedSecondBlock = false;
					std::cout << "Removed selected volume" << std::endl;
				}
			}
		}
		else if (tempVox != NULL) {
			if (tempVox->type != '\0') {
				//tempV = _clickDirection * (i - _step) + _clickStart;
				tempVox = _voxelGrid->getVoxel((int)tempV.x, (int)tempV.y, (int)tempV.z);
				if (tempVox != NULL) {
					if (!_selectedFirstBlock) {
						_selectedFirstBlock = true;
						_selectedX1 = (int)tempV.x;
						_selectedY1 = (int)tempV.y;
						_selectedZ1 = (int)tempV.z;
						std::cout << "X1: " << _selectedX1 << " Y1: " << _selectedY1 << " Z1: " << _selectedZ1 << std::endl;
					}
					else if (!_selectedSecondBlock) {
						_selectedSecondBlock = true;
						_selectedX2 = (int)tempV.x;
						_selectedY2 = (int)tempV.y;
						_selectedZ2 = (int)tempV.z;
						std::cout << "X2: " << _selectedX2 << " Y2: " << _selectedY2 << " Z2: " << _selectedZ2 << std::endl;
					}
					else {
						_selectedFirstBlock = false;
						_selectedSecondBlock = false;
						std::cout << "Removed selected volume" << std::endl;
					}
				}
			}
		}
		break;
	case 'i':
		if (tempV.y < 0){
			tempV -= (_clickDirection * _step);
			tempVox = _voxelGrid->getVoxel((int)tempV.x, (int)tempV.y, (int)tempV.z);
			if (tempVox != NULL){
				if (_currentBrush != NULL)
					drawBrush();
				else
					addVoxel((int)tempV.x, (int)tempV.y, (int)tempV.z);
			}
		}
		else if (tempVox != NULL){
			if (tempVox->type != '\0'){
				tempV -= (_clickDirection * _step); 
				tempVox = _voxelGrid->getVoxel((int)tempV.x, (int)tempV.y, (int)tempV.z);
				if (tempVox != NULL){
					if (tempVox->type == '\0'){
						glm::vec3 apos = tempV;
					}
					if (_currentBrush != NULL)
						drawBrush();
					else
						addVoxel((int)tempV.x, (int)tempV.y, (int)tempV.z);
				}
			}
		}
		break;
	case 'r':
		if (tempVox != NULL){
			if (tempVox->type != '\0'){
				removeVoxel((int)tempV.x, (int)tempV.y, (int)tempV.z);
			}
		}
		break;
	}
}