fix color picker, add project delete button with message box

This commit is contained in:
2017-08-19 12:09:03 +01:00
parent de59ae151c
commit ac3857b697
10 changed files with 102 additions and 46 deletions

View File

@@ -152,13 +152,13 @@
<border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center">
<border thickness="1" border-color=".2" pad="3">
<border width="400" height="30" color=".2 .2 .2 .9" dir="row" align="center" justify="center">
<text text="Just a test message" font-face="arial" font-size="11"></text>
<text id="title" text="Just a test message" font-face="arial" font-size="11"></text>
</border>
<border width="400" color="0 0 0 .9" pad="10" dir="col">
<text text="Longer description for the error or the message." font-face="arial" font-size="11"></text>
<text id="message" text="Longer description for the error or the message." font-face="arial" font-size="11"></text>
<node height="40" grow="1" dir="row" align="flex-end" justify="flex-end">
<button id="btn-ok" text="Ok" width="50" height="30" margin="0 10 0 0"/>
<button text="Cancel" width="60" height="30" pad="10"/>
<button id="btn-cancel" text="Cancel" width="60" height="30" pad="10"/>
</node>
</border>
</border>
@@ -213,6 +213,7 @@
</node>
<!--<text-input width="100" height="100" color=".3"/>-->
<node height="40" grow="1" dir="row" align="flex-end" justify="flex-end">
<node grow="1"><button id="btn-delete" text="Delete Project" width="100" height="30" margin="0 10 0 0" color="1 0 0 1"/></node>
<button id="btn-ok" text="Open Project" width="100" height="30" margin="0 10 0 0"/>
<button id="btn-cancel" text="Cancel" width="60" height="30" pad="10"/>
</node>

View File

