diff --git a/.gitignore b/.gitignore index be80295..1183686 100644 --- a/.gitignore +++ b/.gitignore @@ -41,3 +41,6 @@ Makefile* # QtCtreator CMake CMakeLists.txt.user* +*.db +*.bmp +release diff --git a/mainwindow.ui b/mainwindow.ui index 84fa443..d64b61a 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -2,33 +2,54 @@ MainWindow + + true + 0 0 - 649 - 560 + 800 + 600 + + + 0 + 0 + + MainWindow - - + + + 0 + 0 + + + + - + 1 1 - 500 - 500 + 200 + 200 + + ArrowCursor + + + true + QFrame::StyledPanel @@ -37,7 +58,7 @@ - + 6 @@ -128,8 +149,8 @@ 0 0 - 649 - 20 + 800 + 21 @@ -140,7 +161,11 @@ - + + + true + + &Quit diff --git a/src/viewer/simpleViewer.cpp b/src/viewer/simpleViewer.cpp index 2c15b12..3f9409a 100644 --- a/src/viewer/simpleViewer.cpp +++ b/src/viewer/simpleViewer.cpp @@ -112,8 +112,13 @@ void Viewer::mouseMoveEvent(QMouseEvent* e) { void Viewer::mousePressEvent(QMouseEvent* e) { // Auto Return, but old code left in as reference - //std::cout << "Picking shape at " << e->pos().x() << ", " << e->pos().y() << endl; - Shape* selectedShape = pickGeom(e->pos().x()+20, e->pos().y()+20); + int x = this->x() + e->x() + 10; + int y = this->parentWidget()->height() - e->y() + 21; + std::cout << "--------------------------------------------------\nPicking shape at " << x << " (" << this->x() << " + " << e->x() << "), " << y << endl; + std::cout << "Window geom: " << this->window()->size().width() << "w, " << this->window()->size().height() << "h" << endl; + Shape* selectedShape = pickGeom(x, y); + // OpenGL coords start at the window's bottom-left, not the frame's. ugh. + } void Viewer::deselect(){ @@ -159,12 +164,12 @@ void Viewer::init() initGeometries(); //initGrid(); - /*QColor* color = new QColor(255, 128, 0, 255); + /*QColor* color = new QColor(255, 128, 0, 255); Circle* c = new Circle; c->setColor(*color); SceneGroup* cell = new SceneGroup; cell->addChild(c); - root.addChild(cell);*/ + root.addChild(cell);//*/ //update(); } @@ -359,8 +364,8 @@ void Viewer::changeColor(QColor c){ Shape* Viewer::pickGeom(int x, int y){ QMap mapColorToShape; QColor c; - QRgb startColor = 0xFF000033; // alpha must be 100%, glReadPixels doesn't resturn alpha - unsigned char pixelData[3]; + QRgb startColor = 0xFFFF00ee; // alpha must be 100%, glReadPixels doesn't resturn alpha + unsigned char pixelData[3]; // Traverse tree /* TODO: Make this recurse through SceneGroups, with like "populateMap(map, root, color)" * Right now it's fine because we have simple Minecraft rules @@ -397,13 +402,28 @@ Shape* Viewer::pickGeom(int x, int y){ draw(); glPixelStorei(GL_UNPACK_ALIGNMENT, 1); - // TODO: figure out how to get this weird offset ↓↓ frae position maybe? - glReadPixels(x, camera()->screenHeight() - 1 - y + 62, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixelData); - QColor* pickedColor = new QColor(pixelData[0], pixelData[1], pixelData[2]); + + // for debugging purposes + /*QImage *im = new QImage(64, 64, QImage::Format_RGB32); + for(int i = 0; i< 64; i++){ + for(int j = 0; j< 64; j++){ + glReadPixels(x-31+i, y+31-j, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixelData); + QColor* pickedColor = new QColor(pixelData[0], pixelData[1], pixelData[2]); + if(i==32&&j==32) pickedColor->setRgba(0xFFFFFFFF); + im->setPixelColor(i, j, pickedColor->rgb()); + } + } + im->save("./screenshot.bmp");//*/ + + // TODO: figure out how to get this weird offset ↓↓ frame position maybe? + glReadPixels(x, y, 1, 1, GL_RGBA, GL_UNSIGNED_BYTE, pixelData); + QColor* pickedColor = new QColor(pixelData[0], pixelData[1], pixelData[2]); Shape* pickedShape = mapColorToShape.value(pickedColor->rgba()); - std::cout << "Picked Color: " << pickedColor->red() << " " << pickedColor->green() << " " << pickedColor->blue() << " " << pickedColor->alpha() << endl; - std::cout << "Picked Shape: " << pickedShape << endl; + std::cout << "Picked Color: " << pickedColor->red() << " " << pickedColor->green() << " " << pickedColor->blue() << " " << pickedColor->alpha() << endl; + std::cout << "Picked Shape: " << pickedShape << endl; + + //lastshader->bind(); - return pickedShape; + return pickedShape; }