/* * 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 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); }
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 }