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-2019 by Bradford W. Mott, Stephen Anthony |
12 | // and the Stella Team |
13 | // |
14 | // See the file "License.txt" for information on usage and redistribution of |
15 | // this file, and for a DISCLAIMER OF ALL WARRANTIES. |
16 | //============================================================================ |
17 | |
18 | #include "EventHandler.hxx" |
19 | #include "KeyboardWidget.hxx" |
20 | |
21 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
22 | KeyboardWidget::KeyboardWidget(GuiObject* boss, const GUI::Font& font, |
23 | int x, int y, Controller& controller) |
24 | : ControllerWidget(boss, font, x, y, controller) |
25 | { |
26 | bool leftport = isLeftPort(); |
27 | const string& label = leftport ? "Left (Keyboard)" : "Right (Keyboard)" ; |
28 | |
29 | const int fontHeight = font.getFontHeight(); |
30 | int xpos = x, ypos = y, lwidth = font.getStringWidth("Right (Keyboard)" ); |
31 | StaticTextWidget* t; |
32 | |
33 | t = new StaticTextWidget(boss, font, xpos, ypos+2, lwidth, |
34 | fontHeight, label, TextAlign::Left); |
35 | |
36 | xpos += 30; ypos += t->getHeight() + 20; |
37 | |
38 | for(int i = 0; i < 12; ++i) |
39 | { |
40 | myBox[i] = new CheckboxWidget(boss, font, xpos, ypos, "" , |
41 | CheckboxWidget::kCheckActionCmd); |
42 | myBox[i]->setID(i); |
43 | myBox[i]->setTarget(this); |
44 | xpos += myBox[i]->getWidth() + 5; |
45 | if((i+1) % 3 == 0) |
46 | { |
47 | xpos = x + 30; |
48 | ypos += myBox[i]->getHeight() + 5; |
49 | } |
50 | } |
51 | myEvent = leftport ? ourLeftEvents : ourRightEvents; |
52 | } |
53 | |
54 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
55 | void KeyboardWidget::loadConfig() |
56 | { |
57 | const Event& event = instance().eventHandler().event(); |
58 | for(int i = 0; i < 12; ++i) |
59 | myBox[i]->setState(event.get(myEvent[i])); |
60 | } |
61 | |
62 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
63 | void KeyboardWidget::handleCommand( |
64 | CommandSender* sender, int cmd, int data, int id) |
65 | { |
66 | if(cmd == CheckboxWidget::kCheckActionCmd) |
67 | instance().eventHandler().handleEvent(myEvent[id], myBox[id]->getState()); |
68 | } |
69 | |
70 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
71 | Event::Type KeyboardWidget::ourLeftEvents[12] = { |
72 | Event::KeyboardZero1, Event::KeyboardZero2, Event::KeyboardZero3, |
73 | Event::KeyboardZero4, Event::KeyboardZero5, Event::KeyboardZero6, |
74 | Event::KeyboardZero7, Event::KeyboardZero8, Event::KeyboardZero9, |
75 | Event::KeyboardZeroStar, Event::KeyboardZero0, Event::KeyboardZeroPound |
76 | }; |
77 | |
78 | // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - |
79 | Event::Type KeyboardWidget::ourRightEvents[12] = { |
80 | Event::KeyboardOne1, Event::KeyboardOne2, Event::KeyboardOne3, |
81 | Event::KeyboardOne4, Event::KeyboardOne5, Event::KeyboardOne6, |
82 | Event::KeyboardOne7, Event::KeyboardOne8, Event::KeyboardOne9, |
83 | Event::KeyboardOneStar, Event::KeyboardOne0, Event::KeyboardOnePound |
84 | }; |
85 | |