Skip to content

Commit

Permalink
VKEYBD: Some formatting fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Johannes Schickel committed Jan 3, 2012
1 parent b3e44e0 commit c98a123
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 76 deletions.
8 changes: 4 additions & 4 deletions backends/vkeybd/image-map.cpp
Expand Up @@ -35,7 +35,7 @@ ImageMap::~ImageMap() {
removeAllAreas();
}

Polygon *ImageMap::createArea(const String& id) {
Polygon *ImageMap::createArea(const String &id) {
if (_areas.contains(id)) {
warning("Image map already contains an area with target of '%s'", id.c_str());
return 0;
Expand All @@ -45,23 +45,23 @@ Polygon *ImageMap::createArea(const String& id) {
return p;
}

void ImageMap::removeArea(const String& id) {
void ImageMap::removeArea(const String &id) {
if (!_areas.contains(id))
return;
delete _areas[id];
_areas.erase(id);
}

void ImageMap::removeAllAreas() {
HashMap<String, Polygon*>::iterator it;
HashMap<String, Polygon *>::iterator it;
for (it = _areas.begin(); it != _areas.end(); ++it) {
delete it->_value;
}
_areas.clear();
}

String ImageMap::findMapArea(int16 x, int16 y) {
HashMap<String, Polygon*>::iterator it;
HashMap<String, Polygon *>::iterator it;
for (it = _areas.begin(); it != _areas.end(); ++it) {
if (it->_value->contains(x, y))
return it->_key;
Expand Down
4 changes: 2 additions & 2 deletions backends/vkeybd/image-map.h
Expand Up @@ -40,8 +40,8 @@ class ImageMap {

~ImageMap();

Polygon *createArea(const String& id);
void removeArea(const String& id);
Polygon *createArea(const String &id);
void removeArea(const String &id);
void removeAllAreas();
String findMapArea(int16 x, int16 y);

Expand Down
2 changes: 1 addition & 1 deletion backends/vkeybd/polygon.cpp
Expand Up @@ -42,7 +42,7 @@ bool Polygon::contains(int16 x, int16 y) const {
yflag1 = (vtx1->y >= y);
if (yflag0 != yflag1) {
if (((vtx1->y - y) * (vtx0->x - vtx1->x) >=
(vtx1->x - x) * (vtx0->y - vtx1->y)) == yflag1) {
(vtx1->x - x) * (vtx0->y - vtx1->y)) == yflag1) {
inside_flag = !inside_flag;
}
}
Expand Down
4 changes: 2 additions & 2 deletions backends/vkeybd/polygon.h
Expand Up @@ -46,13 +46,13 @@ struct Polygon {
}
}

void addPoint(const Point& p) {
void addPoint(const Point &p) {
_points.push_back(p);
_bound.extend(Rect(p.x, p.y, p.x, p.y));
}

void addPoint(int16 x, int16 y) {
addPoint(Point(x,y));
addPoint(Point(x, y));
}

uint getPointCount() {
Expand Down
39 changes: 19 additions & 20 deletions backends/vkeybd/virtual-keyboard-gui.cpp
Expand Up @@ -75,8 +75,8 @@ static void blit(Graphics::Surface *surf_dst, Graphics::Surface *surf_src, int16

VirtualKeyboardGUI::VirtualKeyboardGUI(VirtualKeyboard *kbd)
: _kbd(kbd), _displaying(false), _drag(false),
_drawCaret(false), _displayEnabled(false), _firstRun(true),
_cursorAnimateTimer(0), _cursorAnimateCounter(0) {
_drawCaret(false), _displayEnabled(false), _firstRun(true),
_cursorAnimateTimer(0), _cursorAnimateCounter(0) {

assert(_kbd);
assert(g_system);
Expand Down Expand Up @@ -111,7 +111,7 @@ void VirtualKeyboardGUI::initMode(VirtualKeyboard::Mode *mode) {
}
}

void VirtualKeyboardGUI::setupDisplayArea(Rect& r, OverlayColor forecolor) {
void VirtualKeyboardGUI::setupDisplayArea(Rect &r, OverlayColor forecolor) {

_dispFont = FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont);
if (!fontIsSuitable(_dispFont, r)) {
Expand All @@ -135,9 +135,9 @@ void VirtualKeyboardGUI::setupDisplayArea(Rect& r, OverlayColor forecolor) {
_displayEnabled = true;
}

bool VirtualKeyboardGUI::fontIsSuitable(const Graphics::Font *font, const Rect& rect) {
bool VirtualKeyboardGUI::fontIsSuitable(const Graphics::Font *font, const Rect &rect) {
return (font->getMaxCharWidth() < rect.width() &&
font->getFontHeight() < rect.height());
font->getFontHeight() < rect.height());
}

void VirtualKeyboardGUI::checkScreenChanged() {
Expand All @@ -161,7 +161,7 @@ void VirtualKeyboardGUI::run() {
_system->clearOverlay();
}
_overlayBackup.create(_screenW, _screenH, _system->getOverlayFormat());
_system->grabOverlay((OverlayColor*)_overlayBackup.pixels, _overlayBackup.w);
_system->grabOverlay((OverlayColor *)_overlayBackup.pixels, _overlayBackup.w);

setupCursor();

Expand All @@ -171,7 +171,7 @@ void VirtualKeyboardGUI::run() {

removeCursor();

_system->copyRectToOverlay((OverlayColor*)_overlayBackup.pixels, _overlayBackup.w, 0, 0, _overlayBackup.w, _overlayBackup.h);
_system->copyRectToOverlay((OverlayColor *)_overlayBackup.pixels, _overlayBackup.w, 0, 0, _overlayBackup.w, _overlayBackup.h);
if (!g_gui.isActive()) _system->hideOverlay();

_overlayBackup.free();
Expand All @@ -183,16 +183,15 @@ void VirtualKeyboardGUI::close() {
}

void VirtualKeyboardGUI::reset() {
_kbdBound.left = _kbdBound.top
= _kbdBound.right = _kbdBound.bottom = 0;
_kbdBound.left = _kbdBound.top = 0;
_kbdBound.right = _kbdBound.bottom = 0;
_displaying = _drag = false;
_firstRun = true;
_lastScreenChanged = _system->getScreenChangeID();
_kbdSurface = 0;
}

void VirtualKeyboardGUI::moveToDefaultPosition()
{
void VirtualKeyboardGUI::moveToDefaultPosition() {
int16 kbdW = _kbdBound.width(), kbdH = _kbdBound.height();
int16 x = 0, y = 0;
if (_screenW != kbdW) {
Expand Down Expand Up @@ -263,7 +262,7 @@ void VirtualKeyboardGUI::screenChanged() {
_screenH = newScreenH;

_overlayBackup.create(_screenW, _screenH, _system->getOverlayFormat());
_system->grabOverlay((OverlayColor*)_overlayBackup.pixels, _overlayBackup.w);
_system->grabOverlay((OverlayColor *)_overlayBackup.pixels, _overlayBackup.w);

if (!_kbd->checkModeResolutions()) {
_displaying = false;
Expand All @@ -290,19 +289,19 @@ void VirtualKeyboardGUI::mainLoop() {
case Common::EVENT_LBUTTONDOWN:
if (_kbdBound.contains(event.mouse)) {
_kbd->handleMouseDown(event.mouse.x - _kbdBound.left,
event.mouse.y - _kbdBound.top);
event.mouse.y - _kbdBound.top);
}
break;
case Common::EVENT_LBUTTONUP:
if (_kbdBound.contains(event.mouse)) {
_kbd->handleMouseUp(event.mouse.x - _kbdBound.left,
event.mouse.y - _kbdBound.top);
event.mouse.y - _kbdBound.top);
}
break;
case Common::EVENT_MOUSEMOVE:
if (_drag)
move(event.mouse.x - _dragPoint.x,
event.mouse.y - _dragPoint.y);
event.mouse.y - _dragPoint.y);
break;
case Common::EVENT_SCREEN_CHANGED:
screenChanged();
Expand Down Expand Up @@ -367,20 +366,20 @@ void VirtualKeyboardGUI::redraw() {
}

blit(&surf, _kbdSurface, _kbdBound.left - _dirtyRect.left,
_kbdBound.top - _dirtyRect.top, _kbdTransparentColor);
_kbdBound.top - _dirtyRect.top, _kbdTransparentColor);
if (_displayEnabled) {
blit(&surf, &_dispSurface, _dispX - _dirtyRect.left,
_dispY - _dirtyRect.top, _dispBackColor);
_dispY - _dirtyRect.top, _dispBackColor);
}
_system->copyRectToOverlay((OverlayColor*)surf.pixels, surf.w,
_dirtyRect.left, _dirtyRect.top, surf.w, surf.h);
_system->copyRectToOverlay((OverlayColor *)surf.pixels, surf.w,
_dirtyRect.left, _dirtyRect.top, surf.w, surf.h);

surf.free();

resetDirtyRect();
}

uint VirtualKeyboardGUI::calculateEndIndex(const String& str, uint startIndex) {
uint VirtualKeyboardGUI::calculateEndIndex(const String &str, uint startIndex) {
int16 w = 0;
while (w <= _dispSurface.w && startIndex < str.size()) {
w += _dispFont->getCharWidth(str[startIndex++]);
Expand Down
8 changes: 4 additions & 4 deletions backends/vkeybd/virtual-keyboard-gui.h
Expand Up @@ -121,7 +121,7 @@ class VirtualKeyboardGUI {
bool _displaying;
bool _firstRun;

void setupDisplayArea(Rect& r, OverlayColor forecolor);
void setupDisplayArea(Rect &r, OverlayColor forecolor);
void move(int16 x, int16 y);
void moveToDefaultPosition();
void screenChanged();
Expand All @@ -131,8 +131,8 @@ class VirtualKeyboardGUI {
void redraw();
void forceRedraw();
void updateDisplay();
bool fontIsSuitable(const Graphics::Font *font, const Rect& rect);
uint calculateEndIndex(const String& str, uint startIndex);
bool fontIsSuitable(const Graphics::Font *font, const Rect &rect);
uint calculateEndIndex(const String &str, uint startIndex);

bool _drawCaret;
int16 _caretX;
Expand All @@ -141,7 +141,7 @@ class VirtualKeyboardGUI {

static const int kCursorAnimateDelay = 250;
int _cursorAnimateCounter;
int _cursorAnimateTimer;
int _cursorAnimateTimer;
byte _cursor[2048];
void setupCursor();
void removeCursor();
Expand Down
24 changes: 12 additions & 12 deletions backends/vkeybd/virtual-keyboard-parser.cpp
Expand Up @@ -116,7 +116,7 @@ bool VirtualKeyboardParser::parserCallback_mode(ParserNode *node) {
_keyboard->_initialMode = _mode;

String resolutions = node->values["resolutions"];
StringTokenizer tok (resolutions, " ,");
StringTokenizer tok(resolutions, " ,");

// select best resolution simply by minimising the difference between the
// overlay size and the resolution dimensions.
Expand Down Expand Up @@ -189,7 +189,7 @@ bool VirtualKeyboardParser::parserCallback_event(ParserNode *node) {
}
evt->type = VirtualKeyboard::kVKEventKey;

KeyState *ks = (KeyState*) malloc(sizeof(KeyState));
KeyState *ks = (KeyState *)malloc(sizeof(KeyState));
ks->keycode = (KeyCode)atoi(node->values["code"].c_str());
ks->ascii = atoi(node->values["ascii"].c_str());
ks->flags = 0;
Expand All @@ -204,7 +204,7 @@ bool VirtualKeyboardParser::parserCallback_event(ParserNode *node) {
}

evt->type = VirtualKeyboard::kVKEventModifier;
byte *flags = (byte*) malloc(sizeof(byte));
byte *flags = (byte *)malloc(sizeof(byte));
if (!flags)
error("[VirtualKeyboardParser::parserCallback_event] Cannot allocate memory");

Expand All @@ -218,8 +218,8 @@ bool VirtualKeyboardParser::parserCallback_event(ParserNode *node) {
}

evt->type = VirtualKeyboard::kVKEventSwitchMode;
String& mode = node->values["mode"];
char *str = (char*) malloc(sizeof(char) * mode.size() + 1);
String &mode = node->values["mode"];
char *str = (char *)malloc(sizeof(char) * mode.size() + 1);
if (!str)
error("[VirtualKeyboardParser::parserCallback_event] Cannot allocate memory");

Expand Down Expand Up @@ -302,9 +302,9 @@ bool VirtualKeyboardParser::parserCallback_map(ParserNode *node) {
}

bool VirtualKeyboardParser::parserCallback_area(ParserNode *node) {
String& shape = node->values["shape"];
String& target = node->values["target"];
String& coords = node->values["coords"];
String &shape = node->values["shape"];
String &target = node->values["target"];
String &coords = node->values["coords"];

if (target.equalsIgnoreCase("display_area")) {
if (!shape.equalsIgnoreCase("rect"))
Expand All @@ -321,7 +321,7 @@ bool VirtualKeyboardParser::parserCallback_area(ParserNode *node) {
return parserError("Area shape '" + shape + "' not known");
}

byte VirtualKeyboardParser::parseFlags(const String& flags) {
byte VirtualKeyboardParser::parseFlags(const String &flags) {
if (flags.empty())
return 0;

Expand All @@ -338,7 +338,7 @@ byte VirtualKeyboardParser::parseFlags(const String& flags) {
return val;
}

bool VirtualKeyboardParser::parseRect(Rect &rect, const String& coords) {
bool VirtualKeyboardParser::parseRect(Rect &rect, const String &coords) {
int x1, y1, x2, y2;
if (!parseIntegerKey(coords, 4, &x1, &y1, &x2, &y2))
return parserError("Invalid coords for rect area");
Expand All @@ -351,7 +351,7 @@ bool VirtualKeyboardParser::parseRect(Rect &rect, const String& coords) {
return true;
}

bool VirtualKeyboardParser::parsePolygon(Polygon &poly, const String& coords) {
bool VirtualKeyboardParser::parsePolygon(Polygon &poly, const String &coords) {
StringTokenizer tok(coords, ", ");
for (String st = tok.nextToken(); !st.empty(); st = tok.nextToken()) {
int x, y;
Expand All @@ -368,7 +368,7 @@ bool VirtualKeyboardParser::parsePolygon(Polygon &poly, const String& coords) {
return true;
}

bool VirtualKeyboardParser::parseRectAsPolygon(Polygon &poly, const String& coords) {
bool VirtualKeyboardParser::parseRectAsPolygon(Polygon &poly, const String &coords) {
Rect rect;
if (!parseRect(rect, coords))
return false;
Expand Down
27 changes: 14 additions & 13 deletions backends/vkeybd/virtual-keyboard-parser.h
Expand Up @@ -56,31 +56,31 @@ keyboard layouts for different screen resolutions.
<area shape="poly" coords="65,50,67,48,94,48,96,50,96,77,94,79,67,79,65,77" target="q" />
<area shape="poly" coords="105,50,107,48,134,48,136,50,136,77,134,79,107,79,105,77" target="w" />
<area shape="poly" coords="146,50,148,48,174,48,176,50,176,77,174,79,148,79,146,77" target="e" />
...
...
<area shape="poly" coords="11,89,12,88,69,88,70,89,70,116,69,117,12,117,11,116" target="caps" />
</map>
</layout>
<layout resolution="320x200" bitmap="normal_320x200.bmp" transparent_color="255,0,255">
...
</layout>
</layout>
<layout resolution="320x200" bitmap="normal_320x200.bmp" transparent_color="255,0,255">
...
</layout>
<event name="a" type="key" code="97" ascii="97" modifiers="" />
<event name="b" type="key" code="98" ascii="98" modifiers="" />
<event name="c" type="key" code="99" ascii="99" modifiers="" />
...
<event name="caps" type="switch_mode" mode="caps" />
...
<event name="caps" type="switch_mode" mode="caps" />
</mode>
<mode name="caps" resolutions="640x400">
<layout resolution="640x400" bitmap="caps_640x480.bmp" transparent_color="255,0,255">
<map>
<area shape="poly" coords="65,50,67,48,94,48,96,50,96,77,94,79,67,79,65,77" target="Q" />
...
...
</map>
</layout>
<event name="A" type="key" code="97" ascii="65" modifiers="shift" />
<event name="B" type="key" code="98" ascii="66" modifiers="shift" />
<event name="C" type="key" code="99" ascii="67" modifiers="shift" />
...
...
</mode>
</keyboard>
Expand Down Expand Up @@ -188,6 +188,7 @@ class VirtualKeyboardParser : public XMLParser {
* Full parse - when loading keyboard pack for first time
*/
kParseFull,

/**
* Just check resolutions and reload layouts if needed - following a
* change in screen size
Expand Down Expand Up @@ -257,10 +258,10 @@ class VirtualKeyboardParser : public XMLParser {
virtual bool closedKeyCallback(ParserNode *node);

/** Parse helper functions */
byte parseFlags(const String& flags);
bool parseRect(Rect &rect, const String& coords);
bool parsePolygon(Polygon &poly, const String& coords);
bool parseRectAsPolygon(Polygon &poly, const String& coords);
byte parseFlags(const String &flags);
bool parseRect(Rect &rect, const String &coords);
bool parsePolygon(Polygon &poly, const String &coords);
bool parseRectAsPolygon(Polygon &poly, const String &coords);
};

} // End of namespace GUI
Expand Down

0 comments on commit c98a123

Please sign in to comment.