adding open/save project and changing layout

This commit is contained in:
2017-05-01 17:06:59 +01:00
parent 02ffbf3d77
commit c691595767
10 changed files with 136 additions and 93 deletions

View File

@@ -4,14 +4,13 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:2.3.1'
compile 'it.sephiroth.android.exif:library:1.0.1'
}
}
apply plugin: 'android'
android {
compileSdkVersion 19
buildToolsVersion '23.0.2'
buildToolsVersion '25.0.0'
defaultConfig {
applicationId = 'com.omigamedev'

View File

@@ -1,6 +1,6 @@
#Wed Apr 10 15:27:10 PDT 2013
#Mon May 01 13:12:48 BST 2017
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=http\://services.gradle.org/distributions/gradle-2.14.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-3.3-all.zip

View File

@@ -1,21 +0,0 @@
package com.omigamedev;
import android.test.ActivityInstrumentationTestCase2;
/**
* This is a simple framework for a test of an Application. See
* {@link android.test.ApplicationTestCase ApplicationTestCase} for more information on
* how to write and extend Application tests.
* <p/>
* To run this test, you can type:
* adb shell am instrument -w \
* -e class com.omigamedev.DummyActivityTest \
* com.omigamedev.tests/android.test.InstrumentationTestRunner
*/
public class DummyActivityTest extends ActivityInstrumentationTestCase2<DummyActivity> {
public DummyActivityTest() {
super("com.omigamedev", DummyActivity.class);
}
}

View File

@@ -320,6 +320,7 @@ static int engine_init_display(struct engine* engine) {
LOG("All ready");
engine->animating = 1;
ANativeActivity_showSoftInput(engine->app->activity, ANATIVEACTIVITY_SHOW_SOFT_INPUT_FORCED);
return 0;
}

View File

@@ -1,15 +0,0 @@
package com.omigamedev;
import android.app.Activity;
import android.os.Bundle;
public class DummyActivity extends Activity
{
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}

View File

@@ -165,6 +165,24 @@
</border>
</layout>
<!-- Open Dialog Popup -->
<layout id="popup-dialog-open">
<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="Open PanoPainter Project" 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>
<node height="40" grow="1" dir="row" align="flex-end" justify="flex-end">
<button id="btn-ok" text="Open Project" width="100" height="30" margin="0 10 0 0"/>
<button text="Cancel" width="60" height="30" pad="10"/>
</node>
</border>
</border>
</border>
</layout>
<!--settings window-->
<layout id="settings">
<border positioning="absolute" position="0 0" color=".4 .4 .4 .8" width="100%" height="100%" align="center" justify="center">
@@ -326,57 +344,24 @@
</node>
</border>
<!-- toolbar -->
<!--<border id="toolbar" height="50" width="100%" pad="5" dir="row" color=".2">
<border id="toolbar" height="50" width="100%" pad="5" dir="row" color=".2">
<button id="btn-open" width="50" height="100%" margin="0 5 0 0" text="Open"/>
<button id="btn-save" width="50" height="100%" margin="0 5 0 0" text="Save"/>
<button id="btn-export" width="50" height="100%" margin="0 5 0 0" text="Export"/>
<button id="btn-undo" width="50" height="100%" margin="0 5 0 0" text="Undo"/>
<button id="btn-close" width="50" height="100%" margin="0 5 0 0" text="Clear"/>
<button id="btn-popup" width="50" height="100%" margin="0 5 0 0" text="Popup"/>
<ref id="multi-button"/>
<border width="50" margin="0 5 0 0" color=".1" thickness="1" border-color=".5" justify="center" align="center">
<text text="button" font-face="arial" font-size="11"/>
</border>
<separator width="10"/>
<button-custom width="50" margin="0 5 0 0" color=".1" thickness="1" border-color=".5" justify="center" align="center"><text text="red" font-face="arial" font-size="11" color="1 0 0 1"/></button-custom>
<button-custom width="50" margin="0 5 0 0" color=".3" thickness="1" border-color=".5" justify="center" align="center"><text text="green" font-face="arial" font-size="11" color="0 1 0 1"/></button-custom>
<button-custom width="50" margin="0 5 0 0" color=".2" thickness="1" border-color=".5" justify="center" align="center"><text text="blue" font-face="arial" font-size="11" color=".4 .4 1 1"/></button-custom>
<separator width="10"/>
--><!--button with image--><!--
<button-custom width="50" margin="0 5 0 0" thickness="1" border-color=".0" pad="8">
<image path="data/icons.png" region="30 30 90 90" width="100%" height="100%" align="center" justify="flex-end">
--><!--<text text="Groups" font-face="arial" font-size="11" color=".1"/>--><!--
</image>
<button-custom id="btn-bucket" width="50" height="100%" margin="0 5 0 0" thickness="1" border-color="0 0 0 1" pad="2">
<image path="data/ui/bucket.png" width="100%" height="100%" align="center" justify="flex-end"/>
</button-custom>
<button-custom id="btn-settings" width="50" margin="0 5 0 0" thickness="1" border-color=".0" pad="8">
<image path="data/icons.png" region="143 155 203 215" width="100%" height="100%" align="center" justify="flex-end">
--><!--<text text="Settings" font-face="arial" font-size="11"/>--><!--
</image>
<!--
<button-custom id="btn-layer" width="50" height="100%" margin="0 5 0 0" thickness="1" border-color="0 0 0 1" pad="6" align="center" justify="center">
<icon width="100%" height="100%" icon="disk"/>
</button-custom>
<button-custom width="50" margin="0 15 0 0" thickness="1" border-color=".0" pad="8" align="center" justify="center">
<icon width="100%" height="100%" icon="accept"/>
</button-custom>
</border>-->
-->
</border>
<!-- central row -->
<node grow="1" dir="row" wrap="1" height="0">
<border width="60" color=".2 .2 .2 .6" margin="0 0 0 0" dir="col" pad="4" flood-events="1">
<!--<border height="4" margin="-4 0 0 0"/>-->
<!--<button-custom id="btn-stroke" width="50" height="50" margin="5 5 0 0" thickness="1" border-color=".0" pad="12" align="center" justify="center">
<icon width="100%" height="100%" icon="accept"/>
</button-custom>
<button-custom id="btn-brush" width="50" height="50" margin="5 5 0 0" thickness="1" border-color=".0" pad="12" align="center" justify="center">
<icon width="100%" height="100%" icon="arrow_branch"/>
</button-custom>
<button-custom id="btn-color" width="50" height="50" margin="5 5 0 0" thickness="1" border-color=".0" pad="12" align="center" justify="center">
<icon width="100%" height="100%" icon="arrow_refresh"/>
</button-custom>
<button-custom id="btn-layer" width="50" height="50" margin="5 5 0 0" thickness="1" border-color=".0" pad="12" align="center" justify="center">
<icon width="100%" height="100%" icon="disk"/>
</button-custom>-->
<button id="btn-switch" width="50" height="50" margin="0 0 5 0" text="Save"/>
<button id="btn-undo" width="50" height="50" margin="0 0 5 0" text="Undo"/>
<button id="btn-close" width="50" height="50" margin="0 0 5 0" text="Clear"/>
<button-custom id="btn-bucket" width="50" height="50" margin="0 0 5 0" thickness="1" border-color=".1" pad="2">
<image path="data/ui/bucket.png" width="100%" height="100%" align="center" justify="flex-end"/>
</button-custom>
<border width="60" color=".2 .2 .2 .6" margin="0 0 0 0" dir="col" pad="4" flood-events="1" justify="center">
<!--panel togglers-->
<button-custom id="btn-stroke" width="50" height="50" margin="0 0 5 0" thickness="1" border-color=".1" pad="2">
<image path="data/ui/stroke.png" width="100%" height="100%" align="center" justify="flex-end"/>
@@ -418,5 +403,6 @@
</node>
<!--<ref id="settings"/>-->
<!--<ref id="popup-menu"/>-->
<ref id="popup-dialog-open"/>
</layout>
</root>

View File

@@ -463,19 +463,32 @@ void App::initLayout()
};
}
if (auto* button = layout[main_id]->find<NodeButton>("btn-switch"))
if (auto* button = layout[main_id]->find<NodeButton>("btn-export"))
{
button->on_click = [this,button](Node*) {
//exit(0);
if (canvas)
{
canvas->m_canvas->save(data_path);
//canvas->m_canvas->m_use_instanced = !canvas->m_canvas->m_use_instanced;
//button->color_normal = canvas->m_canvas->m_use_instanced ? glm::vec4(1, 0, 0, 1) : glm::vec4(0, 1, 0, 1);
//button->m_text->set_text(canvas->m_canvas->m_use_instanced ? "INST" : "NORM");
}
};
//button->m_text->set_text("NORM");
}
if (auto* button = layout[main_id]->find<NodeButton>("btn-open"))
{
button->on_click = [this,button](Node*) {
if (canvas)
{
canvas->m_canvas->save(data_path);
}
};
}
if (auto* button = layout[main_id]->find<NodeButton>("btn-save"))
{
button->on_click = [this,button](Node*) {
if (canvas)
{
canvas->m_canvas->save_project(data_path);
}
};
}
if (auto* button = layout[main_id]->find<NodeButton>("btn-undo"))
{

View File

@@ -503,6 +503,71 @@ void ui::Canvas::save(std::string data_path)
glActiveTexture(GL_TEXTURE0);
}
void ui::Canvas::save_project(std::string data_path)
{
static char name[128];
sprintf(name, "%s/latlong.pano", data_path.c_str());
FILE* fp = fopen(name, "wb");
if (!fp)
{
LOG("cannot write project to %s", name);
return;
}
fwrite(&m_width, sizeof(int), 1, fp);
fwrite(&m_height, sizeof(int), 1, fp);
int n_layers = (int)m_layers.size();
fwrite(&n_layers, sizeof(int), 1, fp);
for (int i = 0; i < (int)m_layers.size(); i++)
{
int n_order = m_order[i];
fwrite(&n_order, sizeof(int), 1, fp);
auto snap = m_layers[i].snapshot(data_path);
for (int layer_index = 0; layer_index < 6; layer_index++)
{
fwrite(snap.image[i].get(), 1, m_width * m_height * 4, fp);
}
}
fclose(fp);
LOG("project saved to %s", name);
}
void ui::Canvas::open_project(std::string data_path)
{
static char name[128];
sprintf(name, "%s/latlong.pano", data_path.c_str());
FILE* fp = fopen(name, "rb");
if (!fp)
{
LOG("cannot write project to %s", name);
return;
}
fread(&m_width, sizeof(int), 1, fp);
fread(&m_height, sizeof(int), 1, fp);
int n_layers = (int)m_layers.size();
fread(&n_layers, sizeof(int), 1, fp);
const int bytes = m_width * m_height * 4;
Layer::Snapshot snap;
snap.create(m_width, m_height);
m_layers.clear();
m_order.clear();
for (int i = 0; i < n_layers; i++)
{
int n_order = m_order[i];
fread(&n_order, sizeof(int), 1, fp);
m_order.push_back(n_order);
for (int layer_index = 0; layer_index < 6; layer_index++)
{
fread(snap.image[i].get(), 1, bytes, fp);
m_layers.emplace_back();
m_layers.back().create(m_width, m_height, "");
m_layers.back().restore(snap);
}
}
fclose(fp);
LOG("project restore from %s", name);
}
///////////////////////////////////////////////////////////////////////////////////////////
void ui::Layer::destroy()

