/* * InventoryClick: User clicked on inventory box. * Return True iff processing of click should continue. */ Bool InventoryClick(HWND hwnd, BOOL fDoubleClick, int x, int y, UINT keyFlags) { int row, col, old_row, old_col, index; InvItem *item; // Find row and col in absolute coordinates col = x / INVENTORY_BOX_WIDTH; row = top_row + y / INVENTORY_BOX_HEIGHT; switch (GameGetState()) { case GAME_PLAY: SetFocus(hwnd); if (!InventoryItemVisible(row, col)) return False; old_row = cursor_row; old_col = cursor_col; cursor_row = row; cursor_col = col; // Redraw cursor if (InventoryItemVisible(old_row, old_col)) { item = (InvItem *) list_nth_item(items, old_row * cols + old_col); if (item != NULL) InventoryDrawSingleItem(item, old_row - top_row, old_col); } item = (InvItem *) list_nth_item(items, cursor_row * cols + cursor_col); if (item != NULL) InventoryDrawSingleItem(item, cursor_row - top_row, cursor_col); break; case GAME_SELECT: if (InventoryItemVisible(row, col)) { /* User clicked on an object--get its id */ index = row * cols + col; item = (InvItem *) list_nth_item(items, index); if (item != NULL) SelectedObject(item->obj->id); } return False; } return True; }
bool InteractScene::penUp( const OFX::PenArgs& args ) { //TUTTLE_LOG_TRACE("penUp"); bool result = false; if( _creatingSelection ) { _selectionRect.x2 = args.penPosition.x; _selectionRect.y2 = args.penPosition.y; _selected.clear(); //TUTTLE_LOG_VAR4( TUTTLE_TRACE, _selectionRect.x1, _selectionRect.y1, _selectionRect.x2, _selectionRect.y2 ); IsActiveFunctorVector::iterator itActive = _isActive.begin(); for( InteractObjectsVector::iterator it = _objects.begin(), itEnd = _objects.end(); it != itEnd; ++it, ++itActive ) { if( ! itActive->active() ) continue; if( it->isIn( _selectionRect ) ) { it->setSelected(true); _selected.push_back( SelectedObject( &(*it), it->getPosition() ) ); _hasSelection = true; result = true; } else { it->setSelected(false); } } //TUTTLE_LOG_VAR( TUTTLE_TRACE, _selected.size() ); _creatingSelection = false; } _mouseDown = false; _creatingSelection = false; _params.endEditBlock(); return result; }
/* * InventoryKey: User pressed a key on the inventory list. * Return True iff key should NOT be passed on to Windows for default processing. */ Bool InventoryKey(HWND hwnd, UINT key, Bool fDown, int cRepeat, UINT flags) { ID id; Bool held_down = (flags & 0x4000) ? True : False; /* Is key being held down? */ int action, params; InvItem *item; void *action_data; Bool inform; UserDidSomething(); /* See if inventory handles this key specially */ action = TranslateKey(key, inventory_key_table, &action_data); if (action == A_NOACTION) return False; // Skip held-down keys, except for moving cursor around if (held_down && !IsCursorAction(action)) return True; item = InventoryGetCurrentItem(); if (item == NULL) id = INVALID_ID; else id = item->obj->id; // See if we should inform modules about event inform = True; switch (action) { case A_TABFWD: case A_TABBACK: case A_TOGGLEUSE: case A_USE: case A_UNUSE: case A_DROP: case A_APPLY: case A_LOOKINVENTORY: case A_SELECT: action_data = (void *) id; break; default: inform = False; // Modules will be informed in PerformAction call below } // See if a module wants to handle this action if (inform) if (ModuleEvent(EVENT_USERACTION, action, action_data) == False) return True; if (IsCursorAction(action)) { InventoryCursorMove(action); return True; } switch (action) { case A_TABFWD: TextInputSetFocus(True); // ajw //StatsSetFocus(True); break; case A_TABBACK: SetFocus(cinfo->hMain); break; case A_TOGGLEUSE: if (id != INVALID_ID) { if (item->obj->flags & OF_APPLYABLE) StartApply(id); else ToggleUse(id); } break; case A_USE: if (id != INVALID_ID) RequestUse(id); break; case A_UNUSE: if (id != INVALID_ID) RequestUnuse(id); break; case A_DROP: if (id != INVALID_ID) InventoryDropCurrentItem(NULL); break; case A_APPLY: if (id != INVALID_ID) StartApply(id); break; case A_LOOKINVENTORY: if (id == INVALID_ID) break; params = DESC_DROP; if (item->is_using) params |= DESC_UNUSE; else if (item->obj->flags & OF_APPLYABLE) params |= DESC_APPLY; else params |= DESC_USE; SetDescParams(cinfo->hMain, params); RequestLook(id); break; case A_SELECT: if (id != INVALID_ID) SelectedObject(id); break; default: PerformAction(action, action_data); break; } return True; }
bool InteractScene::penDown(const OFX::PenArgs& args) { // TUTTLE_LOG_TRACE("penDown"); const Point2 penPosition = ofxToGil(args.penPosition); _mouseDown = true; _beginPenPosition = penPosition; _selectionRect.x1 = args.penPosition.x; _selectionRect.y1 = args.penPosition.y; _selectionRect.x2 = args.penPosition.x; _selectionRect.y2 = args.penPosition.y; _motionType._mode = eMotionNone; _motionType._axis = eAxisNone; bool result = false; SelectedObject oneSelectedObj; if(_hasSelection && _manipulator) { _motionType = _manipulator->intersect(args); if(_motionType._mode != eMotionNone) { result = true; } } if(!result) { IsActiveFunctorVector::iterator itActive = _isActive.begin(); for(InteractObjectsVector::iterator it = _objects.begin(), itEnd = _objects.end(); it != itEnd; ++it, ++itActive) { if(!itActive->active()) continue; MotionType m = it->intersect(args); if(m._axis != eAxisNone) { // first time if(_motionType._axis == eAxisNone) { oneSelectedObj = SelectedObject(&(*it), it->getPosition()); _motionType = m; } else if(m._axis == eAxisXY) // if we already register an object X or Y and we found an XY intersection { oneSelectedObj = SelectedObject(&(*it), it->getPosition()); _motionType = m; } result = true; if(m._axis == eAxisXY) break; } } } if(_hasSelection) { if(result) { bool objInSelection = false; // compute the offset for each object for(SelectedObjectVector::iterator it = _selected.begin(), itEnd = _selected.end(); it != itEnd; ++it) { it->second = it->first->getPosition(); if(it->first == oneSelectedObj.first) { objInSelection = true; } } if(!objInSelection) { _hasSelection = false; } } else { _hasSelection = false; } } if(!_hasSelection) { for(InteractObjectsVector::iterator it = _objects.begin(), itEnd = _objects.end(); it != itEnd; ++it) { it->setSelected(false); } _selected.clear(); if(result) { _selected.push_back(oneSelectedObj); } } if(_multiSelectionEnabled) { if(!result) { _hasSelection = false; _creatingSelection = true; } } if(_multiSelectionEnabled || result) { _params.beginEditBlock("InteractObjectsGroup"); return true; } return false; }