home *** CD-ROM | disk | FTP | other *** search
/ Stars of Shareware: Programmierung / SOURCE.mdf / programm / msdos / pascal / rehack / text / window.txt < prev   
Encoding:
Text File  |  1993-06-27  |  11.2 KB  |  294 lines

  1. File:            WINDOW.TXT
  2. Path:            ...\REHACK\TEXT\WINDOW.TXT
  3. Version:        0.01
  4. Author:            Pat Reilly
  5. CIS Id:            71333,2764
  6. Created On:        6/23/93
  7. Modified On:    6/27/93
  8. Description:    Doc file for WINDOW.HPP.
  9. Tabs:            4
  10.  
  11. Hierarchy of classes:
  12.  
  13. Visible ──┬── Window ──┬── Game (See GAME.HPP and GAME.TXT)
  14.           │            │
  15.           │            ├── ButtonsWindow (not yet implemented)
  16.           │            │
  17.           │            ├── CharacterWindow (not yet implemented)
  18.           │            │
  19.           │            └── MessageWindow (not yet implemented)
  20.           │
  21.           ├── CloseUp (not yet implemented)
  22.           │
  23.           ├── Automap (not yet implemented)
  24.           │
  25.           ├── Button (not yet implemented)
  26.           .
  27.           .
  28.           .
  29.  
  30. This hierarchy of classes forms an event-driven framework for REHACK's CRPG
  31. program. Game is a generic game class which has a close-up window, an
  32. automap window, a buttons window, a character window, and a message window.
  33. See GAME.TXT for more information on the Game class.
  34.  
  35. NOTE: Right now, the Windows classes have no automatic drawing (or painting)
  36. functionality. This will need to be added in future revisions in order to
  37. put more common functionality in the Visible and Window class (saving on
  38. duplicating the code in all higher classes).
  39.  
  40. Class Visible
  41. =============
  42.  
  43.   This class is the base class for the Windows hierarchy. It encapsulates a
  44. rectangular object which can respond to events. By default (ctor), a Visible
  45. is both visible and can be focused. Right now being visible is meaningless,
  46. since no paint related functionality is in place. Being focused relates to
  47. which events Visible will receive from its owning Window (see Window class
  48. below). Also by default, Visible's are masked from receiving Broadcast
  49. events (see EVENT.TXT).
  50.  
  51. Methods
  52. -------
  53.  
  54.     Visible()    constructor
  55.         Creates a default object which is visible and focusable and can
  56.         receive all events except Broadcasts.
  57.  
  58.     ~Visible()    virtual destructor
  59.         If the object is currently in a Window, removes it before
  60.         destructing.
  61.  
  62.     void get(Event& event)        virtual
  63.         By default, just calls owner->get(event), or clears the event if
  64.         owner == 0. See Window::get() Game::get() (GAME.TXT) for more info.
  65.  
  66.     void handle(Event& event)   virtual
  67.         By default, just handles a left button click in the object's area
  68.         by focusing the object (if flags allow); if PassFirstClick flag
  69.         is set, does not clear the event.
  70.  
  71.     Rect getLocalBounds() const
  72.         Returns the bounding rectangle for this object in this object's
  73.         coordinate system. This means that the returned Rect's topLeft
  74.         member will always be the Point (0,0).
  75.  
  76.     Rect getOwnerBounds() const
  77.         Returns the bounding rectangle for this object in its OWNER'S
  78.         coordinate system. This is the same as the bounds member.
  79.  
  80.     Point makePointLocal(const Point& pt) const
  81.         Converts pt from global coordinates to local coordinates.
  82.  
  83.     Point makePointGlobal(const Point& pt) const
  84.         Converts pt from local coordinates to global coordinates.
  85.  
  86.     void setFlag(dword bits, bool enable)    virtual
  87.         The bits argument should only have one bit (flag) set. If this
  88.         flag is currently clear, setFlags() sets it. When paint-related
  89.         methods are added, this method will be modified to paint the object
  90.         when necessary (if, for example, bits == Visible). Currently,
  91.         Only bits 0..6 are used, but bits 0..15 are reserved for system
  92.         use. Bits 16..31 are available for user flags, with the first
  93.         available bit defined by vfFirstUserFlag.
  94.  
  95.     bool getFlag(dword b) const
  96.         Returns true if all the bits that are set in b are also set in flags,
  97.         otherwise false. Can be used to check if multiple flags are set by
  98.         having b be the logical OR of more than one flag.
  99.  
  100.     bool grabFocus()
  101.         Forces the object to try and take the focus. If the currently
  102.         focused object refuses to give up the focus, or this object is
  103.         disabled, not visible, or is not focusable, returns false and the
  104.         object is not focused. Otherwise the object is focused and returns
  105.         true.
  106.  
  107.     bool canLoseFocus()        virtual
  108.         By default, returns true. If an object requires doing validation
  109.         (such as an editline), this function can be overridden so that it
  110.         refuses to lose the focus until the correct input is received.
  111.  
  112.     Visible* nextObject()
  113.         Returns a pointer to the next object in z-order, or null.
  114.  
  115.     Visible* prevObject()
  116.         Returns a pointer to the previous object in z-order, or null.
  117.  
  118.     word run()        virtual
  119.         By default, just returns IdCancel.
  120.  
  121.     void stopRunning(word id)
  122.         If this object is currently run()ning, stops it by setting
  123.         modalReturnValue to id. Note that it won't stop running if id is
  124.         idNull. If this object isn't running, calls its owner's
  125.         stopRunning(id).
  126.  
  127. Members
  128. -------
  129.  
  130.     Rect bounds
  131.         Objects bounding rectangle in its owner's coordinate system.
  132.  
  133.     dword flags
  134.         Object's state flags.
  135.  
  136.     Window* owner
  137.         Pointer to this object's owner (parent).
  138.  
  139.     Visible* next
  140.         Visible forms a circular singly-linked list; next points to
  141.         the next object in the list. Only valid if owner != 0.
  142.  
  143.     word modalReturnValue
  144.         Value returned by run().
  145.  
  146.  
  147. State flags
  148. -----------
  149.  
  150.     vfVisible
  151.         Indicates if the object is visible (set) or hidden (clear).
  152.  
  153.     vfFocused
  154.         Indicates if the object is currently it's owner's focused object
  155.         (set) or not (clear). Focused objects receive certain events that
  156.         non-focused objects do not. See Window::handle() for more details.
  157.         When painting the object, certain objects might want to paint it
  158.         differently when its focused than when its not; an example would
  159.         be Buttons.
  160.  
  161.     vfDisabled
  162.         Indicates if the object is currently disabled (set) or not (clear).
  163.         Disabled objects will not receive any events. When painting the
  164.         object, a different look might be wanted when the object is disabled
  165.         versus when its not; "grayed" controls are an example.
  166.  
  167.     vfModal
  168.         Indicates if the object (normally a Window) is modal or not. This
  169.         bit is used internally by the windows classes.
  170.  
  171.     vfFocusable
  172.         Indicates whether this object can be made the focus (set) or not.
  173.  
  174.     vfPassFirstClick
  175.         If set, the object is not focused, and it receives a left pos device
  176.         button click, the event is not cleared. This allows focusable objects
  177.         to both gain the focus AND respond all to the same mouse click.
  178.  
  179.     vfFirstUserFlag
  180.         Indicates the first of 16 user-defined flags that can be used with
  181.         getFlag() and setFlag(). Since these are bit flags, the first
  182.         available user flag would be vfFirstUserFlag; the second would be
  183.         vfFirstUserFlag*2, etc.
  184.  
  185.  
  186. Class Window - derived from Visible
  187. ============
  188.  
  189.     The Window class encapsulates a linked list of Visibles. It is meant to
  190. be more of a container than a pure screen object. But it still has a
  191. rectangular region its responsible for; when painting functionality is added,
  192. a Window will ensure that any of its sub-objects (whether Visibles or
  193. Windows) do not paint outside its bounding rectangle.
  194.     Windows can have a focused sub-object; it will be pointed to by the
  195. member currentObject if so. Windows also maintain their linked list of
  196. sub-objects in "Z-order"; whenever a new object is inserted into the Window
  197. it is inserted at the end (furthest from bottomObject) of the list. Because
  198. of this, the objects in a Window can be traversed from bottom to top by
  199. starting at the bottomObject pointer and traversing.
  200.     Since Window is derived from Visible, any non-overridden function from
  201. Visible apply to it.
  202.     One method that Window overrides is the handle(Event&) function. If the
  203. event is positional (pos device), it is passed to the upper-most object (in
  204. z-order) which is visible and contains the position of the event. If the
  205. event is a focused event, it passed only to currentObject (if not null).
  206. Broadcast events are passed to all the sub-objects.
  207.  
  208. Methods
  209. -------
  210.  
  211.     Window(const Rect&)        constructor
  212.         Initializes its base class Visible by passing it the bounding
  213.         rectangle, then initializes its linked list for an empty list and
  214.         no focused object.
  215.  
  216.     ~Window()                destructor
  217.         Deletes each object in its linked list.
  218.  
  219.     void handle(Event& event)    virtual
  220.         If event.isPositional() returns true, the lastObjectThat() iterator
  221.         is called to find the top-most object which contains this point
  222.         and is visible. If one is found, the event is passed to it,
  223.         otherwise the event is ignored.
  224.         If event.isFocused() returns true, passes the event to currentObject
  225.         if its not null, else ignores it.
  226.         If event.isBroadcast() returns true, the forEachObject() iterator
  227.         is called to pass the event to each object in the list.
  228.  
  229.     void insert(Visible* obj)
  230.         If obj is already in another window (its owner member is not null),
  231.         it is removed from its current owner. Then obj is inserted into the
  232.         end of the linked list and obj->grabFocus() is called to make the
  233.         object focused (which might fail, leaving the focus where it is).
  234.  
  235.     void remove(Visible* obj)
  236.         Removes the object if its contained in the Window, and sets its
  237.         owner member to null to indicate that no Window owns the object.
  238.  
  239.     bool moveFocusTo(Visible* obj)
  240.         Attempts to change the focus from the current object to obj. If obj
  241.         is not a sub-object of the Window, returns false. If obj already
  242.         has the focus, returns true. If currentObject is null, or
  243.         currentObject->canLoseFocus() returns true, then the focus is moved
  244.         to obj; but only if obj can accept the focus
  245.         (obj->getFlag(vfFocusable) return true).
  246.  
  247.     void forEachObject(void (*fn)(Visible*, void*), void* args) const
  248.         For each sub-object in the window, fn(obj, args) is called. This
  249.         acts as an iterator function for all sub-objects. The form of fn
  250.         is:
  251.             void foo(Visible* obj, void* args);
  252.  
  253.     Visible* firstObjectThat(bool (*fn)(Visible*, void*), void* args) const
  254.         Iterates through each sub-object in the window, starting at the
  255.         bottom-most (bottomObject) and working up to the top-most; the
  256.         first object for which fn returns true is returned, or null if none
  257.         do. The form of fn is:
  258.             bool foo(Visible* obj, void* args);
  259.  
  260.     Visible* lastObjectThat(bool (*fn)(Visible*, void*), void* args) const
  261.         Same as firstObjectThat(), but instead of iterating from the
  262.         bottom object to the top, it starts at the top object and iterates
  263.         down to the bottom.
  264.  
  265.     word run()        virtual
  266.         Overridden to provide making a Window modal. When called, run()
  267.         will set modalReturnValue to IdNull, then run a loop which calls
  268.         get() to retrieve an event and then (if the event is not null)
  269.         passes it to handle(). This will continue as long as modalReturnValue
  270.         is IdNull. Any object in the Window's chain of sub-objects can
  271.         stop this loop by calling stopRunning() and passing it the value
  272.         that run() should return.
  273.  
  274. Members
  275. =======
  276.  
  277.     Visible* bottomObject
  278.         This is the 'head' of the linked list of sub-objects. It points to
  279.         the sub-object which is lowest in z-order (furthest from the screen).
  280.         The sub-objects for a circular linked list, which means that if
  281.         the list is followed node to node, you will eventually return to
  282.         bottomObject again.
  283.  
  284.     Visible* currentObject
  285.         This points the the currently focused object, or is null. See handle()
  286.         for the implications of the currently focused object.
  287.  
  288. Friends
  289. =======
  290.  
  291.     void makeInc()
  292.         This global function is used in the ASMINC module/program. See
  293.         ASMINC.CPP and ASMINC.TXT for more information.
  294.