Improve texture dialog

master
rubenwardy 2014-11-05 19:00:34 +00:00
parent 60c749c93c
commit 03fc113737
10 changed files with 68 additions and 42 deletions

4
examples/.directory Normal file
View File

@ -0,0 +1,4 @@
[Dolphin]
PreviewsShown=true
Timestamp=2014,11,5,18,15,12
Version=3

BIN
examples/default_dirt.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 730 B

BIN
examples/default_stone.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 388 B

BIN
examples/wool_blue.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 427 B

BIN
examples/wool_green.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 401 B

BIN
examples/wool_red.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 435 B

View File

@ -46,7 +46,7 @@ bool Editor::run(IrrlichtDevice* irr_device,Configuration* conf)
device = irr_device;
IVideoDriver *driver = device->getVideoDriver();
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<s32> 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<s32> 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<s32> 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<s32> rect, bool mousehit)
drawCoord(guienv->getSkin()->getFont(), driver, rect.UpperLeftCorner.X + 10,
rect.LowerRightCorner.Y - 42, L"-X", L"Y");
break;
}
}
}
}

View File

@ -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;

View File

@ -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<s32>(340, 50, 340 + 74 * 3 + 10, 50 + 74 * 3 + 10), true,
narrow_to_wide(std::string(getCubeSideName(face)) + " texture").c_str());
guienv->addButton(rect<s32>(155, 30, 74 * 3, 55), win, 501, L"Apply", L"Apply this texture selection to the node face");
//guienv->addButton(rect<s32>(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<s32>(84, 30, 150, 55), win, 503, L"Import", L"Import images from files");
guienv->addButton(rect<s32>(84, 60, 150, 85), win, 504, L"Export", L"Export the selected texture");
guienv->addButton(rect<s32>(155, 30, 74*3, 55), win, ETD_GUI_ID_APPLY, L"Apply", L"Apply this texture selection to the node face");
guienv->addButton(rect<s32>(155, 60, 74*3, 85), win, ETD_GUI_ID_IMPORT, L"Import", L"Import images from files");
guienv->addButton(rect<s32>(84, 60, 150, 85), win, ETD_GUI_ID_ACTIONS, L"Actions");
// Fill out listbox
lb = guienv->addListBox(rect<s32>(10, 104, 74 * 3, 74 * 3), win, 502);
Media *media = &state->project->media;
std::map<std::string, Media::Image*>& images = media->getList();
int count = 0;
int count = 1;
lb->addItem(L"");
lb->setSelected(0);
for (std::map<std::string, Media::Image*>::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<s32>(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<s32>(x, y, x + 64, y + 64));
} else {
driver->draw2DImage(the_image, rect<s32>(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<std::string, Media::Image*>& 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;
}

View File

@ -17,6 +17,7 @@ private:
IGUIWindow *win;
IGUIListBox *lb;
ITexture *the_image;
IGUIContextMenu *context;
};
#endif