gcsx_animgrouppaint.cpp 53 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389
  1. /* GCSx
  2. ** ANIMGROUPPAINT.CPP
  3. **
  4. ** Animation group editing
  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. // Tool panel
  25. const ToolSelect::ToolIconStruct AnimGroupPaintTools::toolIcons[TOOLSELECT_NUM_TOOLS] = {
  26. { TOOLS_PLACEITEM, 80, 100, "Place components" },
  27. { TOOLS_SELECTITEM, 0, 120, "Select by component" },
  28. { TOOLS_SELECT, 0, 20, "Select via rectangle" },
  29. };
  30. const ToolSelect::ToolIconStruct AnimGroupPaintTools::outlineIcons[TOOLSELECT_NUM_OUTLINE] = {
  31. { VIEW_OUTLINE_NONE, 20, 120, "Don't show outlines" },
  32. { VIEW_OUTLINE_NORMAL, 40, 120, "Show outlines on components" },
  33. { VIEW_OUTLINE_HANDLE, 60, 120, "Show outlines with handles" },
  34. };
  35. int AnimGroupPaintTools::event(int hasFocus, const SDL_Event* event) { start_func
  36. if (event->type == SDL_COMMAND) {
  37. // Choose tool or dots
  38. int newToolL = 0;
  39. int newToolR = 0;
  40. int newOutline = 0;
  41. WButton* toolButtonL = dynamic_cast<WButton*>(findWidget(ID_TOOLL));
  42. WButton* toolButtonR = dynamic_cast<WButton*>(findWidget(ID_TOOLR));
  43. WButton* outlineButton = dynamic_cast<WButton*>(findWidget(ID_OUTLINE));
  44. int x, y;
  45. if (event->user.code == TOOLS_CHOOSE) {
  46. newToolL = toolSelect->run(toolButtonL->getScreenX(), toolButtonL->getScreenY() + toolButtonL->getHeight());
  47. }
  48. else if (event->user.code == TOOLS_CHOOSER) {
  49. newToolR = toolSelect->run(toolButtonR->getScreenX(), toolButtonR->getScreenY() + toolButtonR->getHeight());
  50. }
  51. else if (toolSelect->isTool(event->user.code)) {
  52. newToolL = event->user.code;
  53. }
  54. else if (event->user.code == VIEW_OUTLINE_CHOOSE) {
  55. newOutline = outlineSelect->run(outlineButton->getScreenX(), outlineButton->getScreenY() + outlineButton->getHeight());
  56. }
  57. else if (outlineSelect->isTool(event->user.code)) {
  58. newOutline = event->user.code;
  59. }
  60. if (newToolL) {
  61. if (toolSelect->getToolIcon(newToolL, x, y)) {
  62. toolButtonL->changeIcon(x, y);
  63. *toolLPtr = newToolL;
  64. return 1;
  65. }
  66. }
  67. if (newToolR) {
  68. if (toolSelect->getToolIcon(newToolR, x, y)) {
  69. toolButtonR->changeIcon(x, y);
  70. *toolRPtr = newToolR;
  71. return 1;
  72. }
  73. }
  74. if (newOutline) {
  75. if (outlineSelect->getToolIcon(newOutline, x, y)) {
  76. outlineButton->changeIcon(x, y);
  77. *outlinePtr = newOutline;
  78. paintArea->refresh();
  79. config->write(ANIMEDIT_OUTLINE, *outlinePtr);
  80. return 1;
  81. }
  82. }
  83. if ((event->user.code == TOOLS_CHOOSE) || (event->user.code == TOOLS_CHOOSER) || (event->user.code == VIEW_OUTLINE_CHOOSE)) return 1;
  84. }
  85. return Dialog::event(hasFocus, event);
  86. }
  87. void AnimGroupPaintTools::childModified(Window* modified) { start_func
  88. Dialog::childModified(modified);
  89. // @TODO: detect changes in animation name
  90. // @TODO: selection in listbox should update tilesetPtr
  91. // [outline setting updates all handled in event()]
  92. }
  93. void AnimGroupPaintTools::previewRedraw() { start_func
  94. // @TODO: preview isn't added yet : assert(findWidget(ID_PREVIEW));
  95. // (doesn't throw exceptions)
  96. // @TODO: preview isn't added yet : findWidget(ID_PREVIEW)->load();
  97. }
  98. int AnimGroupPaintTools::wantsToBeDeleted() const { start_func
  99. return 1;
  100. }
  101. FrameWindow* AnimGroupPaintTools::createWindowed() { start_func
  102. // Prevent duplication
  103. if (myFrame) {
  104. return myFrame;
  105. }
  106. // We remember the frame pointer even though it'll delete itself
  107. myFrame = new FrameWindow("Tools", FrameWindow::RESIZING_SNAP, FrameWindow::FRAMETYPE_DIALOG, this, FrameWindow::TITLEBAR_TOOL, 0);
  108. return myFrame;
  109. }
  110. Window::WindowSort AnimGroupPaintTools::windowSort() const { start_func
  111. return WINDOWSORT_ONTOP;
  112. }
  113. AnimGroupPaintTools::AnimGroupPaintTools(AnimGroupPaint* tPaintArea, ImageSelect* mImagebar, int* toolL, int* toolR, int* outline, string* animName, TileSetEdit** tileset) : Dialog(blankString, 1, 0, 1) { start_func
  114. myFrame = NULL;
  115. imagebar = mImagebar;
  116. paintArea = tPaintArea;
  117. toolLPtr = toolL;
  118. toolRPtr = toolR;
  119. outlinePtr = outline;
  120. animNamePtr = animName;
  121. tilesetPtr = tileset;
  122. Widget* w = NULL;
  123. toolSelect = new ToolSelect(getIconSurface(), TOOLSELECT_NUM_TOOLS, toolIcons);
  124. outlineSelect = new ToolSelect(getIconSurface(), TOOLSELECT_NUM_OUTLINE, outlineIcons);
  125. int x = 0;
  126. int y = 0;
  127. toolSelect->getToolIcon(*toolLPtr, x, y);
  128. w = new WButton(ID_TOOLL, getIconSurface(), x, y, 20, 20, Dialog::BUTTON_NOTHING, TOOLS_CHOOSE);
  129. w->setToolTip("Change tool (left button)");
  130. w->addTo(this);
  131. x = y = 0;
  132. toolSelect->getToolIcon(*toolRPtr, x, y);
  133. w = new WButton(ID_TOOLR, getIconSurface(), x, y, 20, 20, Dialog::BUTTON_NOTHING, TOOLS_CHOOSER);
  134. w->setToolTip("Change tool (right button)");
  135. w->addTo(this);
  136. arrangeRow();
  137. w = new WButton(ID_COPY, getIconSurface(), 60, 20, 20, 20, Dialog::BUTTON_NOTHING, EDIT_COPY);
  138. w->setToolTip("Copy");
  139. w->addTo(this);
  140. w = new WButton(ID_PASTE, getIconSurface(), 80, 20, 20, 20, Dialog::BUTTON_NOTHING, EDIT_PASTE);
  141. w->setToolTip("Paste");
  142. w->addTo(this);
  143. outlineSelect->getToolIcon(*outlinePtr, x, y);
  144. w = new WButton(ID_OUTLINE, getIconSurface(), x, y, 20, 20, Dialog::BUTTON_NOTHING, VIEW_OUTLINE_CHOOSE);
  145. w->setToolTip("Control display of component outlines");
  146. w->addTo(this);
  147. arrangeRow();
  148. // @TODO: disable/enable these buttons dynamically?
  149. w = new WButton(ID_TOP, getIconSurface(), 40, 140, 20, 20, Dialog::BUTTON_NOTHING, EDIT_MOVETOP);
  150. w->setToolTip("Move component to top (front)");
  151. w->addTo(this);
  152. w = new WButton(ID_UP, getIconSurface(), 0, 140, 20, 20, Dialog::BUTTON_NOTHING, EDIT_MOVEUP);
  153. w->setToolTip("Move component up (towards front)");
  154. w->addTo(this);
  155. w = new WButton(ID_DOWN, getIconSurface(), 20, 140, 20, 20, Dialog::BUTTON_NOTHING, EDIT_MOVEDOWN);
  156. w->setToolTip("Move component down (towards back)");
  157. w->addTo(this);
  158. w = new WButton(ID_BOTTOM, getIconSurface(), 60, 140, 20, 20, Dialog::BUTTON_NOTHING, EDIT_MOVEBOTTOM);
  159. w->setToolTip("Move component to bottom (back)");
  160. w->addTo(this);
  161. arrangeRow();
  162. w = new WStatic(ID_NAMELABEL, "Animation name:");
  163. w->addTo(this);
  164. arrangeRow();
  165. w = new WTextBox(ID_NAME, animNamePtr, 0);
  166. w->setToolTip("Provide a descriptive name for your sprite animation");
  167. w->addTo(this);
  168. arrangeRow();
  169. w = new WStatic(ID_TILESETLABEL, "Image/Tile set:");
  170. w->addTo(this);
  171. arrangeRow();
  172. w = tilesetList = new WListBox(ID_TILESET, &selectedTileset);
  173. w->setToolTip("Select which image/tile set to use for new components");
  174. w->addTo(this);
  175. arrangeRow();
  176. // @TODO:
  177. // Request initial height based on @TODO:, although this will inevitably be resized
  178. int previewHeight = 96;
  179. // if (*tileSource) previewHeight = (*tileSource)->h * 3;
  180. // w = new WPreview(ID_PREVIEW, tileSource, 166, previewHeight, 1, 0);
  181. // w->setToolTip("Preview");
  182. // w->addTo(this);
  183. // w = NULL;
  184. // arrangeRow();
  185. // Our height if preview is 0 pixels high
  186. minHeight = height - previewHeight;
  187. runAsPanel();
  188. }
  189. AnimGroupPaintTools::~AnimGroupPaintTools() { start_func
  190. delete toolSelect;
  191. delete outlineSelect;
  192. }
  193. void AnimGroupPaintTools::resize(int newWidth, int newHeight, int newViewWidth, int newViewHeight, int fromParent) { start_func
  194. if (newViewHeight == -1) newViewHeight = viewWidth;
  195. if (newViewHeight >= 0) {
  196. // Resize animation preview to fit
  197. // @TODO:
  198. // WPreview* widget = dynamic_cast<WPreview*>(findWidget(ID_PREVIEW));
  199. // if (widget) { start_func
  200. // int previewHeight = newViewHeight - minHeight;
  201. // if (previewHeight > 0) { start_func
  202. // widget->changeSize(166, previewHeight);
  203. // // Doesn't throw exceptions
  204. // widget->load();
  205. // newHeight = newViewHeight;
  206. // }
  207. // else {
  208. // widget->changeSize(166, 0);
  209. // // Doesn't throw exceptions
  210. // widget->load();
  211. // newHeight = minHeight;
  212. // }
  213. // }
  214. }
  215. Window::resize(newWidth, newHeight, newViewWidth, newViewHeight, fromParent);
  216. }
  217. // Main edit window
  218. AnimGroupPaint::AnimGroupPaint(AnimGroupEdit* myAnimGroup, int animId) throw_File : Window(), anim(), selected(), backupSelected() { start_func
  219. assert(myAnimGroup);
  220. // @TODO: assert imageId is valid
  221. haveFocus = partialFocus = 0;
  222. toolActive = 0;
  223. cursorComp = -1;
  224. seqId = animId;
  225. frameId = 0;
  226. frameCount = 1;
  227. selectRect.w = 0;
  228. animgroup = myAnimGroup;
  229. // Intentionally doesn't remember last tool selected
  230. toolL = TOOLS_PLACEITEM;
  231. toolR = TOOLS_SELECTITEM;
  232. // Recall last settings
  233. outline = config->readNum(ANIMEDIT_OUTLINE);
  234. if ((outline != VIEW_OUTLINE_NONE) && (outline != VIEW_OUTLINE_HANDLE)) outline = VIEW_OUTLINE_NORMAL;
  235. // @TODO: store setting and also, this setting isn't used yet
  236. enableGrid = 0;
  237. myFrame = NULL;
  238. tools = NULL;
  239. imagebar = NULL;
  240. colorbar = NULL;
  241. animgroup->markLock(); // Exception point
  242. FrameWindow* toolsFrame = NULL;
  243. FrameWindow* imagebarFrame = NULL;
  244. FrameWindow* colorbarFrame = NULL;
  245. try {
  246. myFrame = new FrameWindow(blankString, FrameWindow::RESIZING_NORMAL, FrameWindow::FRAMETYPE_BEVEL_BK, this);
  247. myFrame->setAutoCenter(1);
  248. refreshData();
  249. refreshName();
  250. // Get tileset to start with
  251. assert(anim.count); // @TODO: if no frames, add one?
  252. if (anim.frames[frameId].count) {
  253. tileset = dynamic_cast<TileSetEdit*>(anim.frames[frameId].comps[0].tileset);
  254. }
  255. else {
  256. // @TODO: if no tilesets, ?
  257. World::TileSetIndex::const_iterator firstTS = animgroup->getWorldEdit()->beginTileSet();
  258. assert(firstTS != animgroup->getWorldEdit()->endTileSet());
  259. tileset = dynamic_cast<TileSetEdit*>((*firstTS).second);
  260. }
  261. imagebar = new ImageSelect(tileset, &colors, 0); // One exeption point (others?)
  262. colorbar = new ColorSelect(&colors, 0, 0);
  263. tools = new AnimGroupPaintTools(this, imagebar, &toolL, &toolR, &outline, &anim.name, &tileset);
  264. imagebarFrame = imagebar->createWindowed();
  265. colorbarFrame = colorbar->createWindowed();
  266. toolsFrame = tools->createWindowed();
  267. updateTitlebar();
  268. myFrame->addToolPanel(imagebarFrame, FrameWindow::CLIENT_BOTTOM);
  269. myFrame->addToolPanel(colorbarFrame, FrameWindow::CLIENT_RIGHT);
  270. myFrame->addToolPanel(toolsFrame, FrameWindow::CLIENT_RIGHT);
  271. myFrame->show(FrameWindow::SHOW_CASCADE, FrameWindow::SHOW_CASCADE, FrameWindow::SHOW_CURRENT, FrameWindow::SHOW_CURRENT);
  272. imagebar->colorRefresh();
  273. }
  274. catch (...) {
  275. if (myFrame) {
  276. myFrame->dropClients();
  277. delete myFrame;
  278. myFrame = NULL;
  279. }
  280. if (toolsFrame) {
  281. delete toolsFrame;
  282. }
  283. else {
  284. delete tools;
  285. }
  286. if (colorbarFrame) {
  287. delete colorbarFrame;
  288. }
  289. else {
  290. delete colorbar;
  291. }
  292. if (imagebarFrame) {
  293. delete imagebarFrame;
  294. }
  295. else {
  296. delete imagebar;
  297. }
  298. animgroup->markUnlock();
  299. throw;
  300. }
  301. // Disabled/etc status on various tools
  302. tools->findWidget(AnimGroupPaintTools::ID_COPY)->disable();
  303. }
  304. AnimGroupPaint::~AnimGroupPaint() { start_func
  305. if (animgroup) animgroup->markUnlock();
  306. }
  307. void AnimGroupPaint::siblingModified(Window* modified) { start_func
  308. // Img selector updates with any color change
  309. if (modified == colorbar) {
  310. if (imagebar) imagebar->colorRefresh();
  311. }
  312. }
  313. void AnimGroupPaint::setDirtyRect(const Rect& rect) { start_func
  314. // Clip
  315. Rect bound = { 0, 0, anim.width, anim.height };
  316. if (intersectRects(bound, rect)) {
  317. // Add rectangle into dirty range
  318. boundRects(dirtyRange, bound);
  319. setDirty();
  320. }
  321. }
  322. void AnimGroupPaint::setDirtyBox(int x1, int y1, int x2, int y2) { start_func
  323. // Create a rectangle
  324. // Add rectangle into dirty range
  325. setDirtyRect(createRect(x1, y1, x2, y2));
  326. }
  327. void AnimGroupPaint::setDirtyComp(int subid) { start_func
  328. assert(subid >= 0);
  329. assert(subid < anim.frames[frameId].count);
  330. Rect rect = { anim.frames[frameId].comps[subid].x, anim.frames[frameId].comps[subid].y,
  331. anim.frames[frameId].comps[subid].tileset->getWidth(),
  332. anim.frames[frameId].comps[subid].tileset->getHeight() };
  333. setDirtyRect(rect);
  334. }
  335. void AnimGroupPaint::refreshData() { start_func
  336. assert(animgroup);
  337. animgroup->loadAnim(seqId, &anim);
  338. resize(anim.width + RESIZE_HANDLE_SIZE, anim.height + RESIZE_HANDLE_SIZE);
  339. // @TODO: lock/unlock tilesets used by animation
  340. }
  341. void AnimGroupPaint::applyData() { start_func
  342. assert(animgroup);
  343. animgroup->saveAnim(seqId, &anim, this);
  344. tools->previewRedraw();
  345. }
  346. void AnimGroupPaint::refreshName() { start_func
  347. assert(animgroup);
  348. animgroup->loadAnimName(seqId, &anim.name);
  349. }
  350. void AnimGroupPaint::applyName() { start_func
  351. assert(animgroup);
  352. animgroup->saveAnimName(seqId, &anim.name, this);
  353. }
  354. // @TODO: call on changes
  355. void AnimGroupPaint::updateTitlebar() { start_func
  356. if ((myFrame) && (animgroup)) {
  357. myFrame->setTitle(formatString("%s : %s : Anim. %s", animgroup->getWorld()->getTitle().c_str(), animgroup->getName().c_str(), anim.name.c_str()));
  358. }
  359. }
  360. int AnimGroupPaint::event(int hasFocus, const SDL_Event* event) { start_func
  361. int changed = 0;
  362. ObjChange* obj;
  363. switch (event->type) {
  364. case SDL_CLOSE:
  365. return 1;
  366. case SDL_SPECIAL:
  367. // Refresh selection rectangle?
  368. if ((event->user.code == SDL_IDLEPHASE) && (partialFocus) && (selectRect.w)) {
  369. setDirtyRect(selectRect);
  370. }
  371. // Refresh cursor?
  372. if (((event->user.code == SDL_IDLECURSOR) || (event->user.code == SDL_IDLEPHASE)) && (haveFocus) && (cursorComp >= 0)) {
  373. setDirtyComp(cursorComp);
  374. }
  375. return 1;
  376. case SDL_COMMAND:
  377. switch (event->user.code) {
  378. case EDIT_UNDO:
  379. // finish instead of cancel- this causes undo to undo current
  380. // tool if one is being used
  381. finishTool();
  382. // (let world handle from here)
  383. break;
  384. case EDIT_REDO:
  385. cancelTool();
  386. // (let world handle from here)
  387. break;
  388. case EDIT_COPY:
  389. copySelection();
  390. return 1;
  391. case EDIT_CUT:
  392. try { // @TODO: Try block not technically needed until undo functions work
  393. animgroup->getWorldEdit()->undo.preUndoBlock();
  394. copySelection();
  395. deleteSelection();
  396. clearSelection();
  397. animgroup->getWorldEdit()->undo.postUndoBlock();
  398. }
  399. catch (UndoException& e) {
  400. }
  401. return 1;
  402. case EDIT_DELETE:
  403. try { // @TODO: Try block not technically needed until undo functions work
  404. deleteSelection();
  405. }
  406. catch (UndoException& e) {
  407. }
  408. return 1;
  409. case EDIT_SELECTALL:
  410. try { // @TODO: Try block not technically needed until undo functions work
  411. animgroup->getWorldEdit()->undo.preUndoBlock();
  412. undoStoreSelect();
  413. animgroup->getWorldEdit()->undo.postUndoBlock();
  414. // Select all
  415. // @TODO:
  416. setDirty(1);
  417. tools->findWidget(AnimGroupPaintTools::ID_COPY)->enable();
  418. }
  419. catch (UndoException& e) {
  420. }
  421. return 1;
  422. case EDIT_DESELECTALL:
  423. cancelTool();
  424. try { // @TODO: Try block not technically needed until undo functions work
  425. clearSelection();
  426. }
  427. catch (UndoException& e) {
  428. }
  429. return 1;
  430. case EDIT_PASTE:
  431. try { // @TODO: Try block not technically needed until undo functions work
  432. pasteSelection();
  433. }
  434. catch (UndoException& e) {
  435. }
  436. // Make sure a selection tool is current
  437. if ((!toolActive) && (toolL != TOOLS_SELECT) && (toolL != TOOLS_SELECTITEM)) {
  438. desktop->broadcastEvent(SDL_COMMAND, TOOLS_SELECTITEM);
  439. desktop->broadcastEvent(SDL_COMMAND, CMD_RELEASE);
  440. }
  441. return 1;
  442. case CMD_RELEASE:
  443. finishTool(); // safe even if no tool
  444. return 1;
  445. case TOOLS_NEXTCOLOR:
  446. colorbar->colorSelection(ColorSelect::SELECTED_FG,
  447. colorbar->colorSelection(ColorSelect::SELECTED_FG) + 1);
  448. return 1;
  449. case TOOLS_PREVCOLOR:
  450. colorbar->colorSelection(ColorSelect::SELECTED_FG,
  451. colorbar->colorSelection(ColorSelect::SELECTED_FG) - 1);
  452. return 1;
  453. case TOOLS_EDITCOLOR:
  454. colorbar->editColor(colorbar->colorSelection(ColorSelect::SELECTED_FG));
  455. return 1;
  456. }
  457. if (animgroup->getWorldEdit()->commandEvent(event->user.code)) return 1;
  458. break;
  459. case SDL_OBJECTCHANGE:
  460. obj = (ObjChange*)event->user.data1;
  461. if (event->user.code & OBJ_TILESET) {
  462. // @TODO:
  463. }
  464. if (event->user.code & OBJ_ANIMGROUP) {
  465. // @TODO:
  466. }
  467. if ((event->user.code & OBJ_WORLD) && (obj->obj == animgroup->getWorld())) {
  468. if (event->user.code & OBJMOD_DELETE) {
  469. imagebar->changeSet(NULL, 1);
  470. animgroup = NULL;
  471. closeWindow();
  472. }
  473. if (event->user.code & OBJMOD_NAME) {
  474. updateTitlebar();
  475. }
  476. }
  477. return 1;
  478. case SDL_MOUSEBUTTONDOWN:
  479. case SDL_MOUSEBUTTONDBL:
  480. if ((event->button.button == SDL_BUTTON_LEFT) || (event->button.button == SDL_BUTTON_RIGHT)) {
  481. // Signed as it could go off the edge
  482. Sint16 cX = event->button.x;
  483. Sint16 cY = event->button.y;
  484. // If unmodified selection-tool left-click and within selection, this is a selection drag
  485. if ((!toolActive) &&
  486. ((toolL == TOOLS_SELECT) || (toolL == TOOLS_SELECTITEM)) &&
  487. !(SDL_GetModState() & (KMOD_CTRL | KMOD_ALT)) &&
  488. (event->button.button == SDL_BUTTON_LEFT) &&
  489. (isInSelection(cX, cY))) {
  490. startToolSelectionDrag(cX, cY);
  491. }
  492. else {
  493. startTool(cX, cY, event->button.button);
  494. }
  495. return 1;
  496. }
  497. break;
  498. case SDL_MOUSEBUTTONUP:
  499. finishTool();
  500. return 1;
  501. case SDL_MOUSEMOTION:
  502. if ((event->motion.state & SDL_BUTTON_LMASK) || (event->motion.state & SDL_BUTTON_RMASK)) {
  503. // Signed as it could go off the edge
  504. dragTool((Sint16)event->motion.x, (Sint16)event->motion.y);
  505. }
  506. else {
  507. // Update mouse pointer
  508. mousePointer((Sint16)event->motion.x, (Sint16)event->motion.y);
  509. }
  510. return 1;
  511. case SDL_MOUSEFOCUS:
  512. if (event->user.code & 1) {
  513. hover = 1;
  514. mousePointer();
  515. }
  516. else {
  517. hover = 0;
  518. selectMouse(MOUSE_NORMAL);
  519. }
  520. return 1;
  521. case SDL_INPUTFOCUS:
  522. if (event->user.code & 1) {
  523. if (!haveFocus) {
  524. haveFocus = partialFocus = 1;
  525. changed = 1;
  526. }
  527. }
  528. else if (event->user.code & 2) {
  529. if (!partialFocus) {
  530. partialFocus = 1;
  531. changed = 1;
  532. }
  533. }
  534. else {
  535. if (partialFocus) {
  536. partialFocus = 0;
  537. changed = 1;
  538. }
  539. }
  540. if (!(event->user.code & 1)) {
  541. if (haveFocus) {
  542. cancelTool();
  543. haveFocus = 0;
  544. changed = 1;
  545. }
  546. }
  547. if (changed) {
  548. // Refresh selection rectangle and cursor
  549. setDirtyRect(selectRect);
  550. if (cursorComp >= 0) setDirtyComp(cursorComp);
  551. }
  552. return 1;
  553. case SDL_KEYUP:
  554. switch (event->key.keysym.sym) {
  555. case SDLK_LALT:
  556. case SDLK_RALT:
  557. case SDLK_LCTRL:
  558. case SDLK_RCTRL:
  559. modifyTool();
  560. return 1;
  561. default:
  562. break;
  563. }
  564. break;
  565. case SDL_KEYDOWN:
  566. switch (event->key.keysym.sym) {
  567. case SDLK_TAB:
  568. // @TODO: change cursor/selection; detect shift
  569. break;
  570. case SDLK_LALT:
  571. case SDLK_RALT:
  572. case SDLK_LCTRL:
  573. case SDLK_RCTRL:
  574. modifyTool();
  575. return 1;
  576. case SDLK_RIGHT:
  577. // @TODO: undo and store for all key-based selection movement
  578. if (event->key.keysym.mod & KMOD_CTRL) moveSelection(anim.width - selectRect.w - selectRect.x, 0);
  579. else moveSelection(1, 0);
  580. return 1;
  581. case SDLK_END:
  582. if (event->key.keysym.mod & KMOD_CTRL) moveSelection(anim.width - selectRect.w - selectRect.x, anim.height - selectRect.h - selectRect.y);
  583. else moveSelection(anim.width - selectRect.w - selectRect.x, 0);
  584. return 1;
  585. case SDLK_LEFT:
  586. if (event->key.keysym.mod & KMOD_CTRL) moveSelection(-selectRect.x, 0);
  587. else moveSelection(-1, 0);
  588. return 1;
  589. case SDLK_HOME:
  590. if (event->key.keysym.mod & KMOD_CTRL) moveSelection(-selectRect.x, -selectRect.y);
  591. else moveSelection(-selectRect.x, 0);
  592. return 1;
  593. case SDLK_DOWN:
  594. if (event->key.keysym.mod & KMOD_CTRL) moveSelection(0, anim.height - selectRect.h - selectRect.y);
  595. else moveSelection(0, 1);
  596. return 1;
  597. case SDLK_UP:
  598. if (event->key.keysym.mod & KMOD_CTRL) moveSelection(0, -selectRect.y);
  599. else moveSelection(0, -1);
  600. return 1;
  601. case SDLK_PAGEDOWN:
  602. moveSelection(0, anim.height - selectRect.h - selectRect.y);
  603. return 1;
  604. case SDLK_PAGEUP:
  605. moveSelection(0, -selectRect.y);
  606. return 1;
  607. default:
  608. break;
  609. }
  610. break;
  611. }
  612. return 0;
  613. }
  614. void AnimGroupPaint::moveSelection(int changeX, int changeY) { start_func
  615. // Ensure a selection exists and we're actually moving it
  616. if ((selectRect.w) && ((changeX) || (changeY))) {
  617. // Dirty old
  618. setDirtyRect(selectRect);
  619. // Clip movement
  620. if (selectRect.x + changeX < 0) changeX = -selectRect.x;
  621. if (selectRect.y + changeY < 0) changeY = -selectRect.y;
  622. if (selectRect.x + changeX + selectRect.w > anim.width) changeX = anim.width - selectRect.w - selectRect.x;
  623. if (selectRect.y + changeY + selectRect.h > anim.height) changeY = anim.height - selectRect.h - selectRect.y;
  624. // Move all selected components
  625. set<int>::iterator end = selected.end();
  626. for (set<int>::iterator pos = selected.begin(); pos != end; ++pos) {
  627. assert(*pos >= 0);
  628. assert(*pos < anim.count);
  629. anim.frames[frameId].comps[*pos].x += changeX;
  630. anim.frames[frameId].comps[*pos].y += changeY;
  631. }
  632. // Modify rect
  633. selectRect.x += changeX;
  634. selectRect.y += changeY;
  635. // Dirty new
  636. setDirtyRect(selectRect);
  637. // @TODO: scroll to view selection
  638. }
  639. }
  640. void AnimGroupPaint::startToolSelectionDrag(int x, int y) { start_func
  641. if (toolActive) return;
  642. toolActive = TOOLS_SELECTDRAG;
  643. toolLastX = toolStartX = x;
  644. toolLastY = toolStartY = y;
  645. toolCtrl = SDL_GetModState() & KMOD_CTRL;
  646. toolAlt = SDL_GetModState() & KMOD_ALT;
  647. mousePointer();
  648. dragTool(x, y, 1);
  649. }
  650. void AnimGroupPaint::startTool(int x, int y, int button) { start_func
  651. if (toolActive) return;
  652. toolActive = button == SDL_BUTTON_LEFT ? toolL : toolR;
  653. toolLastX = toolStartX = x;
  654. toolLastY = toolStartY = y;
  655. toolCtrl = SDL_GetModState() & KMOD_CTRL;
  656. toolAlt = SDL_GetModState() & KMOD_ALT;
  657. mousePointer();
  658. dragTool(x, y, 1);
  659. }
  660. void AnimGroupPaint::modifyTool() { start_func
  661. if (toolActive) {
  662. toolCtrl = SDL_GetModState() & KMOD_CTRL;
  663. toolAlt = SDL_GetModState() & KMOD_ALT;
  664. // Selection tools need entire area dirtied because this may cause
  665. // a deleted selection to reappear
  666. if ((toolActive == TOOLS_SELECT) || (toolActive == TOOLS_SELECTITEM)) {
  667. setDirty(1);
  668. }
  669. dragTool(toolLastX, toolLastY);
  670. }
  671. // Always update mouse pointer even if no active tool
  672. mousePointer();
  673. }
  674. void AnimGroupPaint::dragTool(int x, int y, int firstTime, int lastTime) { start_func
  675. if (toolActive) {
  676. // @TODO:
  677. // int rX, rY;
  678. // int slope1, slope2;
  679. // Rect rect;
  680. // Rect layerBound = { 0, 0, layerWidth, layerHeight };
  681. // int nonDraw = 0;
  682. // if ((toolActive == TOOLS_SELECT) || (toolActive == TOOLS_SELECTELLIPSE) ||
  683. // (toolActive == TOOLS_DROPPER) || (toolActive == TOOLS_WAND) ||
  684. // (toolActive == TOOLS_SELECTDRAG)) { start_func
  685. // nonDraw = 1;
  686. // }
  687. //
  688. // // So that undo warning boxes don't cancel us!
  689. // int tool = toolActive;
  690. // if (lastTime) toolActive = 0;
  691. //
  692. // try { // @TODO: Try block not technically needed until undo functions work
  693. // switch (tool) { start_func
  694. // case TOOLS_SELECTDRAG:
  695. // // Dirty current selection area
  696. // setDirtyBox(selectRect.x + selectionXOffs, selectRect.y + selectionYOffs,
  697. // selectRect.x + selectRect.w - 1 + selectionXOffs,
  698. // selectRect.y + selectRect.h - 1 + selectionYOffs);
  699. //
  700. // // Float selection?
  701. // if (firstTime) { start_func
  702. // floatSelection();
  703. // }
  704. // else {
  705. // // Move selection
  706. // selectionXOffs += virtualCursorX - toolLastX;
  707. // selectionYOffs += virtualCursorY - toolLastY;
  708. //
  709. // // Dirty new area also
  710. // setDirtyBox(selectRect.x + selectionXOffs, selectRect.y + selectionYOffs,
  711. // selectRect.x + selectRect.w - 1 + selectionXOffs,
  712. // selectRect.y + selectRect.h - 1 + selectionYOffs);
  713. // }
  714. // break;
  715. //
  716. // case TOOLS_WAND:
  717. // case TOOLS_SELECT:
  718. // case TOOLS_SELECTELLIPSE:
  719. // // Keep a backup copy of old selection
  720. // if (firstTime) { start_func
  721. // memcpy(backupSelected, selected, selectedPitch * layerHeight);
  722. // backupSelectRect = selectRect;
  723. // }
  724. // // Refresh from backup if dragging with ctrl/alt
  725. // else if ((toolCtrl) || (toolAlt)) { start_func
  726. // memcpy(selected, backupSelected, selectedPitch * layerHeight);
  727. // selectRect = backupSelectRect;
  728. // }
  729. //
  730. // if (tool == TOOLS_WAND) { start_func
  731. // // We get rectangle from previous time
  732. // if (!firstTime) { start_func
  733. // rect.x = toolMinX;
  734. // rect.y = toolMinY;
  735. // rect.w = toolMaxX - toolMinX + 1;
  736. // rect.h = toolMaxY - toolMinY + 1;
  737. //
  738. // // Mark previous rect dirty
  739. // setDirtyRect(rect, 1);
  740. // }
  741. // else {
  742. // rect.w = 0;
  743. // }
  744. // }
  745. // else if (tool == TOOLS_SELECT) { start_func
  746. // rect = createRect(toolStartX, toolStartY, virtualCursorX, virtualCursorY);
  747. // }
  748. // else {
  749. // rX = abs(toolStartX - virtualCursorX);
  750. // rY = abs(toolStartY - virtualCursorY);
  751. //
  752. // // Special case
  753. // if (rX < 1) rX = 1;
  754. // if (rY < 1) rY = 1;
  755. //
  756. // rect = createRect(toolStartX - rX, toolStartY - rY, toolStartX + rX, toolStartY + rY);
  757. // }
  758. //
  759. // // We can't have a selection rect that's bigger than the selection surface
  760. // intersectRects(rect, layerBound);
  761. //
  762. // // Undo?
  763. // if (lastTime) { start_func
  764. // // If we're clearing selection, we must do extra work here
  765. // if ((!toolCtrl) && (!toolAlt)) { start_func
  766. // // Refresh from backup
  767. // memcpy(selected, backupSelected, selectedPitch * layerHeight);
  768. // selectRect = backupSelectRect;
  769. // // Add into rectangle the area we're selecting
  770. // boundRects(selectRect, rect);
  771. // // Clear it AND store undo
  772. // clearSelection();
  773. // }
  774. // else {
  775. // // Just undo the area we're adding/deleting from
  776. // if (rect.w) undoStoreSelect(rect.x, rect.y, rect.w, rect.h);
  777. // }
  778. // }
  779. // // Clear selection if no ctrl/alt
  780. // else if ((!toolCtrl) && (!toolAlt)) clearSelection(0);
  781. //
  782. // // Draw
  783. // if (tool == TOOLS_WAND) { start_func
  784. // // @TODO:
  785. //// if (!toolContiguous) { start_func
  786. //// rect = floodFillNonContiguous32(tile, selection, virtualCursorX, virtualCursorY, mapColor32(0, 0, 0, toolAlt ? 0 : 255), toolTolerance);
  787. //// }
  788. //// else {
  789. //// // Use alpha workspace as temp area, use 255/255/255 as filler color
  790. //// drawRect(0, 0, alphaWorkspace->w, alphaWorkspace->h, mapColor32(255, 255, 255, 255), alphaWorkspace);
  791. //// rect = floodFill32(tile, alphaWorkspace, virtualCursorX, virtualCursorY, mapColor32(0, 0, 0, toolAlt ? 0 : 255), toolTolerance);
  792. //// SDL_SetAlpha(alphaWorkspace, 0, 255);
  793. //// SDL_SetColorKey(alphaWorkspace, SDL_SRCCOLORKEY, mapColor32(255, 255, 255, 255));
  794. //// blit(0, 0, alphaWorkspace, 0, 0, selection, tileWidth, tileHeight);
  795. //// SDL_SetColorKey(alphaWorkspace, 0, 0);
  796. //// SDL_SetAlpha(alphaWorkspace, SDL_SRCALPHA, 255);
  797. //// }
  798. //
  799. // // Remember min/max for undo next time
  800. // if (rect.w) { start_func
  801. // toolMinX = rect.x;
  802. // toolMinY = rect.y;
  803. // toolMaxX = rect.x + rect.w - 1;
  804. // toolMaxY = rect.y + rect.h - 1;
  805. // }
  806. // else {
  807. // // Causes no undo area or undirty to occur next frame
  808. // toolMinX = toolMaxX = -1;
  809. // }
  810. // }
  811. // else if (tool == TOOLS_SELECT) { start_func
  812. // selectRect(toolStartX, toolStartY, virtualCursorX, virtualCursorY, toolAlt ? 0 : 1);
  813. // }
  814. // else {
  815. // selectEllipse(toolStartX, toolStartY, rX, rY, toolAlt ? 0 : 1);
  816. // }
  817. // setDirtyRect(rect, 1);
  818. //
  819. // // Add to overall selection bounding box
  820. // if (!toolAlt) boundRects(selectRect, rect);
  821. // // ...or fix selection rectangle if removing stuff
  822. // else fixSelectionRect();
  823. //
  824. // // Previous
  825. // if (!firstTime) { start_func
  826. // if (tool == TOOLS_WAND) { start_func
  827. // // (was dirtied above, at beginning)
  828. // }
  829. // else if (tool == TOOLS_SELECT) { start_func
  830. // setDirtyBox(toolStartX, toolStartY, toolLastX, toolLastY, 1);
  831. // }
  832. // else {
  833. // rX = abs(toolStartX - toolLastX);
  834. // rY = abs(toolStartY - toolLastY);
  835. // if (rX < 1) rX = 1;
  836. // if (rY < 1) rY = 1;
  837. // setDirtyBox(toolStartX - rX, toolStartY - rY, toolStartX + rX, toolStartY + rY, 1);
  838. // }
  839. // }
  840. //
  841. // // Allow copy now?
  842. // if (lastTime) { start_func
  843. // if (selectRect.w) tools->findWidget(AnimGroupPaintTools::ID_COPY)->enable();
  844. // else tools->findWidget(AnimGroupPaintTools::ID_COPY)->disable();
  845. // }
  846. // break;
  847. //
  848. // case TOOLS_DROPPER:
  849. // // @TODO:
  850. // break;
  851. //
  852. // case TOOLS_PEN:
  853. // if (!lastTime) { start_func
  854. // layerDrawLine(toolStartX, toolStartY, virtualCursorX, virtualCursorY, layerEdit[cursorLayer][0], toolDataMask, toolData);
  855. // if (layerEdit[cursorLayer][1]) layerDrawLine(toolStartX, toolStartY, virtualCursorX, virtualCursorY, layerEdit[cursorLayer][1], toolFxMask, toolFx);
  856. // setDirtyBox(toolStartX, toolStartY, virtualCursorX, virtualCursorY);
  857. // }
  858. //
  859. // // Track area covered for undo
  860. // if (virtualCursorX < toolMinX) toolMinX = virtualCursorX;
  861. // if (virtualCursorX > toolMaxX) toolMaxX = virtualCursorX;
  862. // if (virtualCursorY < toolMinY) toolMinY = virtualCursorY;
  863. // if (virtualCursorY > toolMaxY) toolMaxY = virtualCursorY;
  864. // if (toolStartX < toolMinX) toolMinX = toolStartX;
  865. // if (toolStartX > toolMaxX) toolMaxX = toolStartX;
  866. // if (toolStartY < toolMinY) toolMinY = toolStartY;
  867. // if (toolStartY > toolMaxY) toolMaxY = toolStartY;
  868. //
  869. // toolStartX = virtualCursorX;
  870. // toolStartY = virtualCursorY;
  871. //
  872. // if (lastTime) undoStoreLayerBox(toolMinX, toolMinY, toolMaxX, toolMaxY);
  873. // else if (tools) tools->previewRedraw();
  874. // break;
  875. //
  876. // case TOOLS_FILL:
  877. // // Undo based on rectangle from last time
  878. // if (lastTime) undoStoreLayerBox(toolMinX, toolMinY, toolMaxX, toolMaxY);
  879. //
  880. // // Dirty previous rectangle
  881. // if (!firstTime) { start_func
  882. // refreshData(1, toolMinX, toolMinY, toolMaxX, toolMaxY);
  883. // setDirtyBox(toolMinX, toolMinY, toolMaxX, toolMaxY);
  884. // }
  885. //
  886. // // Flood fill
  887. // if (!toolContiguous) { start_func
  888. // if (layerEdit[cursorLayer][1]) rect = layerMatchFill(virtualCursorX, virtualCursorY, Layer::LAYER_TILE_FILL_MASK, layerEdit[cursorLayer][0], toolDataMask, toolData, layerEdit[cursorLayer][1], toolFxMask, toolFx);
  889. // else rect = layerMatchFill(virtualCursorX, virtualCursorY, Layer::LAYER_TILE_FILL_MASK, layerEdit[cursorLayer][0], toolDataMask, toolData);
  890. // }
  891. // else {
  892. // if (layerEdit[cursorLayer][1]) rect = layerFloodFill(virtualCursorX, virtualCursorY, Layer::LAYER_TILE_FILL_MASK, layerEdit[cursorLayer][0], toolDataMask, toolData, layerEdit[cursorLayer][1], toolFxMask, toolFx);
  893. // else rect = layerFloodFill(virtualCursorX, virtualCursorY, Layer::LAYER_TILE_FILL_MASK, layerEdit[cursorLayer][0], toolDataMask, toolData);
  894. // }
  895. // setDirtyRect(rect);
  896. //
  897. // // Remember min/max for undo on last time
  898. // if (rect.w) { start_func
  899. // toolMinX = rect.x;
  900. // toolMinY = rect.y;
  901. // toolMaxX = rect.x + rect.w - 1;
  902. // toolMaxY = rect.y + rect.h - 1;
  903. // }
  904. // else {
  905. // // Causes no undo area or undirty to occur next frame
  906. // toolMinX = toolMaxX = -1;
  907. // }
  908. // break;
  909. //
  910. // case TOOLS_LINE:
  911. // case TOOLS_RECT:
  912. // case TOOLS_RECTFILL:
  913. // if (lastTime) undoStoreLayerBox(toolStartX, toolStartY, virtualCursorX, virtualCursorY);
  914. //
  915. // // Reload from last time, not entire layer
  916. // if (!firstTime) refreshData(1, toolStartX, toolStartY, toolLastX, toolLastY);
  917. //
  918. // rX = virtualCursorX;
  919. // rY = virtualCursorY;
  920. //
  921. // // Limit to square or straight line?
  922. // if (toolCtrl) { start_func
  923. // if (tool == TOOLS_LINE) { start_func
  924. // // Determine approximate slope of line
  925. // slope1 = abs(toolStartX - rX);
  926. // slope2 = abs(toolStartY - rY);
  927. // // (we only care, if both sizes are > 0)
  928. // if ((slope1) && (slope2)) { start_func
  929. // if (slope1 > slope2) swap(slope1, slope2);
  930. // // slope1/slope2 will be a fraction between 0 (flat) and
  931. // // 1 (diagonal of 45deg multiple); cutoff point is 0.5
  932. // if (slope1 * 2 / slope2 >= 1) { start_func
  933. // // Square
  934. // if (abs(toolStartX - rX) < abs(toolStartY - rY)) { start_func
  935. // rY = toolStartY + abs(toolStartX - rX) * (toolStartY < rY ? 1 : -1);
  936. // }
  937. // else {
  938. // rX = toolStartX + abs(toolStartY - rY) * (toolStartX < rX ? 1 : -1);
  939. // }
  940. // }
  941. // else {
  942. // // Flat line
  943. // if (abs(toolStartX - rX) < abs(toolStartY - rY)) { start_func
  944. // rX = toolStartX;
  945. // }
  946. // else {
  947. // rY = toolStartY;
  948. // }
  949. // }
  950. // }
  951. // }
  952. // else {
  953. // // Square
  954. // if (abs(toolStartX - rX) < abs(toolStartY - rY)) { start_func
  955. // rY = toolStartY + abs(toolStartX - rX) * (toolStartY < rY ? 1 : -1);
  956. // }
  957. // else {
  958. // rX = toolStartX + abs(toolStartY - rY) * (toolStartX < rX ? 1 : -1);
  959. // }
  960. // }
  961. // }
  962. //
  963. // if (tool == TOOLS_LINE) { start_func
  964. // layerDrawLine(toolStartX, toolStartY, rX, rY, layerEdit[cursorLayer][0], toolDataMask, toolData);
  965. // if (layerEdit[cursorLayer][1]) layerDrawLine(toolStartX, toolStartY, rX, rY, layerEdit[cursorLayer][1], toolFxMask, toolFx);
  966. // }
  967. // else if (tool == TOOLS_RECT) { start_func
  968. // layerDrawBox(toolStartX, toolStartY, rX, rY, layerEdit[cursorLayer][0], toolDataMask, toolData);
  969. // if (layerEdit[cursorLayer][1]) layerDrawBox(toolStartX, toolStartY, rX, rY, layerEdit[cursorLayer][1], toolFxMask, toolFx);
  970. // }
  971. // else {
  972. // layerDrawRect(toolStartX, toolStartY, rX, rY, layerEdit[cursorLayer][0], toolDataMask, toolData);
  973. // if (layerEdit[cursorLayer][1]) layerDrawRect(toolStartX, toolStartY, rX, rY, layerEdit[cursorLayer][1], toolFxMask, toolFx);
  974. // }
  975. // setDirtyBox(toolStartX, toolStartY, rX, rY);
  976. // // (no need to limit based on toolCtrl, as a limited area will always
  977. // // be smaller than this area we use here)
  978. // if (!firstTime) setDirtyBox(toolStartX, toolStartY, toolLastX, toolLastY);
  979. // break;
  980. //
  981. // case TOOLS_ELLIPSE:
  982. // case TOOLS_ELLIPSEFILL:
  983. // rX = abs(toolStartX - virtualCursorX);
  984. // rY = abs(toolStartY - virtualCursorY);
  985. //
  986. // // Special case
  987. // if (rX < 1) rX = 1;
  988. // if (rY < 1) rY = 1;
  989. //
  990. // // Circle?
  991. // if (toolCtrl) { start_func
  992. // rX = min(rX, rY);
  993. // rY = rX;
  994. // }
  995. //
  996. // if (lastTime) undoStoreLayerBox(toolStartX - rX, toolStartY - rY, toolStartX + rX, toolStartY + rY);
  997. // // reload from area affected last time, not entire layer
  998. // int prX, prY;
  999. // if (!firstTime) { start_func
  1000. // prX = abs(toolStartX - toolLastX);
  1001. // prY = abs(toolStartY - toolLastY);
  1002. // if (prX < 1) prX = 1;
  1003. // if (prY < 1) prY = 1;
  1004. // // (no need to limit to a circle based on toolCtrl, this will always
  1005. // // cover the minimum area needed)
  1006. // refreshData(1, toolStartX - prX, toolStartY - prY, toolStartX + prX, toolStartY + prY);
  1007. // }
  1008. //
  1009. // if (tool == TOOLS_ELLIPSE) { start_func
  1010. // layerDrawEllipse(toolStartX, toolStartY, rX, rY, layerEdit[cursorLayer][0], toolDataMask, toolData);
  1011. // if (layerEdit[cursorLayer][1]) layerDrawEllipse(toolStartX, toolStartY, rX, rY, layerEdit[cursorLayer][1], toolFxMask, toolFx);
  1012. // }
  1013. // else {
  1014. // layerDrawEllipseFill(toolStartX, toolStartY, rX, rY, layerEdit[cursorLayer][0], toolDataMask, toolData);
  1015. // if (layerEdit[cursorLayer][1]) layerDrawEllipseFill(toolStartX, toolStartY, rX, rY, layerEdit[cursorLayer][1], toolFxMask, toolFx);
  1016. // }
  1017. //
  1018. // setDirtyBox(toolStartX - rX, toolStartY - rY, toolStartX + rX, toolStartY + rY);
  1019. //
  1020. // // Previous
  1021. // if (!firstTime) { start_func
  1022. // setDirtyBox(toolStartX - prX, toolStartY - prY, toolStartX + prX, toolStartY + prY);
  1023. // }
  1024. // break;
  1025. // }
  1026. // }
  1027. // catch (UndoException& e) { start_func
  1028. // toolActive = tool;
  1029. // cancelTool();
  1030. // return;
  1031. // }
  1032. //
  1033. // if ((lastTime) && (!nonDraw)) { start_func
  1034. // // @TODO: only apply a section (to reduce overhead on preview updates)
  1035. // applyData(1);
  1036. // }
  1037. // else if (!nonDraw) tools->previewRedraw();
  1038. //
  1039. // toolLastX = virtualCursorX;
  1040. // toolLastY = virtualCursorY;
  1041. }
  1042. }
  1043. void AnimGroupPaint::cancelTool() { start_func
  1044. if (toolActive) {
  1045. switch (toolActive) {
  1046. // @TODO:
  1047. default:
  1048. break;
  1049. }
  1050. mousePointer();
  1051. toolActive = 0;
  1052. }
  1053. }
  1054. void AnimGroupPaint::finishTool() { start_func
  1055. if (toolActive) {
  1056. dragTool(toolLastX, toolLastY, 0, 1);
  1057. mousePointer();
  1058. // toolActive = 0 taken care of by dragtool
  1059. // @TODO: verify the above statement
  1060. }
  1061. }
  1062. void AnimGroupPaint::display(SDL_Surface* destSurface, Rect& toDisplay, const Rect& clipArea, int xOffset, int yOffset) { start_func
  1063. assert(destSurface);
  1064. if (visible) {
  1065. // If dirty, redraw range or all
  1066. if (dirty) {
  1067. if (totalDirty) {
  1068. // Range should include entire area, so we cover "outside" current
  1069. // animation if appropriate
  1070. toDisplay = clipArea;
  1071. }
  1072. else {
  1073. dirtyRange.x += x + xOffset;
  1074. dirtyRange.y += y + yOffset;
  1075. // Range must include requested update area as well
  1076. boundRects(toDisplay, dirtyRange);
  1077. }
  1078. dirty = totalDirty = 0;
  1079. dirtyRange.w = 0;
  1080. intersectRects(toDisplay, clipArea);
  1081. }
  1082. xOffset += x;
  1083. yOffset += y;
  1084. // Anything to draw?
  1085. if (toDisplay.w) {
  1086. SDL_SetClipRect(destSurface, &toDisplay);
  1087. SDL_FillRect(destSurface, &toDisplay, guiPacked[COLOR_BKFILL]);
  1088. // Border
  1089. // @TODO: top/left border
  1090. drawVLine(yOffset, yOffset + anim.height, xOffset + anim.width, guiPacked[COLOR_GRID], destSurface);
  1091. drawHLine(xOffset, xOffset + anim.width, yOffset + anim.height, guiPacked[COLOR_GRID], destSurface);
  1092. drawRect(xOffset + anim.width, yOffset + anim.height, RESIZE_HANDLE_SIZE, RESIZE_HANDLE_SIZE, guiPacked[COLOR_GRID], destSurface);
  1093. // @TODO: Draw all visible components, bottom up
  1094. // with outlines
  1095. // with cursor glow
  1096. // with selection outlines
  1097. // @TODO: Draw current selection tool outline
  1098. }
  1099. }
  1100. }
  1101. void AnimGroupPaint::undoStore() throw_Undo { start_func
  1102. // @TODO: (check exceptions too)
  1103. }
  1104. void AnimGroupPaint::undoStoreSelect() throw_Undo { start_func
  1105. // @TODO: (check exceptions too)
  1106. }
  1107. void AnimGroupPaint::clearSelection(int storeUndo) throw_Undo { start_func
  1108. // @TODO: (check exceptions too)
  1109. if (selectRect.w) {
  1110. // @TODO:
  1111. if (storeUndo) ;
  1112. setDirtyRect(selectRect);
  1113. selected.clear();
  1114. selectRect.w = 0;
  1115. tools->findWidget(AnimGroupPaintTools::ID_COPY)->disable();
  1116. }
  1117. }
  1118. void AnimGroupPaint::pasteSelection() throw_Undo { start_func
  1119. // @TODO: (check exceptions too)
  1120. // @TODO:
  1121. // if (canConvertClipboard(CLIPBOARD_)) {
  1122. // }
  1123. }
  1124. void AnimGroupPaint::copySelection() { start_func
  1125. if (selectRect.w) {
  1126. // @TODO:
  1127. }
  1128. }
  1129. void AnimGroupPaint::deleteSelection() throw_Undo { start_func
  1130. // @TODO: (check exceptions too)
  1131. }
  1132. int AnimGroupPaint::isInSelection(int x, int y) const { start_func
  1133. if (!selectRect.w) return 0;
  1134. // @TODO:
  1135. return 0;
  1136. }
  1137. void AnimGroupPaint::mousePointer(int mouseX, int mouseY) { start_func
  1138. lastMouseX = mouseX;
  1139. lastMouseY = mouseY;
  1140. mousePointer();
  1141. }
  1142. void AnimGroupPaint::mousePointer() { start_func
  1143. if (!hover) return;
  1144. if ((lastMouseX > anim.width) && (lastMouseX < anim.width + RESIZE_HANDLE_SIZE) &&
  1145. (lastMouseY > anim.height) && (lastMouseY < anim.height + RESIZE_HANDLE_SIZE)) {
  1146. selectMouse(MOUSE_DIAGDOWN);
  1147. return;
  1148. }
  1149. if ((toolActive == TOOLS_SELECT) || (toolActive == TOOLS_SELECTITEM)) {
  1150. if (toolAlt) {
  1151. selectMouse(MOUSE_SUBTRACT);
  1152. return;
  1153. }
  1154. else if (toolCtrl) {
  1155. selectMouse(MOUSE_ADD);
  1156. return;
  1157. }
  1158. }
  1159. if (toolActive == TOOLS_SELECTDRAG) {
  1160. selectMouse(MOUSE_FOURDIRECTION);
  1161. return;
  1162. }
  1163. if ((!toolActive) && ((toolL == TOOLS_SELECT) || (toolL == TOOLS_SELECTITEM))) {
  1164. if (SDL_GetModState() & KMOD_ALT) {
  1165. selectMouse(MOUSE_SUBTRACT);
  1166. return;
  1167. }
  1168. if (SDL_GetModState() & KMOD_CTRL) {
  1169. selectMouse(MOUSE_ADD);
  1170. return;
  1171. }
  1172. if (isInSelection(lastMouseX, lastMouseY)) {
  1173. selectMouse(MOUSE_FOURDIRECTION);
  1174. return;
  1175. }
  1176. }
  1177. selectMouse(MOUSE_NORMAL);
  1178. }
  1179. Window::CommandSupport AnimGroupPaint::supportsCommand(int code) const { start_func
  1180. switch (code) {
  1181. // These are always available
  1182. case TOOLS_CHOOSE:
  1183. case TOOLS_CHOOSER:
  1184. case TOOLS_SELECT:
  1185. case TOOLS_SELECTITEM:
  1186. case TOOLS_PLACEITEM:
  1187. case VIEW_OUTLINE_CHOOSE:
  1188. case VIEW_OUTLINE_NONE:
  1189. case VIEW_OUTLINE_NORMAL:
  1190. case VIEW_OUTLINE_HANDLE:
  1191. case EDIT_SELECTALL:
  1192. case TOOLS_SETTINGS:
  1193. case TOOLS_EDITCOLOR:
  1194. case TOOLS_NEXTCOLOR:
  1195. case TOOLS_PREVCOLOR:
  1196. return Window::COMMAND_ENABLE;
  1197. case EDIT_COPY:
  1198. case EDIT_CUT:
  1199. case EDIT_DELETE:
  1200. case EDIT_DESELECTALL:
  1201. if (selectRect.w) return Window::COMMAND_ENABLE;
  1202. else return Window::COMMAND_DISABLE;
  1203. case EDIT_PASTE:
  1204. // @TODO: if (canConvertClipboard(CLIPBOARD_)) return Window::COMMAND_ENABLE;
  1205. // @TODO: else
  1206. return Window::COMMAND_DISABLE;
  1207. }
  1208. return animgroup->getWorldEdit()->supportsCommand(code);
  1209. }
  1210. void AnimGroupPaint::refresh() { start_func
  1211. setDirty(1);
  1212. }
  1213. Window::WindowType AnimGroupPaint::windowType() const { start_func
  1214. return WINDOW_CLIENT;
  1215. }