implement document resize with menu and dialog

This commit is contained in:
2018-10-05 18:10:26 +02:00
parent 4723bedc31
commit 5baa807cce
14 changed files with 245 additions and 15 deletions

View File

@@ -203,6 +203,8 @@
ADFD32172166AA0800F46F85 /* GeneratePreviewForURL.c in Sources */ = {isa = PBXBuildFile; fileRef = ADFD32162166AA0800F46F85 /* GeneratePreviewForURL.c */; }; ADFD32172166AA0800F46F85 /* GeneratePreviewForURL.c in Sources */ = {isa = PBXBuildFile; fileRef = ADFD32162166AA0800F46F85 /* GeneratePreviewForURL.c */; };
ADFD32192166AA0800F46F85 /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = ADFD32182166AA0800F46F85 /* main.c */; }; ADFD32192166AA0800F46F85 /* main.c in Sources */ = {isa = PBXBuildFile; fileRef = ADFD32182166AA0800F46F85 /* main.c */; };
ADFD32222166AB2F00F46F85 /* QLPlugin.qlgenerator in CopyFiles */ = {isa = PBXBuildFile; fileRef = ADFD32122166AA0800F46F85 /* QLPlugin.qlgenerator */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; }; ADFD32222166AB2F00F46F85 /* QLPlugin.qlgenerator in CopyFiles */ = {isa = PBXBuildFile; fileRef = ADFD32122166AA0800F46F85 /* QLPlugin.qlgenerator */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
ADFD32272166C9A000F46F85 /* node_dialog_resize.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ADFD32262166C9A000F46F85 /* node_dialog_resize.cpp */; };
ADFD32282166C9A000F46F85 /* node_dialog_resize.cpp in Sources */ = {isa = PBXBuildFile; fileRef = ADFD32262166C9A000F46F85 /* node_dialog_resize.cpp */; };
/* End PBXBuildFile section */ /* End PBXBuildFile section */
/* Begin PBXContainerItemProxy section */ /* Begin PBXContainerItemProxy section */
@@ -470,6 +472,8 @@
ADFD32182166AA0800F46F85 /* main.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = "<group>"; }; ADFD32182166AA0800F46F85 /* main.c */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.c; path = main.c; sourceTree = "<group>"; };
ADFD321A2166AA0800F46F85 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; }; ADFD321A2166AA0800F46F85 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
ADFD32232166B12A00F46F85 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; ADFD32232166B12A00F46F85 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
ADFD32252166C9A000F46F85 /* node_dialog_resize.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = node_dialog_resize.h; sourceTree = "<group>"; };
ADFD32262166C9A000F46F85 /* node_dialog_resize.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = node_dialog_resize.cpp; sourceTree = "<group>"; };
/* End PBXFileReference section */ /* End PBXFileReference section */
/* Begin PBXFrameworksBuildPhase section */ /* Begin PBXFrameworksBuildPhase section */
@@ -629,6 +633,8 @@
ADC6F4601F3AFA2A004177FA /* node_dialog_layer_rename.h */, ADC6F4601F3AFA2A004177FA /* node_dialog_layer_rename.h */,
ADC0EB401FC36E88004079BB /* node_dialog_picker.cpp */, ADC0EB401FC36E88004079BB /* node_dialog_picker.cpp */,
ADC0EB411FC36E88004079BB /* node_dialog_picker.h */, ADC0EB411FC36E88004079BB /* node_dialog_picker.h */,
ADFD32262166C9A000F46F85 /* node_dialog_resize.cpp */,
ADFD32252166C9A000F46F85 /* node_dialog_resize.h */,
AD10635F1EC7ADFA002A525F /* node_icon.cpp */, AD10635F1EC7ADFA002A525F /* node_icon.cpp */,
AD1063601EC7ADFA002A525F /* node_icon.h */, AD1063601EC7ADFA002A525F /* node_icon.h */,
AD1063611EC7ADFA002A525F /* node_image_texture.cpp */, AD1063611EC7ADFA002A525F /* node_image_texture.cpp */,
@@ -1270,6 +1276,7 @@
AD0E5CDB1ECC72AD00C35669 /* font.cpp in Sources */, AD0E5CDB1ECC72AD00C35669 /* font.cpp in Sources */,
ADBC8C561FAFD0530094B339 /* app_cloud.cpp in Sources */, ADBC8C561FAFD0530094B339 /* app_cloud.cpp in Sources */,
AD0E5CDA1ECC72AD00C35669 /* event.cpp in Sources */, AD0E5CDA1ECC72AD00C35669 /* event.cpp in Sources */,
ADFD32282166C9A000F46F85 /* node_dialog_resize.cpp in Sources */,
AD0E5CCB1ECC72AD00C35669 /* node_scroll.cpp in Sources */, AD0E5CCB1ECC72AD00C35669 /* node_scroll.cpp in Sources */,
AD0E5CBF1ECC72AD00C35669 /* node_dialog_open.cpp in Sources */, AD0E5CBF1ECC72AD00C35669 /* node_dialog_open.cpp in Sources */,
ADE4911B1F86E65E00FB8E92 /* advancing_front.cc in Sources */, ADE4911B1F86E65E00FB8E92 /* advancing_front.cc in Sources */,
@@ -1408,6 +1415,7 @@
ADD7D2A01EBF9E1C00D5A897 /* image.cpp in Sources */, ADD7D2A01EBF9E1C00D5A897 /* image.cpp in Sources */,
ADD7D2A11EBF9E1C00D5A897 /* texture.cpp in Sources */, ADD7D2A11EBF9E1C00D5A897 /* texture.cpp in Sources */,
AD0E119C1ECA215600CDA6BB /* app_events.cpp in Sources */, AD0E119C1ECA215600CDA6BB /* app_events.cpp in Sources */,
ADFD32272166C9A000F46F85 /* node_dialog_resize.cpp in Sources */,
ADBC8C551FAFD0520094B339 /* app_cloud.cpp in Sources */, ADBC8C551FAFD0520094B339 /* app_cloud.cpp in Sources */,
ADD7D2961EBF9E1C00D5A897 /* brush.cpp in Sources */, ADD7D2961EBF9E1C00D5A897 /* brush.cpp in Sources */,
ADE4911A1F86E65D00FB8E92 /* sweep.cc in Sources */, ADE4911A1F86E65D00FB8E92 /* sweep.cc in Sources */,

