{"action":"created","comment":{"url":"https://api.github.com/repos/scummvm/scummvm/pulls/comments/48360958","id":48360958,"diff_hunk":"@@ -0,0 +1,154 @@\n+/* ScummVM - Graphic Adventure Engine\n+ *\n+ * ScummVM is the legal property of its developers, whose names\n+ * are too numerous to list here. Please refer to the COPYRIGHT\n+ * file distributed with this source distribution.\n+ *\n+ * This program is free software; you can redistribute it and/or\n+ * modify it under the terms of the GNU General Public License\n+ * as published by the Free Software Foundation; either version 2\n+ * of the License, or (at your option) any later version.\n+ *\n+ * This program is distributed in the hope that it will be useful,\n+ * but WITHOUT ANY WARRANTY; without even the implied warranty of\n+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n+ * GNU General Public License for more details.\n+ *\n+ * You should have received a copy of the GNU General Public License\n+ * along with this program; if not, write to the Free Software\n+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n+ *\n+ */\n+\n+/*\n+ * This code is based on Labyrinth of Time code with assistance of\n+ *\n+ * Copyright (c) 1993 Terra Nova Development\n+ * Copyright (c) 2004 The Wyrmkeep Entertainment Co.\n+ *\n+ */\n+\n+#include \"common/events.h\"\n+\n+#include \"lab/lab.h\"\n+\n+#include \"lab/dispman.h\"\n+#include \"lab/eventman.h\"\n+#include \"lab/image.h\"\n+#include \"lab/utils.h\"\n+\n+namespace Lab {\n+\n+Button *EventManager::createButton(uint16 x, uint16 y, uint16 id, uint16 key, Image *image, Image *altImage) {\n+\tButton *button = new Button();\n+\n+\tif (button) {\n+\t\tbutton->_x = _vm->_utils->vgaScaleX(x);\n+\t\tbutton->_y = y;\n+\t\tbutton->_buttonId = id;\n+\t\tbutton->_keyEquiv = key;\n+\t\tbutton->_image = image;\n+\t\tbutton->_altImage = altImage;\n+\t\tbutton->_isEnabled = true;\n+\n+\t\treturn button;\n+\t} else\n+\t\treturn nullptr;\n+}\n+\n+void EventManager::freeButtonList(ButtonList *buttonList) {\n+\tfor (ButtonList::iterator buttonIter = buttonList->begin(); buttonIter != buttonList->end(); ++buttonIter) {\n+\t\tButton *button = *buttonIter;\n+\t\tdelete button->_image;\n+\t\tdelete button->_altImage;\n+\t\tdelete button;\n+\t}\n+\n+\tbuttonList->clear();\n+}\n+\n+void EventManager::drawButtonList(ButtonList *buttonList) {\n+\tfor (ButtonList::iterator button = buttonList->begin(); button != buttonList->end(); ++button) {\n+\t\ttoggleButton((*button), 1, true);\n+\n+\t\tif (!(*button)->_isEnabled)\n+\t\t\ttoggleButton((*button), 1, false);\n+\t}\n+}\n+\n+void EventManager::toggleButton(Button *button, uint16 disabledPenColor, bool enable) {\n+\tif (!enable)\n+\t\t_vm->_graphics->overlayRect(disabledPenColor, button->_x, button->_y, button->_x + button->_image->_width - 1, button->_y + button->_image->_height - 1);\n+\telse\n+\t\tbutton->_image->drawImage(button->_x, button->_y);\n+\n+\tbutton->_isEnabled = enable;\n+}\n+\n+uint16 EventManager::makeButtonKeyEquiv(uint16 key) {\n+\tif (Common::isAlnum(key))\n+\t\tkey = tolower(key);\n+\n+\treturn key;\n+}\n+\n+Button *EventManager::checkNumButtonHit(ButtonList *buttonList, uint16 key) {\n+\tuint16 gkey = key - '0';","path":"engines/lab/interface.cpp","position":96,"original_position":96,"commit_id":"56680d324a5ab7a328df37f330210b3394649961","original_commit_id":"56680d324a5ab7a328df37f330210b3394649961","user":{"login":"lordhoto","id":177695,"avatar_url":"https://avatars.githubusercontent.com/u/177695?v=3","gravatar_id":"","url":"https://api.github.com/users/lordhoto","html_url":"https://github.com/lordhoto","followers_url":"https://api.github.com/users/lordhoto/followers","following_url":"https://api.github.com/users/lordhoto/following{/other_user}","gists_url":"https://api.github.com/users/lordhoto/gists{/gist_id}","starred_url":"https://api.github.com/users/lordhoto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lordhoto/subscriptions","organizations_url":"https://api.github.com/users/lordhoto/orgs","repos_url":"https://api.github.com/users/lordhoto/repos","events_url":"https://api.github.com/users/lordhoto/events{/privacy}","received_events_url":"https://api.github.com/users/lordhoto/received_events","type":"User","site_admin":false},"body":"`key` seems to come from a `Common::KeyCode` (inside `EventManager::getMsg`). Doing arithmetic like it is an ASCII character is something you should avoid at any cost.\r\nOverall, I suggest to use proper types to avoid these issues from coming up. Here's a short list of suggestions:\r\n1) Make `createButton` take a `Common::KeyCode` for `key`, adjust `Button`'s `_keyEquiv` to be a `Common::KeyCode` too, and finally make all callers of `createButton` pass key codes instead of ASCII values or similar (which is the case right now).\r\n2) I think this allows to get rid of `makeButtonKeyEquiv` too. Right now it treats its input as ASCII even though it's always a `Common::KeyCode`. Thus, the `tolower` etc. is unnecessary because key codes work different from ASCII codes.\r\n3) Make this function take a `Common::KeyCode` for `key` and adapt it properly, i.e. the `gkey` type etc. too.\r\n4) Adapt all code using `VKEY_UPARROW` etc. to use `Common::KeyCode` values too.\r\n5) Make `IntuiMessage::_code` a `Common::KeyCode` too to reflect that it stores values of that type. This might not be trivial because it seems there is an inflow from a `Button`'s `_buttonId` too. Thus, some more tickeling down or other efforts to increase (type) safety might be required.","created_at":"2015-12-23T16:53:54Z","updated_at":"2015-12-23T16:53:54Z","html_url":"https://github.com/scummvm/scummvm/pull/636#discussion_r48360958","pull_request_url":"https://api.github.com/repos/scummvm/scummvm/pulls/636","_links":{"self":{"href":"https://api.github.com/repos/scummvm/scummvm/pulls/comments/48360958"},"html":{"href":"https://github.com/scummvm/scummvm/pull/636#discussion_r48360958"},"pull_request":{"href":"https://api.github.com/repos/scummvm/scummvm/pulls/636"}}},"pull_request":{"url":"https://api.github.com/repos/scummvm/scummvm/pulls/636","id":53637181,"html_url":"https://github.com/scummvm/scummvm/pull/636","diff_url":"https://github.com/scummvm/scummvm/pull/636.diff","patch_url":"https://github.com/scummvm/scummvm/pull/636.patch","issue_url":"https://api.github.com/repos/scummvm/scummvm/issues/636","number":636,"state":"open","locked":false,"title":"LAB: Engine","user":{"login":"sev-","id":365188,"avatar_url":"https://avatars.githubusercontent.com/u/365188?v=3","gravatar_id":"","url":"https://api.github.com/users/sev-","html_url":"https://github.com/sev-","followers_url":"https://api.github.com/users/sev-/followers","following_url":"https://api.github.com/users/sev-/following{/other_user}","gists_url":"https://api.github.com/users/sev-/gists{/gist_id}","starred_url":"https://api.github.com/users/sev-/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sev-/subscriptions","organizations_url":"https://api.github.com/users/sev-/orgs","repos_url":"https://api.github.com/users/sev-/repos","events_url":"https://api.github.com/users/sev-/events{/privacy}","received_events_url":"https://api.github.com/users/sev-/received_events","type":"User","site_admin":false},"body":"This is a pull request for the game The Labyrinth of Time. This game is currently available on www.wyrmkeep.com and on GOG.com. The game should be completable: it was completable a month ago and we did regularly regression testing. All the work has been based on sources kindly provided by Wyrmkeep.\r\n\r\nThe DOS and the Windows versions are supported by this engine.","created_at":"2015-12-14T23:15:34Z","updated_at":"2015-12-23T16:53:54Z","closed_at":null,"merged_at":null,"merge_commit_sha":"0683d10c330b64b8ecb7ef97757f0c5e9daa6664","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/scummvm/scummvm/pulls/636/commits","review_comments_url":"https://api.github.com/repos/scummvm/scummvm/pulls/636/comments","review_comment_url":"https://api.github.com/repos/scummvm/scummvm/pulls/comments{/number}","comments_url":"https://api.github.com/repos/scummvm/scummvm/issues/636/comments","statuses_url":"https://api.github.com/repos/scummvm/scummvm/statuses/56680d324a5ab7a328df37f330210b3394649961","head":{"label":"sev-:lab","ref":"lab","sha":"56680d324a5ab7a328df37f330210b3394649961","user":{"login":"sev-","id":365188,"avatar_url":"https://avatars.githubusercontent.com/u/365188?v=3","gravatar_id":"","url":"https://api.github.com/users/sev-","html_url":"https://github.com/sev-","followers_url":"https://api.github.com/users/sev-/followers","following_url":"https://api.github.com/users/sev-/following{/other_user}","gists_url":"https://api.github.com/users/sev-/gists{/gist_id}","starred_url":"https://api.github.com/users/sev-/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sev-/subscriptions","organizations_url":"https://api.github.com/users/sev-/orgs","repos_url":"https://api.github.com/users/sev-/repos","events_url":"https://api.github.com/users/sev-/events{/privacy}","received_events_url":"https://api.github.com/users/sev-/received_events","type":"User","site_admin":false},"repo":{"id":6312553,"name":"scummvm","full_name":"sev-/scummvm","owner":{"login":"sev-","id":365188,"avatar_url":"https://avatars.githubusercontent.com/u/365188?v=3","gravatar_id":"","url":"https://api.github.com/users/sev-","html_url":"https://github.com/sev-","followers_url":"https://api.github.com/users/sev-/followers","following_url":"https://api.github.com/users/sev-/following{/other_user}","gists_url":"https://api.github.com/users/sev-/gists{/gist_id}","starred_url":"https://api.github.com/users/sev-/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sev-/subscriptions","organizations_url":"https://api.github.com/users/sev-/orgs","repos_url":"https://api.github.com/users/sev-/repos","events_url":"https://api.github.com/users/sev-/events{/privacy}","received_events_url":"https://api.github.com/users/sev-/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/sev-/scummvm","description":"ScummVM main repository","fork":true,"url":"https://api.github.com/repos/sev-/scummvm","forks_url":"https://api.github.com/repos/sev-/scummvm/forks","keys_url":"https://api.github.com/repos/sev-/scummvm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/sev-/scummvm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/sev-/scummvm/teams","hooks_url":"https://api.github.com/repos/sev-/scummvm/hooks","issue_events_url":"https://api.github.com/repos/sev-/scummvm/issues/events{/number}","events_url":"https://api.github.com/repos/sev-/scummvm/events","assignees_url":"https://api.github.com/repos/sev-/scummvm/assignees{/user}","branches_url":"https://api.github.com/repos/sev-/scummvm/branches{/branch}","tags_url":"https://api.github.com/repos/sev-/scummvm/tags","blobs_url":"https://api.github.com/repos/sev-/scummvm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/sev-/scummvm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/sev-/scummvm/git/refs{/sha}","trees_url":"https://api.github.com/repos/sev-/scummvm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/sev-/scummvm/statuses/{sha}","languages_url":"https://api.github.com/repos/sev-/scummvm/languages","stargazers_url":"https://api.github.com/repos/sev-/scummvm/stargazers","contributors_url":"https://api.github.com/repos/sev-/scummvm/contributors","subscribers_url":"https://api.github.com/repos/sev-/scummvm/subscribers","subscription_url":"https://api.github.com/repos/sev-/scummvm/subscription","commits_url":"https://api.github.com/repos/sev-/scummvm/commits{/sha}","git_commits_url":"https://api.github.com/repos/sev-/scummvm/git/commits{/sha}","comments_url":"https://api.github.com/repos/sev-/scummvm/comments{/number}","issue_comment_url":"https://api.github.com/repos/sev-/scummvm/issues/comments{/number}","contents_url":"https://api.github.com/repos/sev-/scummvm/contents/{+path}","compare_url":"https://api.github.com/repos/sev-/scummvm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/sev-/scummvm/merges","archive_url":"https://api.github.com/repos/sev-/scummvm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/sev-/scummvm/downloads","issues_url":"https://api.github.com/repos/sev-/scummvm/issues{/number}","pulls_url":"https://api.github.com/repos/sev-/scummvm/pulls{/number}","milestones_url":"https://api.github.com/repos/sev-/scummvm/milestones{/number}","notifications_url":"https://api.github.com/repos/sev-/scummvm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/sev-/scummvm/labels{/name}","releases_url":"https://api.github.com/repos/sev-/scummvm/releases{/id}","created_at":"2012-10-20T18:59:43Z","updated_at":"2015-11-07T12:35:56Z","pushed_at":"2015-12-23T10:59:56Z","git_url":"git://github.com/sev-/scummvm.git","ssh_url":"git@github.com:sev-/scummvm.git","clone_url":"https://github.com/sev-/scummvm.git","svn_url":"https://github.com/sev-/scummvm","homepage":"http://www.scummvm.org/","size":205329,"stargazers_count":0,"watchers_count":0,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"scummvm:master","ref":"master","sha":"64f9c902ddf0c8294fd9e5f66cf96661eb12040b","user":{"login":"scummvm","id":365181,"avatar_url":"https://avatars.githubusercontent.com/u/365181?v=3","gravatar_id":"","url":"https://api.github.com/users/scummvm","html_url":"https://github.com/scummvm","followers_url":"https://api.github.com/users/scummvm/followers","following_url":"https://api.github.com/users/scummvm/following{/other_user}","gists_url":"https://api.github.com/users/scummvm/gists{/gist_id}","starred_url":"https://api.github.com/users/scummvm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scummvm/subscriptions","organizations_url":"https://api.github.com/users/scummvm/orgs","repos_url":"https://api.github.com/users/scummvm/repos","events_url":"https://api.github.com/users/scummvm/events{/privacy}","received_events_url":"https://api.github.com/users/scummvm/received_events","type":"Organization","site_admin":false},"repo":{"id":1358940,"name":"scummvm","full_name":"scummvm/scummvm","owner":{"login":"scummvm","id":365181,"avatar_url":"https://avatars.githubusercontent.com/u/365181?v=3","gravatar_id":"","url":"https://api.github.com/users/scummvm","html_url":"https://github.com/scummvm","followers_url":"https://api.github.com/users/scummvm/followers","following_url":"https://api.github.com/users/scummvm/following{/other_user}","gists_url":"https://api.github.com/users/scummvm/gists{/gist_id}","starred_url":"https://api.github.com/users/scummvm/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/scummvm/subscriptions","organizations_url":"https://api.github.com/users/scummvm/orgs","repos_url":"https://api.github.com/users/scummvm/repos","events_url":"https://api.github.com/users/scummvm/events{/privacy}","received_events_url":"https://api.github.com/users/scummvm/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/scummvm/scummvm","description":"ScummVM main repository","fork":false,"url":"https://api.github.com/repos/scummvm/scummvm","forks_url":"https://api.github.com/repos/scummvm/scummvm/forks","keys_url":"https://api.github.com/repos/scummvm/scummvm/keys{/key_id}","collaborators_url":"https://api.github.com/repos/scummvm/scummvm/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/scummvm/scummvm/teams","hooks_url":"https://api.github.com/repos/scummvm/scummvm/hooks","issue_events_url":"https://api.github.com/repos/scummvm/scummvm/issues/events{/number}","events_url":"https://api.github.com/repos/scummvm/scummvm/events","assignees_url":"https://api.github.com/repos/scummvm/scummvm/assignees{/user}","branches_url":"https://api.github.com/repos/scummvm/scummvm/branches{/branch}","tags_url":"https://api.github.com/repos/scummvm/scummvm/tags","blobs_url":"https://api.github.com/repos/scummvm/scummvm/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/scummvm/scummvm/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/scummvm/scummvm/git/refs{/sha}","trees_url":"https://api.github.com/repos/scummvm/scummvm/git/trees{/sha}","statuses_url":"https://api.github.com/repos/scummvm/scummvm/statuses/{sha}","languages_url":"https://api.github.com/repos/scummvm/scummvm/languages","stargazers_url":"https://api.github.com/repos/scummvm/scummvm/stargazers","contributors_url":"https://api.github.com/repos/scummvm/scummvm/contributors","subscribers_url":"https://api.github.com/repos/scummvm/scummvm/subscribers","subscription_url":"https://api.github.com/repos/scummvm/scummvm/subscription","commits_url":"https://api.github.com/repos/scummvm/scummvm/commits{/sha}","git_commits_url":"https://api.github.com/repos/scummvm/scummvm/git/commits{/sha}","comments_url":"https://api.github.com/repos/scummvm/scummvm/comments{/number}","issue_comment_url":"https://api.github.com/repos/scummvm/scummvm/issues/comments{/number}","contents_url":"https://api.github.com/repos/scummvm/scummvm/contents/{+path}","compare_url":"https://api.github.com/repos/scummvm/scummvm/compare/{base}...{head}","merges_url":"https://api.github.com/repos/scummvm/scummvm/merges","archive_url":"https://api.github.com/repos/scummvm/scummvm/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/scummvm/scummvm/downloads","issues_url":"https://api.github.com/repos/scummvm/scummvm/issues{/number}","pulls_url":"https://api.github.com/repos/scummvm/scummvm/pulls{/number}","milestones_url":"https://api.github.com/repos/scummvm/scummvm/milestones{/number}","notifications_url":"https://api.github.com/repos/scummvm/scummvm/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/scummvm/scummvm/labels{/name}","releases_url":"https://api.github.com/repos/scummvm/scummvm/releases{/id}","created_at":"2011-02-12T15:50:57Z","updated_at":"2015-12-19T02:29:32Z","pushed_at":"2015-12-23T16:10:38Z","git_url":"git://github.com/scummvm/scummvm.git","ssh_url":"git@github.com:scummvm/scummvm.git","clone_url":"https://github.com/scummvm/scummvm.git","svn_url":"https://github.com/scummvm/scummvm","homepage":"http://www.scummvm.org/","size":211424,"stargazers_count":554,"watchers_count":554,"language":"C++","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":277,"mirror_url":null,"open_issues_count":23,"forks":277,"open_issues":23,"watchers":554,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/scummvm/scummvm/pulls/636"},"html":{"href":"https://github.com/scummvm/scummvm/pull/636"},"issue":{"href":"https://api.github.com/repos/scummvm/scummvm/issues/636"},"comments":{"href":"https://api.github.com/repos/scummvm/scummvm/issues/636/comments"},"review_comments":{"href":"https://api.github.com/repos/scummvm/scummvm/pulls/636/comments"},"review_comment":{"href":"https://api.github.com/repos/scummvm/scummvm/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/scummvm/scummvm/pulls/636/commits"},"statuses":{"href":"https://api.github.com/repos/scummvm/scummvm/statuses/56680d324a5ab7a328df37f330210b3394649961"}}}}