Exemplo n.º 1
0
    /*
     * Labels player word list with specified name and draws a line underneath.
     * Also sets up the score label for the specified player.
     */
    static void setupPlayerLabels(Player player, string name) {
        gwp->setColor(LABEL_COLOR);
        gwp->drawLine(gState.scoreBox[player].x, gState.scoreBox[player].y,
                      gState.scoreBox[player].x + gState.scoreBox[player].w,
                      gState.scoreBox[player].y);
        GLabel* lab = new GLabel(name);
        lab->setFont(SCORE_FONT + "-" + integerToString(SCORE_FONT_SIZE));
        gwp->add(lab, gState.scoreBox[player].x, gState.scoreBox[player].y + LABEL_DY);

        GLabel** scoreLabel = player == COMPUTER ? &computerScoreLabel : &humanScoreLabel;
        *scoreLabel = new GLabel("0");
        (*scoreLabel)->setFont(SCORE_FONT + "-" + integerToString(SCORE_FONT_SIZE));
        (*scoreLabel)->setColor(LABEL_COLOR);
        int offset = 32;
        gwp->add(*scoreLabel, gState.scoreBox[player].x + gState.scoreBox[player].w - offset,
                 gState.scoreBox[player].y + LABEL_DY);
    }
Exemplo n.º 2
0
void drawGraph(Vector<pair<string, int> > operands, pair<double, double> scope, int scale, string formula) {
    GWindow graphicsWindow(800, 600);
    graphicsWindow.setColor("BLACK");
    pair<double, double> center = drawCoordinateSystem(graphicsWindow, scale);
    GLabel* formulaMark = new GLabel("y = " + formula, 20, 30);
    formulaMark->setFont("Courier New");
    graphicsWindow.add(formulaMark);
    graphicsWindow.setColor("RED");
    double prewX = scope.first;
    double prewY = calculateFunction(operands, prewX);
    for (double x = scope.first + 0.01; x <= scope.second; x += 0.01) {
        double y = calculateFunction(operands, x);
        graphicsWindow.drawLine(center.first + prewX * scale, center.second - prewY * scale,
                                center.first + x * scale, center.second - y * scale);
        prewX = x;
        prewY = y;
    }
}
Exemplo n.º 3
0
 void recordWord(string word, Player player) {
     ensureInitialized();
     if (player != HUMAN && player != COMPUTER) {
         error("recordWord called with invalid player argument.");
     }
     word = toLowerCase(trim(word));
     GLabel* label = new GLabel(word);
     label->setFont(WORD_FONT + "-" + integerToString(WORD_FONT_SIZE));
     label->setColor(WORD_COLOR);
     int wordCountInRow = int(gState.scoreBox[player].w/gState.wordColumnWidth);
     int row = gState.wordCount[player] / wordCountInRow;
     int col = gState.wordCount[player] % wordCountInRow;
     gState.wordCount[player]++;
     gwp->add(label, gState.scoreBox[player].x + col * gState.wordColumnWidth,
                   gState.scoreBox[player].y + (row + 1) * WORD_FONT_SIZE + WORD_DY);
     if (col == wordCountInRow - 1) {
         gwp->repaint();
     }
     recordedWordLabels.add(label);
 }
Exemplo n.º 4
0
    void labelCube(int row, int col, char letter, bool highlighted) {
        ensureInitialized();
        if (row < 0 || row >= gState.rowCount || col < 0 || col >= gState.columnCount) {
            error(string("labelCube called with invalid row, col arguments.  Must be between (0, 0) and (")
                  + integerToString(gState.rowCount) + ", " + integerToString(gState.columnCount) + ")");
        }
        if (!isalpha(letter) && letter != ' ') {
            error(string("labelCube called with non-alphabetic character: '") + letter);
        }

        setHighlighted(row, col, highlighted);

        GLabel* label = letterCubes[row][col].label;
        label->setLabel(string(1, letter));
        if (isalpha(letter)) {
            label->setLocation(
                    letterCubes[row][col].rect->getX() + gState.cubeSize/2 - 0.45 * label->getWidth(),
                    letterCubes[row][col].rect->getY() + gState.cubeSize/2 + 0.36 * gState.fontSize);
        }
    }