View File

@@ -71,6 +71,7 @@ add_library(
../src/node_dialog_open.cpp ../src/node_dialog_open.cpp
../src/node_dialog_picker.cpp ../src/node_dialog_picker.cpp
../src/node_dialog_layer_rename.cpp ../src/node_dialog_layer_rename.cpp
../src/node_dialog_resize.cpp
../src/node_icon.cpp ../src/node_icon.cpp
../src/node_image.cpp ../src/node_image.cpp
../src/node_image_texture.cpp ../src/node_image_texture.cpp

View File

@@ -411,6 +411,28 @@
</border> </border>
</layout> </layout>
<!-- Dialog Resize -->
<layout id="dialog-resize">
<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="Resize Document Resolution" font-face="arial" font-size="11"></text>
</border>
<border width="400" color="0 0 0 .9" pad="10" dir="col">
<border dir="row" align="center" height="30" color=".2 .2 .2 1">
<node grow="1"><text id="current-res" text="Current: 1024px" font-face="arial" font-size="11" margin="0 5 0 5"/></node>
<text text="New Resolution:" font-face="arial" font-size="11" margin="0 5 0 5"/>
<combobox id="resolution" width="100" height="30" text="1024" combo-list="512px,1024px,1536px,2048px" default="1"/>
</border>
<node height="40" grow="1" dir="row" align="flex-end" justify="flex-end">
<button id="btn-ok" text="Resize" width="70" height="30" margin="0 10 0 0"/>
<button id="btn-cancel" text="Cancel" width="60" height="30" pad="10"/>
</node>
</border>
</border>
</border>
</layout>
<!-- Browse Dialog Popup --> <!-- Browse Dialog Popup -->
<layout id="dialog-browse-item"> <layout id="dialog-browse-item">
@@ -777,7 +799,7 @@ Here's a list of what's available in this release.
<text text="Ctrl-N" color=".4" justify="flex-end" margin="0 10 0 10" font-face="arial" font-size="11"/> <text text="Ctrl-N" color=".4" justify="flex-end" margin="0 10 0 10" font-face="arial" font-size="11"/>
</button-custom> </button-custom>
<button-custom id="file-import" height="40" align="center" color=".2" pad="0 0 0 10" dir="row"> <button-custom id="file-import" height="40" align="center" color=".2" pad="0 0 0 10" dir="row">
<icon icon="page_add" width="20"/> <icon icon="image_add" width="20"/>
<text text="Import" grow="1" margin="0 0 0 5" font-face="arial" font-size="11"/> <text text="Import" grow="1" margin="0 0 0 5" font-face="arial" font-size="11"/>
</button-custom> </button-custom>
<!-- <!--
@@ -787,7 +809,7 @@ Here's a list of what's available in this release.
</button-custom> </button-custom>
--> -->
<button-custom id="file-browse" text="Menu" height="40" align="center" color=".2" pad="0 0 0 10" dir="row"> <button-custom id="file-browse" text="Menu" height="40" align="center" color=".2" pad="0 0 0 10" dir="row">
<icon icon="page_add" width="20"/> <icon icon="images" width="20"/>
<text text="Browse" grow="1" margin="0 0 0 5" font-face="arial" font-size="11"/> <text text="Browse" grow="1" margin="0 0 0 5" font-face="arial" font-size="11"/>
<text text="Ctrl-O" color=".4" justify="flex-end" margin="0 10 0 10" font-face="arial" font-size="11"/> <text text="Ctrl-O" color=".4" justify="flex-end" margin="0 10 0 10" font-face="arial" font-size="11"/>
</button-custom> </button-custom>
@@ -797,18 +819,22 @@ Here's a list of what's available in this release.
<text text="Ctrl-S" color=".4" justify="flex-end" margin="0 10 0 10" font-face="arial" font-size="11"/> <text text="Ctrl-S" color=".4" justify="flex-end" margin="0 10 0 10" font-face="arial" font-size="11"/>
</button-custom> </button-custom>
<button-custom id="file-save-as" text="Menu" height="40" align="center" color=".2" pad="0 0 0 10" dir="row"> <button-custom id="file-save-as" text="Menu" height="40" align="center" color=".2" pad="0 0 0 10" dir="row">
<icon icon="disk" width="20"/> <icon icon="disk_multiple" width="20"/>
<text text="Save As.." grow="1" margin="0 0 0 5" font-face="arial" font-size="11"/> <text text="Save As.." grow="1" margin="0 0 0 5" font-face="arial" font-size="11"/>
</button-custom> </button-custom>
<button-custom id="file-save-ver" text="Menu" height="40" align="center" color=".2" pad="0 0 0 10" dir="row"> <button-custom id="file-save-ver" text="Menu" height="40" align="center" color=".2" pad="0 0 0 10" dir="row">
<icon icon="disk" width="20"/> <icon icon="disk_multiple" width="20"/>
<text text="Save Version" grow="1" margin="0 0 0 5" font-face="arial" font-size="11"/> <text text="Save Version" grow="1" margin="0 0 0 5" font-face="arial" font-size="11"/>
<text text="Ctrl-Shift-S" color=".4" justify="flex-end" margin="0 10 0 10" font-face="arial" font-size="11"/> <text text="Ctrl-Shift-S" color=".4" justify="flex-end" margin="0 10 0 10" font-face="arial" font-size="11"/>
</button-custom> </button-custom>
<button-custom id="file-export" text="Menu" height="40" align="center" color=".2" pad="0 0 0 10" dir="row"> <button-custom id="file-export" text="Menu" height="40" align="center" color=".2" pad="0 0 0 10" dir="row">
<icon icon="disk" width="20"/> <icon icon="picture_go" width="20"/>
<text text="Export JPG" grow="1" margin="0 0 0 5" font-face="arial" font-size="11"/> <text text="Export JPG" grow="1" margin="0 0 0 5" font-face="arial" font-size="11"/>
</button-custom> </button-custom>
<button-custom id="file-resize" text="Menu" height="40" align="center" color=".2" pad="0 0 0 10" dir="row">
<icon icon="arrow_out" width="20"/>
<text text="Resize Document" grow="1" margin="0 0 0 5" font-face="arial" font-size="11"/>
</button-custom>
<!-- <!--
<button-custom id="file-export-cubes" text="Menu" height="40" align="center" color=".2" pad="0 0 0 10" dir="row"> <button-custom id="file-export-cubes" text="Menu" height="40" align="center" color=".2" pad="0 0 0 10" dir="row">
<icon icon="page_white_stack" width="20"/> <icon icon="page_white_stack" width="20"/>

View File

@@ -152,6 +152,7 @@ public:
void dialog_export(); void dialog_export();
void dialog_export_cubes(); void dialog_export_cubes();
void dialog_layer_rename(); void dialog_layer_rename();
void dialog_resize();
void cloud_upload(); void cloud_upload();
void cloud_upload_all(); void cloud_upload_all();

View File

@@ -2,6 +2,7 @@
#include "app.h" #include "app.h"
#include "node_dialog_open.h" #include "node_dialog_open.h"
#include "node_dialog_browse.h" #include "node_dialog_browse.h"
#include "node_dialog_resize.h"
#include "node_dialog_cloud.h" #include "node_dialog_cloud.h"
#include "node_about.h" #include "node_about.h"
#include "node_changelog.h" #include "node_changelog.h"
@@ -244,8 +245,11 @@ void App::dialog_browse()
dialog->btn_ok->on_click = [this, dialog](Node*) dialog->btn_ok->on_click = [this, dialog](Node*)
{ {
open_document(dialog->selected_path); if (dialog->is_selected())
dialog->destroy(); {
open_document(dialog->selected_path);
dialog->destroy();
}
}; };
async_end(); async_end();
}; };
@@ -389,6 +393,30 @@ void App::dialog_export()
} }
} }
void App::dialog_resize()
{
auto dialog = std::make_shared<NodeDialogResize>();
dialog->m_manager = &layout;
dialog->init();
dialog->create();
dialog->loaded();
layout[main_id]->add_child(dialog);
layout[main_id]->update();
dialog->btn_ok->on_click = [this,dialog](Node*)
{
int res = dialog->get_resolution();
if (canvas)
canvas->m_canvas->resize(res, res);
App::I.title_update();
dialog->destroy();
};
popup->mouse_release();
popup->destroy();
}
void App::dialog_export_cubes() void App::dialog_export_cubes()
{ {
if (canvas) if (canvas)

View File

@@ -429,6 +429,12 @@ void App::init_menu_file()
dialog_export(); dialog_export();
popup->mouse_release(); popup->mouse_release();
popup->destroy(); popup->destroy();
};
if (auto b = popup->find<NodeButtonCustom>("file-resize"))
b->on_click = [this](Node*) {
dialog_resize();
popup->mouse_release();
popup->destroy();
}; };
if (auto b = popup->find<NodeButtonCustom>("file-export-cubes")) if (auto b = popup->find<NodeButtonCustom>("file-export-cubes"))
b->on_click = [this](Node*) { b->on_click = [this](Node*) {

View File

@@ -136,7 +136,11 @@ void ui::Canvas::clear(const glm::vec4& c/*={0,0,0,1}*/)
snap_history({ 0, 1, 2, 3, 4, 5 }); snap_history({ 0, 1, 2, 3, 4, 5 });
m_layers[m_current_layer_idx].clear(c); m_layers[m_current_layer_idx].clear(c);
m_unsaved = true; m_unsaved = true;
App::I.title_update(); }
void ui::Canvas::clear_all()
{
for (auto& l : m_layers)
l.clear({0, 0, 0, 0});
} }
void ui::Canvas::snap_history(const std::vector<int>& planes) void ui::Canvas::snap_history(const std::vector<int>& planes)
{ {
@@ -908,9 +912,9 @@ void ui::Canvas::resize(int width, int height)
m_tex2[i].create(width, height, GL_RGBA8); m_tex2[i].create(width, height, GL_RGBA8);
} }
for (auto& l : m_layers) for (auto& l : m_layers)
{ l.resize(width, height);
l.create(width, height, ""); m_smask.create(width*2, height*2, "mask");
} m_unsaved = true;
} }
bool ui::Canvas::create(int width, int height) bool ui::Canvas::create(int width, int height)
{ {
@@ -1733,12 +1737,13 @@ void ui::Canvas::project_open_thread(std::string file_path)
int progress = 0; int progress = 0;
int total = n_layers * 6; int total = n_layers * 6;
App::I.async_start(); App::I.async_start();
for (auto& l : m_layers) for (auto& l : m_layers)
l.destroy(); l.destroy();
m_layers.clear(); m_layers.clear();
m_order.clear(); m_order.clear();
//clear_all();
resize(m_width, m_height); resize(m_width, m_height);
App::I.async_end(); App::I.async_end();
@@ -1757,6 +1762,7 @@ void ui::Canvas::project_open_thread(std::string file_path)
fread(&name_len, sizeof(int), 1, fp); fread(&name_len, sizeof(int), 1, fp);
std::string name(name_len, '\0'); std::string name(name_len, '\0');
fread((char*)name.data(), name_len, 1, fp); fread((char*)name.data(), name_len, 1, fp);
snap.clear();
for (int plane_index = 0; plane_index < 6; plane_index++) for (int plane_index = 0; plane_index < 6; plane_index++)
{ {
int has_data; int has_data;
@@ -1802,6 +1808,7 @@ void ui::Canvas::project_open_thread(std::string file_path)
tmp_layers.emplace_back(); tmp_layers.emplace_back();
tmp_layers.back().m_opacity = layer_opacity; tmp_layers.back().m_opacity = layer_opacity;
tmp_layers.back().create(m_width, m_height, name.c_str()); tmp_layers.back().create(m_width, m_height, name.c_str());
tmp_layers.back().clear({0, 0, 0, 0});
tmp_layers.back().restore(snap); tmp_layers.back().restore(snap);
tmp_order.push_back(n_order); tmp_order.push_back(n_order);
App::I.async_end(); App::I.async_end();
@@ -2106,12 +2113,20 @@ void ui::Layer::restore(const Snapshot& snap)
m_dirty_box[i] = snap.m_dirty_box[i]; m_dirty_box[i] = snap.m_dirty_box[i];
m_dirty_face[i] = snap.m_dirty_face[i]; m_dirty_face[i] = snap.m_dirty_face[i];
m_rtt[i].recreate(); // TODO: this should not be recreated here! Sorry I messed up with this, just quick fix DON'T SHIP!! // TODO: this should not be recreated here!
// Sorry I messed up with this,
// it's just a quick fix DON'T SHIP!!
//m_rtt[i].recreate();
m_rtt[i].bindTexture(); m_rtt[i].bindTexture();
glm::vec2 box_sz = zw(m_dirty_box[i]) - xy(m_dirty_box[i]); glm::vec2 box_sz = zw(m_dirty_box[i]) - xy(m_dirty_box[i]);
glTexSubImage2D(GL_TEXTURE_2D, 0, m_dirty_box[i].x, m_dirty_box[i].y, box_sz.x, box_sz.y, GL_RGBA, GL_UNSIGNED_BYTE, snap.image[i].get()); glTexSubImage2D(GL_TEXTURE_2D, 0,
m_dirty_box[i].x, m_dirty_box[i].y,
box_sz.x, box_sz.y, GL_RGBA, GL_UNSIGNED_BYTE,
snap.image[i].get());
m_rtt[i].unbindTexture(); m_rtt[i].unbindTexture();
LOG("restore face %d - %d bytes (%dx%d)", i, (int)box_sz.x * (int)box_sz.y * 4, (int)box_sz.x, (int)box_sz.y); LOG("restore face %d - %d bytes (%dx%d)", i,
(int)box_sz.x * (int)box_sz.y * 4, (int)box_sz.x, (int)box_sz.y);
} }
} }
@@ -2195,3 +2210,16 @@ bool ui::Layer::create(int width, int height, std::string name)
} }
return true; return true;
} }
void ui::Layer::resize(int width, int height)
{
glm::vec2 ratio = glm::vec2(width, height) / glm::vec2(w, h);
w = width;
h = height;
for (int i = 0; i < 6; i++)
{
m_rtt[i].resize(width, height);
m_dirty_box[i] = m_dirty_box[i] * glm::vec4(ratio, ratio);
//m_dirty_face[i] = true;
}
}

