added color picking with ALT key, added crash report library for windows

This commit is contained in:
2017-05-29 08:47:04 +01:00
parent 6d14ccd426
commit 0f721393bb
19 changed files with 170 additions and 26 deletions

View File

@@ -71,23 +71,23 @@
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>libs\glm;libs\glew-2.0.0\include;libs\stb;libs\tinyxml2;libs\yoga;libs\curl-win\include;libs\jpeg;libs\wacom;$(IncludePath)</IncludePath>
<LibraryPath>libs\curl-win\lib\dll-$(Configuration)-$(PlatformShortName);libs\glew-2.0.0\lib\Release\$(Platform);$(LibraryPath)</LibraryPath>
<IncludePath>libs\glm;libs\glew-2.0.0\include;libs\stb;libs\tinyxml2;libs\yoga;libs\curl-win\include;libs\jpeg;libs\wacom;C:\Users\omar\Downloads\BugTrap-master\BugTrap-master\source\Client;$(IncludePath)</IncludePath>
<LibraryPath>libs\curl-win\lib\dll-$(Configuration)-$(PlatformShortName);libs\glew-2.0.0\lib\Release\$(Platform);C:\Users\omar\Downloads\BugTrap-master\BugTrap-master\bin;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LinkIncremental>true</LinkIncremental>
<IncludePath>libs\glm;libs\glew-2.0.0\include;libs\stb;libs\tinyxml2;libs\yoga;libs\curl-win\include;libs\jpeg;libs\wacom;$(IncludePath)</IncludePath>
<LibraryPath>libs\curl-win\lib\dll-$(Configuration)-$(PlatformShortName);libs\glew-2.0.0\lib\Release\$(Platform);$(LibraryPath)</LibraryPath>
<IncludePath>libs\glm;libs\glew-2.0.0\include;libs\stb;libs\tinyxml2;libs\yoga;libs\curl-win\include;libs\jpeg;libs\wacom;C:\Users\omar\Downloads\BugTrap-master\BugTrap-master\source\Client;$(IncludePath)</IncludePath>
<LibraryPath>libs\curl-win\lib\dll-$(Configuration)-$(PlatformShortName);libs\glew-2.0.0\lib\Release\$(Platform);C:\Users\omar\Downloads\BugTrap-master\BugTrap-master\bin;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>libs\glm;libs\glew-2.0.0\include;libs\stb;libs\tinyxml2;libs\yoga;libs\curl-win\include;libs\jpeg;libs\wacom;$(IncludePath)</IncludePath>
<LibraryPath>libs\curl-win\lib\dll-$(Configuration)-$(PlatformShortName);libs\glew-2.0.0\lib\Release\$(Platform);$(LibraryPath)</LibraryPath>
<IncludePath>libs\glm;libs\glew-2.0.0\include;libs\stb;libs\tinyxml2;libs\yoga;libs\curl-win\include;libs\jpeg;libs\wacom;C:\Users\omar\Downloads\BugTrap-master\BugTrap-master\source\Client;$(IncludePath)</IncludePath>
<LibraryPath>libs\curl-win\lib\dll-$(Configuration)-$(PlatformShortName);libs\glew-2.0.0\lib\Release\$(Platform);C:\Users\omar\Downloads\BugTrap-master\BugTrap-master\bin;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LinkIncremental>false</LinkIncremental>
<IncludePath>libs\glm;libs\glew-2.0.0\include;libs\stb;libs\tinyxml2;libs\yoga;libs\curl-win\include;libs\jpeg;libs\wacom;$(IncludePath)</IncludePath>
<LibraryPath>libs\curl-win\lib\dll-$(Configuration)-$(PlatformShortName);libs\glew-2.0.0\lib\Release\$(Platform);$(LibraryPath)</LibraryPath>
<IncludePath>libs\glm;libs\glew-2.0.0\include;libs\stb;libs\tinyxml2;libs\yoga;libs\curl-win\include;libs\jpeg;libs\wacom;C:\Users\omar\Downloads\BugTrap-master\BugTrap-master\source\Client;$(IncludePath)</IncludePath>
<LibraryPath>libs\curl-win\lib\dll-$(Configuration)-$(PlatformShortName);libs\glew-2.0.0\lib\Release\$(Platform);C:\Users\omar\Downloads\BugTrap-master\BugTrap-master\bin;$(LibraryPath)</LibraryPath>
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
@@ -124,6 +124,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
@@ -141,6 +142,7 @@
<IntrinsicFunctions>true</IntrinsicFunctions>
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<PrecompiledHeaderFile>pch.h</PrecompiledHeaderFile>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>

