Beispiel #1
0
//Mouse Function
void mouse(int btn, int state, int x, int y)
{
	if ((btn == GLUT_LEFT_BUTTON ) && (state == GLUT_DOWN)) 
	{
		toggleCell(x, glutGet(GLUT_WINDOW_HEIGHT) - y);
	}
}
Beispiel #2
0
void MainWindow::cellClicked(int index)
{
  if(!start && (isGameOver() || lcd->intValue() == 0))
  {
    if(soundaction->isChecked())
      clicksound->play();
    blink(index);
  }
  else
  {
    if(soundaction->isChecked())
      turnsound->play();

    //qApp->processEvents(QEventLoop::ExcludeUserInputEvents);
    Cell* cell = board[index];
    toggleCell(cell);
    toggleCell(lCell(cell));
    toggleCell(rCell(cell));
    toggleCell(uCell(cell));
    toggleCell(ulCell(cell));
    toggleCell(urCell(cell));
    toggleCell(dCell(cell));
    toggleCell(dlCell(cell));
    toggleCell(drCell(cell));

    //qApp->processEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::WaitForMoreEvents);

    if(soundaction->isChecked())
      connectsound->play();

    if (!start) lcd->display(lcd->intValue() - 1);
    cellsLcd->display(cellsCount());

    if(isGameOver() && !start)
    {
      if(soundaction->isChecked())
        winsound->play();
      blink(index);    
      if(lcd->intValue() <= highscores.at(2 * (skill + 1) * NumHighscores - 1).toInt())
        addHighscore(lcd->intValue());
                   QMessageBox::information(this,tr("Game Over"),tr("Congratulations! Score %1").arg(lcd->intValue()));
    }
  }
}
Beispiel #3
0
void MVListBase::handleEvent(MVEvent& event,phaseType phase)
/****************************************************************************
*
* Function:     MVListBase::handleEvent
* Parameters:   event   - Event to handle
*               phase   - Current phase for the event (pre,focus,post)
*
* Description:  Event handling mechanism for the MVListBase class.
*
****************************************************************************/
{
    MVView::handleEvent(event,phase);

    switch (event.what) {
        case evMouseDown:
            if (range.isEmpty())
                return;

            if (event.mouse.buttons & mbLeftButton) {
                while (event.what != evMouseUp) {
                    switch (event.what) {
                        case evMouseDown:
                            if (!(event.mouse.modifiers & mdShift)
                                    && !(flags & lsDisjointSelect)) {
                                clearSelection();
                                selectCell(cursor);
                                refresh();
                                }
                            if (event.mouse.doubleClick) {
                                MV_message(owner,evBroadcast,cmListItemSelected,this);
                                goto doneMouse;
                                }
                        case evMouseAuto:
                        case evMouseMove:
                            MVPoint loc;
                            uint    modifiers = mdShift;

                            if (event.what == evMouseDown)
                                modifiers = event.mouse.modifiers;
                            if (flags & lsDisjointSelect)
                                modifiers = 0;

                            uint pos = findCellHit(event.where,loc);
                            if (pos == lsInside && event.what != evMouseAuto) {
                                // Selection within the list
                                if (loc == cursor && event.what == evMouseDown) {
                                    // Post a message to ensure updates
                                    // occur for the first mouse down event
                                    // in the list box.
                                    MV_message(owner,evBroadcast,
                                        cmListCursorChanged,this);
                                    }

                                if (loc.x < cursor.x)
                                    selectLeft(cursor.x - loc.x,modifiers);
                                else if (loc.x > cursor.x)
                                    selectRight(loc.x - cursor.x,modifiers);

                                if (loc.y < cursor.y)
                                    selectUp(cursor.y - loc.y,modifiers);
                                else if (loc.y > cursor.y)
                                    selectDown(loc.y - cursor.y,modifiers);
                                }
                            else if (event.what == evMouseAuto) {
                                // Auto selection outside window to scroll
                                if (pos & lsAbove)
                                    selectUp(1,modifiers);
                                if (pos & lsBelow)
                                    selectDown(1,modifiers);
                                if (pos & lsLeft)
                                    selectLeft(1,modifiers);
                                if (pos & lsRight)
                                    selectRight(1,modifiers);
                                }
                            if (event.what == evMouseDown
                                    && flags & lsDisjointSelect) {
                                toggleCell(cursor);
                                refresh();
                                }
                            break;
                        }
                    getEvent(event);
                    }

doneMouse:
                clearEvent(event);
                }
            break;
        case evKeyDown:
        case evKeyAuto:
            if (range.isEmpty())
                return;

            switch (event.key.charScan.scanCode) {
                case kbSpace:
                    if (event.what == evKeyAuto)
                        break;
                    if (flags & lsDisjointSelect) {
                        toggleCell(cursor);
                        refresh();
                        }
                    break;
                case kbLeft:
                    selectLeft(1,event.key.modifiers);
                    break;
                case kbRight:
                    selectRight(1,event.key.modifiers);
                    break;
                case kbUp:
                    selectUp(1,event.key.modifiers);
                    break;
                case kbDown:
                    selectDown(1,event.key.modifiers);
                    break;
                case kbHome:
                    selectNext(lsLeft | lsAbove,range.bottom(),
                        event.key.modifiers);
                    break;
                case kbEnd:
                    selectNext(lsRight | lsBelow,range.bottom(),
                        event.key.modifiers);
                    break;
                case kbPgUp:
                    selectUp(visible.bottom()-visible.top(),
                        event.key.modifiers,true);
                    break;
                case kbPgDn:
                    selectDown(visible.bottom()-visible.top(),
                        event.key.modifiers,true);
                default:
                    // Key press is not handled by us, so simply return.
                    return;
                }
            clearEvent(event);
            break;
        case evBroadcast:
            if (options & ofSelectable) {
                if (event.message.command == cmScrollBarClicked &&
                        (event.message.infoPtr == hScroll ||
                         event.message.infoPtr == vScroll))
                    select();
                else if (event.message.command == cmScrollBarChanged) {
                    if (range.isEmpty())
                        return;
                    if (event.message.infoPtr == hScroll)
                        hScrollTo(hScroll->getValue());
                    else if (event.message.infoPtr == vScroll)
                        vScrollTo(vScroll->getValue());
                    }
                }
            break;
        }
}