Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AppCmd commands dispatcher for menu and application commands #15

Merged
merged 11 commits into from
Oct 17, 2024
4 changes: 4 additions & 0 deletions cpp.hint
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Hint files help the Visual Studio IDE interpret Visual C++ identifiers
// such as names of functions and macros.
// For more information see https://go.microsoft.com/fwlink/?linkid=865984
#define DECLARE_$NEW(T, __VA_ARGS__) T* T##_$new(E) { void* pObject = malloc(sizeof(T)); if (pObject) { memset(pObject, 0, sizeof(T)); T##_$init((T*)pObject, __VA_ARGS__); } return (T*)pObject; }
36 changes: 36 additions & 0 deletions panitent.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,42 +15,78 @@ Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
MinSizeRel|x64 = MinSizeRel|x64
MinSizeRel|x86 = MinSizeRel|x86
Release|x64 = Release|x64
Release|x86 = Release|x86
RelWithDebInfo|x64 = RelWithDebInfo|x64
RelWithDebInfo|x86 = RelWithDebInfo|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{F95C4EF5-0539-455C-B247-96029C28E36D}.Debug|x64.ActiveCfg = Debug|x64
{F95C4EF5-0539-455C-B247-96029C28E36D}.Debug|x64.Build.0 = Debug|x64
{F95C4EF5-0539-455C-B247-96029C28E36D}.Debug|x86.ActiveCfg = Debug|Win32
{F95C4EF5-0539-455C-B247-96029C28E36D}.Debug|x86.Build.0 = Debug|Win32
{F95C4EF5-0539-455C-B247-96029C28E36D}.MinSizeRel|x64.ActiveCfg = Release|x64
{F95C4EF5-0539-455C-B247-96029C28E36D}.MinSizeRel|x64.Build.0 = Release|x64
{F95C4EF5-0539-455C-B247-96029C28E36D}.MinSizeRel|x86.ActiveCfg = Release|Win32
{F95C4EF5-0539-455C-B247-96029C28E36D}.MinSizeRel|x86.Build.0 = Release|Win32
{F95C4EF5-0539-455C-B247-96029C28E36D}.Release|x64.ActiveCfg = Release|x64
{F95C4EF5-0539-455C-B247-96029C28E36D}.Release|x64.Build.0 = Release|x64
{F95C4EF5-0539-455C-B247-96029C28E36D}.Release|x86.ActiveCfg = Release|Win32
{F95C4EF5-0539-455C-B247-96029C28E36D}.Release|x86.Build.0 = Release|Win32
{F95C4EF5-0539-455C-B247-96029C28E36D}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{F95C4EF5-0539-455C-B247-96029C28E36D}.RelWithDebInfo|x64.Build.0 = Release|x64
{F95C4EF5-0539-455C-B247-96029C28E36D}.RelWithDebInfo|x86.ActiveCfg = Release|Win32
{F95C4EF5-0539-455C-B247-96029C28E36D}.RelWithDebInfo|x86.Build.0 = Release|Win32
{290557A9-3D88-4047-AE9C-F84118A13ADE}.Debug|x64.ActiveCfg = Debug|x64
{290557A9-3D88-4047-AE9C-F84118A13ADE}.Debug|x64.Build.0 = Debug|x64
{290557A9-3D88-4047-AE9C-F84118A13ADE}.Debug|x86.ActiveCfg = Debug|Win32
{290557A9-3D88-4047-AE9C-F84118A13ADE}.Debug|x86.Build.0 = Debug|Win32
{290557A9-3D88-4047-AE9C-F84118A13ADE}.MinSizeRel|x64.ActiveCfg = Release|x64
{290557A9-3D88-4047-AE9C-F84118A13ADE}.MinSizeRel|x64.Build.0 = Release|x64
{290557A9-3D88-4047-AE9C-F84118A13ADE}.MinSizeRel|x86.ActiveCfg = Release|Win32
{290557A9-3D88-4047-AE9C-F84118A13ADE}.MinSizeRel|x86.Build.0 = Release|Win32
{290557A9-3D88-4047-AE9C-F84118A13ADE}.Release|x64.ActiveCfg = Release|x64
{290557A9-3D88-4047-AE9C-F84118A13ADE}.Release|x64.Build.0 = Release|x64
{290557A9-3D88-4047-AE9C-F84118A13ADE}.Release|x86.ActiveCfg = Release|Win32
{290557A9-3D88-4047-AE9C-F84118A13ADE}.Release|x86.Build.0 = Release|Win32
{290557A9-3D88-4047-AE9C-F84118A13ADE}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{290557A9-3D88-4047-AE9C-F84118A13ADE}.RelWithDebInfo|x64.Build.0 = Release|x64
{290557A9-3D88-4047-AE9C-F84118A13ADE}.RelWithDebInfo|x86.ActiveCfg = Release|Win32
{290557A9-3D88-4047-AE9C-F84118A13ADE}.RelWithDebInfo|x86.Build.0 = Release|Win32
{DC50FB1F-44E3-478C-9CE3-C82F809309AD}.Debug|x64.ActiveCfg = Debug|x64
{DC50FB1F-44E3-478C-9CE3-C82F809309AD}.Debug|x64.Build.0 = Debug|x64
{DC50FB1F-44E3-478C-9CE3-C82F809309AD}.Debug|x86.ActiveCfg = Debug|Win32
{DC50FB1F-44E3-478C-9CE3-C82F809309AD}.Debug|x86.Build.0 = Debug|Win32
{DC50FB1F-44E3-478C-9CE3-C82F809309AD}.MinSizeRel|x64.ActiveCfg = Release|x64
{DC50FB1F-44E3-478C-9CE3-C82F809309AD}.MinSizeRel|x64.Build.0 = Release|x64
{DC50FB1F-44E3-478C-9CE3-C82F809309AD}.MinSizeRel|x86.ActiveCfg = Release|Win32
{DC50FB1F-44E3-478C-9CE3-C82F809309AD}.MinSizeRel|x86.Build.0 = Release|Win32
{DC50FB1F-44E3-478C-9CE3-C82F809309AD}.Release|x64.ActiveCfg = Release|x64
{DC50FB1F-44E3-478C-9CE3-C82F809309AD}.Release|x64.Build.0 = Release|x64
{DC50FB1F-44E3-478C-9CE3-C82F809309AD}.Release|x86.ActiveCfg = Release|Win32
{DC50FB1F-44E3-478C-9CE3-C82F809309AD}.Release|x86.Build.0 = Release|Win32
{DC50FB1F-44E3-478C-9CE3-C82F809309AD}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{DC50FB1F-44E3-478C-9CE3-C82F809309AD}.RelWithDebInfo|x64.Build.0 = Release|x64
{DC50FB1F-44E3-478C-9CE3-C82F809309AD}.RelWithDebInfo|x86.ActiveCfg = Release|Win32
{DC50FB1F-44E3-478C-9CE3-C82F809309AD}.RelWithDebInfo|x86.Build.0 = Release|Win32
{5427E0AA-9701-4AD6-B223-7404B614BA04}.Debug|x64.ActiveCfg = Debug|x64
{5427E0AA-9701-4AD6-B223-7404B614BA04}.Debug|x64.Build.0 = Debug|x64
{5427E0AA-9701-4AD6-B223-7404B614BA04}.Debug|x86.ActiveCfg = Debug|Win32
{5427E0AA-9701-4AD6-B223-7404B614BA04}.Debug|x86.Build.0 = Debug|Win32
{5427E0AA-9701-4AD6-B223-7404B614BA04}.MinSizeRel|x64.ActiveCfg = Release|x64
{5427E0AA-9701-4AD6-B223-7404B614BA04}.MinSizeRel|x64.Build.0 = Release|x64
{5427E0AA-9701-4AD6-B223-7404B614BA04}.MinSizeRel|x86.ActiveCfg = Release|Win32
{5427E0AA-9701-4AD6-B223-7404B614BA04}.MinSizeRel|x86.Build.0 = Release|Win32
{5427E0AA-9701-4AD6-B223-7404B614BA04}.Release|x64.ActiveCfg = Release|x64
{5427E0AA-9701-4AD6-B223-7404B614BA04}.Release|x64.Build.0 = Release|x64
{5427E0AA-9701-4AD6-B223-7404B614BA04}.Release|x86.ActiveCfg = Release|Win32
{5427E0AA-9701-4AD6-B223-7404B614BA04}.Release|x86.Build.0 = Release|Win32
{5427E0AA-9701-4AD6-B223-7404B614BA04}.RelWithDebInfo|x64.ActiveCfg = Release|x64
{5427E0AA-9701-4AD6-B223-7404B614BA04}.RelWithDebInfo|x64.Build.0 = Release|x64
{5427E0AA-9701-4AD6-B223-7404B614BA04}.RelWithDebInfo|x86.ActiveCfg = Release|Win32
{5427E0AA-9701-4AD6-B223-7404B614BA04}.RelWithDebInfo|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
26 changes: 25 additions & 1 deletion panitent.vcxproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
Expand All @@ -20,6 +20,7 @@
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\aboutbox.c" />
<ClCompile Include="src\appcmd.c" />
<ClCompile Include="src\binview\audioplayer.c" />
<ClCompile Include="src\binview\audiosource.c" />
<ClCompile Include="src\binview\binview.c" />
Expand All @@ -46,6 +47,8 @@
<ClCompile Include="src\floatingwindowcontainer.c" />
<ClCompile Include="src\glwindow.c" />
<ClCompile Include="src\grimstroke\bresenhamshapestrategy.c" />
<ClCompile Include="src\grimstroke\msaa.c" />
<ClCompile Include="src\grimstroke\msaaplotterproxy.c" />
<ClCompile Include="src\grimstroke\pixelbuffer.c" />
<ClCompile Include="src\grimstroke\plotter.c" />
<ClCompile Include="src\grimstroke\polygon.c" />
Expand All @@ -72,6 +75,10 @@
<ClCompile Include="src\pntxml.c" />
<ClCompile Include="src\propgriddialog.c" />
<ClCompile Include="src\rbhashmapviz.c" />
<ClCompile Include="src\s11n\bsonserializer.c" />
<ClCompile Include="src\s11n\jsonserializer.c" />
<ClCompile Include="src\s11n\serializable_example.c" />
<ClCompile Include="src\s11n\xmlserializer.c" />
<ClCompile Include="src\settings.c" />
<ClCompile Include="src\settings_dialog.c" />
<ClCompile Include="src\settings_wnd.c" />
Expand Down Expand Up @@ -116,6 +123,7 @@
</ItemGroup>
<ItemGroup>
<ClInclude Include="src\aboutbox.h" />
<ClInclude Include="src\appcmd.h" />
<ClInclude Include="src\binview\audioplayer.h" />
<ClInclude Include="src\binview\audiosource.h" />
<ClInclude Include="src\binview\binview.h" />
Expand All @@ -142,7 +150,11 @@
<ClInclude Include="src\flexible.h" />
<ClInclude Include="src\floatingwindowcontainer.h" />
<ClInclude Include="src\glwindow.h" />
<ClInclude Include="src\grimstroke\basic_plotter.h" />
<ClInclude Include="src\grimstroke\bresenhamshapestrategy.h" />
<ClInclude Include="src\grimstroke\msaa.h" />
<ClInclude Include="src\grimstroke\msaaplotterproxy.h" />
<ClInclude Include="src\grimstroke\path.h" />
<ClInclude Include="src\grimstroke\pixelbuffer.h" />
<ClInclude Include="src\grimstroke\plotter.h" />
<ClInclude Include="src\grimstroke\polygon.h" />
Expand Down Expand Up @@ -173,7 +185,13 @@
<ClInclude Include="src\propgriddialog.h" />
<ClInclude Include="src\rbhashmapviz.h" />
<ClInclude Include="src\resource.h" />
<ClInclude Include="src\s11n\bsonserializer.h" />
<ClInclude Include="src\s11n\tentany.h" />
<ClInclude Include="src\s11n\jsonserializer.h" />
<ClInclude Include="src\s11n\xmlserializer.h" />
<ClInclude Include="src\sdk\panitent.h" />
<ClInclude Include="src\s11n\propertytree.h" />
<ClInclude Include="src\s11n\serializable_example.h" />
<ClInclude Include="src\settings.h" />
<ClInclude Include="src\settings_dialog.h" />
<ClInclude Include="src\settings_wnd.h" />
Expand All @@ -188,6 +206,8 @@
<ClInclude Include="src\splittercontainer.h" />
<ClInclude Include="src\swatch.h" />
<ClInclude Include="src\swatch2.h" />
<ClInclude Include="src\swatchstorage.h" />
<ClInclude Include="src\swatchstoragebase.h" />
<ClInclude Include="src\test.h" />
<ClInclude Include="src\tool.h" />
<ClInclude Include="src\toolbox.h" />
Expand All @@ -213,7 +233,11 @@
<ClInclude Include="src\util\pntstring.h" />
<ClInclude Include="src\util\queue.h" />
<ClInclude Include="src\util\rbhashmap.h" />
<ClInclude Include="src\s11n\serializable.h" />
<ClInclude Include="src\s11n\serializer.h" />
<ClInclude Include="src\util\stack.h" />
<ClInclude Include="src\util\tentobj.h" />
<ClInclude Include="src\util\tenttypes.h" />
<ClInclude Include="src\util\tree.h" />
<ClInclude Include="src\util\utf.h" />
<ClInclude Include="src\util\vector.h" />
Expand Down
16 changes: 16 additions & 0 deletions panitent.vcxproj.user
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,20 @@
<PropertyGroup>
<ShowAllFiles>true</ShowAllFiles>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<LocalDebuggerCommandArguments>--enable-experimental-dock</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<LocalDebuggerCommandArguments>--enable-experimental-dock</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<LocalDebuggerCommandArguments>--enable-experimental-dock</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<LocalDebuggerCommandArguments>--enable-experimental-dock</LocalDebuggerCommandArguments>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>
3 changes: 3 additions & 0 deletions panitent_test.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
<Project>{f95c4ef5-0539-455c-b247-96029c28e36d}</Project>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="cpp.hint" />
</ItemGroup>
<PropertyGroup Label="Globals">
<VCProjectVersion>16.0</VCProjectVersion>
<Keyword>Win32Proj</Keyword>
Expand Down
12 changes: 7 additions & 5 deletions panitent_test/test_window.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@