View File

@@ -9,7 +9,7 @@ void ActionManager::add(Action *action)
{
I.m_actions.emplace(action);
I.m_memory += action->memory();
LOG("History: %.2f KB", I.m_memory / 1024.f);
//LOG("History: %.2f KB", I.m_memory / 1024.f);
App::I.update_memory_usage(I.m_memory);
}
@@ -18,7 +18,7 @@ void ActionManager::undo()
I.m_actions.top()->undo();
I.m_memory -= I.m_actions.top()->memory();
I.m_actions.pop();
LOG("History: %.2f KB", I.m_memory / 1024.f);
//LOG("History: %.2f KB", I.m_memory / 1024.f);
App::I.update_memory_usage(I.m_memory);
}
@@ -27,6 +27,6 @@ void ActionManager::clear()
while (!I.m_actions.empty())
I.m_actions.pop();
I.m_memory = 0;
LOG("History: %.2f KB", I.m_memory / 1024.f);
//LOG("History: %.2f KB", I.m_memory / 1024.f);
App::I.update_memory_usage(I.m_memory);
}

View File

@@ -40,6 +40,7 @@ void App::initAssets()
void App::initLog()
{
LogRemote::I.start();
LogRemote::I.file_init();
}
void App::init()

View File

@@ -43,6 +43,7 @@ public:
const uint16_t main_id = const_hash("main");
float width;
float height;
bool keys[256];
glm::vec2 gesture_p0;
glm::vec2 gesture_p1;
#ifdef __ANDROID__

View File

