예제 #1
0
/* Depending on how you approach your problem decomposition, you
 * may want to rewrite some of these lines, move them inside loops,
 * or move them inside helper functions, etc.
 *
 * TODO: rewrite this comment.
 */
int main() {
    GWindow gw;
    gw.setTitle("Fauxtoshop");
    gw.setVisible(true);

    cout << "Welcome to Fauxtoshop!" << endl;


    cout << "Enter name of image file to open (or blank to quiet): ";

    string img_name;
    getline(cin, img_name);

    cout << "Opening image file, may take a minute..." << endl;

    GBufferedImage img;
    while (!openImageFromFilename(img, img_name))
    {
        cout << "Can't open the file, please enter again: ";
        getline(cin, img_name);
    }

    gw.setSize(img.getWidth(), img.getHeight());
    gw.add(&img,0,0);

    string menu = "Which image filter would you like to apply?\n"
                  "         1 - Scatter\n"
                  "         2 - Edge detection\n"
                  "         3 - \"Green screen\" with another image\n"
                  "         4 - Compare image with another image";
    cout << menu << endl;

    string choice_str = "Your choice: ";
    int choice = getInteger(choice_str, choice_str);

    switch(choice)
    {
        case 1:
            scatter(img);
            break;
        case 2:
            edge_detection(img);
            break;
        case 3:
            green_screen(img);
            break;
    }


    int row, col;
    getMouseClickLocation(row, col);
    return 0;
}
예제 #2
0
void radioButtonTest() {
    GWindow gw;
    gw.setTitle("Radio Button Test");
    GRadioButton* rb1 = new GRadioButton("Red");
    GRadioButton* rb2 = new GRadioButton("Green", "", true);
    GRadioButton* rb3 = new GRadioButton("Blue");
    gw.addToRegion(rb1, "SOUTH");
    gw.addToRegion(rb2, "SOUTH");
    gw.addToRegion(rb3, "SOUTH");

    // a second group of buttons
    GRadioButton* rb4 = new GRadioButton("Black", "N", true);
    GRadioButton* rb5 = new GRadioButton("White", "N");
    gw.addToRegion(rb4, "NORTH");
    gw.addToRegion(rb5, "NORTH");
    
    gw.setVisible(true);
}
예제 #3
0
/* Depending on how you approach your problem decomposition, you
 * may want to rewrite some of these lines, move them inside loops,
 * or move them inside helper functions, etc.
 *
 * TODO: rewrite this comment.
 */