Exemplo n.º 5
0
    /*
     * Creates all cubes in position, including a blank letter centered in
     * the middle of each cube.  Initially the cubes are not highlighted.
     */
    static void setupLetterCubes() {
        double lineWidth = 2;
        double cubeSize = gState.cubeSize - lineWidth;
        double cubeY = gState.board.y + BOARD_BORDER/2;
        for (int row = 0; row < gState.rowCount; row++) {
            double cubeX = gState.board.x + BOARD_BORDER/2;
            for (int col = 0; col < gState.columnCount; col++) {
                // display the letter cubes as rounded rectangles
                double cubeRoundRadius = gState.cubeSize/5;
                GRoundRect* rect = new GRoundRect(cubeX, cubeY, cubeSize,
                                                  cubeSize, cubeRoundRadius * 2);
                rect->setLineWidth(lineWidth);
                rect->setColor("Black");
                rect->setFilled(true);
                rect->setFillColor(DIE_COLOR);
                gwp->add(rect);
                letterCubes[row][col].rect = rect;

                // draw the letter on the cube
                GLabel* label = new GLabel("M");   // start as "M" for getWidth
                label->setFont(CUBE_FONT + "-" + integerToString(int(gState.fontSize)));
                label->setColor(LETTER_COLOR);
                label->setLocation(cubeX + gState.cubeSize/2 - label->getWidth()/2,
                                   cubeY + gState.cubeSize/2 + 0.4 * gState.fontSize);
                label->setLabel(" ");
                gwp->add(label);
                letterCubes[row][col].label = label;
                cubeX += (int) cubeSize + lineWidth;
            }
            cubeY += (int) cubeSize + lineWidth;
        }
    }
