This is BetView.rtf in view mode; [Download] [Up]
BetView Inherits From: View : Responder : Object Conforms To: NXDraggingSource (Informal) NXDraggingDestination Declared In: BetView.h Class Description Instances of this class provide a visual representation of chips on the table. Users can simply mouse-down on a BetView to place bets. However, the decision on when this is allowed and what happens as a result are left to the BetView's delegate. BetViews are sort of a cross between a View and Matrix, where the cells of the Matrix are ChipPiles (see the documentation on the ChipPile class for more information). BetViews arrange their chips in a four column by one row matrix. You can change the number of rows and columns, and you can change the position of each chip individually. Currently, BetViews only allow a matrix of 4 by 4. Perhaps future versions of BetView will allow larger matrices, if necessary. Each chip position can have its own payout set, which makes paying off bets very simple. Use the setPayoff methods and the payBet methods to set and pay bets, respectively. There are a zillion ways to modify the bets within a BetView. I have tried to anticipate any action you may want to perform on a BetView. There are methods to copy all bets from one BetView to another BetView, to swap bets, multipy bets, increment bets, clear bets, collect bets, etc. It should be sufficient. When a user mouses down in a BetView, it sends its delegate the player:willBet:onView: message. It is then the delegate's responsibility to interpret the user's action and to make place the bet with the BetView. You can give a BetView an identity either by setting its tag, or its viewType or both. NEXTVegas modules should definately use BetView's whenever they need to display and have the user interact with bets. I would like to keep a constant interface across all NVModules. If the current incarnation of the BetView class does not do everything that you need, please let me know so we can modify it together. Any modules that use the BetView class now will automatically be enhanced with the next version of NEXTVegas. Instance Variables id delegate id tableWindow id displayFont int tag int viewType int numPositions struct NVChips chipMatrix[MAX_POSITIONS] BOOL isEnabled BOOL doSound id chipSound BOOL trackingRectWasSet id draggingPBoard delegate The object's delegate. tableWindow The window that will display the BetView. displayFont The font used inside each chip. tag The BetView's tag. viewType User defined type. numCols Number of columns displayed in the view. numRows Number of rows displayed in the view. chipMatrix Matrix of NVChip structures, which hold chip positions, color, and amounts, etc. isEnabled If YES, BetView responds to mouseDown and drag and drop messages. doSound If YES, BetView plays chipSound when it receives mouseDown messages. chipSound The SoundEffect object played by BetView. trackingRectWasSet If YES, BetView will remove its tracking rectangle when it is freed. draggingPBoard The Pasteboard object that the BetView uses when dragging ChipPiles. Adopted Protocols NXDraggingSource (Informal) - draggingSourceOperationMaskForLocal: - draggedImage:beganAt: - draggedImage:endedAt:deposited: - ignoreModifierKeysWhileDragging: NXDraggingDestination - prepareForDragOperation: - draggingEntered: - performDragOperation: Method Types Initializing the class + initialize Creating and freeing ± free ± initFrame: Managing related objects ± delegate ± setDelegate: ± chipPileAtRow:col: Getting info from the BetView + BetViewPBoardType + dragTypes ± amountAtRow:col: ± getChipPosition::atRow:col: ± getPayoff:atRow:col ± numRows ± numCols ± isEnabled: ± isSoundEnabled: ± tag ± viewType Displaying the BetView ± setChipPosition::atRow:col: ± setChipColumn:atCol: ± setChipRow:atRow: ± setNumCols: ± setNumRows: ± positionChips ± positionColumns ± positionRows Placing Bets ± bet:atRow:col: ± removeBet:atRow:col: ± switchOnOffAtRow:col: Paying Off Bets ± clearBets ± clearBetAtRow:col: ± clearBetsAtRow: ± clearBetsAtColumn: ± collectBets ± collectBetAtRow:col: ± payBets ± payBetAtRow:col: ± setPayoff:cost: ± setPayoff:cost:atRow:col: Modifying Bets Within BetView ± addBetsFrom: ± copyBetsFrom: ± getBetsFrom: ± incrementBetsBy: ± incrementBetAtRow:col:by: ± incrementBetsAtRow:by: ± incrementBetsAtCol:by: ± multiplyBetsBy: ± multiplyBetAtRow:col:by: ± multiplyBetsAtRow:by: ± multiplyBetsAtCol:by: ± setOff:atRow:col: ± sumColumnsToRow: ± tradeBetsWith: Responder methods ± mouseDown: ± mouseEntered: ± mouseExited: Utility methods ± getRow:andCol:underPoint: ± offsetRow:by: ± setEnabled: ± setSoundEnabled: ± setTag: ± setViewType: ± setTrackingRectForWindow: ± discardTrackingRect Class Methods initialize + initialize Initializes the class object. Returns self. See also: + initialize (Object) BetViewPBoardType + (NXAtom *)BetViewPBoardType Returns the name of the PasteBoard object used by BetView. dragTypes + (const char *const*)dragTypes Returns a pointer to the drag types that BetView's pasteboard allows. Instance Methods addBetsFrom: - addBetsFrom:otherView Removes the bets from otherView and adds them to the receiving BetView. Re-displays itself and returns self. amountAtRow:col: - (int)amountAtRow:(int)r col:(int)c Returns the integer amount bet at row r and column c. bet:atRow:col: - bet:(int)units atRow:(int)r col:(int)c Adds units to the bet at row r and column c. Re-displays itself, plays a chip sound if sound is enabled, and returns self. See also: - removeBet:atRow:col: chipPileAtRow:col: - chipPileAtRow:(int)row col:(int)col Returns the id of the instance of ChipPile at row row and column col. clearBets - clearBets Removes the bets at each position, unless the bet has been turned "off". Re-displays the view. Returns self. See also: - clearBetsAtRow:col: clearBetAtRow:col: - clearBetAtRow:(int)r col:(int)c Removes the bet at row r and column c, unless the bet has been turned "off". Does not re-display itself. Returns self. See also: - clearBets clearBetsAtColumn: - clearBetsAtColumn:(int)c Removes the bets at column c, unless they have been turned "off". Re-displays itself and returns self. See also: - clearBetsAtRow: clearBetsAtRow: - clearBetsAtRow:(int)r Removes the bets at row r, unless they have been turned "off". Re-displays itself and returns self. See also: - clearBetsAtColumn: copyBetsFrom: - copyBetsFrom:otherView Replaces the receiving BetView's bets with those from otherView. Does not remove otherView's bets. Does not redisplay the view. Returns self. See also: collectBets - (int)collectBets Removes all bets within the BetView, and returns their total amount. Re-displays itself. See also: - collectBetAtRow:col: collectBetAtRow:col: - (int)collectBetAtRow:(int)r col:(int)c Removes the amount bet at row r and column c, and returns that amount. Re-displays itself. See also: -collectBets delegate - delegate Returns the object's delegate, or nil if it has none. See also: ± setDelegate: discardTrackingRect - discardTrackingRect Removes the trackingRect set for this view if it was previously set with setTrackingRectForWindow: See also: ± setTrackingRectForWindow: drawSelf: - drawSelf:(NXRect *)theRect :(int)rectCount Draws a visual representation of our BetView. Use the display message, rather than calling this method directly. See also: ± display (View) free - free Frees all memory used by the BetView (including all NXImages), and frees the BetView itself. Returns nil. See also: ± initFrame: getBetsFrom: - getBetsFrom:otherView Replaces the receivers bets with those from otherView, and then clears otherView's bets. Returns self. getChipPosition::atRow:col: - getChipPosition:(float *)x :(float *)y atRow:(int)r col:(int)c Returns by reference the x and y values of the NXPoint used to display the chip at row r and column c. Returns self. See also: - setChipPosition::atRow:col: getPayoff:cost:atRow:col: - getPayoff:(int *)payoff cost:(int *)cost atRow:(int)r col:(int)c Returns by reference the cost and payoff used with the payBets method. Returns self. See also: - setPayoff:atRow:col:, - payBetAtRow:col: getRow:andCol:underPoint: - getRow:(int *)r andCol:(int *)c underPoint:(NXPoint *)mousePoint Returns by reference the row r and column c of the chip under the point mousePoint. Returns self. See also: - myReference incrementBetsBy: - incrementBetsBy:(int)amount Adds amount to all the bets in the BetView. Redisplays itself and returns self. See also: - incrementBetAtRow:col:by: incrementBetAtRow:col:by: - incrementBetAtRow:(int)r col:(int)c by:(int)amount Adds amount to the bet at row r and column c. Re-displays itself and returns self. See also: - incrementBetsBy: incrementBetsAtCol:by: - incrementBetsAtCol:(int)c by:(int)amount Adds amount to all the bets in column c. Redisplays itself and returns self. See also: - incrementBetsAtRow:by: incrementBetsAtRow:by: - incrementBetsAtRow:(int)r by:(int)amount Adds amount to all the bets in row r. Redisplays itself and returns self. See also: - incrementBetsAtColumn:by: initFrame: - initFrame:(const NXRect *)frameRect Initializes a newly allocated BetView instance. Returns self. See also: - incrementBetAtRow:col:by: isEnabled - (BOOL)isEnabled Returns YES if the BetView responds to mouseDown: and mouseEntered: events, NO if not. isSoundEnabled - (BOOL)isSoundEnabled Returns YES if the BetView plays sounds when bets are made or removed, NO if not. See also: mouseDown: - mouseDown:(NXEvent *)theEvent Finds out what kinds of control keys were pressed durring the event theEvent, and sends its delegate the message aPlayer:willBet:onView:, or initiates a dragging session. You should never call this method directly. Returns self. mouseEntered: - mouseEntered:(NXEvent *)theEvent Sends its delegate the mouseEnteredView: message. You should never call this method directly. Returns self. mouseExited: - mouseExited:(NXEvent *)theEvent Sends its delegate the mouseExistedView: message. You should never call this method directly. Returns self. multiplyBetsBy: - multiplyBetsBy:(float)amount Multiplies amount to all the bets in the BetView Redisplays itself and returns self. See also: - multiplyBetsAtRow:col:by: multiplyBetAtRow:col:by: - multiplyBetAtRow:(int)r col:(int)c by:(float)amount Multiplies amount to the bet at row r and column c. Redisplays itself and returns self. See also: - multiplyBetsBy: multiplyBetsAtCol:by: - multiplyBetsAtCol:(int)c by:(float)amount Multiplies amount to the bet at column c. Redisplays itself and returns self. See also: - multiplyBetsAtRow:by: multiplyBetsAtRow:by: - multiplyBetsAtRow:(int)r by:(float)amount Multiplies amount to the bet at row r. Redisplays itself and returns self. See also: - multiplyBetsAtCol:by: numCols - (int)numCols Returns the number of columns in the BetView. See also: - numRows numRows - (int)numRows Returns the number rows currently in the BetView. See also: - numCols payBets - payBets Pays all the bets in the Betview. Redisplays itself and returns self. See also: - payBetAtRow:col: payBetAtRow:col: - payBetAtRow:(int)r col:(int)c Increments the bet at row r and col c by the payoff and cost set with the setPayoff:cost... methods. Bets that are "off" are uneffected. Returns self If the amount of the bet is 10, and the payoff is 1 and cost is 1 (ie 1 for every 1 bet), then the new amount will be 20 (10*1/1+10). If the amount is 10, and the payoff is 2 and cost is 1 (ie 2 for every 1 bet), then the new amount will be 30. If the amount is 10, payoff 3 and cost 2 (ie 3 for every 2 bet), then the new amount will be 25. You get the idea... See also: - setPayoff:cost:, - setPayoff:cost:atRow:col: positionChips - positionChips Distributes the chips evenly across the view. The number of positions used is set through setNumRows: and setNumCols: methods. Will overwrite any positions set with setChipPositionAtRow:col:. Does not redisplay itself. Returns self. See also: - setNumRows:, - setNumCols: positionColumns - positionColumns Re-distributes the columns in the Betview evenly accross it, but leaves the row positions intact. Does not redisplay itself. Returns self. See also: - positionRows positionRows - positionRows Re-distributes the rows in the Betview evenly accross it, but leaves the column positions intact. Does not redisplay itself. Returns self. See also: - positionColumns removeBet:atRow:col: - removeBet:(int)units atRow:(int)r col:(int)c Removes units from the amount bet at row r and column c. If sound is enabled, will play a sound. Redisplays itself and returns self. See also: - bet:atRow:col: setChipColumn:atCol: - setChipColumn:(float)x atCol:(int)col Sets the x coordinates of the column col. Leaves the y coordinates intact. Does not redisplay itself. Returns self. See also: - setChipRow:atRow: setChipPosition::atRow:col: - setChipPosition:(float)x :(float)y atRow:(int)r col:(int)c Sets the x and y coordinates of the chip at row r and column c. Returns self. See also: - getChipPosition::atRow:col: setChipRow:atRow: - setChipRow:(float)y atRow:(int)row Sets the y coordinate of the chips at row row to y. Leaves the x coordinate intact. Returns self. See also: - setChipColumn:atCol: setNumCols: - setNumCols:(int)cols Sets the number of columns used in the BetView. By default, the BetView will display BV_MAXCOLS columns. Won't allow more than BV_MAXCOLS. Returns self. See also: - setNumRows: setNumRows: - setNumRows:(int)rows Sets the number of rows used in the BetView. By default, the BetView will display 1 row. Won't allow more than BV_MAXROWS. Returns self. See also: - setNumCols: setOff:atRow:col: - setOff:(BOOL)flag atRow:(int)r col:(int)c If flag is YES, turns the bet at row r and column c to "off", otherwise it turns it "on". Bets that are off won't be cleared with the clearBets* methods, and won't be incremented with the payBets* methods. Redisplays itself and returns self. setPayoff:cost: - setPayoff:(int)payoff cost:(int)cost Sets the payoff and cost for all rows and columns in the BetView Returns self. See also: - getPayoff:cost:atRow:col: setPayoff:cost:atRow:col: - setPayoff:(int)payoff cost:(int)cost atRow:(int)r col:(int)c Sets the payoff and cost for the bet at row r and column c. Returns self. See also: - getPayoff:cost:atRow:col: setDelegate: - setDelegate:anObject Sets the delegate for the BetView. Returns self. See also: Delegate methods below. setEnabled: - setEnabled:(BOOL)flag Set whether the BetView responds to any mouse events. Returns self. See also: ± isEnabled setSoundEnabled: - setSoundEnabled:(BOOL)flag Returns YES if sound is enabled, and NO if not. See also: - isSoundEnabled setTag: - setTag:(int)theTag Sets the view's tag. Returns self. See also: ± tag setTrackingRectForWindow: - setTrackingRectForWindow:aWindow Instructs the receiving view to set its tracking rectangle with the window aWindow. Returns self. See also: ± discardTrackingRect setViewType: - setViewType:(int)aType Sets the viewType instance variable to aType. aType can be any int you want it to be -- only your module will use it. Use this to create groups of BetViews. For example, Blackjack has insurance views and regular views. Returns self. See also: ± viewType sumColumnsToRow: - sumColumnsToRow:(int)r Totals all the bets in each column, and places those totals in row r. All bets except those in row r will be cleared. Redisplays itself and returns self. See also: - myReference switchBetOnOffAtRow:col: - switchBetOnOffAtRow:(int)r col:(int)c If the bet at row r and column c is off, this method will turn it on. If the bet is on, this method will turn it off. If sound is enabled, will play a sound. Redisplays itself. Returns self. See also: - myReference tag - (int)tag Returns the BetView's tag. See also: ± setTag: tradeBetsWith: - tradeBetsWith:otherView Receiver swaps its bets with those in otherView. Returns self. See also: viewType - viewType Returns the instance variable viewType, which was previously set with setViewType. See also: ± setViewType: Methods For Drag And Drop concludeDragOperation: - concludeDragOperation:sender Method description here. See also: - myReference draggedImage:beganAt: - draggedImage:(NXImage *) beganAt:(NXPoint *)screenPoint Method description here. See also: - myReference draggedImage:endedAt:deposited: - draggedImage:(NXImage *) endedAt:(NXPoint *)screenPoint deposited:(BOOL)flag Method description here. See also: - myReference draggingEntered: - (NXDragOperation)draggingEntered:sender Method description here. See also: - myReference draggingSourceOperationMaskForLocal: - (NXDragOperation)draggingSourceOperationMaskForLocal:(BOOL)flag Method description here. See also: - myReference ignoreModifierKeysWhileDragging - (BOOL)ignoreModifierKeysWhileDragging Method description here. See also: - myReference performDragOperation: - (BOOL)performDragOperation:sender Method description here. See also: - myReference prepareForDragOperation: - (BOOL)prepareForDragOperation:sender Method description here. See also: - myReference Methods Implemented By The Delegate mouseEnteredView: - mouseEnteredView:sender Sent by the BetView sender when ever the mouse enters its bounds. The Craps module uses this method to display a set of rules for a given bet on the table. mouseExitedView: - mouseExitedView:sender Sent by the BetView sender when ever the mouse leaves its bounds. player:willBet:onView: - player:aPlayer willBet:(int)betType onView:aBetView Sent by aBetView when a player mouses down on it. aPlayer is the current player (which is not necessarily the player that is making the bet). betType is one of the following constants: Constant Description NV_BET When the player simply mouses down on the view NV_REMOVEBET When the player mouses down while pressing the SHIFT key. NV_BETOTHER When the player mouses down while pressing the ALTERNATE key. NV_REMOVEOTHER When the player mouses down while pressing the ALTERNATE & SHIFT keys. NV_BETOFF When the player mouses down while pressing the CONTROL key. The delegate object must interpret the message and decide what to do. It should first decide which player is actually making the bet (it may not necessarily be aPlayer). It can then either make a bet for the player (by sending sender the bet:atRow:col:, for example), remove a bet, etc. It can also choose to ignore the message if placing a bet at the time is inappropriate.
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.