gcsx_toolselect.cpp 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. /* GCSx
  2. ** TOOLSELECT.CPP
  3. **
  4. ** Tool selection popup dialogs
  5. */
  6. /*****************************************************************************
  7. ** Copyright (C) 2003-2006 Janson
  8. **
  9. ** This program is free software; you can redistribute it and/or modify
  10. ** it under the terms of the GNU General Public License as published by
  11. ** the Free Software Foundation; either version 2 of the License, or
  12. ** (at your option) any later version.
  13. **
  14. ** This program is distributed in the hope that it will be useful,
  15. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ** GNU General Public License for more details.
  18. **
  19. ** You should have received a copy of the GNU General Public License
  20. ** along with this program; if not, write to the Free Software
  21. ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
  22. *****************************************************************************/
  23. #include "all.h"
  24. ToolSelect::ToolSelect(SDL_Surface* tIconSurface, int myNumTools, const ToolIconStruct* toolStructs) : Dialog(blankString, 0, 0) { start_func
  25. assert(myNumTools);
  26. assert(toolStructs);
  27. iconSurface = tIconSurface;
  28. numTools = myNumTools;
  29. tools = toolStructs;
  30. Widget* w = NULL;
  31. for (int pos = 0; pos < numTools; ++pos) {
  32. w = new WButton(toolStructs[pos].id, iconSurface, toolStructs[pos].x, toolStructs[pos].y, 20, 20, Dialog::BUTTON_OK);
  33. w->setToolTip(toolStructs[pos].tooltip);
  34. w->addTo(this);
  35. if (pos % 4 == 3) arrangeRow();
  36. }
  37. arrangeRow();
  38. }
  39. ToolSelect::~ToolSelect() { start_func
  40. }
  41. int ToolSelect::run(int atX, int atY) { start_func
  42. return runModal(atX, atY);
  43. }
  44. int ToolSelect::getToolIcon(int id, int& iX, int& iY) const { start_func
  45. for (int pos = 0; pos < numTools; ++pos) {
  46. if (tools[pos].id == id) {
  47. iX = tools[pos].x;
  48. iY = tools[pos].y;
  49. return 1;
  50. }
  51. }
  52. return 0;
  53. }
  54. int ToolSelect::isTool(int id) const { start_func
  55. for (int pos = 0; pos < numTools; ++pos) {
  56. if (tools[pos].id == id) {
  57. return 1;
  58. }
  59. }
  60. return 0;
  61. }