@@ -10,6 +10,13 @@
AAssetManager* Asset::m_am;
#endif
bool Asset::delete_file(const std::string& path)
{
LOG("delete project: %s", path.c_str());
std::remove(path.c_str());
return true;
}
std::vector<std::string> Asset::list_files(std::string folder, bool is_asset, const std::string& filter_regex)
{
std::vector<std::string> names;

View File

@@ -8,6 +8,7 @@ public:
AAsset* m_asset = nullptr;
#endif
static std::vector<std::string> list_files(std::string folder, bool is_asset, const std::string& filter_regex);
static bool delete_file(const std::string& path);
std::string m_current_path;
FILE* m_fp = nullptr;

View File

@@ -69,10 +69,8 @@ void ui::Canvas::pick_update(int plane)
// prepare common states
glViewport(0, 0, m_width, m_height);
glDisable(GL_BLEND);
glEnable(GL_BLEND);
//for (int i = 0; i < 6; i++)
{
int i = plane;
m_tmp[i].bindFramebuffer();
m_tmp[i].clear({ 1, 1, 1, 1 });
@@ -108,7 +106,6 @@ void ui::Canvas::pick_update(int plane)
m_pick_data[plane] = std::make_unique<glm::u8vec4[]>(m_width*m_height);
glReadPixels(0, 0, m_width, m_height, GL_RGBA, GL_UNSIGNED_BYTE, m_pick_data[plane].get());
m_tmp[i].unbindFramebuffer();
}
// restore viewport and clear color states
blend ? glEnable(GL_BLEND) : glDisable(GL_BLEND);

View File

@@ -66,10 +66,14 @@ void NodeButton::parse_attributes(kAttribute ka, const tinyxml2::XMLAttribute* a
{
switch (ka)
{
case kAttribute::Color:
m_border->parse_attributes(ka, attr);
color_normal = m_border->m_color;
color_hover = glm::clamp(m_border->m_color + glm::vec4(.1, .1, .1, 0), {0,0,0,0}, {1,1,1,1});
color_down = glm::clamp(m_border->m_color + glm::vec4(.2, .2, .2, 0), {0,0,0,0}, {1,1,1,1});
case kAttribute::Padding:
case kAttribute::Width:
case kAttribute::Height:
case kAttribute::Color:
case kAttribute::Thickness:
case kAttribute::BorderColor:
m_border->parse_attributes(ka, attr);

View File

@@ -164,15 +164,16 @@ void NodeCanvas::draw()
// if (m_canvas->m_show_tmp && m_canvas->m_current_layer_idx == layer_index)
// {
// glDisable(GL_BLEND);
// ui::ShaderManager::use(kShader::TextureAlpha);
// ui::ShaderManager::u_int(kShaderUniform::Tex, 0);
// ui::ShaderManager::u_float(kShaderUniform::Alpha, m_canvas->m_layers[layer_index].m_opacity);
// ui::ShaderManager::u_mat4(kShaderUniform::MVP, plane_mvp_z);
// ui::ShaderManager::u_float(kShaderUniform::Alpha,
// m_canvas->m_current_stroke->m_brush.m_tip_opacity * m_canvas->m_layers[layer_index].m_opacity);
// ui::ShaderManager::u_float(kShaderUniform::Alpha, 1);
// m_canvas->m_tmp[plane_index].bindTexture();
// m_face_plane.draw_fill();
// m_canvas->m_tmp[plane_index].unbindTexture();
// glEnable(GL_BLEND);
// }
}
}

View File

@@ -4,6 +4,8 @@
#include "canvas.h"
#include "node_image_texture.h"
#include "asset.h"
#include "node_message_box.h"
#include "app.h"
Node* NodeDialogOpen::clone_instantiate() const
{
@@ -32,6 +34,40 @@ void NodeDialogOpen::init_controls()
btn_cancel->on_click = [this](Node*) {
destroy();
};
btn_delete = find<NodeButton>("btn-delete");
btn_delete->on_click = [this](Node*) {
if (!current)
return;
auto msgbox = new NodeMessageBox();
msgbox->m_manager = m_manager;
msgbox->init();
msgbox->m_title->set_text("Delete Project");
msgbox->m_message->set_text(("Are you sure you want to delete " + current->m_file_name + "?").c_str());
msgbox->btn_ok->on_click = [this,msgbox](Node*){
auto path = current->m_path;
int idx = container->get_child_index(current);
container->remove_child(current);
if (!container->m_children.empty())
{
int newidx = std::min<int>(idx, (int)container->m_children.size() - 1);
auto next = (NodeDialogOpenItem*)container->get_child_at(newidx);
current = nullptr;
next->on_selected(next);
next->m_selected = true;
}
else
{
current = nullptr;
auto image_tex = find<NodeImageTexture>("thumb-tex");
image_tex->tex.destroy();
}
Asset::delete_file(path);
msgbox->destroy();
};
root()->add_child(msgbox);
root()->update();
};
container = find<Node>("files-list");
auto names = Asset::list_files(data_path, false, ".*\\.pano");
for (const auto& n : names)
@@ -43,7 +79,6 @@ void NodeDialogOpen::init_controls()
node->m_path = data_path + "/" + n;
node->m_file_name = n;
node->on_selected = [&](NodeDialogOpenItem* target) {
static NodeDialogOpenItem* current = nullptr;
if (target == current)
return;
ui::Image thumb = ui::Canvas::I->thumbnail_read(target->m_path);

View File

@@ -31,6 +31,8 @@ class NodeDialogOpen : public NodeBorder
public:
NodeButton* btn_cancel;
NodeButton* btn_ok;
NodeButton* btn_delete;
NodeDialogOpenItem* current = nullptr;
Node* container;
std::string selected_path;
std::string selected_file;

View File

@@ -16,6 +16,10 @@ void NodeMessageBox::init()
SetPositioning(YGPositionTypeAbsolute);
m_template = (*m_manager)[const_hash("message-box")]->m_children[0]->clone();
add_child(m_template);
btnOk = m_template->find<NodeButton>("btn-ok");
btnOk->on_click = [&](Node*) { destroy(); };
m_title = m_template->find<NodeText>("title");
m_message = m_template->find<NodeText>("message");
btn_ok = m_template->find<NodeButton>("btn-ok");
btn_ok->on_click = [&](Node*) { destroy(); };
btn_cancel = m_template->find<NodeButton>("btn-cancel");
btn_cancel->on_click = [&](Node*) { destroy(); };
}

View File

@@ -1,12 +1,16 @@
#pragma once
#include "node.h"
#include "node_button.h"
#include "node_text.h"
class NodeMessageBox : public Node
{
public:
Node* m_template;
NodeButton* btnOk;
NodeButton* btn_ok;
NodeButton* btn_cancel;
NodeText* m_message;
NodeText* m_title;
virtual Node* clone_instantiate() const override;
virtual void init() override;
};