コード例 #1
0
/* Reacts to a mouse event in the window. */
static void processMouseEvent(State& state, GMouseEvent e) {
  switch (state.uiState) {
    /* Already have something drawn?  Clear it and pretend we're fresh. */
    case DRAWN:
      restoreWorldDisplay();
      state.uiState = FRESH;
      /* deliberate: don't break. */

    /* In a fresh state?  Try to select what the user clicked on. */
    case FRESH:
      if (registerClick(state.world, e.getX(), e.getY(),
                        state.worldType)) {
        state.uiState = MARKED;
      }
      break;

      /* Already marked?  Try to select what the user clicked on, then
       * try to find a path if it worked.
       */
    case MARKED:
      if (registerClick(state.world, e.getX(), e.getY(),
                        state.worldType)) {
				runSearch(state);
        state.uiState = DRAWN;
      }
  }
}
コード例 #2
0
ファイル: fauxtoshop.cpp プロジェクト: chuzui/courses
/* STARTER CODE HELPER FUNCTION - DO NOT EDIT
 *
 * Waits for a mouse click in the GWindow and reports click location.
 *
 * When this function returns, row and col are set to the row and
 * column where a mouse click was detected.
 */
static void getMouseClickLocation(int &row, int &col) {
    GMouseEvent me;
    do {
        me = getNextEvent(MOUSE_EVENT);
    } while (me.getEventType() != MOUSE_CLICKED);
    row = me.getY();
    col = me.getX();
}
コード例 #3
0
GPoint getMouseClick() {
   while (true) {
      GMouseEvent e;
      waitForEvent(e);
      if (e.getEventType() == MOUSE_CLICKED) {
      	 return GPoint(e.getX(), e.getY());
      }
   }
   return GPoint();
}
コード例 #4
0
void pathfinderEventLoop() {
   while (true) {
      GMouseEvent e;
      waitForEvent(e);
      if (e.getEventType() == MOUSE_CLICKED) {
         int index = findButtonIndex(e.getX(), e.getY());
         if (index == -1) {
            GPoint pt = GPoint(e.getX(), e.getY());
            if (pt.getY() < WINDOW_HEIGHT && clickHook != NULL) {
               clickHook->apply(pt);
               repaint();
            }
         } else {
            buttons[index].callback->apply();
            repaint();
	 }
      }
   }
}
コード例 #5
0
/*
 * (public function)
 * Reacts to a mouse event in the window.
 */
void processMouseEvent(GMouseEvent e) {
    if (e.getEventType() == MOUSE_CLICKED) {
        switch (state.uiState) {
        case DRAWN:
            // Already have something drawn?  Clear it and pretend we're fresh.
            restoreWorldDisplay();
            state.uiState = FRESH;
        // deliberate: don't break.

        case FRESH:
            // In a fresh state?  Try to select what the user clicked on.
            if (registerClick(state.world, e.getX(), e.getY(), state.worldType)) {
                state.uiState = MARKED;
            }
            break;

        case MARKED:
            // Already marked?  Try to select what the user clicked on, then
            // try to find a path if it worked.
            if (registerClick(state.world, e.getX(), e.getY(),
                              state.worldType)) {
                runSearch(state);
                state.uiState = DRAWN;
            }
        }
    } else if (e.getEventType() == MOUSE_MOVED) {
        // update display of current mouse row/col position to aid testing
        TBLoc loc = coordToLoc(e.getX(), e.getY());
        if (state.world.inBounds(loc.row, loc.col)) {
            string newPositionText = vertexName(loc.row, loc.col, state.world);
            if (newPositionText != gPositionFieldText) {
                gPositionFieldText = newPositionText;
                gPositionField->setText(newPositionText);
            }
        }
    }
}
コード例 #6
0
ファイル: marblegraphics.cpp プロジェクト: MoonighT/CS106B
bool MarbleGraphics::getNextUserMove(Move& move) {
    GMouseEvent me;
    bool startClick = true;
    while (true) {
        me = getNextEvent(MOUSE_EVENT);
        if (me.getEventType() == MOUSE_CLICKED) {
            GObject* obj = getGObjectAt(me.getX(),me.getY());
            if (obj == NULL) {
                startClick = true;
                errorNotification();
            }
            // User clicked in SOLVE button
            else if (obj->getType() == "GRoundRect" || obj->getType() == "GLabel"){
                return false;
            }
            // User clicked in MARBLE
            else if (obj->getType() == "GImage") {
                // First click = starting location
                if (startClick) {
                    move.startRow = marbleCoords[(GImage*)obj].row;
                    move.startCol = marbleCoords[(GImage*)obj].col;
                    //If click on visible marble (Flash it to show selection detected)
                    if(((GImage*)obj)->isVisible()){
                        ((GImage*) obj)->setVisible(false);
                        pause(50);
                        ((GImage*) obj)->setVisible(true);
                    }
                    startClick = false;
                }
            }
            //User clicked in empty valid space on playing board
            else if (obj->getType() == "GOval"){
                // Second click = ending location
                if (!startClick) {
                    move.endRow = spaceCoords[(GOval*)obj].row;
                    move.endCol = spaceCoords[(GOval*)obj].col;
                    return true;
                }
            }
        }
    }
    return false;
}