Skip to content

Commit 9338a54

Browse files
author
bob.burrough
committed
Initial import of Natives UI abstraction library.
0 parents  commit 9338a54

File tree

7 files changed

+301
-0
lines changed

7 files changed

+301
-0
lines changed

Natives.sdf

34.2 MB
Binary file not shown.

Natives.sln

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 14
4+
VisualStudioVersion = 14.0.23107.0
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Natives", "Natives\Natives.vcxproj", "{44B46E4E-C88D-493F-8FCC-6DF46C1CB4FC}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|x64 = Debug|x64
11+
Debug|x86 = Debug|x86
12+
Release|x64 = Release|x64
13+
Release|x86 = Release|x86
14+
EndGlobalSection
15+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
16+
{44B46E4E-C88D-493F-8FCC-6DF46C1CB4FC}.Debug|x64.ActiveCfg = Debug|x64
17+
{44B46E4E-C88D-493F-8FCC-6DF46C1CB4FC}.Debug|x64.Build.0 = Debug|x64
18+
{44B46E4E-C88D-493F-8FCC-6DF46C1CB4FC}.Debug|x86.ActiveCfg = Debug|Win32
19+
{44B46E4E-C88D-493F-8FCC-6DF46C1CB4FC}.Debug|x86.Build.0 = Debug|Win32
20+
{44B46E4E-C88D-493F-8FCC-6DF46C1CB4FC}.Release|x64.ActiveCfg = Release|x64
21+
{44B46E4E-C88D-493F-8FCC-6DF46C1CB4FC}.Release|x64.Build.0 = Release|x64
22+
{44B46E4E-C88D-493F-8FCC-6DF46C1CB4FC}.Release|x86.ActiveCfg = Release|Win32
23+
{44B46E4E-C88D-493F-8FCC-6DF46C1CB4FC}.Release|x86.Build.0 = Release|Win32
24+
EndGlobalSection
25+
GlobalSection(SolutionProperties) = preSolution
26+
HideSolutionNode = FALSE
27+
EndGlobalSection
28+
EndGlobal

Natives/Natives.vcxproj