void testQwindow() {
    static GWindow* window = new GWindow(900, 300);
    window->setTitle("QtGui Window");
    window->setResizable(true);
    window->setExitOnClose(true);
    window->center();

//    window->setColor("red");
//    window->fillRect(0, 0, 900, 300);

    // NORTH AREA

    GLabel* label = new GLabel("Type <b>stuff</b> <i>now</i> (North):");
    // label->setIcon("triangle-icon.png");
    label->setColor(GColor::GREEN);
    // label->setBackground(GColor::YELLOW);
    label->setActionListener([=]() {
        std::cout << "label clicked!" << std::endl;
        label->setBackground(label->getBackground() == "cyan" ? "yellow" : "cyan");
    });
    label->setDoubleClickListener(GEvent::LOG_EVENT);
    window->addToRegion(label, GWindow::REGION_NORTH);
    cout << "label:     " << label->toString() << endl;

    //        static GTextField* textField = new GTextField(42.0);
    static GTextField* textField = new GTextField("Marty");
    textField->setPlaceholder("type your name");
    // textField->setEditable(false);
    textField->setAutocompleteList({"matt", "Marty", "Stuart", "steve", "yana", "yes", "no"});
    textField->setTextChangeListener([]() {
        cout << "textfield text changed! text is:" << endl << textField->getText() << endl;
    });
    textField->setActionListener([]() {
        cout << "textfield action performed! text is:" << endl << textField->getText() << endl;
    });
    window->addToRegion(textField, GWindow::REGION_NORTH);
    cout << "textfield: " << textField->toString() << endl;

    static GSlider* slider = new GSlider();
    slider->setMinorTickSpacing(20);
    slider->setPaintLabels(true);
    slider->setPaintTicks(true);
    slider->setActionListener([](GEvent event) {
        cout << "sliderChangeHandler: slider was slid!" << endl;
        cout << "value: " << slider->getValue() << endl;
        cout << "event: " << event << endl;
        window->removeTimerListener();
    });

    window->addToRegion(slider, GWindow::REGION_NORTH);
    cout << "slider:    " << slider->toString() << endl;


    // WEST AREA

    static GCheckBox* checkBox = new GCheckBox("Question?", true);
    checkBox->setActionListener([](const GEvent&) {
        cout << "checkbox clicked! " << boolalpha << checkBox->isChecked() << endl;
    });
    window->addToRegion(checkBox, GWindow::REGION_WEST);
    window->addToRegion(new GLabel("Hi!"), GWindow::REGION_WEST);
    window->addToRegion(new GLabel("^_^"), GWindow::REGION_WEST);
    // window->setRegionAlignment(GWindow::REGION_WEST, "Top Right");
    cout << "checkbox:  " << checkBox->toString() << endl;


    // EAST AREA

    static GRadioButton* radio1group1 = new GRadioButton("A", "group1");
    static GRadioButton* radio2group1 = new GRadioButton("B", "group1", true);
    static GRadioButton* radio3group1 = new GRadioButton("C", "group1");
    static GRadioButton* radio1group2 = new GRadioButton("XX", "group2", true);
    static GRadioButton* radio2group2 = new GRadioButton("YY", "group2");

    GEventListenerVoid radioChangeHandler = []() {
        cout << "checkbox clicked! " << boolalpha
             << radio1group1->isChecked() << " "
             << radio2group1->isChecked() << " "
             << radio3group1->isChecked() << " "
             << radio1group2->isChecked() << " "
             << radio2group2->isChecked() << endl;
    };
    radio1group1->setActionListener(radioChangeHandler);
    radio1group1->setDoubleClickListener(GEvent::LOG_EVENT);
    radio2group1->setActionListener(radioChangeHandler);
    radio2group1->setDoubleClickListener(GEvent::LOG_EVENT);
    radio3group1->setActionListener(radioChangeHandler);
    radio3group1->setDoubleClickListener(GEvent::LOG_EVENT);
    radio1group2->setActionListener(radioChangeHandler);
    radio2group2->setActionListener(radioChangeHandler);

//    static QGScrollBar* scrollBar = new QGScrollBar(QGScrollBar::VERTICAL, 0, 10, 0, 500);
//    scrollBar->setValueChangeHandler([]() {
//        cout << "value: " << scrollBar->getValue() << endl;
//    });
//    window->addToRegion(scrollBar, GWindow::REGION_EAST);

    window->addToRegion(radio1group1, GWindow::REGION_EAST);
    window->addToRegion(radio2group1, GWindow::REGION_EAST);
    window->addToRegion(radio3group1, GWindow::REGION_EAST);
    window->addToRegion(radio1group2, GWindow::REGION_EAST);
    window->addToRegion(radio2group2, GWindow::REGION_EAST);
    // window->setRegionAlignment(GWindow::REGION_EAST, "Bottom Left");
//    cout << "radio:     " << radio1group1->toString() << endl;


    // SOUTH AREA

    static GChooser* chooser = new GChooser({"one", "two", "three four"});
    chooser->setColor(GColor::RED);
    chooser->setBackground(GColor::CYAN);
    chooser->setActionListener([]() {
        cout << "changeHandler: chooser was clicked!" << endl;
        cout << "selected: " << chooser->getSelectedIndex() << " : "
             << chooser->getSelectedItem() << endl;
        cout << "size: " << chooser->size() << endl << endl;
    });
    window->addToRegion(chooser, GWindow::REGION_SOUTH);
    cout << "chooser:   " << chooser->toString() << endl;

    GButton* button = new GButton("Triforce");
    button->setColor(GColor::RED);
    button->setBackground(GColor::YELLOW);
    button->setIcon("triangle-icon.png");
    button->setTextPosition(GInteractor::TEXT_BESIDE_ICON);
    button->setActionListener([](GEvent event) {
        cout << "button click! event = " << event << endl;
        cout.flush();
        window->restore();

        a();

//        window->setResizable(!window->isResizable());
//        cout << "clickHandler: button was clicked!" << endl;
//        cout << "location:  " << window->getLocation() << endl;
//        cout << "size:      " << window->getSize() << endl;
//        cout << "visible:   " << boolalpha << window->isVisible() << endl;
//        cout << "resizable: " << boolalpha << window->isResizable() << endl << endl;

//        // test GOptionPane
//        GOptionPane::showMessageDialog("I love Yana! <3");

//        Vector<string> choices = {"One", "Two", "Three"};
//        string result = GOptionPane::showOptionDialog("Pick a thing", choices);
//        cout << "You chose: " << result << endl;

        //    int result = GOptionPane::showConfirmDialog("Is Yana the most beautiful?", "Important Question", GOptionPane::YES_NO_CANCEL);
        //    cout << "You chose: " << result << endl;
        //    std::string answer = GOptionPane::showInputDialog("Who is my baby?", "Baby's name?", "bozo");
        //    cout << "You typed: " << answer << endl;

        //    string filename = QGFileChooser::showOpenDialog("", "*.txt, *.cpp, *.h");
        //    cout << "You chose: " << filename << endl;
        // window->clear();
    });

    //        button->setClickHandler([]() {
    //            // grayscale(image);
    //        });
    button->setDoubleClickListener([](GEvent event) {
        cout << "button double-click! event = " << event << endl;
    });
    button->setAccelerator("Ctrl-T");
    window->addToRegion(button, GWindow::REGION_SOUTH);
    cout << "button:    " << button->toString() << endl;
    cout << "button accelerator: " << button->getAccelerator() << endl;
    cout << "button font: " << button->getFont() << endl;
    button->setFont("Monospaced-Bold-14");

    static GButton* button4 = new GButton("HI!");
    window->addToRegion(button4, GWindow::REGION_SOUTH);

    static GCheckBox* checkboxs = new GCheckBox("&Visible?", /* checked */ true);
    checkboxs->setActionListener([]() {
        std::cout << "checkbox clicked!" << std::endl;
        // button4->setVisible(checkboxs->isChecked());
        if (checkboxs->isChecked()) {
            window->addToRegion(button4, GWindow::REGION_SOUTH);
        } else {
            window->removeFromRegion(button4, GWindow::REGION_SOUTH);
        }
    });
    checkboxs->setDoubleClickListener([]() {
        std::cout << "checkbox double-clicked!" << std::endl;
    });
    window->addToRegion(checkboxs, GWindow::REGION_SOUTH);

    GButton* timerButton = new GButton("Timer");
    GTimer* timer = nullptr;
    timerButton->setActionListener([&timer]() {
        if (timer) {
            timer->stop();
            delete timer;
            timer = nullptr;
        } else {
            timer = new GTimer(1000);
            timer->start();
        }
    });
    window->addToRegion(timerButton, GWindow::REGION_SOUTH);

//    window->setRegionAlignment(GWindow::REGION_SOUTH, "Center");

    // GLabel* oopsButton = new GLabel("I should not show up!!!!!");
    // oopsButton->setVisible(true);


    // CENTER AREA

//    static GTextArea* textArea = new GTextArea("This is \na multi-line\n\ntext area");
//    textArea->setPlaceholder("type some text");
//    textArea->setTextChangeListener([](GEvent) {
//        cout << "textarea text changed! text is:" << endl << textArea->getText() << endl;
//    });
//    window->addToRegion(textArea, "Center");

    GBrowserPane* pane = new GBrowserPane();
    pane->readTextFromFile("resfile3.html");
    pane->setLinkListener([](GEvent event) {
        cout << "event: " << event << ", url: " << event.getRequestURL() << endl;
    });
    window->addToRegion(pane, GWindow::REGION_CENTER);
    cout << "browser:  " << pane->toString() << endl;

    // window->pack();

//    while (true) {
//        GEvent event = waitForEvent(TIMER_EVENT);
//        cout << "event: " << event << endl;
//    }

    // will crash
    // a();

//    int* x = nullptr;
//    (*x)++;   // boom
}
bool MainWindow::parseImgElement(const QDomElement &element, TextEdit *t)
{
    QDomNode child = element.firstChild();

    int n = rand();

    while (!child.isNull()) {
//        qDebug() << child.toElement().tagName();
        if (child.toElement().tagName() == "img") {
            QString str1 = child.toElement().attribute("src");
            qDebug() << str1;

            if (str1.indexOf("file:///") != -1)
                str1.remove("file:///");

            GLabel *label;
            if (n % 2) {
                label = new GLabel(teout, GLabel::Me);
            } else {
                label = new GLabel(teout, GLabel::She);
            }

            label->setGeometry(5, a, 100, 66);
            if(str1.indexOf("gif") != -1) {
                label->setGifPixmap(str1);
            }
            else {
                label->setOurPixmap(str1);
            }
            label->show();
            a = label->y() + label->height() + 10;

            t->insertHtml(tr("<img src='") + str1 + tr("'/>"));
            t->addAnimate(QUrl(str1), str1);

            parseImgElement(child.toElement(), t);

        } else if (child.toElement().tagName() == "p") {
            qDebug() << child.toElement().text();
            if (child.toElement().text() != "") {
                GLabel *label;
                if (n % 2) {
                    label = new GLabel(teout, GLabel::Me);
                } else {
                    label = new GLabel(teout, GLabel::She);
                }

                label->setGeometry(5, a, 100, 66);
                label->setOurText(child.toElement().text());
                label->show();
                a = label->y()+label->height() + 10;

                t->append(str1);
            }
            parseImgElement(child.toElement(), t);
        }
        child = child.nextSibling();
    }
}
Exemplo n.º 8
0
 void setScore(int points, Player player) {
     ensureInitialized();
     GLabel* scoreLabel = player == COMPUTER ? computerScoreLabel : humanScoreLabel;
     scoreLabel->setLabel(integerToString(points));
 }