123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- /* GCSx
- ** IMGDIALOG.CPP
- **
- ** Image selection dialog (from animgroup/tileset)
- ** Not a full dialog- used as a base for others
- */
- /*****************************************************************************
- ** Copyright (C) 2003-2006 Janson
- **
- ** This program is free software; you can redistribute it and/or modify
- ** it under the terms of the GNU General Public License as published by
- ** the Free Software Foundation; either version 2 of the License, or
- ** (at your option) any later version.
- **
- ** This program is distributed in the hope that it will be useful,
- ** but WITHOUT ANY WARRANTY; without even the implied warranty of
- ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- ** GNU General Public License for more details.
- **
- ** You should have received a copy of the GNU General Public License
- ** along with this program; if not, write to the Free Software
- ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
- *****************************************************************************/
- #include "all.h"
- ImageDialog::ImageDialog() : Dialog(blankString) { start_func
- libTree = NULL;
- imgChoose = NULL;
- world = NULL;
- libId = 0;
- }
- ImageDialog::~ImageDialog() { start_func
- if (libTree) {
- WidgetScroll* ws = dynamic_cast<WidgetScroll*>(libTree->getParent());
- if (ws) ws->newClient();
- delete libTree;
- }
- }
- void ImageDialog::addLibTree(int id) { start_func
- libTree = new TreeView(blankString, NULL, 0, NULL, 1);
- libTree->addTo(this, 0, 5, id);
- libId = id;
- }
- void ImageDialog::addImgChoose(int id) { start_func
- imgChoose = new ImageChooser(NULL);
- int w = -1;
- int h = -1;
- if (libId) {
- WidgetScroll* ws = dynamic_cast<WidgetScroll*>(findWidget(libId));
- if (ws) {
- w = ws->getClientWidth();
- h = ws->getClientHeight();
- }
- }
- imgChoose->addTo(this, w, h, id);
- }
- void ImageDialog::selectImage(AnimGroup* animGroup, TileSet* tileSet, int animTileId) { start_func
- TreeView* found = NULL;
- if (animGroup) {
- found = libTree->findRecursive(animGroup->getId(), treeViewWrapAnimGroup);
- }
- else if (tileSet) {
- found = libTree->findRecursive(tileSet->getId(), treeViewWrapTileSet);
- }
- if (found) {
- found->selectMe();
- imgChoose->cursorState(animTileId - 1);
- }
- }
- void ImageDialog::fillLibTree() { start_func
- libTree->removeAll();
- if (world) {
- libTree->insert(new TreeView("(no image)", this, 0, treeViewWrapAnimGroup), (animId == 0) && (tileId == 0));
- TreeView* item = NULL;
- World::AnimGroupIndex::const_iterator endAL = world->endAnimGroup();
- for (World::AnimGroupIndex::const_iterator pos = world->beginAnimGroup(); pos != endAL; ++pos) {
- AnimGroupEdit* pAnimGroup = dynamic_cast<AnimGroupEdit*>((*pos).second);
- libTree->insert(item = new TreeView(pAnimGroup->getName(), this, pAnimGroup->getId(), treeViewWrapAnimGroup), pAnimGroup->getId() == animId);
- item->setIcon(7);
- }
-
- World::TileSetIndex::const_iterator endTS = world->endTileSet();
- for (World::TileSetIndex::const_iterator pos = world->beginTileSet(); pos != endTS; ++pos) {
- TileSetEdit* pTileSet = dynamic_cast<TileSetEdit*>((*pos).second);
- libTree->insert(item = new TreeView(pTileSet->getName(), this, pTileSet->getId(), treeViewWrapTileSet), pTileSet->getId() == tileId);
- item->setIcon(pTileSet->getIsFont() ? 4 : (pTileSet->getCollisionCount() ? 9 : 5));
- }
- }
- }
-
- int ImageDialog::treeViewWrapTileSet(void* ptr, int code, int command, int check) { start_func
- return ((ImageDialog*)ptr)->treeViewTileSet(code, command, check);
- }
- int ImageDialog::treeViewTileSet(int code, int command, int check) { start_func
- if (check) {
- return Window::COMMAND_HIDE;
- }
-
- if (command == LV_MOVE) {
- TileSetEdit* tileset = dynamic_cast<TileSetEdit*>(world->findTileSet(code));
- if (tileset) {
- animId = 0;
- tileId = tileset->getId();
- imgChoose->setTileset(tileset);
- imgChoose->cursorState(subId - 1);
- }
- return 1;
- }
-
- return 0;
- }
-
- int ImageDialog::treeViewWrapAnimGroup(void* ptr, int code, int command, int check) { start_func
- return ((ImageDialog*)ptr)->treeViewAnimGroup(code, command, check);
- }
- int ImageDialog::treeViewAnimGroup(int code, int command, int check) { start_func
- if (check) {
- return Window::COMMAND_HIDE;
- }
-
- if (command == LV_MOVE) {
- if (code) {
- AnimGroupEdit* animgroup = dynamic_cast<AnimGroupEdit*>(world->findAnimGroup(code));
- if (animgroup) {
- tileId = 0;
- animId = animgroup->getId();
- imgChoose->setTileset(NULL);
- imgChoose->cursorState(subId - 1);
- }
- }
- else {
- tileId = 0;
- animId = 0;
- imgChoose->setTileset(NULL);
- imgChoose->cursorState(subId - 1);
- }
- return 1;
- }
-
- return 0;
- }
- void ImageDialog::runComplete(AnimGroup** animGroup, TileSet** tileSet, int* animTileId, int justChecking) { start_func
- if ((animId) || (tileId))
- subId = imgChoose->cursorState() + 1;
- else
- subId = 0;
-
- AnimGroup* aLib = NULL;
- TileSet* tSet = NULL;
- if ((animId) && (subId > 0)) {
- aLib = world->findAnimGroup(animId);
- if (!aLib->getCount()) {
- subId = 0;
- aLib = NULL;
- }
- else assert(subId <= aLib->getCount());
- }
- else if ((tileId) && (subId > 0)) {
- tSet = world->findTileSet(tileId);
- if (!tSet->getCount()) {
- subId = 0;
- tSet = NULL;
- }
- else assert(subId <= tSet->getCount());
- }
- else {
- subId = 0;
- }
- if (animGroup) *animGroup = aLib;
- if (tileSet) *tileSet = tSet;
- if (animTileId) *animTileId = subId;
-
- if (!justChecking) {
- imgChoose->setTileset(NULL);
- world = NULL;
- }
- }
- void ImageDialog::runPrep(WorldEdit* nWorld, AnimGroup* animGroup, TileSet* tileSet, int animTileId) { start_func
- world = nWorld;
- animId = tileId = subId = 0;
- if (animGroup) {
- animId = animGroup->getId();
- subId = animTileId;
- }
- else if (tileSet) {
- tileId = tileSet->getId();
- subId = animTileId;
- }
- fillLibTree();
- }
|