Lines changed: 129 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project DefaultTargets="Build" ToolsVersion="14.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup Label="ProjectConfigurations">
4+
<ProjectConfiguration Include="Debug|Win32">
5+
<Configuration>Debug</Configuration>
6+
<Platform>Win32</Platform>
7+
</ProjectConfiguration>
8+
<ProjectConfiguration Include="Release|Win32">
9+
<Configuration>Release</Configuration>
10+
<Platform>Win32</Platform>
11+
</ProjectConfiguration>
12+
<ProjectConfiguration Include="Debug|x64">
13+
<Configuration>Debug</Configuration>
14+
<Platform>x64</Platform>
15+
</ProjectConfiguration>
16+
<ProjectConfiguration Include="Release|x64">
17+
<Configuration>Release</Configuration>
18+
<Platform>x64</Platform>
19+
</ProjectConfiguration>
20+
</ItemGroup>
21+
<PropertyGroup Label="Globals">
22+
<ProjectGuid>{44B46E4E-C88D-493F-8FCC-6DF46C1CB4FC}</ProjectGuid>
23+
<RootNamespace>Natives</RootNamespace>
24+
<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
25+
</PropertyGroup>
26+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
27+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
28+
<ConfigurationType>DynamicLibrary</ConfigurationType>
29+
<UseDebugLibraries>true</UseDebugLibraries>
30+
<PlatformToolset>v140</PlatformToolset>
31+
<CharacterSet>MultiByte</CharacterSet>
32+
</PropertyGroup>
33+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
34+
<ConfigurationType>Application</ConfigurationType>
35+
<UseDebugLibraries>false</UseDebugLibraries>
36+
<PlatformToolset>v140</PlatformToolset>
37+
<WholeProgramOptimization>true</WholeProgramOptimization>
38+
<CharacterSet>MultiByte</CharacterSet>
39+
</PropertyGroup>
40+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
41+
<ConfigurationType>Application</ConfigurationType>
42+
<UseDebugLibraries>true</UseDebugLibraries>
43+
<PlatformToolset>v140</PlatformToolset>
44+
<CharacterSet>MultiByte</CharacterSet>
45+
</PropertyGroup>
46+
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
47+
<ConfigurationType>Application</ConfigurationType>
48+
<UseDebugLibraries>false</UseDebugLibraries>
49+
<PlatformToolset>v140</PlatformToolset>
50+
<WholeProgramOptimization>true</WholeProgramOptimization>
51+
<CharacterSet>MultiByte</CharacterSet>
52+
</PropertyGroup>
53+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
54+
<ImportGroup Label="ExtensionSettings">
55+
</ImportGroup>
56+
<ImportGroup Label="Shared">
57+
</ImportGroup>
58+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
59+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
60+
</ImportGroup>
61+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
62+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
63+
</ImportGroup>
64+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
65+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
66+
</ImportGroup>
67+
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
68+
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
69+
</ImportGroup>
70+
<PropertyGroup Label="UserMacros" />
71+
<PropertyGroup />
72+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
73+
<ClCompile>
74+
<WarningLevel>Level3</WarningLevel>
75+
<Optimization>Disabled</Optimization>
76+
<SDLCheck>true</SDLCheck>
77+
</ClCompile>
78+
<Link>
79+
<GenerateDebugInformation>true</GenerateDebugInformation>
80+
</Link>
81+
</ItemDefinitionGroup>
82+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
83+
<ClCompile>
84+
<WarningLevel>Level3</WarningLevel>
85+
<Optimization>Disabled</Optimization>
86+
<SDLCheck>true</SDLCheck>
87+
</ClCompile>
88+
<Link>
89+
<GenerateDebugInformation>true</GenerateDebugInformation>
90+
</Link>
91+
</ItemDefinitionGroup>
92+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
93+
<ClCompile>
94+
<WarningLevel>Level3</WarningLevel>
95+
<Optimization>MaxSpeed</Optimization>
96+
<FunctionLevelLinking>true</FunctionLevelLinking>
97+
<IntrinsicFunctions>true</IntrinsicFunctions>
98+
<SDLCheck>true</SDLCheck>
99+
</ClCompile>
100+
<Link>
101+
<GenerateDebugInformation>true</GenerateDebugInformation>
102+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
103+
<OptimizeReferences>true</OptimizeReferences>
104+
</Link>
105+
</ItemDefinitionGroup>
106+
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
107+
<ClCompile>
108+
<WarningLevel>Level3</WarningLevel>
109+
<Optimization>MaxSpeed</Optimization>
110+
<FunctionLevelLinking>true</FunctionLevelLinking>
111+
<IntrinsicFunctions>true</IntrinsicFunctions>
112+
<SDLCheck>true</SDLCheck>
113+
</ClCompile>
114+
<Link>
115+
<GenerateDebugInformation>true</GenerateDebugInformation>
116+
<EnableCOMDATFolding>true</EnableCOMDATFolding>
117+
<OptimizeReferences>true</OptimizeReferences>
118+
</Link>
119+
</ItemDefinitionGroup>
120+
<ItemGroup>
121+
<ClInclude Include="natives.h" />
122+
</ItemGroup>
123+
<ItemGroup>
124+
<ClCompile Include="natives.cpp" />
125+
</ItemGroup>
126+
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
127+
<ImportGroup Label="ExtensionTargets">
128+
</ImportGroup>
129+
</Project>

Natives/Natives.vcxproj.filters

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<ItemGroup>
4+
<Filter Include="Source Files">
5+
<UniqueIdentifier>{4FC737F1-C7A5-4376-A066-2A32D752A2FF}</UniqueIdentifier>
6+
<Extensions>cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx</Extensions>
7+
</Filter>
8+
<Filter Include="Header Files">
9+
<UniqueIdentifier>{93995380-89BD-4b04-88EB-625FBE52EBFB}</UniqueIdentifier>
10+
<Extensions>h;hh;hpp;hxx;hm;inl;inc;xsd</Extensions>
11+
</Filter>
12+
<Filter Include="Resource Files">
13+
<UniqueIdentifier>{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}</UniqueIdentifier>
14+
<Extensions>rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms</Extensions>
15+
</Filter>
16+
</ItemGroup>
17+
<ItemGroup>
18+
<ClInclude Include="natives.h">
19+
<Filter>Source Files</Filter>
20+
</ClInclude>
21+
</ItemGroup>
22+
<ItemGroup>
23+
<ClCompile Include="natives.cpp">
24+
<Filter>Source Files</Filter>
25+
</ClCompile>
26+
</ItemGroup>
27+
</Project>

Natives/Source.cpp

Whitespace-only changes.