View File

@@ -29,12 +29,27 @@ public:
std::unique_ptr<uint8_t[]> image[6] = SIXPLETTE(0); std::unique_ptr<uint8_t[]> image[6] = SIXPLETTE(0);
glm::vec4 m_dirty_box[6] = SIXPLETTE(glm::vec4(0)); glm::vec4 m_dirty_box[6] = SIXPLETTE(glm::vec4(0));
bool m_dirty_face[6] = SIXPLETTE(false); bool m_dirty_face[6] = SIXPLETTE(false);
int width = 0;
int height = 0;
void create(int w, int h) void create(int w, int h)
{ {
for (int i = 0; i < 6; i++) for (int i = 0; i < 6; i++)
{
image[i] = std::make_unique<uint8_t[]>(w*h*4); image[i] = std::make_unique<uint8_t[]>(w*h*4);
std::fill_n(image[i].get(), w*h*4, 0);
}
}
void clear()
{
for (int i = 0; i < 6; i++)
{
m_dirty_face[i] = false;
m_dirty_box[i] = glm::vec4(0);
std::fill_n(image[i].get(), width*height*4, 0);
}
} }
}; };
void resize(int width, int height);
bool create(int width, int height, std::string name); bool create(int width, int height, std::string name);
void clear(const glm::vec4& c); void clear(const glm::vec4& c);
Snapshot snapshot(std::string data_path); Snapshot snapshot(std::string data_path);
@@ -182,6 +197,7 @@ public:
void stroke_cancel(); void stroke_cancel();
void stroke_commit(); void stroke_commit();
void clear(const glm::vec4& color = { 1, 1, 1, 0 }); void clear(const glm::vec4& color = { 1, 1, 1, 0 });
void clear_all();
void pick_start(); void pick_start();
void pick_update(int plane); void pick_update(int plane);
glm::vec4 pick_get(glm::vec2 canvas_loc); glm::vec4 pick_get(glm::vec2 canvas_loc);