int main() {
    GWindow gw;
    gw.setTitle("Fauxtoshop");
    gw.setVisible(true);
    GBufferedImage img;
    while (true) {
        ifstream infile;
        cout << "Welcome to Fauxtoshop!" << endl;
        string prompt = "Enter the name of image file to open (or blank to quit):";
        string filename= openFile(infile, prompt, img);
        if (filename == "") break;
        gw.setSize(img.getWidth(), img.getHeight());
        gw.add(&img,0,0);
        int choice = chooseFilter();
        dealWithImage(img, choice);
        saveImage(img);
    }


    /*int row, col;
    getMouseClickLocation(row, col);*/
    return 0;
}
예제 #4
0
void gbufferedImageTest() {
    GWindow gw;
    gw.setSize(900, 700);
    gw.setTitle("Test");

    GButton* button1 = new GButton("Click Me 1");
    gw.add(button1, 250, 80);
    //GButton* button2 = new GButton("Click Me 2");
    //gw.addToRegion(button2, "NORTH");

    GLabel* label = new GLabel("test!");
    gw.add(label, 10, 60);
    
    std::cout << "About to construct GBufferedImage." << std::endl;
    GBufferedImage* img = new GBufferedImage(10, 80, 200, 250);
    std::cout << "Done constructing GBufferedImage." << std::endl;
    gw.add(img, 50, 50);
    // gw.addToRegion(img, "SOUTH");
    gw.setVisible(true);
    
//    GBufferedImage* img2 = new GBufferedImage(20, 20);
//    img2->fill(GBufferedImage::createRgbPixel(255, 0, 255));
//    Grid<int> grid = img2->toGrid();
//    cout << "grid of pixels before: " << grid << endl;
//    for (int y = 4; y <= 18; y++) {
//        for (int x = 2; x <= 9; x++) {
//            grid[y][x] = GBufferedImage::createRgbPixel(0, 255, 0);
//        }
//    }
//    cout << "grid of pixels after: " << grid << endl;
//    img2->fromGrid(grid);
//    gw.add(img2, 350, 20);
    
    GBufferedImage* img3 = new GBufferedImage();
    img3->load("rainbow.png");
    cout << "adding the image!" << endl;
    gw.add(img3, 10, 20);
    // pause(2000);
    
    cout << "start toGrid" << endl;
    Grid<int> grid3 = img3->toGrid();
    cout << "end toGrid, start rgb shit" << endl;
    for (int y = 0; y < grid3.height(); y++) {
        for (int x = 0; x < grid3.width(); x++) {
            int red, green, blue;
            GBufferedImage::getRedGreenBlue(grid3[y][x], red, green, blue);
            grid3[y][x] = GBufferedImage::createRgbPixel(green, red, blue);
        }
    }
    cout << "end rgb shit, start fromGrid" << endl;
    img3->fromGrid(grid3);
    cout << "end fromGrid" << endl;
    
    pause(2000);
    return;

    // fill
    img->fill(0xff00ff);  // purple

    std::cout << "About to setRGB on GBufferedImage." << std::endl;
    for (int y = 2; y < img->getHeight() - 2; y++) {
        for (int x = 5; x <= img->getWidth() - 5; x++) {
            img->setRGB(x, y, 0xffcc33);
        }
    }
    std::cout << "Done setting RGB on GBufferedImage." << std::endl;
    border(img);
    pause(500);
    
    std::cout << "About to resize on GBufferedImage." << std::endl;
    img->resize(100, 50);
    border(img);
    pause(500);
    
    std::cout << "About to resize on GBufferedImage." << std::endl;
    img->resize(200, 80);
    border(img);
    pause(500);
    
    std::cout << "About to setRGB on GBufferedImage." << std::endl;
    for (int y = 10; y < img->getHeight() - 10; y++) {
        for (int x = 10; x <= img->getWidth() - 10; x++) {
            img->setRGB(x, y, 0xff33cc);
        }
    }
    border(img);
    
    std::cout << "About to remove other shit." << std::endl;
    pause(200);
    gw.remove(label);
    gw.remove(button1);
    //gw.removeFromRegion(button2, "NORTH");
    pause(200);
    
    std::cout << "About to remove GBufferedImage." << std::endl;
    pause(200);
    gw.remove(img);
    // gw.removeFromRegion(img, "SOUTH");
    pause(200);
    std::cout << "Test complete." << std::endl;
    std::cout << std::endl;
}
예제 #5
0
void gtableTest() {
    GWindow gw;
    gw.setTitle("GTable Test");
    
    GTable* table = new GTable(5, 3);
    // table->setColor("#0000cc");
    // table->setFont("Monospaced-Bold-20");
    // table->setHorizontalAlignment(GTable::Alignment::RIGHT);
    table->select(0, 1);
    gw.addToRegion(table, "NORTH");
    
//    GTable* table2 = new GTable(4, 2, 0, 0, 100, 400);
//    gw.addToRegion(table2, "EAST");
    
    GButton* buttget = new GButton("Get All");
    gw.addToRegion(buttget, "SOUTH");
    
    GButton* buttset = new GButton("Set All");
    gw.addToRegion(buttset, "SOUTH");
    
    GButton* buttclear = new GButton("Clear");
    gw.addToRegion(buttclear, "SOUTH");
    
    GButton* buttrowadd = new GButton("+R");
    gw.addToRegion(buttrowadd, "SOUTH");
    
    GButton* buttrowrem = new GButton("-R");
    gw.addToRegion(buttrowrem, "SOUTH");
    
    GButton* buttcoladd = new GButton("+C");
    gw.addToRegion(buttcoladd, "SOUTH");
    
    GButton* buttcolrem = new GButton("-C");
    gw.addToRegion(buttcolrem, "SOUTH");
    
    GButton* buttwidthadd = new GButton("+W");
    gw.addToRegion(buttwidthadd, "SOUTH");
    
    GButton* buttwidthrem = new GButton("-W");
    gw.addToRegion(buttwidthrem, "SOUTH");
    
    gw.setVisible(true);
    
    while (true) {
        GEvent event = waitForEvent(ACTION_EVENT | TABLE_EVENT | WINDOW_EVENT);
        if (event.getEventClass() == ACTION_EVENT) {
            GActionEvent actionEvent(event);
            if (actionEvent.getSource() == buttget) {
                for (int row = 0; row < table->numRows(); row++) {
                    for (int col = 0; col < table->numCols(); col++) {
                        cout << "R" << row << "C" << col << "=\"" << table->get(row, col) << "\" ";
                    }
                    cout << endl;
                }
                int row, col;
                table->getSelectedCell(row, col);
                cout << "selected: R" << row << "C" << col << endl;
            } else if (actionEvent.getSource() == buttset) {
                for (int row = 0; row < table->numRows(); row++) {
                    for (int col = 0; col < table->numCols(); col++) {
                        std::string value = "R" + integerToString(row) + "C" + integerToString(col);
                        table->set(row, col, value);
                    }
                }
                table->select(1, 2);
            } else if (actionEvent.getSource() == buttclear) {
                table->clear();
            } else if (actionEvent.getSource() == buttrowadd) {
                table->resize(table->numRows() + 1, table->numCols());
            } else if (actionEvent.getSource() == buttrowrem) {
                table->resize(table->numRows() - 1, table->numCols());
            } else if (actionEvent.getSource() == buttcoladd) {
                table->resize(table->numRows(), table->numCols() + 1);
            } else if (actionEvent.getSource() == buttcolrem) {
                table->resize(table->numRows(), table->numCols() - 1);
            } else if (actionEvent.getSource() == buttwidthadd) {
                table->setColumnWidth(1, table->getColumnWidth(1) + 20);
            } else if (actionEvent.getSource() == buttwidthrem) {
                table->setColumnWidth(1, table->getColumnWidth(1) - 20);
            }
        } else if (event.getEventClass() == WINDOW_EVENT) {
            if (event.getEventType() == WINDOW_CLOSED) {
                break;
            }
        } else if (event.getEventClass() == TABLE_EVENT) {
            GTableEvent tableEvent(event);
            std::cout << "cell updated: " << tableEvent.toString() << std::endl;
        }
    }
}