~ubuntu-branches/debian/squeeze/stella/squeeze

« back to all changes in this revision

Viewing changes to src/gui/PopUpWidget.hxx

  • Committer: Bazaar Package Importer
  • Author(s): Mario Iseli
  • Date: 2006-04-08 18:38:25 UTC
  • mfrom: (1.1.2 upstream) (2.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20060408183825-vu1jk57rk929derx
* New Maintainer (Closes: #361345)
* New upstream release (Closes: #349725)
* Build-Depend now on libslang2-dev (Closes: #325577)
* Complete rebuild of debian/, upgraded to policy-standards
  3.6.2 and compat-level 5.
* Removed stellarc since stella only reads ~/.stellarc and even
  works without a first config.
* New debian/watch file.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//============================================================================
 
2
//
 
3
//   SSSS    tt          lll  lll       
 
4
//  SS  SS   tt           ll   ll        
 
5
//  SS     tttttt  eeee   ll   ll   aaaa 
 
6
//   SSSS    tt   ee  ee  ll   ll      aa
 
7
//      SS   tt   eeeeee  ll   ll   aaaaa  --  "An Atari 2600 VCS Emulator"
 
8
//  SS  SS   tt   ee      ll   ll  aa  aa
 
9
//   SSSS     ttt  eeeee llll llll  aaaaa
 
10
//
 
11
// Copyright (c) 1995-2005 by Bradford W. Mott and the Stella team
 
12
//
 
13
// See the file "license" for information on usage and redistribution of
 
14
// this file, and for a DISCLAIMER OF ALL WARRANTIES.
 
15
//
 
16
// $Id: PopUpWidget.hxx,v 1.12 2006/02/22 17:38:04 stephena Exp $
 
17
//
 
18
//   Based on code from ScummVM - Scumm Interpreter
 
19
//   Copyright (C) 2002-2004 The ScummVM project
 
20
//============================================================================
 
21
 
 
22
#ifndef POPUP_WIDGET_HXX
 
23
#define POPUP_WIDGET_HXX
 
24
 
 
25
class GUIObject;
 
26
class PopUpDialog;
 
27
 
 
28
#include "Dialog.hxx"
 
29
 
 
30
#include "Widget.hxx"
 
31
#include "Command.hxx"
 
32
#include "Array.hxx"
 
33
#include "GuiUtils.hxx"
 
34
 
 
35
#include "bspf.hxx"
 
36
 
 
37
/**
 
38
 * Popup or dropdown widget which, when clicked, "pop up" a list of items and
 
39
 * lets the user pick on of them.
 
40
 *
 
41
 * Implementation wise, when the user selects an item, then a kPopUpItemSelectedCmd 
 
42
 * is broadcast, with data being equal to the tag value of the selected entry.
 
43
 */
 
44
class PopUpWidget : public Widget, public CommandSender
 
45
{
 
46
  friend class PopUpDialog;
 
47
 
 
48
  struct Entry {
 
49
    string name;
 
50
    int tag;
 
51
  };
 
52
 
 
53
  typedef Common::Array<Entry> EntryList;
 
54
 
 
55
  protected:
 
56
    EntryList _entries;
 
57
    int       _selectedItem;
 
58
    string    _label;
 
59
    int       _labelWidth;
 
60
 
 
61
  public:
 
62
    PopUpWidget(GuiObject* boss, const GUI::Font& font,
 
63
                int x, int y, int w, int h,
 
64
                const string& label, int labelWidth = 0, int cmd = 0);
 
65
    ~PopUpWidget();
 
66
 
 
67
    void handleMouseDown(int x, int y, int button, int clickCount);
 
68
 
 
69
    void appendEntry(const string& entry, int tag = (int)-1);
 
70
    void clearEntries();
 
71
 
 
72
    /** Select the entry at the given index. */
 
73
    void setSelected(int item);
 
74
        
 
75
    /** Select the first entry matching the given tag. */
 
76
    void setSelectedTag(int tag);
 
77
 
 
78
    int getSelected() const              { return _selectedItem; }
 
79
    int getSelectedTag() const           { return (_selectedItem >= 0) ? _entries[_selectedItem].tag : (int)-1; }
 
80
    const string& getSelectedString() const { return (_selectedItem >= 0) ? _entries[_selectedItem].name : EmptyString; }
 
81
 
 
82
  protected:
 
83
    void drawWidget(bool hilite);
 
84
 
 
85
  protected:
 
86
    int _cmd;
 
87
 
 
88
  private:
 
89
    PopUpDialog* myPopUpDialog;
 
90
    int myArrowsY;
 
91
    int myTextY;
 
92
};
 
93
 
 
94
//
 
95
// PopUpDialog
 
96
//
 
97
class PopUpDialog : public Dialog
 
98
{
 
99
  friend class PopUpWidget;
 
100
 
 
101
  public:
 
102
    PopUpDialog(PopUpWidget* boss, int clickX, int clickY);
 
103
        
 
104
    void drawDialog();
 
105
 
 
106
    void handleMouseDown(int x, int y, int button, int clickCount);
 
107
    void handleMouseWheel(int x, int y, int direction);         // Scroll through entries with scroll wheel
 
108
    void handleMouseMoved(int x, int y, int button);            // Redraw selections depending on mouse position
 
109
    void handleKeyDown(int ascii, int keycode, int modifiers);  // Scroll through entries with arrow keys etc.
 
110
 
 
111
  protected:
 
112
    void drawMenuEntry(int entry, bool hilite);
 
113
 
 
114
    void recalc();
 
115
    int findItem(int x, int y) const;
 
116
    void setSelection(int item);
 
117
    bool isMouseDown();
 
118
        
 
119
    void moveUp();
 
120
    void moveDown();
 
121
 
 
122
  private:
 
123
    void sendSelection();
 
124
    void cancelSelection();
 
125
 
 
126
  protected:
 
127
    PopUpWidget* _popUpBoss;
 
128
    int          _clickX, _clickY;
 
129
    uInt8*       _buffer;
 
130
    int          _selection;
 
131
    int          _oldSelection;
 
132
    int          _openTime;
 
133
    bool         _twoColumns;
 
134
    int          _entriesPerColumn;
 
135
};
 
136
 
 
137
#endif