#include "test_application.h"
#include "../src/palette_window.h"
#include "../src/util/tentobj.h"

static const WCHAR szClassName[] = L"TestWindowClass";

TestWindow* TestWindow_Create(struct Application* app);
void TestWindow_Init(TestWindow*, Application*);
/* Forward declarations */
DECLARE_$NEW(TestWindow)
void TestWindow_$init(TestWindow*, Application*);

void TestWindow_PreRegister(LPWNDCLASSEX);
void TestWindow_PreCreate(LPCREATESTRUCT);
Expand All @@ -17,7 +19,7 @@ void TestWindow_OnSize(TestWindow*, UINT, int, int);
void TestWindow_OnPaint(TestWindow*);
LRESULT CALLBACK TestWindow_UserProc(struct Window*, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam);

TestWindow* TestWindow_Create(struct Application* app)
TestWindow* TestWindow_$new()
{
TestWindow* pTestWindow = (TestWindow*)malloc(sizeof(TestWindow));
if (pTestWindow)
Expand All @@ -29,7 +31,7 @@ TestWindow* TestWindow_Create(struct Application* app)
return pTestWindow;
}

void TestWindow_Init(TestWindow* window, struct Application* app)
void TestWindow_$init(TestWindow* window)
{
Window_Init(&window->base, app);

Expand All @@ -41,7 +43,7 @@ void TestWindow_Init(TestWindow* window, struct Application* app)
window->base.OnPaint = TestWindow_OnPaint;
window->base.UserProc = TestWindow_UserProc;

window->paletteWindow = PaletteWindow_Create(window->base.app, ((struct TestApplication*)app)->palette);
window->paletteWindow = PaletteWindow_Create(((struct TestApplication*)app)->palette);
}

