From 03fc1137372e87c5ed168b1ce334a1ff1af30a9d Mon Sep 17 00:00:00 2001 From: rubenwardy Date: Wed, 5 Nov 2014 19:00:34 +0000 Subject: [PATCH] Improve texture dialog --- examples/.directory | 4 +++ examples/default_dirt.png | Bin 0 -> 730 bytes examples/default_stone.png | Bin 0 -> 388 bytes examples/wool_blue.png | Bin 0 -> 427 bytes examples/wool_green.png | Bin 0 -> 401 bytes examples/wool_red.png | Bin 0 -> 435 bytes src/Editor.cpp | 32 ++++++++--------- src/MenuState.hpp | 3 +- src/TextureDialog.cpp | 70 ++++++++++++++++++++++++------------- src/TextureDialog.hpp | 1 + 10 files changed, 68 insertions(+), 42 deletions(-) create mode 100644 examples/.directory create mode 100644 examples/default_dirt.png create mode 100644 examples/default_stone.png create mode 100644 examples/wool_blue.png create mode 100644 examples/wool_green.png create mode 100644 examples/wool_red.png diff --git a/examples/.directory b/examples/.directory new file mode 100644 index 0000000..4c68a2a --- /dev/null +++ b/examples/.directory @@ -0,0 +1,4 @@ +[Dolphin] +PreviewsShown=true +Timestamp=2014,11,5,18,15,12 +Version=3 diff --git a/examples/default_dirt.png b/examples/default_dirt.png new file mode 100644 index 0000000000000000000000000000000000000000..397647c1e0c4fb0d5b53d03523146288586e50eb GIT binary patch literal 730 zcmV<00ww*4P)uZ;*%Jt~#?&(4On1pO1V1WcuBv!21 z@;Uq_3&bi)CZc;_`ssSwzP57?`||mNF-EtVbH3SZ6Cr-=_uI|pa5$VVM^#kI`9im? zBUe`yBImDGscvs&Sqd)5)A@Yyp89?WF|O`b<1~5i`(Arbd9HM;h4&+C#K>}0&g$7>K6lpD zRb{LJfMIBrs;o7PAu@)@&zI*nuilCzNzyDGh9ME6>uxc|2;j)A*So9MmaMTR#+atr z>V9jiK}YWS*VC-7kLMEr#2EMce+KA(GLIhbY!%<^38i%g|8V_D92+bsZG zucys=w_M!ct``7sM0Hg;OEED`|IOiGE!yY6;69YcgXSIBwW>2d6oDuefz>lpxK zn*9%FlyWd?HrRIn000_vMObuGZ)S9NVRB^vP+@6qbS_RsR3LUUE;TMOF-P-4Hvj+t M07*qoM6N<$f<44tiU0rr literal 0 HcmV?d00001 diff --git a/examples/default_stone.png b/examples/default_stone.png new file mode 100644 index 0000000000000000000000000000000000000000..23fba6abd1d9f1ad67e8ee6cadad24210411c1b9 GIT binary patch literal 388 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!63?wyl`GbK}SAb85tCyRrpSPF4k9PnN`T7L- z`Gy1rgaieK0#R^KXh?8aNN_j^g@lKOM1+JygoeaNN5#iPCje1wOd<%yCdL6#Tw;7& zQhZ!;LVQX>d`3!gZe~VqR%RX$WoP9BQBHP#PELMqPC-s~L2gbV5as1om6ufmQAK%E zeO;7X>~f&1wtBiahDb=V9z5vRVj$9X@qNCbv4O5n4=1Ny%npNn|Gjr!*{RFon{Vr$ zE%NuewW*@hh2II4^7~Fs%1I1(&=xPNyJ|{1L!PXRr^ N;OXk;vd$@?2>|qGk}v=O literal 0 HcmV?d00001 diff --git a/examples/wool_blue.png b/examples/wool_blue.png new file mode 100644 index 0000000000000000000000000000000000000000..710a9a27a37ee54f77d819eac472ec4313d7b29e GIT binary patch literal 427 zcmV;c0aX5pP)Rs06KpFJAeQ@fdD;&06&EQK!yN8 zhX6r{078iXLy7=IivUE707Z=eMveeSj{r!J07#JlNs<6clK@MU085nsOqKvmmjF$e z08W?yPniHxo&Zyy092p=R-yn_qX1W=09d5}S*8G4rvO^009&a8l0C%$007fTL_t&- z83n-!VuCOb0Kjc)O+`zVNKnkNIgkR8HUEEIXCRU|h5=*>c)lyCA*yAGnfVc3oE$UM z{pufBJ$=xqyNVr6?{_J*smyaN}j*Yy#~JS1ka zfTA14r*q=RCyjjoGM7e;@__!-OzB$!CEl##bxiw~pIo5qE>=$N#n^M5EWn4(J!UUY zSJ$*T!>twgFl`&GlrFXk%ym96X#HKAs#uq#Qz_97CoYL#Z4^tQ<$Q97(SnO0gVEw;W5l98J6&PQn~g!W>k@ z99730RmvPz%^X(G99YsES=Ag_*Bo5k9A4KPUfLXB-5g=y9Ae@eV&xoU=p1M89BA_# zX!RUx`y6lh9B};{asM21{~UDx99?l%M{zKU zLuVfyi^JdtfGAb{TQx+j(dz|TygSb&mCcDNd%$L#+i#-wFNnh_0mr_xv$qp0iv>UbR5ENU91I#YyYx0lr+GFbDITs2g&I_t4@Jhaq`mNCpeB{~QLl?dA1k vt`+ve={Q2T3MDO)0Bw>MS4K0_&rQ~U*-9E0{1T1(00000NkvXXu0mjf(jcLH literal 0 HcmV?d00001 diff --git a/examples/wool_red.png b/examples/wool_red.png new file mode 100644 index 0000000000000000000000000000000000000000..4a5d43a229b65b0291378d6788cbcf662ad06b10 GIT binary patch literal 435 zcmV;k0ZjghP)M=35N*@i3$pf3JQ!13ylj4kqiu!4GoqJ z4VDfLm<|q_4-cFV51kJWpAQeA4-cUb5Tg(fr4bRP5fP{n5vmdrs}d5d6BDiz6R;E% zu@n@u6cn@+6txr-ycQO}7Z<=67sMDC#TgmK85zhK8Oa$L%NZHX8XC?T8hw0Png9R* z)k#D_R2Ufr!3ko5Fc1L1ZEKZ^mMjs2LXOR$6o{<(|KmCXfew4$gNPnacPSJEInN<6 zkN(BcGDF!ewy@Uxrk>x4pl&T4;7WM*a*t6#8x;2PR8v&wOaq`pVRK`4nu|8P0cWF@ zW%POKBQqJmLpxNT)>c0*D(pOvKG$*(J9NkT5x)gcgetVideoDriver(); ISceneManager *smgr = device->getSceneManager(); - IGUIEnvironment *guienv = device->getGUIEnvironment(); + IGUIEnvironment *guienv = device->getGUIEnvironment(); device->setEventReceiver(this); device->setWindowCaption(L"Node Box Editor"); @@ -72,7 +72,7 @@ bool Editor::run(IrrlichtDevice* irr_device,Configuration* conf) proj->media.debug(); // Load user interface - LoadScene(); + LoadScene(); state->SelectMode(0); int LastX = driver->getScreenSize().Width; @@ -98,7 +98,7 @@ bool Editor::run(IrrlichtDevice* irr_device,Configuration* conf) int ResX = driver->getScreenSize().Width; if (!state->settings->getBool("hide_sidebar")) ResX -= 256; - + int ResY = driver->getScreenSize().Height; if (currentWindow == -1) { @@ -179,7 +179,7 @@ bool Editor::run(IrrlichtDevice* irr_device,Configuration* conf) dtime = double(now - last) / 1000; last = now; - click_handled = true; + click_handled = true; } return true; @@ -208,18 +208,18 @@ bool Editor::OnEvent(const SEvent& event) } if (state->menu){ - if (state->menu->OnEvent(event)){ + if (state->menu->OnEvent(event)) { return true; } } - if (event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.Key < NUMBER_OF_KEYS){ + if (event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.Key < NUMBER_OF_KEYS) { if (event.KeyInput.PressedDown) { state->keys[event.KeyInput.Key] = EKS_DOWN; } else { state->keys[event.KeyInput.Key] = EKS_UP; } - + if ( state->device->getGUIEnvironment()->getFocus() && state->device->getGUIEnvironment()->getFocus()->getType() == EGUIET_EDIT_BOX @@ -292,7 +292,7 @@ void Editor::LoadScene() target->setPosition(vector3df(0, 0, 0)); // Create cameras - pivot = smgr->addEmptySceneNode(target, 199); + pivot = smgr->addEmptySceneNode(target, 199); pivot->setRotation(vector3df(25, -45, 0)); recreateCameras(); @@ -329,7 +329,7 @@ void Editor::recreateCameras() // Get screen sizes int ResX = driver->getScreenSize().Width; if (!state->settings->getBool("hide_sidebar")) - ResX -= 256; + ResX -= 256; int ResY = driver->getScreenSize().Height; // reset matrix @@ -354,7 +354,7 @@ void Editor::recreateCameras() camera[i]->setParent(pivot); camera[i]->setAspectRatio((float)ResX / (float)ResY); pivot->setRotation(oldrot); - } else { + } else { camera[i] = smgr->addCameraSceneNode(target); switch(type) { case VIEWT_TOP: @@ -364,8 +364,8 @@ void Editor::recreateCameras() camera[i]->setPosition(vector3df(0, -2, -0.01)); break; case VIEWT_LEFT: - camera[i]->setPosition(vector3df(-5, 0, 0)); - break; + camera[i]->setPosition(vector3df(-5, 0, 0)); + break; case VIEWT_RIGHT: camera[i]->setPosition(vector3df(5, 0, 0)); break; @@ -434,7 +434,7 @@ void Editor::viewportTick(Viewport viewport, rect rect, bool mousehit) if (state->Mode()) state->Mode()->viewportTick(viewport, driver, rect); - // Draw text + // Draw text driver->setViewPort(rects32(0, 0, driver->getScreenSize().Width, driver->getScreenSize().Height)); { static const wchar_t* labels[7] = {L"Perspective", L"Front", L"Left", L"Top", L"Back", L"Right", L"Bottom"}; @@ -477,7 +477,7 @@ void Editor::viewportTick(Viewport viewport, rect rect, bool mousehit) } // Context menu - if (context_is_open) { + if (context_is_open) { // Context menu background driver->draw2DRectangle(SColor(100, 32, 32, 32), backgroundrect); s32 y2 = rect.UpperLeftCorner.Y + ((rect.UpperLeftCorner.Y < 50)?52:32); @@ -523,7 +523,7 @@ void Editor::viewportTick(Viewport viewport, rect rect, bool mousehit) case VIEWT_LEFT: drawCoord(guienv->getSkin()->getFont(), driver, rect.UpperLeftCorner.X + 10, rect.LowerRightCorner.Y - 42, L"-Z", L"Y"); - break; + break; case VIEWT_RIGHT: drawCoord(guienv->getSkin()->getFont(), driver, rect.UpperLeftCorner.X + 10, rect.LowerRightCorner.Y - 42, L"Z", L"Y"); @@ -536,7 +536,7 @@ void Editor::viewportTick(Viewport viewport, rect rect, bool mousehit) drawCoord(guienv->getSkin()->getFont(), driver, rect.UpperLeftCorner.X + 10, rect.LowerRightCorner.Y - 42, L"-X", L"Y"); break; - } + } } } diff --git a/src/MenuState.hpp b/src/MenuState.hpp index 53cf17f..c3acfae 100644 --- a/src/MenuState.hpp +++ b/src/MenuState.hpp @@ -80,7 +80,8 @@ enum GUI_ID // File Dialog GUI_FILEDIALOG_PATH = 222 + SIDEBAR_MAX_IDS, GUI_FILEDIALOG_FORM = 223 + SIDEBAR_MAX_IDS, - GUI_DIALOG_SUBMIT = 224 + SIDEBAR_MAX_IDS + GUI_DIALOG_SUBMIT = 224 + SIDEBAR_MAX_IDS, + GUI_DIALOG = 225 }; class EditorState; diff --git a/src/TextureDialog.cpp b/src/TextureDialog.cpp index f36f52e..ab281cd 100644 --- a/src/TextureDialog.cpp +++ b/src/TextureDialog.cpp @@ -3,6 +3,15 @@ #include "ImageDialog.hpp" #include "util/filesys.hpp" +enum TEXTURE_DIALOG_GUI_IDS +{ + ETD_GUI_ID_APPLY = GUI_DIALOG, + ETD_GUI_ID_IMPORT, + ETD_GUI_ID_ACTIONS, + ETD_GUI_ID_ACTIONS_CM, + ETD_GUI_ID_EXPORT +}; + const char* getCubeSideName(CubeSide face) { switch (face) { @@ -29,7 +38,8 @@ TextureDialog::TextureDialog(EditorState *pstate, Node *pnode, CubeSide pface): node(pnode), face(pface), lb(NULL), - the_image(NULL) + the_image(NULL), + context(NULL) { IVideoDriver *driver = state->device->getVideoDriver(); IGUIEnvironment *guienv = state->device->getGUIEnvironment(); @@ -37,24 +47,22 @@ TextureDialog::TextureDialog(EditorState *pstate, Node *pnode, CubeSide pface): // Window and basic items win = guienv->addWindow(rect(340, 50, 340 + 74 * 3 + 10, 50 + 74 * 3 + 10), true, narrow_to_wide(std::string(getCubeSideName(face)) + " texture").c_str()); - guienv->addButton(rect(155, 30, 74 * 3, 55), win, 501, L"Apply", L"Apply this texture selection to the node face"); - //guienv->addButton(rect(155, 60, 74 * 3, 85), win, 505, L"Unique", - // L"Duplicate the current texture, and make it so only this face uses it."); - guienv->addButton(rect(84, 30, 150, 55), win, 503, L"Import", L"Import images from files"); - guienv->addButton(rect(84, 60, 150, 85), win, 504, L"Export", L"Export the selected texture"); + guienv->addButton(rect(155, 30, 74*3, 55), win, ETD_GUI_ID_APPLY, L"Apply", L"Apply this texture selection to the node face"); + guienv->addButton(rect(155, 60, 74*3, 85), win, ETD_GUI_ID_IMPORT, L"Import", L"Import images from files"); + guienv->addButton(rect(84, 60, 150, 85), win, ETD_GUI_ID_ACTIONS, L"Actions"); // Fill out listbox lb = guienv->addListBox(rect(10, 104, 74 * 3, 74 * 3), win, 502); Media *media = &state->project->media; std::map& images = media->getList(); - int count = 0; + int count = 1; lb->addItem(L""); lb->setSelected(0); for (std::map::const_iterator it = images.begin(); it != images.end(); ++it) { if (!it->second) { - continue; + continue; } if (it->second->name == "default") { lb->addItem(L""); @@ -71,13 +79,20 @@ TextureDialog::TextureDialog(EditorState *pstate, Node *pnode, CubeSide pface): if (image) { the_image = driver->addTexture("tmpicon.png", image->get()); } + + // Context menu + context = guienv->addContextMenu(rect(84, 85, 150, 180), win, ETD_GUI_ID_ACTIONS_CM); + context->addItem(L"Export", ETD_GUI_ID_EXPORT); + context->setCloseHandling(ECMC_HIDE); + context->setVisible(false); + context->setEventParent(win); } void TextureDialog::draw(IVideoDriver *driver) { int x = win->getAbsolutePosition().UpperLeftCorner.X + 10; int y = win->getAbsolutePosition().UpperLeftCorner.Y + 30; - if (!the_image) { + if (!the_image) { driver->draw2DRectangle(SColor(100, 0, 0, 0), rect(x, y, x + 64, y + 64)); } else { driver->draw2DImage(the_image, rect(x, y, x + 64, y + 64), @@ -127,8 +142,8 @@ bool TextureDialog::OnEvent(const SEvent &event) if (event.GUIEvent.EventType == EGET_BUTTON_CLICKED) { switch (event.GUIEvent.Caller->getID()) { - case 501: { - if (lb->getSelected() == 0) { + case ETD_GUI_ID_APPLY: { + if (lb->getSelected() == 0) { node->setTexture(face, NULL); node->remesh(); return true; @@ -148,15 +163,23 @@ bool TextureDialog::OnEvent(const SEvent &event) count++; } - + close(); return true; } - case 503: { + case ETD_GUI_ID_IMPORT: { ImageDialog::show(state, node, face); - return true; + return false; } - case 504: { + case ETD_GUI_ID_ACTIONS: + context->setVisible(true); + state->device->getGUIEnvironment()->setFocus(context); + return false; + } + } else if (event.GUIEvent.EventType == EGET_MENU_ITEM_SELECTED) { + IGUIContextMenu *menu = (IGUIContextMenu *)event.GUIEvent.Caller; + switch (menu->getItemCommandId(menu->getSelectedItem())) { + case ETD_GUI_ID_EXPORT: { if (lb->getSelected() == 0) return true; @@ -170,7 +193,8 @@ bool TextureDialog::OnEvent(const SEvent &event) Media::Image *image = it->second; std::string path = getSaveLoadDirectory(state->settings->get("save_directory"), state->settings->getBool("installed")) + image->name; - state->device->getVideoDriver()->writeImageToFile(image->get(), + std::cerr << "Exported image to " << path.c_str() << std::endl; + state->device->getVideoDriver()->writeImageToFile(image->get(), path.c_str()); state->device->getGUIEnvironment()->addMessageBox(L"Saved Image to: ", narrow_to_wide(path).c_str()); @@ -178,16 +202,14 @@ bool TextureDialog::OnEvent(const SEvent &event) } count++; } - return true; + return false; }} // end of switch - } - - if (event.GUIEvent.EventType == EGET_LISTBOX_CHANGED && event.GUIEvent.Caller == lb) { + } else if (event.GUIEvent.EventType == EGET_LISTBOX_CHANGED && event.GUIEvent.Caller == lb) { if (lb->getSelected() == 0) { the_image = NULL; return true; } - + int count = 0; Media *media = &state->project->media; std::map& images = media->getList(); @@ -201,12 +223,10 @@ bool TextureDialog::OnEvent(const SEvent &event) count++; } return true; - } - - if (event.GUIEvent.EventType == EGET_ELEMENT_CLOSED && event.GUIEvent.Caller == win) { + } else if (event.GUIEvent.EventType == EGET_ELEMENT_CLOSED && event.GUIEvent.Caller == win) { if (canClose()) close(); - return true; + return true; } return false; } diff --git a/src/TextureDialog.hpp b/src/TextureDialog.hpp index 58c4536..231d96e 100644 --- a/src/TextureDialog.hpp +++ b/src/TextureDialog.hpp @@ -17,6 +17,7 @@ private: IGUIWindow *win; IGUIListBox *lb; ITexture *the_image; + IGUIContextMenu *context; }; #endif