View File

@@ -19,6 +19,11 @@ public:
struct Snapshot
{
std::unique_ptr<uint8_t[]> image[6];
void create(int w, int h)
{
for (int i = 0; i < 6; i++)
image[i] = std::make_unique<uint8_t[]>(w*h*4);
}
};
bool create(int width, int height, std::string name);
void clear(const glm::vec4& c);
@@ -79,6 +84,8 @@ public:
void snapshot_restore();
void clear_context();
void save(std::string data_path);
void save_project(std::string data_path);
void open_project(std::string data_path);
};

View File

@@ -653,7 +653,7 @@ public:
default:
break;
}
return kEventResult::Consumed;
return m_mouse_inside ? kEventResult::Consumed : kEventResult::Available;
}
};
@@ -705,6 +705,7 @@ public:
}
break;
default:
return kEventResult::Available;
break;
}
return kEventResult::Consumed;
@@ -771,6 +772,7 @@ public:
destroy();
break;
default:
return kEventResult::Available;
break;
}
return kEventResult::Consumed;
@@ -823,6 +825,7 @@ public:
on_click(this);
break;
default:
return kEventResult::Available;
break;
}
return kEventResult::Consumed;
@@ -1096,6 +1099,7 @@ public:
}
break;
default:
return kEventResult::Available;
break;
}
return kEventResult::Consumed;
@@ -1207,6 +1211,7 @@ public:
checked = !checked;
break;
default:
return kEventResult::Available;
break;
}
return kEventResult::Consumed;
@@ -1297,6 +1302,7 @@ public:
case kEventType::MouseUpL:
break;
default:
return kEventResult::Available;
break;
}
return kEventResult::Consumed;
@@ -1615,6 +1621,7 @@ public:
}
break;
default:
return kEventResult::Available;
break;
}
return kEventResult::Consumed;
@@ -2062,6 +2069,7 @@ public:
//m_zoom_canvas = m_zoom_start + ge->m_distance_delta * .001f;
break;
default:
return kEventResult::Available;
break;
}
return kEventResult::Consumed;