static void splash(void) { int r; clrscr(); setbg(blue); horizontal(1,79,1); horizontal(1,79,24); setfg(white); setbg(white); rect(20,7, 60,18); setbg(red); frect(21,8, 59,17); bold(); moveto(28,9); printf("tctetris - version 0.90"); normal(); setbg(red); setfg(white); moveto(23,10); printf("Copyright (c) 2006, Ivo van Poorten"); moveto(MENUX,12); printf("n - new game"); moveto(MENUX,14); printf("s - speed [%02d]", sspeed); moveto(MENUX,16); printf("q - quit"); moveto(1,23); flush(); }
bool WarpGrid::isReset() const { for (size_t y = 0; y < vertical(); ++y) for (size_t x = 0; x < horizontal(); ++x) { if (QVector2D(getPoint(x, y)->pos()) != (getTexCoord(x, y) - QVector2D(0.5, 0.5))) return false; } return true; }
// OPTIMIZATION Given: dy = line[1].fY - line[0].fY // and: xIntercept / (y - line[0].fY) == (line[1].fX - line[0].fX) / dy // then: xIntercept * dy == (line[1].fX - line[0].fX) * (y - line[0].fY) // Assuming that dy is always > 0, the line segment intercepts if: // left * dy <= xIntercept * dy <= right * dy // thus: left * dy <= (line[1].fX - line[0].fX) * (y - line[0].fY) <= right * dy // (clever as this is, it does not give us the t value, so may be useful only // as a quick reject -- and maybe not then; it takes 3 muls, 3 adds, 2 cmps) int SkIntersections::horizontal(const SkDLine& line, double left, double right, double y) { int result = horizontal(line, y); if (result != 1) { SkASSERT(0); return result; } double xIntercept = line[0].fX + fT[0][0] * (line[1].fX - line[0].fX); if (!precisely_between(left, xIntercept, right)) { return fUsed = 0; } return result; }
unsigned long long products(std::vector<std::vector<int>> &matrix){ unsigned long long greatest = 0; for(int row = 0; i<20;i++){ for(int col = 0; j<20; j++){ greatest = std::max(greatest, vertical(row, col, matrix)); greatest = std::max(greatest, horizontal(row, col, matrix)); greatest = std::max(greatest, fordiag(row, col, matrix)); greatest = std::max(greatest, backdiag(row, col, matrix)); } } return greatest; }
static void first_pass(char pattern[9][9], char possibilities[9][9][9]) { for (int x = 0; x <= 6; x = x + 3) { for (int y = 0; y <= 6; y = y + 3) { square(x,y, pattern, possibilities); } } for (int x = 0; x < 9; x++) { horizontal(x, pattern, possibilities); } for (int y = 0; y < 9; y++) { vertical(y, pattern, possibilities); } }
// Blur an image, given a kernel and its size Image_uc ApplyGaussBlur(const Image_uc& im, int radius, const std::vector<double>& kernel) { Image_uc vertical(im.Height(), im.Width()); for (int i = 0; i < im.Height(); ++i) { for (int j = 0; j < im.Width(); ++j) { double acc = 0.0; for (int k = 0; k < 2*radius+1; ++k) { acc += kernel[k] * im(i + k - radius, j); } vertical(i, j) = (unsigned char)acc; } } Image_uc horizontal(im.Height(), im.Width()); for (int i = 0; i < im.Height(); ++i) { for (int j = 0; j < im.Width(); ++j) { double acc = 0.0; for (int k = 0; k < 2*radius+1; ++k) { acc += kernel[k] * vertical(i, j + k - radius); } horizontal(i, j) = (unsigned char)acc; } } return horizontal; }
bool GameControllerStandard::checkRow(int x, int y, data::IPlayer *p) { // Functions return number of player-cells in a row (if >= 4: Win!) if (diagLeftRight(x, y, p) >= 4) return true; if (diagRightLeft(x, y, p) >= 4) return true; if (horizontal(x, y, p) >= 4) return true; if (down(x, y, p) >= 4) return true; return false; }
Peice verify(Board b){ for(unsigned y=0;y<Board::Y;++y){ auto h = horizontal(b,y); if(h != Peice::EMPTY){ return h; } } for(unsigned x=0;x<Board::X;++x){ auto h = vertical(b,x); if(h != Peice::EMPTY){ return h; } } auto d = diagonal(b); return d; }
int ccc_win_main() { Point top_left(1, 3); Point top_right(1, 4); Point bottom_left(2, 3); Line horizontal(top_left, top_right); Line vertical(top_left, bottom_left); cwin << horizontal << vertical; horizontal.move(1, 0); vertical.move(0, 1); cwin << horizontal << vertical; return 0; }
Point Line::intercept(Line l) const { ASSERT(could_intercept(l), "Lines must intercept"); double m = slope(), lm = l.slope(); bool vert = vertical(), lvert = l.vertical(); if ((vert && lvert) || (horizontal() && l.horizontal())) return midpoint(center(), l.center()); else if (vert) return {x1, (int) l.y_at(x1)}; else if (lvert) return {l.x1, (int) y_at(l.x1)}; else { // Derived from y-y1=m(x-x1), y = m(x-x1)+y1, ma(x-xa)+ya=mb(x-xb)+yb... double x = (x1*m - l.x1*lm + l.y1 - y1)/(m - lm); return {(int) x, (int) y_at(x)}; } }
int main() { int n, corrente; printf("Digite um numero inteiro: \n"); scanf("%d", &n); printf("--+\n"); printf(" |\n"); corrente = n; for (corrente = n; (corrente-1) >= 1; corrente--) { printf(" "); horizontal(n, corrente); printf(" "); vertical(n, corrente); } return 0; }
void Editor::draw(const Dot &dot) { // Cross sf::RectangleShape horizontal(sf::Vector2f(7, 3)), vertical(sf::Vector2f(3, 7)); horizontal.setPosition(dot.pos().x-3, dot.pos().y-1); vertical.setPosition(dot.pos().x-1, dot.pos().y-3); // Text sf::Text text(std::to_string(dot.number()), _font); text.setCharacterSize(12); text.setPosition(dot.pos().x - 5, dot.pos().y - 18); // Colors horizontal.setFillColor(sf::Color::Red); vertical.setFillColor(sf::Color::Red); text.setColor(sf::Color::Black); // Draw _window.draw(horizontal); _window.draw(vertical); _window.draw(text); }
int SkIntersections::horizontal(const SkDLine& line, double left, double right, double y, bool flipped) { int result = horizontal(line, y); switch (result) { case 0: break; case 1: { double xIntercept = line[0].fX + fT[0][0] * (line[1].fX - line[0].fX); if (!precisely_between(left, xIntercept, right)) { return fUsed = 0; } fT[1][0] = (xIntercept - left) / (right - left); break; } case 2: double a0 = line[0].fX; double a1 = line[1].fX; double b0 = flipped ? right : left; double b1 = flipped ? left : right; // FIXME: share common code below double at0 = (a0 - b0) / (a0 - a1); double at1 = (a0 - b1) / (a0 - a1); if ((at0 < 0 && at1 < 0) || (at0 > 1 && at1 > 1)) { return fUsed = 0; } fT[0][0] = SkTMax(SkTMin(at0, 1.0), 0.0); fT[0][1] = SkTMax(SkTMin(at1, 1.0), 0.0); int bIn = (a0 - a1) * (b0 - b1) < 0; fT[1][bIn] = SkTMax(SkTMin((b0 - a0) / (b0 - b1), 1.0), 0.0); fT[1][!bIn] = SkTMax(SkTMin((b0 - a1) / (b0 - b1), 1.0), 0.0); bool second = fabs(fT[0][0] - fT[0][1]) > FLT_EPSILON; SkASSERT((fabs(fT[1][0] - fT[1][1]) <= FLT_EPSILON) ^ second); return computePoints(line, 1 + second); } if (flipped) { // OPTIMIZATION: instead of swapping, pass original line, use [1].fX - [0].fX for (int index = 0; index < result; ++index) { fT[1][index] = 1 - fT[1][index]; } } return computePoints(line, result); }
int SkIntersections::horizontal(const SkDLine& line, double left, double right, double y, bool flipped) { // see if end points intersect the opposite line double t; if (checkEndPoint(left, y, line, &t, true)) { insert(t, flipped, left, y); } if (left != right) { if (checkEndPoint(right, y, line, &t, true)) { insert(t, !flipped, right, y); } for (int index = 0; index < 2; ++index) { if (!checkEndPointH(line[index], left, right, y, flipped, &t)) { continue; } insert(index, t, line[index]); } } if (used() > 0) { SkASSERT(fUsed <= 2); return used(); // coincident lines are returned here } int result = horizontal(line, y); if (!result) { return 0; } SkASSERT(result == 1); double xIntercept = line[0].fX + fT[0][0] * (line[1].fX - line[0].fX); if (!precisely_between(left, xIntercept, right)) { return fUsed = 0; } fT[1][0] = (xIntercept - left) / (right - left); if (flipped) { // OPTIMIZATION: ? instead of swapping, pass original line, use [1].fX - [0].fX for (int index = 0; index < result; ++index) { fT[1][index] = 1 - fT[1][index]; } } return computePoints(line, result); }
// Return the location of the left/top edge of a box of slider_size() would // be if the area the slider can move in is of width/height w. int Fl_Slider::slider_position(double value, int w) { double A = minimum(); double B = maximum(); if (B == A) return 0; bool flip = B < A; if (flip) {A = B; B = minimum();} if (!horizontal()) flip = !flip; // if both are negative, make the range positive: if (B <= 0) {flip = !flip; double t = A; A = -B; B = -t; value = -value;} double fraction; if (!log()) { // linear slider fraction = (value-A)/(B-A); } else if (A > 0) { // logatithmic slider if (value <= A) fraction = 0; else fraction = (::log(value)-::log(A))/(::log(B)-::log(A)); } else if (A == 0) { // squared slider if (value <= 0) fraction = 0; else fraction = sqrt(value/B); } else { // squared signed slider if (value < 0) fraction = (1-sqrt(value/A))*.5; else fraction = (1+sqrt(value/B))*.5; } if (flip) fraction = 1-fraction; w -= slider_size_; if (w <= 0) return 0; if (fraction >= 1) return w; else if (fraction <= 0) return 0; else return int(fraction*w+.5); }
void Room::create(Level* pLevel, int cellX, int cellY, int width, int height, const std::vector<int> &cellIndices, int background) { _pLevel = pLevel; _background = background; _cellX = cellX; _cellY = cellY; _quadtree.create(sf::FloatRect(0.0f, 0.0f, _width, _height)); _width = width; _height = height; sf::Vector2f center(_width * 0.5f, _height * 0.5f); sf::FloatRect horizontal(0.0f, 0.0f, _portalSize * 2.0f, _portalSize); sf::FloatRect vertical(0.0f, 0.0f, _portalSize, _portalSize * 2.0f); const float wallExtention = 256.0f; sf::FloatRect wall0(-wallExtention, 0.0f, wallExtention + _wallRange, getHeight() * 0.5f - _portalSize * 0.5f); sf::FloatRect wall1(-wallExtention, center.y + _portalSize * 0.5f, wallExtention + _wallRange, getHeight() * 0.5f - _portalSize * 0.5f); sf::FloatRect wall2(getWidth() - _wallRange, 0.0f, wallExtention + _wallRange, getHeight() * 0.5f - _portalSize * 0.5f); sf::FloatRect wall3(getWidth() - _wallRange, center.y + _portalSize * 0.5f, wallExtention + _wallRange, getHeight() * 0.5f - _portalSize * 0.5f); sf::FloatRect wall4(0.0f, -wallExtention, getWidth() * 0.5f - _portalSize * 0.5f, wallExtention + _wallRange); sf::FloatRect wall5(center.x + _portalSize * 0.5f, -wallExtention + _wallRange, getWidth() * 0.5f - _portalSize * 0.5f, wallExtention + _wallRange); sf::FloatRect wall6(0.0f, getHeight() - _wallRange, getWidth() * 0.5f - _portalSize * 0.5f, wallExtention + _wallRange); sf::FloatRect wall7(center.x + _portalSize * 0.5f, getHeight() - _wallRange, getWidth() * 0.5f - _portalSize * 0.5f, wallExtention + _wallRange); _walls.push_back(wall0); _walls.push_back(wall1); _walls.push_back(wall2); _walls.push_back(wall3); _walls.push_back(wall4); _walls.push_back(wall5); _walls.push_back(wall6); _walls.push_back(wall7); }
int Room::getPortalContains(const sf::FloatRect &aabb) { sf::Vector2f center(_width * 0.5f, _height * 0.5f); sf::FloatRect horizontal(0.0f, 0.0f, (_portalSize + _wallRange) * 2.0f, _portalSize * 0.99f); sf::FloatRect vertical(0.0f, 0.0f, _portalSize * 0.99f, (_portalSize + _wallRange) * 2.0f); if (getCellX() > 0 && getLevel()->getCell(getCellX() - 1, getCellY())._room != nullptr) if (ltbl::rectContains(ltbl::rectRecenter(horizontal, sf::Vector2f(0.0f, center.y)), aabb)) return 2; if (getCellX() < getLevel()->getWidth() - 1 && getLevel()->getCell(getCellX() + 1, getCellY())._room != nullptr) if (ltbl::rectContains(ltbl::rectRecenter(horizontal, sf::Vector2f(_width, center.y)), aabb)) return 0; if (getCellY() > 0 && getLevel()->getCell(getCellX(), getCellY() - 1)._room != nullptr) if (ltbl::rectContains(ltbl::rectRecenter(vertical, sf::Vector2f(center.x, 0.0f)), aabb)) return 3; if (getCellY() < getLevel()->getHeight() - 1 && getLevel()->getCell(getCellX(), getCellY() + 1)._room != nullptr) if (ltbl::rectContains(ltbl::rectRecenter(vertical, sf::Vector2f(center.x, _height)), aabb)) return 1; return -1; }
int main() { int dice1[6], dice2[6]; int i = 0, is_same = 0, j = 0; for(i = 0; i < 6; i++){ scanf("%d", &dice1[i]); printf("%d\t", dice1[i]); } printf("\n"); for(i = 0; i < 6; i++){ scanf("%d", &dice2[i]); printf("%d\t", dice2[i]); } printf("\n"); for(j = 0; j < 4; j++){ vertical(dice1); if(is_same == 0) is_same = judge(dice1, dice2); for(i = 0; i < 4; i++){ horizontal(dice1); if(is_same == 0) is_same = judge(dice1, dice2); } vertical(dice1); for(i = 0; i < 4; i++){ clockwise(dice1); if(is_same == 0) is_same = judge(dice1, dice2); } } if(is_same == 0) printf("\nNO\n"); else printf("\nYES\n"); return 0; }
static cairo_time_t horizontal_wide (cairo_t *cr, int width, int height, int loops) { cairo_set_line_width (cr, 5.); return horizontal (cr, width, height, loops); }
void QStyleItem::initStyleOption() { QString type = elementType(); if (m_styleoption) m_styleoption->state = 0; switch (m_itemType) { case Button: { if (!m_styleoption) m_styleoption = new QStyleOptionButton(); QStyleOptionButton *opt = qstyleoption_cast<QStyleOptionButton*>(m_styleoption); opt->text = text(); opt->features = (activeControl() == "default") ? QStyleOptionButton::DefaultButton : QStyleOptionButton::None; } break; case ItemRow: { if (!m_styleoption) m_styleoption = new QStyleOptionViewItem(); QStyleOptionViewItem *opt = qstyleoption_cast<QStyleOptionViewItem*>(m_styleoption); opt->features = 0; if (activeControl() == "alternate") opt->features |= QStyleOptionViewItem::Alternate; } break; case Splitter: { if (!m_styleoption) { m_styleoption = new QStyleOption; } } break; case Item: { if (!m_styleoption) { m_styleoption = new QStyleOptionViewItem(); } QStyleOptionViewItem *opt = qstyleoption_cast<QStyleOptionViewItem*>(m_styleoption); opt->features = QStyleOptionViewItem::HasDisplay; opt->text = text(); opt->textElideMode = Qt::ElideRight; QPalette pal = m_styleoption->palette; pal.setBrush(QPalette::Base, Qt::NoBrush); m_styleoption->palette = pal; } break; case Header: { if (!m_styleoption) m_styleoption = new QStyleOptionHeader(); QStyleOptionHeader *opt = qstyleoption_cast<QStyleOptionHeader*>(m_styleoption); opt->text = text(); opt->sortIndicator = activeControl() == "down" ? QStyleOptionHeader::SortDown : activeControl() == "up" ? QStyleOptionHeader::SortUp : QStyleOptionHeader::None; if (info() == QLatin1String("beginning")) opt->position = QStyleOptionHeader::Beginning; else if (info() == QLatin1String("end")) opt->position = QStyleOptionHeader::End; else if (info() == QLatin1String("only")) opt->position = QStyleOptionHeader::OnlyOneSection; else opt->position = QStyleOptionHeader::Middle; } break; case ToolButton: { if (!m_styleoption) m_styleoption = new QStyleOptionToolButton(); QStyleOptionToolButton *opt = qstyleoption_cast<QStyleOptionToolButton*>(m_styleoption); opt->subControls = QStyle::SC_ToolButton; opt->state |= QStyle::State_AutoRaise; opt->activeSubControls = QStyle::SC_ToolButton; } break; case ToolBar: { if (!m_styleoption) m_styleoption = new QStyleOptionToolBar(); } break; case Tab: { if (!m_styleoption) m_styleoption = new QStyleOptionTab(); QStyleOptionTab *opt = qstyleoption_cast<QStyleOptionTab*>(m_styleoption); opt->text = text(); opt->shape = info() == "South" ? QTabBar::RoundedSouth : QTabBar::RoundedNorth; if (activeControl() == QLatin1String("beginning")) opt->position = QStyleOptionTab::Beginning; else if (activeControl() == QLatin1String("end")) opt->position = QStyleOptionTab::End; else if (activeControl() == QLatin1String("only")) opt->position = QStyleOptionTab::OnlyOneTab; else opt->position = QStyleOptionTab::Middle; } break; case Menu: { if (!m_styleoption) m_styleoption = new QStyleOptionMenuItem(); } break; case Frame: { if (!m_styleoption) m_styleoption = new QStyleOptionFrame(); QStyleOptionFrame *opt = qstyleoption_cast<QStyleOptionFrame*>(m_styleoption); opt->frameShape = QFrame::StyledPanel; opt->lineWidth = 1; opt->midLineWidth = 1; } break; case TabFrame: { if (!m_styleoption) m_styleoption = new QStyleOptionTabWidgetFrame(); QStyleOptionTabWidgetFrame *opt = qstyleoption_cast<QStyleOptionTabWidgetFrame*>(m_styleoption); opt->shape = (info() == "South") ? QTabBar::RoundedSouth : QTabBar::RoundedNorth; if (minimum()) opt->selectedTabRect = QRect(value(), 0, minimum(), height()); opt->tabBarSize = QSize(minimum() , height()); // oxygen style needs this hack opt->leftCornerWidgetSize = QSize(value(), 0); } break; case MenuItem: case ComboBoxItem: { if (!m_styleoption) m_styleoption = new QStyleOptionMenuItem(); QStyleOptionMenuItem *opt = qstyleoption_cast<QStyleOptionMenuItem*>(m_styleoption); opt->checked = false; opt->text = text(); } break; case CheckBox: case RadioButton: { if (!m_styleoption) m_styleoption = new QStyleOptionButton(); QStyleOptionButton *opt = qstyleoption_cast<QStyleOptionButton*>(m_styleoption); if (!on()) opt->state |= QStyle::State_Off; opt->text = text(); } break; case Edit: { if (!m_styleoption) m_styleoption = new QStyleOptionFrame(); QStyleOptionFrame *opt = qstyleoption_cast<QStyleOptionFrame*>(m_styleoption); opt->lineWidth = 1; // this must be non-zero } break; case ComboBox :{ if (!m_styleoption) m_styleoption = new QStyleOptionComboBox(); QStyleOptionComboBox *opt = qstyleoption_cast<QStyleOptionComboBox*>(m_styleoption); opt->currentText = text(); } break; case SpinBox: { if (!m_styleoption) m_styleoption = new QStyleOptionSpinBox(); QStyleOptionSpinBox *opt = qstyleoption_cast<QStyleOptionSpinBox*>(m_styleoption); opt->frame = true; if (value() & 0x1) opt->activeSubControls = QStyle::SC_SpinBoxUp; else if (value() & (1<<1)) opt->activeSubControls = QStyle::SC_SpinBoxDown; opt->subControls = QStyle::SC_All; opt->stepEnabled = 0; if (value() & (1<<2)) opt->stepEnabled |= QAbstractSpinBox::StepUpEnabled; if (value() & (1<<3)) opt->stepEnabled |= QAbstractSpinBox::StepDownEnabled; } break; case Slider: case Dial: { if (!m_styleoption) m_styleoption = new QStyleOptionSlider(); QStyleOptionSlider *opt = qstyleoption_cast<QStyleOptionSlider*>(m_styleoption); opt->minimum = minimum(); opt->maximum = maximum(); opt->sliderPosition = value(); opt->singleStep = step(); if (opt->singleStep) { qreal numOfSteps = (opt->maximum - opt->minimum) / opt->singleStep; // at least 5 pixels between tick marks if (numOfSteps && (width() / numOfSteps < 5)) opt->tickInterval = qRound((5*numOfSteps / width()) + 0.5)*step(); else opt->tickInterval = opt->singleStep; } else // default Qt-components implementation opt->tickInterval = opt->maximum != opt->minimum ? 1200 / (opt->maximum - opt->minimum) : 0; opt->sliderValue = value(); opt->subControls = QStyle::SC_SliderGroove | QStyle::SC_SliderHandle; opt->tickPosition = (activeControl() == "tick" ? QSlider::TicksBelow : QSlider::NoTicks); if (opt->tickPosition != QSlider::NoTicks) opt->subControls |= QStyle::SC_SliderTickmarks; opt->activeSubControls = QStyle::SC_None; } break; case ProgressBar: { if (!m_styleoption) m_styleoption = new QStyleOptionProgressBar(); QStyleOptionProgressBar *opt = qstyleoption_cast<QStyleOptionProgressBar*>(m_styleoption); opt->orientation = horizontal() ? Qt::Horizontal : Qt::Vertical; opt->minimum = minimum(); opt->maximum = maximum(); opt->progress = value(); } break; case GroupBox: { if (!m_styleoption) m_styleoption = new QStyleOptionGroupBox(); QStyleOptionGroupBox *opt = qstyleoption_cast<QStyleOptionGroupBox*>(m_styleoption); opt->text = text(); opt->lineWidth = 1; opt->subControls = QStyle::SC_GroupBoxLabel; opt->features = 0; if (sunken()) { // Qt draws an ugly line here so I ignore it opt->subControls |= QStyle::SC_GroupBoxFrame; } else { opt->features |= QStyleOptionFrame::Flat; } if (activeControl() == "checkbox") opt->subControls |= QStyle::SC_GroupBoxCheckBox; } break; case ScrollBar: { if (!m_styleoption) m_styleoption = new QStyleOptionSlider(); QStyleOptionSlider *opt = qstyleoption_cast<QStyleOptionSlider*>(m_styleoption); opt->minimum = minimum(); opt->maximum = maximum(); opt->pageStep = qMax(0, int(horizontal() ? width() : height())); opt->orientation = horizontal() ? Qt::Horizontal : Qt::Vertical; opt->sliderPosition = value(); opt->sliderValue = value(); opt->activeSubControls = (activeControl() == QLatin1String("up")) ? QStyle::SC_ScrollBarSubLine : (activeControl() == QLatin1String("down")) ? QStyle::SC_ScrollBarAddLine: QStyle::SC_ScrollBarSlider; opt->sliderValue = value(); opt->subControls = QStyle::SC_All; } case MenuBar: if (!m_styleoption) { QStyleOptionMenuItem *menuOpt = new QStyleOptionMenuItem(); menuOpt->menuItemType = QStyleOptionMenuItem::EmptyArea; m_styleoption = menuOpt; } break; case MenuBarItem: if (!m_styleoption) { QStyleOptionMenuItem *menuOpt = new QStyleOptionMenuItem(); menuOpt->text = text(); menuOpt->menuItemType = QStyleOptionMenuItem::Normal; m_styleoption = menuOpt; } break; default: break; } if (!m_styleoption) m_styleoption = new QStyleOption(); m_styleoption->styleObject = this; m_styleoption->rect = QRect(m_paintMargins, m_paintMargins, width() - 2* m_paintMargins, height() - 2 * m_paintMargins); if (isEnabled()) m_styleoption->state |= QStyle::State_Enabled; if (m_active) m_styleoption->state |= QStyle::State_Active; if (m_sunken) m_styleoption->state |= QStyle::State_Sunken; if (m_raised) m_styleoption->state |= QStyle::State_Raised; if (m_selected) m_styleoption->state |= QStyle::State_Selected; if (m_focus) m_styleoption->state |= QStyle::State_HasFocus; if (m_on) m_styleoption->state |= QStyle::State_On; if (m_hover) m_styleoption->state |= QStyle::State_MouseOver; if (m_horizontal) m_styleoption->state |= QStyle::State_Horizontal; if (m_hint.indexOf("mini") != -1) { m_styleoption->state |= QStyle::State_Mini; } else if (m_hint.indexOf("small") != -1) { m_styleoption->state |= QStyle::State_Small; } }
MainWindow::MainWindow() { openAction = new QAction(tr("&Open"), this); saveAction = new QAction(tr("&Save"), this); exitAction = new QAction(tr("E&xit"), this); equalAction = new QAction(tr("&Equalization"), this); otsuAction = new QAction(tr("&otsu"), this); isodataAction = new QAction(tr("&Isodata"), this); manualAction = new QAction(tr("&Manual"), this); gammaAction = new QAction(tr("&Gamma"), this); stretchingAction = new QAction(tr("&Stretching"), this); sigmaAction = new QAction(tr("&Sigma"), this); medianAction = new QAction(tr("&Median"), this); lineAction = new QAction(tr("&Lines"), this); pixelAction = new QAction(tr("&Pixels"), this); gaussianAction = new QAction(tr("&Gaussian"), this); sobelAction = new QAction(tr("&Sobel"), this); horizontalAction = new QAction(tr("&Line Intensity"), this); cannyAction = new QAction(tr("&Canny"),this); sumAction = new QAction(tr("&Add"),this); resAction = new QAction(tr("&Substract"),this); multAction = new QAction(tr("&Multiply"),this); divAction = new QAction(tr("&Divide"),this); avgAction = new QAction(tr("A&verage"),this); andAction = new QAction(tr("&And"),this); orAction = new QAction(tr("&Or"),this); xorAction = new QAction(tr("&Xor"),this); notAction = new QAction(tr("&Not"),this); minAction = new QAction(tr("M&in"),this); maxAction = new QAction(tr("M&ax"),this); kmeansAction = new QAction(tr("&Kmeans"),this); saveAction->setEnabled(false); connect(openAction, SIGNAL(triggered()), this, SLOT(open())); connect(saveAction, SIGNAL(triggered()), this, SLOT(save())); connect(exitAction, SIGNAL(triggered()), qApp, SLOT(quit())); connect(equalAction, SIGNAL(triggered()), this, SLOT(equalization())); connect(otsuAction, SIGNAL(triggered()), this, SLOT(otsuThresh())); connect(isodataAction, SIGNAL(triggered()), this, SLOT(isodataSlot())); connect(manualAction, SIGNAL(triggered()), this, SLOT(manual())); connect(gammaAction,SIGNAL(triggered()),this,SLOT(gamma())); connect(stretchingAction,SIGNAL(triggered()),this,SLOT(stretching())); connect(sigmaAction, SIGNAL(triggered()), this, SLOT(sigma())); connect(medianAction, SIGNAL(triggered()), this, SLOT(median())); connect(lineAction, SIGNAL(triggered()), this, SLOT(line())); connect(pixelAction, SIGNAL(triggered()), this, SLOT(pixel())); connect(gaussianAction, SIGNAL(triggered()), this, SLOT(gaussian())); connect(sobelAction, SIGNAL(triggered()), this, SLOT(sobelEdges())); connect(horizontalAction,SIGNAL(triggered()),this,SLOT(horizontal())); connect(cannyAction,SIGNAL(triggered()),this,SLOT(cannySlot())); connect(sumAction,SIGNAL(triggered()),this,SLOT(sum())); connect(resAction,SIGNAL(triggered()),this,SLOT(res())); connect(multAction,SIGNAL(triggered()),this,SLOT(mult())); connect(divAction,SIGNAL(triggered()),this,SLOT(div())); connect(avgAction,SIGNAL(triggered()),this,SLOT(avg())); connect(andAction,SIGNAL(triggered()),this,SLOT(andSlot())); connect(orAction,SIGNAL(triggered()),this,SLOT(orSlot())); connect(xorAction,SIGNAL(triggered()),this,SLOT(xorSlot())); connect(notAction,SIGNAL(triggered()),this,SLOT(notSlot())); connect(minAction,SIGNAL(triggered()),this,SLOT(minSlot())); connect(maxAction,SIGNAL(triggered()),this,SLOT(maxSlot())); connect(kmeansAction,SIGNAL(triggered()),this,SLOT(kmeansSlot())); fileMenu = menuBar()->addMenu(tr("&File")); equalizationMenu = menuBar()->addMenu(tr("&Equalization")); thresholdMenu = menuBar()->addMenu(tr("&Thresholding")); contrastMenu = menuBar()->addMenu(tr("&Contrast")); noiseMenu = menuBar()->addMenu(tr("&Noise")); edgeMenu = menuBar()->addMenu(tr("E&dge")); operationMenu = menuBar()->addMenu(tr("&Operation")); boolMenu = operationMenu->addMenu(tr("&Boolean")); arithMenu = operationMenu->addMenu(tr("&Arithmetic")); relMenu = operationMenu->addMenu(tr("&Relational")); segmentationMenu = menuBar()->addMenu(tr("&Segmentation")); equalizationMenu->setEnabled(false); thresholdMenu->setEnabled(false); contrastMenu->setEnabled(false); noiseMenu->setEnabled(false); edgeMenu->setEnabled(false); operationMenu->setEnabled(false); segmentationMenu->setEnabled(false); fileMenu->addAction(openAction); fileMenu->addAction(saveAction); fileMenu->addSeparator(); fileMenu->addAction(exitAction); equalizationMenu->addAction(equalAction); thresholdMenu->addAction(otsuAction); thresholdMenu->addAction(isodataAction); thresholdMenu->addAction(manualAction); contrastMenu->addAction(gammaAction); contrastMenu->addAction(stretchingAction); noiseMenu->addAction(sigmaAction); noiseMenu->addAction(medianAction); noiseMenu->addAction(lineAction); noiseMenu->addAction(pixelAction); noiseMenu->addAction(gaussianAction); edgeMenu->addAction(sobelAction); edgeMenu->addAction(horizontalAction); edgeMenu->addAction(cannyAction); boolMenu->addAction(andAction); boolMenu->addAction(orAction); boolMenu->addAction(xorAction); boolMenu->addAction(notAction); arithMenu->addAction(sumAction); arithMenu->addAction(resAction); arithMenu->addAction(multAction); arithMenu->addAction(divAction); arithMenu->addAction(avgAction); relMenu->addAction(minAction); relMenu->addAction(maxAction); segmentationMenu->addAction(kmeansAction); //----- viewer = new ImageViewer(this); QScrollArea * scrollArea = new QScrollArea; scrollArea->setWidget(viewer); scrollArea->setFixedWidth(600); scrollArea->setWidgetResizable(true); boxW = new QSpinBox(); boxW->setEnabled(false); boxW->setMaximum(65535); boxC = new QSpinBox(); boxC->setEnabled(false); boxC->setMaximum(65535); histoViewer = new ImageViewer(this); QScrollArea * histoArea = new QScrollArea; histoArea->setWidget(histoViewer); histoArea->setFixedSize(268,278); histoArea->setWidgetResizable(false); QVBoxLayout * rightLayout = new QVBoxLayout; rightLayout->addWidget(new QLabel("Window:",this)); rightLayout->addWidget(boxW); rightLayout->addWidget(new QLabel("Level:",this)); rightLayout->addWidget(boxC); rightLayout->addWidget(histoArea); connect(boxW,SIGNAL(valueChanged(int)),this,SLOT(changeW(int))); connect(boxC,SIGNAL(valueChanged(int)),this,SLOT(changeC(int))); QWidget * rightSide = new QWidget; rightSide->setLayout(rightLayout); QHBoxLayout *mainLayout = new QHBoxLayout; mainLayout->addWidget(scrollArea); mainLayout->addWidget(rightSide); QWidget * centralWidget = new QWidget(); centralWidget->setLayout(mainLayout); setCentralWidget(centralWidget); setWindowTitle(tr("DICOM Image Processor")); setFixedSize(QSize(900,600)); }
int main( int ac, char** av ) { bool verbose = false; try { comma::command_line_options options( ac, av ); if( options.exists( "--help,-h" ) ) { usage(); } const auto& unnamed = options.unnamed( "--accumulate,-a,--no-inertial,--output-fields,--verbose,-v" ); if( unnamed.empty() ) { std::cerr << "control-from-console: please specify operation" << std::endl; return 1; } if( unnamed.size() > 1 ) { std::cerr << "control-from-console: expected one operation, got: " << comma::join( unnamed, ',' ) << std::endl; return 1; } std::string operation = unnamed[0]; if( options.exists( "--output-fields" ) ) { if( operation == "cartesian" ) { std::cout << "velocity/x,velocity/y" << std::endl; return 0; } if( operation == "drive" ) { std::cout << "velocity,turn_rate" << std::endl; return 0; } if( operation == "pantilt" ) { std::cout << "pan,tilt" << std::endl; return 0; } std::cerr << "control-from-console: expected operation, got: \"" << operation << "\"" << std::endl; return 1; } std::pair< double, double > steps = default_steps( operation ); const auto& s = comma::split( options.value< std::string >( "--step,-s", "" ), ',' ); switch( s.size() ) { case 1: if( !s[0].empty() ) { steps.first = boost::lexical_cast< double >( s[0] ); } break; case 2: if( !s[0].empty() ) { steps.first = boost::lexical_cast< double >( s[0] ); } if( !s[1].empty() ) { steps.second = boost::lexical_cast< double >( s[1] ); } break; default: std::cerr << "control-from-console: expected --step <first>[,<second>]; got: \"" << options.value< std::string >( "--step,-s", "" ) << "\"" << std::endl; return 1; } bool inertial = !options.exists( "--no-inertial" ); verbose = options.exists( "--verbose,-v" ); bool accumulate = options.exists( "--accumulate,-a" ); if( verbose ) { std::cerr << "control-from-console: step: " << steps.first << "," << steps.second << std::endl; } comma::io::select select; select.read().add( 0 ); inertial::pair horizontal( boost::posix_time::millisec( inertial ? 500 : 0 ), inertial ? 5 : 1 ); inertial::pair vertical( boost::posix_time::millisec( inertial ? 500 : 0 ), inertial ? 5 : 1 ); comma::signal_flag is_shutdown; char b = 0; boost::posix_time::time_duration threshold = boost::posix_time::millisec( 200 ); boost::posix_time::ptime last = boost::posix_time::microsec_clock::universal_time(); std::pair< double, double > accumulated( 0, 0 ); while( !is_shutdown && std::cout.good() && !std::cout.eof() && std::cin.good() && !std::cin.eof() ) { // todo: it does not exit, if std::cout closed; catch sigpipe? if( select.wait( boost::posix_time::seconds( 1 ) ) == 0 ) { continue; } char c; if( ::read( 0, &c, 1 ) != 1 ) { break; } if( verbose ) { std::cerr << "control-from-console: got " << c << std::endl; } switch( c ) { case 0x41: ++vertical; break; case 0x42: --vertical; break; case 0x43: ++horizontal; break; case 0x44: --horizontal; break; default: continue; } boost::posix_time::ptime now = boost::posix_time::microsec_clock::universal_time(); if( b != c || ( now - last ) > threshold ) { if( accumulate ) { accumulated.first += steps.first * horizontal.pick(); accumulated.second += steps.second * vertical.pick(); std::cout << accumulated.first << "," << accumulated.second << std::endl; } else { std::cout << ( steps.first * horizontal.pick() ) << "," << ( steps.second * vertical.pick() ) << std::endl; } std::cout.flush(); last = now; } b = c; } if( verbose ) { std::cerr << "control-from-console: done" << std::endl; } return 0; } catch( comma::last_error::interrupted_system_call_exception& ) { if( verbose ) { std::cerr << "control-from-console: done" << std::endl; } return 0; } catch( std::exception& ex ) { std::cerr << "control-from-console: " << ex.what() << std::endl; } catch( ... ) { std::cerr << "control-from-console: unknown exception" << std::endl; } return 1; }
double Line::x_at(int y) const { ASSERT(!horizontal(), "line must not be horizontal"); return (y-y1)/slope() + x1; }
bool Fl_Slider::draw(int ix, int iy, int iw, int ih, Fl_Flags flags, bool slot) { // for back compatability, use type flag to set slider size: if (type()&FILL) slider_size(0); // if user directly set selected_color we use it: if (style()->selection_color) flags.set(FL_SELECTED); // figure out where the slider should be: int sx = ix, sy = iy, sw = iw, sh = ih; int sp; if (horizontal()) { sx = sp = ix+slider_position(value(),iw); sw = slider_size_; if (!sw) // fill slider { sw = sx-ix; sx = ix; } } else { sy = sp = iy+slider_position(value(),ih); sh = slider_size_; if (!sh) sh = iy+ih-sy; // fill slider } if (damage()&FL_DAMAGE_ALL) { fl_push_clip(0, 0, w(), h()); // draw the slider draw_glyph(0, sx, sy, sw, sh, flags); // clip out the area of the slider fl_clip_out(sx, sy, sw, sh); } else if (sp != old_position) { // update a moving slider: // draw slider in new position draw_glyph(0, sx, sy, sw, sh, flags); // clip to the region the old slider was in: if (horizontal()) { if (slider_size_) fl_push_clip(old_position, sy, sw, sh); else fl_push_clip(ix, iy, old_position, ih); } else { if (slider_size_) fl_push_clip(sx, old_position, sw, sh); else fl_push_clip(ix, old_position, iw, iy+ih-old_position); } // don't erase new slider fl_clip_out(sx, sy, sw, sh); } else { // update for the highlight turning on/off if (damage() & FL_DAMAGE_HIGHLIGHT) draw_glyph(0, sx, sy, sw, sh, flags); // otherwise no changes return false; } old_position = sp; // we draw a slot if it seems the box has no border: if (slot) { const int slot_size_ = 6; int slx, sly, slw, slh; int dx = (slider_size_-slot_size_)/2; if (dx < 0) dx = 0; if (horizontal()) { slx = dx; slw = iw-2*dx; slx += ix; sly = iy+(ih-slot_size_+1)/2; slh = slot_size_; } else { sly = dx; slh = ih-2*dx; sly += iy; slx = ix+(iw-slot_size_+1)/2; slw = slot_size_; } button_box()->draw(slx, sly, slw, slh, FL_BLACK, flags&FL_INACTIVE|FL_VALUE); fl_clip_out(slx, sly, slw, slh); } return true; }
int Fl_Value_Slider_Input::handle(int event) { int mx = Fl::event_x(); int my = Fl::event_y(); static int indrag = 0; static int sldrag = 0; int sxx = x(), syy = y(), sww = w(), shh = h(); int border_size=Fl::box_dx(box()); if (horizontal()) { sxx += textboxsize(); sww -= textboxsize(); } else { fl_font(input.textfont(), input.textsize()); syy += fl_height()+(border_size+1)*2; shh -= fl_height()+(border_size+1)*2; } if( !indrag && ( !sldrag || !((mx>=sxx && mx<=(sxx+sww)) && (my>=syy && my<=(syy+shh))))) { indrag=0; switch(event) { case FL_PUSH: case FL_DRAG: sldrag=1; break; case FL_FOCUS: input.take_focus(); break; case FL_UNFOCUS: redraw(); break; case FL_KEYBOARD: switch (Fl::event_key()) { case FL_Up: if (!horizontal()) indrag=1 ; break; case FL_Down: if (!horizontal()) indrag=1 ; break; case FL_Left: if (horizontal()) indrag=1 ; break; case FL_Right: if (horizontal()) indrag=1 ; break; } break; default: sldrag=0; } if(!indrag) { input.type(step()>=1.0 ? FL_INT_INPUT : FL_FLOAT_INPUT); return input.handle(event); } } switch (event) { case FL_PUSH: ix = mx; drag = Fl::event_button(); indrag=1; return Fl_Slider::handle(event,sxx,syy,sww,shh); case FL_DRAG: indrag=1; return Fl_Slider::handle(event,sxx,syy,sww,shh); case FL_RELEASE: // if (!step()) goto DEFAULT; if (value() != previous_value() || !Fl::event_is_click()) { handle_release(); } else { input.handle(FL_PUSH); input.handle(FL_RELEASE); } indrag=0; return 1; case FL_FOCUS: indrag=0; input.take_focus(); return Fl_Slider::handle(event,sxx,syy,sww,shh); default: indrag=0; input.type(step()>=1.0 ? FL_INT_INPUT : FL_FLOAT_INPUT); input.handle(event); return Fl_Slider::handle(event,sxx,syy,sww,shh); } }
TEST_F(SimulatorTest, fire) { House newHouse(Point(0, 1), 2); Street verticalLeft("VerticalLeft", Point(2, 2), Point(2, 1)); Street horizontal("Horizontal", Point(2, 2), Point(4, 2)); Street verticalRight("VerticalRight", Point(4, 3), Point(4, 2)); ASSERT_TRUE(ptrCity->add(newHouse)); ASSERT_TRUE(ptrCity->add(horizontal)); ASSERT_TRUE(ptrCity->add(verticalLeft)); ASSERT_TRUE(ptrCity->add(verticalRight)); Simulator sim(ptrCity, ptrOutput); House* ptrHouse = ptrCity->getHouses()[0]; ASSERT_TRUE(ptrHouse != NULL); EXPECT_NO_FATAL_FAILURE(sim.fireBreaksOut()); EXPECT_TRUE(ptrHouse->isBurning()); EXPECT_EQ(2, ptrHouse->getHealth()); EXPECT_NO_FATAL_FAILURE(sim.burningDown()); EXPECT_TRUE(ptrHouse->isBurning()); EXPECT_EQ(1, ptrHouse->getHealth()); EXPECT_FALSE(sim.sendFireTrucks()); // oh, there isn't even a firedepot // now build a firedepot FireDepot newDepot(Point(4, 7), Point(4, 3), "Firedepot", 1); ASSERT_TRUE(ptrCity->add(newDepot)); FireDepot* ptrDepot = ptrCity->findFireDepot("Firedepot"); ASSERT_TRUE(ptrDepot != NULL); EXPECT_FALSE(sim.sendFireTrucks()); // oh, there isn't even a firetruck // add a firetruck FireTruck newTruck("Truck", ptrDepot); ASSERT_TRUE(ptrCity->add(newTruck)); FireTruck* ptrTruck = ptrCity->getFireTrucks()[0]; ASSERT_TRUE(ptrTruck != NULL); EXPECT_TRUE(sim.sendFireTrucks()); EXPECT_TRUE(ptrTruck->isAtEntranceDepot()); EXPECT_TRUE(ptrHouse->isFireTruckAssigned()); EXPECT_EQ(Point(2, 1), ptrTruck->getDestination()); EXPECT_NO_FATAL_FAILURE(sim.drive()); EXPECT_EQ(Point(4, 2), ptrTruck->getPosition()); EXPECT_NO_FATAL_FAILURE(sim.drive()); EXPECT_EQ(Point(3, 2), ptrTruck->getPosition()); EXPECT_NO_FATAL_FAILURE(sim.drive()); EXPECT_EQ(Point(2, 2), ptrTruck->getPosition()); EXPECT_NO_FATAL_FAILURE(sim.drive()); EXPECT_EQ(Point(2, 1), ptrTruck->getPosition()); EXPECT_TRUE(ptrTruck->isArrived()); EXPECT_NO_FATAL_FAILURE(sim.drive()); EXPECT_EQ(ptrDepot->getEntrance(), ptrTruck->getDestination()); EXPECT_FALSE(ptrHouse->isBurning()); EXPECT_FALSE(ptrHouse->isFireTruckAssigned()); EXPECT_NO_FATAL_FAILURE(sim.repairBuildings()); EXPECT_EQ(1.5, ptrHouse->getHealth()); EXPECT_NO_FATAL_FAILURE(sim.fireBreaksOut()); EXPECT_NO_FATAL_FAILURE(sim.fireBreaksOut()); EXPECT_TRUE(ptrHouse->isBurning()); EXPECT_TRUE(ptrDepot->isBurning()); EXPECT_NO_FATAL_FAILURE(sim.drive()); EXPECT_EQ(Point(2, 2), ptrTruck->getPosition()); EXPECT_NO_FATAL_FAILURE(sim.drive()); EXPECT_EQ(Point(3, 2), ptrTruck->getPosition()); EXPECT_NO_FATAL_FAILURE(sim.drive()); EXPECT_EQ(Point(4, 2), ptrTruck->getPosition()); EXPECT_NO_FATAL_FAILURE(sim.drive()); EXPECT_EQ(Point(4, 3), ptrTruck->getPosition()); EXPECT_TRUE(ptrTruck->isAtEntranceDepot()); EXPECT_TRUE(ptrTruck->isArrived()); EXPECT_NO_FATAL_FAILURE(sim.burningDown()); EXPECT_EQ(0.5, ptrHouse->getHealth()); EXPECT_EQ(-1, ptrDepot->getHealth()); EXPECT_TRUE(ptrDepot->isDead()); EXPECT_FALSE(ptrDepot->isBurning()); EXPECT_NO_FATAL_FAILURE(sim.drive()); EXPECT_TRUE(ptrTruck->isAtEntranceDepot()); EXPECT_NO_FATAL_FAILURE(sim.burningDown()); EXPECT_EQ(-0.5, ptrHouse->getHealth()); EXPECT_EQ(-1, ptrDepot->getHealth()); EXPECT_TRUE(sim.endSimulation()); }
TEST_F(SimulatorTest, robbing) { Shop appleStore(Point(0, 1), Size(2), 1, 2); Street verticalLeft("VerticalLeft", Point(2, 2), Point(2, 1)); Street horizontal("Horizontal", Point(2, 2), Point(4, 2)); Street verticalRight("VerticalRight", Point(4, 3), Point(4, 2)); ASSERT_TRUE(ptrCity->add(appleStore)); ASSERT_TRUE(ptrCity->add(horizontal)); ASSERT_TRUE(ptrCity->add(verticalLeft)); ASSERT_TRUE(ptrCity->add(verticalRight)); Simulator sim(ptrCity, ptrOutput); Shop* ptrShop = ptrCity->getShops()[0]; ASSERT_TRUE(ptrShop != NULL); EXPECT_TRUE(sim.commitRob()); EXPECT_TRUE(ptrShop->isRobbing()); EXPECT_EQ(2, ptrShop->getSecurity()); EXPECT_TRUE(sim.robbing()); EXPECT_TRUE(ptrShop->isRobbing()); EXPECT_EQ(1, ptrShop->getSecurity()); EXPECT_FALSE(sim.sendPoliceTrucks()); // oh, there isn't even a policedepot // now build a policedepot PoliceDepot newDepot(Point(4, 7), Point(4, 3), Size(4), "Policedepot", 1); ASSERT_TRUE(ptrCity->add(newDepot)); PoliceDepot* ptrDepot = ptrCity->findPoliceDepot("Policedepot"); ASSERT_TRUE(ptrDepot != NULL); EXPECT_FALSE(sim.sendFireTrucks()); // oh, there isn't even a policetruck // add a policetruck PoliceTruck newTruck("Truck", ptrDepot); ASSERT_TRUE(ptrCity->add(newTruck)); PoliceTruck* ptrTruck = ptrCity->getPoliceTrucks()[0]; ASSERT_TRUE(ptrTruck != NULL); EXPECT_TRUE(sim.sendPoliceTrucks()); EXPECT_TRUE(ptrTruck->isAtEntranceDepot()); EXPECT_TRUE(ptrShop->isPoliceTruckAssigned()); EXPECT_EQ(Point(2, 1), ptrTruck->getDestination()); EXPECT_TRUE(sim.drive()); EXPECT_EQ(Point(4, 2), ptrTruck->getPosition()); EXPECT_TRUE(sim.drive()); EXPECT_EQ(Point(3, 2), ptrTruck->getPosition()); EXPECT_TRUE(sim.drive()); EXPECT_EQ(Point(2, 2), ptrTruck->getPosition()); EXPECT_TRUE(sim.drive()); EXPECT_EQ(Point(2, 1), ptrTruck->getPosition()); EXPECT_TRUE(ptrTruck->isArrived()); EXPECT_TRUE(sim.drive()); EXPECT_EQ(ptrDepot->getEntrance(), ptrTruck->getDestination()); EXPECT_FALSE(ptrShop->isRobbing()); EXPECT_FALSE(ptrShop->isPoliceTruckAssigned()); EXPECT_FALSE(sim.robbing()); EXPECT_FALSE(ptrShop->isRobbing()); EXPECT_TRUE(sim.commitRob()); EXPECT_TRUE(ptrShop->isRobbing()); EXPECT_TRUE(sim.robbing()); EXPECT_FALSE(ptrShop->isRobbing()); EXPECT_TRUE(sim.fireBreaksOut()); EXPECT_TRUE(sim.fireBreaksOut()); EXPECT_TRUE(ptrDepot->isBurning()); EXPECT_TRUE(ptrShop->isBurning()); EXPECT_NO_FATAL_FAILURE(sim.drive()); EXPECT_EQ(Point(2, 2), ptrTruck->getPosition()); EXPECT_NO_FATAL_FAILURE(sim.drive()); EXPECT_EQ(Point(3, 2), ptrTruck->getPosition()); EXPECT_NO_FATAL_FAILURE(sim.drive()); EXPECT_EQ(Point(4, 2), ptrTruck->getPosition()); EXPECT_NO_FATAL_FAILURE(sim.drive()); EXPECT_EQ(Point(4, 3), ptrTruck->getPosition()); EXPECT_TRUE(ptrTruck->isAtEntranceDepot()); EXPECT_TRUE(ptrTruck->isArrived()); EXPECT_TRUE(sim.drive()); EXPECT_TRUE(ptrTruck->isAtEntranceDepot()); EXPECT_TRUE(sim.burningDown()); EXPECT_EQ(-1, ptrShop->getHealth()); EXPECT_EQ(-1, ptrDepot->getHealth()); EXPECT_TRUE(ptrDepot->isDead()); EXPECT_FALSE(ptrDepot->isBurning()); EXPECT_TRUE(ptrShop->isDead()); EXPECT_TRUE(sim.endSimulation()); }
KFR_MEM_INTRINSIC Tout get() { return internal::reduce_call_final(finalfn, counter, horizontal(value, reducefn)); }
int ext_setup() { extern char *null_ptr; WINDOW *ext_win, *newwin(); int i, ret_code; char *str, *get_str(); void disp_ext(); ext_win = newwin(23, 80, 0, 0); horizontal(ext_win, 0, 0, 27); mvwattrstr(ext_win, 0, 28, A_BOLD, "External Protocol Setup"); horizontal(ext_win, 0, 52, 27); mvwaddstr(ext_win, 3, 36, "UPLOAD"); mvwaddstr(ext_win, 5, 8, "Name"); mvwaddstr(ext_win, 5, 21, "Command line"); mvwaddstr(ext_win, 5, 54, "Requires file list?"); mvwaddstr(ext_win, 10, 35, "DOWNLOAD"); mvwaddstr(ext_win, 12, 8, "Name"); mvwaddstr(ext_win, 12, 21, "Command line"); mvwaddstr(ext_win, 12, 54, "Requires file list?"); /* display the current list */ disp_ext(ext_win); horizontal(ext_win, 19, 0, 80); mvwattrstr(ext_win, 20, 0, A_BOLD, "OPTION ==> "); mvwaddstr(ext_win, 20, 58, "Press <ESC> to return"); wmove(ext_win, 20, 12); touchwin(ext_win); wrefresh(ext_win); /* get the option */ ret_code = 0; while ((str = get_str(ext_win, 1, "1234356", "")) != NULL) { switch(*str) { case '1': if (ext_prompt(ext_win, 1, 0, 6)) ret_code++; break; case '2': if (ext_prompt(ext_win, 1, 1, 7)) ret_code++; break; case '3': if (ext_prompt(ext_win, 1, 2, 8)) ret_code++; break; case '4': if (ext_prompt(ext_win, 0, 0, 13)) ret_code++; break; case '5': if (ext_prompt(ext_win, 0, 1, 14)) ret_code++; break; case '6': if (ext_prompt(ext_win, 0, 2, 15)) ret_code++; break; } mvwaddstr(ext_win, 20, 12, " "); clear_line(ext_win, 21, 0, FALSE); clear_line(ext_win, 22, 0, FALSE); wmove(ext_win, 20, 12); wrefresh(ext_win); } /* * Recalculate the number of entries. Please notice that if you * create an empty entry (a hole), all entries after that are ignored. * The software doesn't compact the holes out.. you're on your own. */ if (ret_code) { for (i=0; i<3; i++) { if (extrnl->name[1][i] == null_ptr) break; } extrnl->up_entries = i; for (i=0; i<3; i++) { if (extrnl->name[0][i] == null_ptr) break; } extrnl->dn_entries = i; } delwin(ext_win); return(ret_code); }
int Fl_Slider::handle(int event, int x, int y, int w, int h) { switch (event) { case FL_FOCUS: case FL_UNFOCUS: redraw(FL_DAMAGE_ALL); return 1; case FL_PUSH: redraw(FL_DAMAGE_HIGHLIGHT); handle_push(); case FL_DRAG: { // figure out the space the slider moves in and where the event is: int mx; if (horizontal()) { w = w-box()->dw(); mx = Fl::event_x()-x-box()->dx(); } else { w = h-box()->dh(); mx = Fl::event_y()-y-box()->dy(); } if (w <= slider_size_) return 1; static int offcenter; int X = slider_position(value(), w); if (event == FL_PUSH) { offcenter = mx-X; // we are done if they clicked on the slider: if (offcenter >= (slider_size() ? 0 : -8) && offcenter <= slider_size_) return 1; if (Fl::event_button() > 1) { // Move the near end of the slider to the cursor. This is good // for scrollbars. offcenter = (offcenter < 0) ? 0 : slider_size_; } else { // Center the slider under the cursor, what most toolkits do offcenter = slider_size_/2; } } double v; RETRY: X = mx-offcenter; if (X < 0) { X = 0; offcenter = mx; if (offcenter < 0) offcenter = 0; } else if (X > (w-slider_size_)) { X = w-slider_size_; offcenter = mx-X; if (offcenter > slider_size_) offcenter = slider_size_; } v = position_value(X, w); handle_drag(v); // make sure a click outside the sliderbar moves it: if (event == FL_PUSH && value() == previous_value()) { offcenter = slider_size_/2; event = FL_DRAG; goto RETRY; } return 1; } case FL_RELEASE: handle_release(); redraw(FL_DAMAGE_HIGHLIGHT); return 1; case FL_KEY: // Only arrows in the correct direction are used. This allows the // opposite arrows to be used to navigate between a set of parellel // sliders. switch (Fl::event_key()) { case FL_Up: case FL_Down: if (horizontal()) return 0; break; case FL_Left: case FL_Right: if (!horizontal()) return 0; } default: return Fl_Valuator::handle(event); } }