@@ -95,6 +95,7 @@ bool App::gesture_end()
}
bool App::key_down(kKey key)
{
keys[(int)key] = true;
KeyEvent e;
e.m_type = kEventType::KeyDown;
e.m_key = key;
@@ -104,6 +105,7 @@ bool App::key_down(kKey key)
}
bool App::key_up(kKey key)
{
keys[(int)key] = false;
KeyEvent e;
e.m_type = kEventType::KeyUp;
e.m_key = key;

View File

@@ -399,6 +399,15 @@ void ui::Canvas::stroke_update(glm::vec2 point, float pressure)
}
void ui::Canvas::stroke_start(glm::vec2 point, float pressure, const ui::Brush& brush)
{
// need to commit this now before starting a new stroke
if (m_current_stroke && m_commit_delayed)
{
stroke_commit();
m_current_stroke = nullptr;
m_show_tmp = false;
m_commit_delayed = false;
}
m_current_stroke = std::make_unique<Stroke>();
m_current_stroke->m_camera = { m_cam_rot, m_cam_fov };
m_current_stroke->start(brush);

View File

@@ -5,6 +5,7 @@
#include "canvas.h"
#include "shader.h"
#include "node_canvas.h"
#include "app.h"
NodeCanvas* CanvasMode::node;
ui::Canvas* CanvasMode::canvas;
@@ -71,23 +72,65 @@ void CanvasModePen::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
switch (me->m_type)
{
case kEventType::MouseDownL:
canvas->stroke_start(loc, me->m_pressure, node->m_brush);
m_dragging = true;
if (App::I.keys[(int)kKey::KeyAlt])
{
m_picking = true;
}
else
{
canvas->stroke_start(loc, me->m_pressure, node->m_brush);
m_dragging = true;
}
node->mouse_capture();
break;
case kEventType::MouseUpL:
canvas->stroke_end();
m_dragging = false;
node->mouse_release();
if (m_dragging)
{
canvas->stroke_end();
m_dragging = false;
node->mouse_release();
}
if (m_picking)
{
m_picking = false;
node->mouse_release();
int x = me->m_pos.x;
int y = App::I.height - me->m_pos.y - 1;
float pix[3];
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glReadPixels(x, y, 1, 1, GL_RGB, GL_FLOAT, pix);
auto hsv = convert_rgb2hsv(glm::vec3(pix[0], pix[1], pix[2]));
App::I.color->m_hue->set_value(hsv.x);
App::I.color->m_quad->set_value(1.f - hsv.y, 1.f - hsv.z);
}
break;
case kEventType::MouseMove:
if (m_dragging)
canvas->stroke_update(loc, me->m_pressure);
if (m_picking)
{
int x = me->m_pos.x;
int y = App::I.height - me->m_pos.y - 1;
float pix[3];
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glReadPixels(x, y, 1, 1, GL_RGB, GL_FLOAT, pix);
auto hsv = convert_rgb2hsv(glm::vec3(pix[0], pix[1], pix[2]));
App::I.color->m_hue->set_value(hsv.x);
App::I.color->m_quad->set_value(1.f - hsv.y, 1.f - hsv.z);
}
break;
case kEventType::MouseCancel:
canvas->stroke_cancel();
m_dragging = false;
node->mouse_release();
if (m_dragging)
{
canvas->stroke_cancel();
m_dragging = false;
node->mouse_release();
}
if (m_picking)
{
m_picking = false;
node->mouse_release();
}
break;
default:
break;

View File

@@ -35,6 +35,7 @@ public:
class CanvasModePen : public CanvasMode
{
bool m_dragging = false;
bool m_picking = false;
glm::vec2 m_pan_start;
float m_camera_fov;
float m_zoom_canvas = 1.f;

View File

@@ -9,6 +9,7 @@ enum class kKey : uint8_t
AndroidBack,
KeySpacebar,
KeyE,
KeyAlt
};
enum class kEventResult : uint8_t

View File

@@ -248,7 +248,7 @@ kKey convert_key(int key)
CASE(VK_RETURN, kKey::Unknown);
CASE(VK_SHIFT, kKey::Unknown);
CASE(VK_CONTROL, kKey::Unknown);
CASE(VK_MENU, kKey::Unknown);
CASE(VK_MENU, kKey::KeyAlt);
CASE(VK_PAUSE, kKey::Unknown);
CASE(VK_CAPITAL, kKey::Unknown);
CASE(VK_KANA, kKey::Unknown);

View File

@@ -17,6 +17,7 @@ void LogRemote::start()
m_running = true;
m_thread = std::thread([&] {
BT_SetTerminate();
net_init();
auto session_string = net_request("/start");
m_session = atoi(session_string.c_str());
@@ -65,6 +66,16 @@ void LogRemote::net_close()
curl = nullptr;
m_running = false;
}
void LogRemote::file_init()
{
if (!m_logfile.is_open())
m_logfile.open("log.txt");
}
void LogRemote::file_close()
{
if (!m_logfile.is_open())
m_logfile.close();
}
void LogRemote::log(const char* format, ...)
{
static char buffer[4096];
@@ -73,6 +84,12 @@ void LogRemote::log(const char* format, ...)
int n = vsnprintf(buffer, sizeof(buffer), format, arglist);
va_end(arglist);
m_mq.Post(std::string(buffer, n));
if (m_logfile.is_open())
{
auto line = std::string(buffer, n) + "\n";
m_logfile.write(line.data(), line.size());
m_logfile.flush();
}
}
void LogRemote::log(const wchar_t* format, ...)
{
@@ -98,6 +115,12 @@ void LogRemote::log(const wchar_t* format, ...)
//std::string converted_str = converter.to_bytes(string_to_convert);
m_mq.Post(std::move(converted));
if (m_logfile.is_open())
{
auto line = converted + "\n";
m_logfile.write(line.data(), line.size());
m_logfile.flush();
}
}
LogRemote::~LogRemote()
{

View File

@@ -23,11 +23,14 @@ public:
std::string readBuffer;
std::string m_url = "http://omigamedev.ddns.net:8083";
int m_session;
std::ofstream m_logfile;
void start();
void net_init();
std::string net_request(std::string cmd, std::string data = "");
void net_close();
void file_init();
void file_close();
void log(const char* format, ...);
void log(const wchar_t* format, ...);
~LogRemote();

View File

@@ -478,6 +478,42 @@ int read_WMI_info()
return 0;
}
INT_PTR g_iLogHandle = -1;
static void SetupExceptionHandler()
{
// Setup exception handler
BT_SetAppName(_T("PanoPainter"));
//BT_SetSupportEMail(_T("your@email.com"));
BT_SetFlags(BTF_DETAILEDMODE | BTF_ATTACHREPORT | BTF_SCREENCAPTURE);
// = BugTrapServer ===========================================
BT_SetSupportServer(_T("omigamedev.ddns.net"), 8088);
// - or -
//BT_SetSupportServer(_T("127.0.0.1"), 9999);
// = BugTrapWebServer ========================================
//BT_SetSupportServer(_T("http://localhost/BugTrapWebServer/RequestHandler.aspx"), BUGTRAP_HTTP_PORT);
//BT_SetSupportServer(_T("http://omigamedev.ddns.net:8088/source/Server/BugTrapWebServer/RequestHandler.aspx"), BUGTRAP_HTTP_PORT);
// required for VS 2005 & 2008
BT_InstallSehFilter();
// Add custom log file using default name
// g_iLogHandle = BT_OpenLogFile(NULL, BTLF_TEXT);
// BT_SetLogSizeInEntries(g_iLogHandle, 100);
// BT_SetLogFlags(g_iLogHandle, BTLF_SHOWTIMESTAMP);
// BT_SetLogEchoMode(g_iLogHandle, BTLE_STDERR | BTLE_DBGOUT);
//
// PCTSTR pszLogFileName = BT_GetLogFileName(g_iLogHandle);
TCHAR wpath[1024];
GetFullPathNameW(L"log.txt", 1024, wpath, nullptr);
BT_AddLogFile(wpath);
BT_SetPreErrHandler([](INT_PTR){
LogRemote::I.file_close();
}, 0);
}
int main()
{
WNDCLASS wc;
@@ -485,6 +521,9 @@ int main()
App::I.initLog();
SetupExceptionHandler();
BT_SetTerminate();
read_WMI_info();
App::I.create();
@@ -629,6 +668,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
{
switch (msg)
{
case WM_CREATE:
BT_SetTerminate();
break;
case WM_CLOSE:
PostQuitMessage(0);
break;
@@ -647,10 +689,12 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
case WT_PACKET:
WacomTablet::I.handle_message(hWnd, msg, wp, lp);
break;
case WM_SYSKEYDOWN:
case WM_KEYDOWN:
keys[wp] = true;
App::I.key_down(convert_key((int)wp));
break;
case WM_SYSKEYUP:
case WM_KEYUP:
keys[wp] = false;
App::I.key_up(convert_key((int)wp));
@@ -666,6 +710,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT msg, WPARAM wp, LPARAM lp)
SetCapture(hWnd);
break;
case WM_LBUTTONUP:
WacomTablet::I.reset_pressure();
App::I.mouse_up(0, (float)GET_X_LPARAM(lp), (float)GET_Y_LPARAM(lp));
ReleaseCapture();
break;

View File

@@ -156,6 +156,7 @@ void NodeCanvas::handle_resize(glm::vec2 old_size, glm::vec2 new_size)
kEventResult NodeCanvas::handle_event(Event* e)
{
static std::vector<CanvasMode>* old_mode = nullptr;
Node::handle_event(e);
MouseEvent* me = static_cast<MouseEvent*>(e);
KeyEvent* ke = static_cast<KeyEvent*>(e);
@@ -186,6 +187,7 @@ kEventResult NodeCanvas::handle_event(Event* e)
if (ke->m_key == kKey::AndroidBack)
if (!ActionManager::empty())
ActionManager::undo();
break;
case kEventType::KeyUp:
// if (ke->m_key == kKey::KeyE)

View File

@@ -29,7 +29,7 @@ void NodeColorQuad::set_value(float x, float y)
{
auto sz = GetSize();
auto pos = glm::clamp(glm::vec2(x, y) * sz, { 0, 0 }, sz);
m_picker->SetPosition(pos.x, pos.y);
m_picker->SetPosition(pos - m_picker->GetSize() * .5f);
m_value = pos / glm::max({ 1,1 }, sz); // avoid div0
if (on_value_changed)
on_value_changed(this, m_value);
@@ -45,8 +45,8 @@ kEventResult NodeColorQuad::handle_event(Event* e)
dragging = true;
mouse_capture();
auto sz = GetSize();
auto pos = glm::clamp(((MouseEvent*)e)->m_pos - m_pos, { 0, 0 }, sz) - m_picker->GetSize() * .5f;
m_picker->SetPosition(pos.x, pos.y);
auto pos = glm::clamp(((MouseEvent*)e)->m_pos - m_pos, { 0, 0 }, sz);
m_picker->SetPosition(pos - m_picker->GetSize() * .5f);
m_value = pos / glm::max({ 1,1 }, sz); // avoid div0
if (on_value_changed)
on_value_changed(this, m_value);
@@ -60,8 +60,8 @@ kEventResult NodeColorQuad::handle_event(Event* e)
if (dragging)
{
auto sz = GetSize();
auto pos = glm::clamp(((MouseEvent*)e)->m_pos - m_pos, { 0, 0 }, sz) - m_picker->GetSize() * .5f;
m_picker->SetPosition(pos.x, pos.y);
auto pos = glm::clamp(((MouseEvent*)e)->m_pos - m_pos, { 0, 0 }, sz);
m_picker->SetPosition(pos - m_picker->GetSize() * .5f);
m_value = pos / glm::max({ 1,1 }, sz); // avoid div0
if (on_value_changed)
on_value_changed(this, m_value);

View File

@@ -13,3 +13,6 @@
#pragma comment (lib, "libcurl.lib")
#endif // DEBUG
#ifdef _WIN32
#pragma comment(lib, "BugTrapU-x64.lib")
#endif // _WIN32

View File

@@ -45,9 +45,11 @@
#define _SCL_SECURE_NO_WARNINGS
#include <windows.h>
#include <windowsx.h>
#include <tchar.h>
#include <gl\glew.h>
#include <gl\wglew.h>
#include <gl\GL.h>
#include <BugTrap.h>
#define SHADER_VERSION "#version 150\n"
@@ -68,6 +70,7 @@
#include <vector>
#include <random>
#include <thread>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <functional>

View File

@@ -178,5 +178,9 @@ void WacomTablet::handle_message(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lPar
float WacomTablet::get_pressure() const
{
return m_pen_down ? m_pen_pres : 1.f;
return m_pen_pres;
}
void WacomTablet::reset_pressure()
{
m_pen_pres = 1.f;
}

View File

@@ -26,4 +26,5 @@ public:
void handle_message(HWND hwnd, UINT Msg, WPARAM wParam, LPARAM lParam);
void set_focus(int activate);
float get_pressure() const;
void reset_pressure();
};