View File

@@ -61,6 +61,9 @@ void NodeDialogBrowse::init_controls()
else else
{ {
current = nullptr; current = nullptr;
selected_path = "";
selected_file = "";
selected_name = "";
} }
Asset::delete_file(path); Asset::delete_file(path);
msgbox->destroy(); msgbox->destroy();
@@ -108,6 +111,11 @@ void NodeDialogBrowse::init_controls()
// } // }
} }
bool NodeDialogBrowse::is_selected()
{
return current != nullptr;
}
void NodeDialogBrowse::loaded() void NodeDialogBrowse::loaded()
{ {
} }

View File

@@ -43,4 +43,5 @@ public:
virtual void init() override; virtual void init() override;
void init_controls(); void init_controls();
virtual void loaded() override; virtual void loaded() override;
bool is_selected();
}; };

View File

@@ -0,0 +1,54 @@
#include "pch.h"
#include "log.h"
#include "node_dialog_resize.h"
#include "canvas.h"
#include "node_image_texture.h"
#include "app.h"
#include <array>
Node* NodeDialogResize::clone_instantiate() const
{
return new NodeDialogResize();
}
void NodeDialogResize::clone_finalize(Node* dest) const
{
NodeDialogResize* n = static_cast<NodeDialogResize*>(dest);
n->init_controls();
}
void NodeDialogResize::init()
{
auto tpl = static_cast<const NodeBorder*>(init_template("dialog-resize"));
m_color = tpl->m_color;
m_border_color = tpl->m_border_color;;
m_thinkness = tpl->m_thinkness;;
init_controls();
}
void NodeDialogResize::init_controls()
{
btn_ok = find<NodeButton>("btn-ok");
btn_cancel = find<NodeButton>("btn-cancel");
combo = find<NodeComboBox>("resolution");
text = find<NodeText>("current-res");
resolution = ui::Canvas::I->m_width;
static char txt[128];
sprintf(txt, "Current: %dpx", resolution);
text->set_text(txt);
btn_cancel->on_click = [this](Node*) {
destroy();
};
}
void NodeDialogResize::loaded()
{
// ui::Image thumb = ui::Canvas::I->thumbnail_read(data_path);
// auto image_tex = find<NodeImageTexture>("thumb-tex");
// image_tex->tex.create(thumb);
}
int NodeDialogResize::get_resolution()
{
return combo ? res_map[combo->m_current_index] : 512;
}