Natives/natives.cpp

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
2+
#define BLIT_IT_NATIVES_DLL_COMPILE
3+
4+
#include "natives.h"
5+
#include "threadutils.h"
6+
7+
#include <Windows.h>
8+
9+
using namespace std;
10+
11+
ChooseFileSuccessCallback _chooseFileSuccessCallback = NULL;
12+
ChooseFileCancelledCallback _chooseFileCancelledCallback = NULL;
13+
14+
pthread_mutex_t file_picker_mutex = PTHREAD_MUTEX_INITIALIZER;
15+
pthread_t file_picker_thread;
16+
bool file_picker_running = false;
17+
18+
void* LoadGcodeAsync(void* arg)
19+
{
20+
const int buf_len = 260;
21+
TCHAR cwd[buf_len] = { 0 };
22+
23+
GetCurrentDirectory(buf_len, cwd);
24+
25+
OPENFILENAME ofn; // common dialog box structure
26+
TCHAR szFile[buf_len]; // buffer for file name
27+
//HWND hwnd; // owner window
28+
//HANDLE hf; // file handle
29+
TCHAR filter[64] = TEXT("G-code\0*.gcode\0All\0*.*\0");
30+
31+
// Initialize OPENFILENAME
32+
ZeroMemory(&ofn, sizeof(ofn));
33+
ofn.lStructSize = sizeof(ofn);
34+
//ofn.hwndOwner = hwnd;
35+
ofn.lpstrFile = szFile;
36+
// Set lpstrFile[0] to '\0' so that GetOpenFileName does not
37+
// use the contents of szFile to initialize itself.
38+
ofn.lpstrFile[0] = '\0';
39+
ofn.nMaxFile = buf_len;
40+
ofn.lpstrFilter = filter;
41+
ofn.nFilterIndex = 1;
42+
ofn.lpstrFileTitle = NULL;
43+
ofn.nMaxFileTitle = 0;
44+
ofn.lpstrInitialDir = NULL;
45+
ofn.Flags = OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_NOCHANGEDIR | OFN_READONLY;
46+
47+
SetCurrentDirectory(cwd);
48+
49+
if (GetOpenFileName(&ofn))
50+
{
51+
if (_chooseFileSuccessCallback)
52+
_chooseFileSuccessCallback();
53+
}
54+
else
55+
{
56+
if (_chooseFileCancelledCallback)
57+
_chooseFileCancelledCallback();
58+
}
59+
60+
return NULL;
61+
}
62+
63+
64+
void __stdcall RegisterChooseFileSuccessCallback(ChooseFileSuccessCallback callback)
65+
{
66+
_chooseFileSuccessCallback = callback;
67+
}
68+
69+
70+
void __stdcall RegisterChooseFileCancelledCallback(ChooseFileCancelledCallback callback)
71+
{
72+
_chooseFileCancelledCallback = callback;
73+
}
74+
75+
76+
void __stdcall ChooseFile()
77+
{
78+
pthread_mutex_lock(&shared_machine_mutex);
79+
if (shared_machine == NULL)
80+
{
81+
shared_machine = new Machine();
82+
loading_thread_started = true;
83+
pthread_create(&loading_thread, NULL, LoadGcodeAsync, NULL);
84+
}
85+
pthread_mutex_unlock(&shared_machine_mutex);
86+
}
87+
88+
89+

Natives/natives.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#ifndef _BLIT_IT_NATIVES_H_
2+
3+
#include <stdint.h>
4+
5+
#ifdef __cplusplus
6+
extern "C"
7+
{
8+
#endif
9+
10+
#ifdef BLIT_IT_NATIVES_DLL_COMPILE
11+
#define DLLEXPORT extern __declspec(dllexport)
12+
#else
13+
#define DLLEXPORT extern __declspec(dllimport)
14+
#endif
15+
16+
typedef void(__stdcall *ChooseFileSuccessCallback)();
17+
DLLEXPORT void __stdcall RegisterChooseFileSuccessCallback(ChooseFileSuccessCallback callback);
18+
19+
typedef void(__stdcall *ChooseFileCancelledCallback)();
20+
DLLEXPORT void __stdcall RegisterChooseFileCancelledCallback(ChooseFileCancelledCallback callback);
21+
22+
DLLEXPORT void __stdcall ChooseFile();
23+
24+
#ifdef __cplusplus
25+
}
26+
#endif
27+
28+
#endif //_BLIT_IT_NATIVES_H_

0 commit comments

Comments
 (0)