LRESULT CALLBACK TestWindow_UserProc(struct Window* window, HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
Expand Down
2 changes: 1 addition & 1 deletion panitent_test/test_window.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ struct TestWindow {
PaletteWindow* paletteWindow;
};

TestWindow* TestWindow_Create(Application*);
TestWindow* TestWindow_$new(Application*);

#endif /* _TEST_WINDOW_H_INLUCDED */
47 changes: 47 additions & 0 deletions res/panitent.rc
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,53 @@ END



//
// Menu resources
//
IDC_MAINMENU MENU
BEGIN
POPUP "&File"
BEGIN
MENUITEM "&New\tCtrl+N", IDM_FILE_NEW
MENUITEM "&Open\tCtrl+O", IDM_FILE_OPEN
MENUITEM "&Save\tCtrl+S", IDM_FILE_SAVE
MENUITEM "Export image to clipboard", IDM_FILE_CLIPBOARD_EXPORT
MENUITEM "BinView", IDM_FILE_BINVIEW
MENUITEM "&Close", IDM_FILE_CLOSE
END
POPUP "&Edit"
BEGIN
MENUITEM "&Undo", IDM_EDIT_UNDO
MENUITEM "&Redo", IDM_EDIT_REDO
MENUITEM "&Clear canvas", IDM_EDIT_CLRCANVAS
END
POPUP "&Scripting"
BEGIN
MENUITEM "Run last script", IDM_FILE_RUN_SCRIPT
MENUITEM "Run script...", IDM_FILE_RUN_SCRIPT
END
POPUP "&Window"
BEGIN
MENUITEM "&Tools", IDM_WINDOW_TOOLS
MENUITEM "&Activity...", IDM_WINDOW_ACTIVITY_DIALOG
MENUITEM "&Property Grid...", IDM_WINDOW_PROPERTY_GRID
END
POPUP "&Settings"
BEGIN
MENUITEM "&Options", IDM_OPTIONS_SETTINGS
END
POPUP "&Help"
BEGIN
MENUITEM "Help &Topics", IDM_HELP_TOPICS
MENUITEM "&Log", IDM_HELP_LOG
MENUITEM "&RBTreeViz", IDM_HELP_RBTREEVIZ
MENUITEM "&About", IDM_HELP_ABOUT
MENUITEM "&Display pixel buffer", IDM_HELP_DISPLAYPIXELBUFFER
END
END



//
// Cursor resources
//
Expand Down
44 changes: 44 additions & 0 deletions src/appcmd.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "precomp.h"

#include "appcmd.h"
#include "util/assert.h"
#include "panitentapp.h"

int AppCmd_KeyCompare(void* pKey1, void* pKey2) {
if ((UINT)pKey1 == (UINT)pKey2) {
return 0;
}
else if ((UINT)pKey1 > (UINT)pKey2) {
return 1;
}

return -1;
}

void AppCmd_Init(AppCmd* pAppCmd) {
ASSERT(pAppCmd);
memset(pAppCmd, 0, sizeof(AppCmd));

HashMap* pHashMap = HashMap_Create(16, &AppCmd_KeyCompare);
ASSERT(pHashMap);
pAppCmd->pCmdMap = pHashMap;
}

void AppCmd_AddCommand(AppCmd* pAppCmd, UINT cmdId, PFNAppCmdCallback* pfnCallback) {
ASSERT(pAppCmd);
ASSERT(pfnCallback);
HashMap_Put(pAppCmd->pCmdMap, (void*)cmdId, (void*)pfnCallback);
}

void AppCmd_Execute(AppCmd* pAppCmd, UINT cmdId, PanitentApp* pPanitentApp) {
ASSERT(pAppCmd);
PFNAppCmdCallback *pfnCallback = (PFNAppCmdCallback*)HashMap_Get(pAppCmd->pCmdMap, (void*)cmdId);
ASSERT(pfnCallback);
pfnCallback(pPanitentApp);
}

void AppCmd_Destroy(AppCmd* pAppCmd) {
ASSERT(pAppCmd);
HashMap_Destroy(pAppCmd->pCmdMap);
pAppCmd->pCmdMap = NULL;
}
21 changes: 21 additions & 0 deletions src/appcmd.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#ifndef PANITENT_APPCMD_H
#define PANITENT_APPCMD_H

#include "util/hashmap.h"

typedef struct PanitentApp PanitentApp;

typedef void (PFNAppCmdCallback)(PanitentApp*);

typedef struct AppCmd AppCmd;
typedef struct AppCmd {
HashMap* pCmdMap;
};

/* Public Interface */
void AppCmd_Init(AppCmd* pAppCmd);
void AppCmd_AddCommand(AppCmd* pAppCmd, UINT cmdId, PFNAppCmdCallback* pfnCallback);
void AppCmd_Execute(AppCmd* pAppCmd, UINT cmdId, PanitentApp* pPanitentApp);
void AppCmd_Destroy(AppCmd* pAppCmd);

#endif /* PANITENT_APPCMD_H */
Loading
Loading