22
src/node_dialog_resize.h Normal file
View File

@@ -0,0 +1,22 @@
#pragma once
#include "node_border.h"
#include "node_button.h"
#include "node_combobox.h"
#include "node_text.h"
class NodeDialogResize : public NodeBorder
{
public:
const std::array<int, 4> res_map{512, 1024, 1536, 2048};
NodeButton* btn_cancel;
NodeButton* btn_ok;
NodeComboBox* combo;
NodeText* text;
int resolution;
virtual Node* clone_instantiate() const override;
virtual void clone_finalize(Node* dest) const override;
virtual void init() override;
void init_controls();
virtual void loaded() override;
int get_resolution();
};

View File

@@ -15,6 +15,34 @@ RTT::~RTT()
//destroy(); //destroy();
} }
void RTT::resize(int width, int height)
{
RTT new_rtt;
glGetIntegerv(GL_DRAW_FRAMEBUFFER_BINDING, &oldDFboID);
glGetIntegerv(GL_READ_FRAMEBUFFER_BINDING, &oldRFboID);
new_rtt.create(width, height, -1, int_fmt);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, new_rtt.fboID);
glBindFramebuffer(GL_READ_FRAMEBUFFER, fboID);
glBlitFramebuffer(0, 0, w, h, 0, 0, new_rtt.w, new_rtt.h, GL_COLOR_BUFFER_BIT, GL_LINEAR);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, oldDFboID);
glBindFramebuffer(GL_READ_FRAMEBUFFER, oldRFboID);
destroy();
oldRFboID = 0;
oldDFboID = 0;
fboID = new_rtt.fboID;
rboID = new_rtt.rboID;
texID = new_rtt.texID;
int_fmt = new_rtt.int_fmt;
w = new_rtt.w;
h = new_rtt.h;
}
void RTT::destroy() void RTT::destroy()
{ {
if (rboID) if (rboID)
@@ -47,6 +75,7 @@ bool RTT::create(int width, int height, int tex/* = -1*/, GLint internal_format)
w = width; w = width;
h = height; h = height;
int_fmt = internal_format;
if (tex == -1) if (tex == -1)
{ {

View File

@@ -8,6 +8,7 @@ class RTT
GLuint fboID = 0; GLuint fboID = 0;
GLuint rboID = 0; GLuint rboID = 0;
GLuint texID = 0; GLuint texID = 0;
GLint int_fmt = 0;
int w = 0; int w = 0;
int h = 0; int h = 0;
@@ -16,6 +17,7 @@ public:
~RTT(); ~RTT();
void destroy(); void destroy();
void resize(int width, int height);
bool create(int width, int height, int tex = -1, GLint internal_format = GL_RGBA8); bool create(int width, int height, int tex = -1, GLint internal_format = GL_RGBA8);
bool recreate() { return create(w, h); } bool recreate() { return create(w, h); }
void clear(glm::vec4 color = glm::vec4(0)); void clear(glm::vec4 color = glm::vec4(0));