A MacaoCardStack handles a list of cards and arrages them on the page. You can use a stack to handle a deck of cards, a row of cards on the table or a hand of cards of a player.
A stack may or may be not a visible object. The stack needs to be visible (have a look), if the user needs to drop cards on the stack using Drag & Drop.
You can add cards to a stack using the methods addCard(), addCards(), addSubstack(), insertCard() and insertSubstack(). A card usually should be on a stack. A card can only be on one stack at a time. So adding a card to a stack will automatically remove it from its previous stack. You can remove a card explicitely from a source stack before you add it to a target stack in order to prevent multiple time consuming adjustments of the source stack.
The cards on a stack are in a row from the bottom card to the top card. A substack is defined as a sublist of this cards from a start card to the top card.
The behavior of a stack is defined by an exposed schema and a drag schema (see the EXPOSED_SCHEMA_ and DRAG_SCHEMA_ constants). This schemes define, which cards of the stack are exposed and which can be dragged by the user. The offset values define, how the cards are arranged by the stack. By setting large offsets, you can put the cards beside each other. By setting small offsets you can arrange the cards to a deck. Even if the offset values are in pixels, an offset can be a float value like 0.2 pixels.
The defined schemes and offsets and the stacking are used by the method adjustCards() to adjust the cards exposure, drag activation, position and stacking. This functionality is time consuming. So you should pay attention to only trigger it once for a stack after a user action.
Internally the stack works with a double linked list of stack items. Each stack item has the attributes prevItem, nextItem and card. The stack holds references to the bottom item and the top item.
Field Summary | |
---|---|
String | DRAG_SCHEMA_ALL This constant defines the drag schema, where all of the cards of the stack can be dragged by the user. |
String | DRAG_SCHEMA_ALL_SUBSTACK This constant defines the drag schema, where all of the cards of the stack can be dragged by the user. Dragging a card will cause the entire substack to be dragged. |
String | DRAG_SCHEMA_EXPOSED This constant defines the drag schema, where only the exposed cards of the stack can be dragged by the user. |
String | DRAG_SCHEMA_EXPOSED_SUBSTACK This constant defines the drag schema, where only the exposed cards of the stack can be dragged by the user. Dragging a card will cause the entire substack to be dragged. |
String | DRAG_SCHEMA_INDIVIDUAL This constant defines the drag schema, where you control individually, which of the cards of the stack can be dragged by the user. |
String | DRAG_SCHEMA_INDIVIDUAL_SUBSTACK This constant defines the drag schema, where you control individually, which of the cards of the stack can be dragged by the user. Dragging a card will cause the entire substack to be dragged. |
String | DRAG_SCHEMA_NONE This constant defines the drag schema, where none of the cards of the stack can be dragged by the user. |
String | DRAG_SCHEMA_TOP This constant defines the drag schema, where only the top card of the stack can be dragged by the user. |
String | EXPOSED_SCHEMA_ALL This constant defines the exposed schema, where all of the cards of the stack are exposed. |
String | EXPOSED_SCHEMA_INDIVIDUAL This constant defines the exposed schema, where the exposure of each card is controlled individually. |
String | EXPOSED_SCHEMA_NONE This constant defines the exposed schema, where none of the cards of the stack is exposed. |
String | EXPOSED_SCHEMA_SUBSTACK This constant defines the exposed schema, where a number of cards at the top of the stack are exposed. |
String | EXPOSED_SCHEMA_TOP This constant defines the exposed schema, where the top card of the stack is exposed. |
boolean | IS_STACK This constant marks a stack as stack. It is always true. |
Inherited Fields |
---|
BUNCH_TYPE_SAY, BUNCH_TYPE_STAND, BUNCH_TYPE_WALK |
Constructor Summary |
---|
MacaoCardStack(String name, String title, number left, number top, String stackType, boolean standardLook, number baseOffsetX, number baseOffsetY, number cardOffsetX, number cardOffsetY, String exposedSchema, String dragSchema)
Use this constructor to create a new stack object. |
Method Summary | |
---|---|
void | addCard(MacaoCard card, optional boolean dontAdjustCards)
Call this method to add a single card to the top of the stack. |
void | addCards(Array cards, optional boolean dontAdjustCards)
Call this method to add an array of cards to the top of the stack. |
void | addSubstack(MacaoCard startCard, optional boolean dontAdjustCards)
Call this method to move a substack from another stack to the top of this stack. |
void | adjustCards(optional MacaoCard startCard)
Call this method to adjust the exposure, the drag activation, the position and the stacking of the cards in the stack. |
Array | getAllCards()
Call this method to get all cards of the stack. |
number | getBaseOffsetX()
Call this method to get the offset between the left edge of the stack and the bottom card. |
number | getBaseOffsetY()
Call this method to get the offset between the top edge of the stack and the bottom card. |
MacaoCard | getBottomCard()
Call this method to get the bottom card of the stack. |
MacaoCard | getCardAt(integer index)
Call this method to get a card of the stack by its index. |
integer | getCardIndex(MacaoCard card)
Call this method to calculate the position of the card in the stack. |
number | getCardOffsetX()
Call this method to get the offset between the left edges of two cards |
number | getCardOffsetY()
Call this method to get the offset between the top edges of two cards |
String | getDragSchema()
Call this method to get the drag schema of the stack. |
String | getExposedSchema()
Call this method to get the exposed schema of the stack. |
MacaoCard | getNextCard(MacaoCard card)
Call this method to get the next card of a card. |
MacaoCard | getPreviousCard(MacaoCard card)
Call this method to get the previous card of a card. |
integer | getSize()
Call this method to evaluate how many cards are on the stack. |
String | getStackType()
Call this method to get the stack type. |
Array | getSubstack(MacaoCard startCard)
Call this method to get the cards of a substack of this stack. |
MacaoCard | getTopCard()
Call this method to get the top card of the stack. |
boolean | hasCard(MacaoCard card)
Call this method to check, if a card is element of a stack. |
void | initCardStack(String name, String title, number left, number top, String stackType, boolean standardLook, number baseOffsetX, number baseOffsetY, number cardOffsetX, number cardOffsetY, String exposedSchema, String dragSchema)
This method is called by the constructor to initialize the stack. |
void | insertCard(MacaoCard card, optional MacaoCard afterCard, optional boolean dontAdjustCards)
Call this method to insert a card into the stack. |
void | insertSubstack(MacaoCard startCard, optional MacaoCard afterCard, optional boolean dontAdjustCards)
Call this method to insert a substack into this stack. |
boolean | isDragSubstack()
Call this method to check, if a dragging means to drag a substack. |
boolean | isEmpty()
Call this method to check, if the stack is empty. |
void | onAdjustCards()
This event handler is called after the method adjustCards() has been called. |
void | onClickStack(Event event, number mouseX, number mouseY)
This event handler is called, when the user clicks on the stack. |
void | onDblClickStack(Event event, number mouseX, number mouseY)
This event handler is called, when the user double clicks on the stack. |
void | removeAllCards()
Call this method to remove all cards from the stack. |
void | removeCard(MacaoCard card, optional boolean dontAdjustCards)
Call this method to remove a card from the stack. |
void | removeSubstack(MacaoCard startCard, optional boolean dontAdjustCards)
Call this method to remove a substack from the stack. |
void | setAllExposed(optional boolean exposed, optional boolean dontAdjustCards)
Call this method to make all cards of the stack show their front side or rear side. |
void | setCardOffsets(number baseOffsetX, number baseOffsetY, number cardOffsetX, number cardOffsetY)
Call this method to change the offset of the cards. |
void | setDragSchema(String dragSchema)
Call this method to change the drag schema of the stack. |
void | setExposedSchema(String exposedSchema)
Call this method to change the exposed schema of the stack. |
void | shuffle(optional boolean dontAdjustCards)
Call this method to shuffle the cards of the stack. |
void | sort(optional Function compareFunction, optional boolean dontAdjustCards)
Call this method to sort the cards of the stack. |
integer | sumCardValues()
Call this method to get the sum of the values of all cards in the stack. |
Field Details |
---|
This constant defines the drag schema, where all of the cards of the stack can be dragged by the user.
You can use the following code to access the constant:
MacaoCardStack.prototype.DRAG_SCHEMA_ALL
This constant defines the drag schema, where all of the cards of the stack can be dragged by the user. Dragging a card will cause the entire substack to be dragged.
You can use the following code to access the constant:
MacaoCardStack.prototype.DRAG_SCHEMA_ALL_SUBSTACK
This constant defines the drag schema, where only the exposed cards of the stack can be dragged by the user.
You can use the following code to access the constant:
MacaoCardStack.prototype.DRAG_SCHEMA_EXPOSED
This constant defines the drag schema, where only the exposed cards of the stack can be dragged by the user. Dragging a card will cause the entire substack to be dragged.
You can use the following code to access the constant:
MacaoCardStack.prototype.DRAG_SCHEMA_EXPOSED_SUBSTACK
This constant defines the drag schema, where you control individually, which of the cards of the stack can be dragged by the user.
Use the method MacaoObject.activateDrag() to control the drag activation for each card.
You can use the following code to access the constant:
MacaoCardStack.prototype.DRAG_SCHEMA_INDIVIDUAL
This constant defines the drag schema, where you control individually, which of the cards of the stack can be dragged by the user. Dragging a card will cause the entire substack to be dragged.
Use the method MacaoObject.activateDrag() to control the drag activation for each card.
You can use the following code to access the constant:
MacaoCardStack.prototype.DRAG_SCHEMA_INDIVIDUAL_SUBSTACK
This constant defines the drag schema, where none of the cards of the stack can be dragged by the user.
You can use the following code to access the constant:
MacaoCardStack.prototype.DRAG_SCHEMA_NONE
This constant defines the drag schema, where only the top card of the stack can be dragged by the user.
You can use the following code to access the constant:
MacaoCardStack.prototype.DRAG_SCHEMA_TOP
This constant defines the exposed schema, where all of the cards of the stack are exposed.
All cards are showing their front side.
You can use the following code to access the constant:
MacaoCardStack.prototype.EXPOSED_SCHEMA_ALL
This constant defines the exposed schema, where the exposure of each card is controlled individually.
Use the methods MacaoCard.setExposed() and setAllExposed() to control the exposure of the cards.
You can use the following code to access the constant:
MacaoCardStack.prototype.EXPOSED_SCHEMA_INDIVIDUAL
This constant defines the exposed schema, where none of the cards of the stack is exposed.
All of the cards are showing their rear side.
You can use the following code to access the constant:
MacaoCardStack.prototype.EXPOSED_SCHEMA_NONE
This constant defines the exposed schema, where a number of cards at the top of the stack are exposed.
The cards at the bottom of the stack are showing their rear side. You can control the first exposed card of the stack by calling the method MacaoCard.setExposed().
You can use the following code to access the constant:
MacaoCardStack.prototype.EXPOSED_SCHEMA_SUBSTACK
This constant defines the exposed schema, where the top card of the stack is exposed.
All other cards are showing their rear side.
You can use the following code to access the constant:
MacaoCardStack.prototype.EXPOSED_SCHEMA_TOP
This constant marks a stack as stack. It is always true.
Use this constant to check if an object like a dropped object is a stack. Use the following code for example:
if (object.IS_STACK) { //... }
Constructor Details |
---|
Use this constructor to create a new stack object.
Method Details |
---|
Call this method to add a single card to the top of the stack.
Call this method to add an array of cards to the top of the stack.
Call this method to move a substack from another stack to the top of this stack.
Call this method to adjust the exposure, the drag activation, the position and the stacking of the cards in the stack.
The cards are adjusted according to the set exposed schema, drag schema and offsets. The stacking means the setting of the z-index of the cards. The z-index starts with the z-index of the stack plus 1 for the bottom card. The z-index is incremented for each card on top.
Keep in mind, that adjusting the cards is a time consuming operation. You should adjust the cards only once for each user operation.
Call this method to get all cards of the stack.
Call this method to get the offset between the left edge of the stack and the bottom card.
Call this method to get the offset between the top edge of the stack and the bottom card.
Call this method to get the bottom card of the stack.
Call this method to get a card of the stack by its index.
Keep in mind, that its time consuming to access cards by their index. If you have to process a number of cards of the same stack, you shoud better call getAllCards() to get the cards of the stack as an array and process the array.
Call this method to calculate the position of the card in the stack.
Call this method to get the offset between the left edges of two cards
Call this method to get the offset between the top edges of two cards
Call this method to get the drag schema of the stack.
Call this method to get the exposed schema of the stack.
Call this method to get the next card of a card.
Call this method to get the previous card of a card.
Call this method to evaluate how many cards are on the stack.
Call this method to get the stack type.
Call this method to get the cards of a substack of this stack.
Call this method to get the top card of the stack.
Call this method to check, if a card is element of a stack.
This method is called by the constructor to initialize the stack.
Call this method, if you inherit your own class from MacaoCardStack.
Call this method to insert a card into the stack.
Call this method to insert a substack into this stack.
Call this method to check, if a dragging means to drag a substack.
Call this method to check, if the stack is empty.
This event handler is called after the method adjustCards() has been called.
You can implement this event handler to override the standard adjustment of the cards. There is no default implementation for this event handler.
This event handler is called, when the user clicks on the stack.
You can implement this event handler to react to the event. There is no default implementation.
This event handler is called, when the user double clicks on the stack.
You can implement this event handler to react to the event. There is no default implementation.
Call this method to remove all cards from the stack.
Call this method to remove a card from the stack.
Call this method to remove a substack from the stack.
Call this method to make all cards of the stack show their front side or rear side.
Call this method to change the offset of the cards.
Call this method to change the drag schema of the stack.
Call this method to change the exposed schema of the stack.
Call this method to shuffle the cards of the stack.
Call this method to sort the cards of the stack.
Call this method to get the sum of the values of all cards in the stack.