Skip to content

Commit

Permalink
Merge branch 'master' into iserialization
Browse files Browse the repository at this point in the history
  • Loading branch information
Philosoph228 authored Oct 17, 2024
2 parents 48a332e + caf1b5d commit 5cc20d8
Show file tree
Hide file tree
Showing 13 changed files with 372 additions and 158 deletions.
4 changes: 3 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 Down Expand Up @@ -122,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 Down
2 changes: 1 addition & 1 deletion panitent_test/test_application.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ void TestApplication_Init(TestApplication* app)
Application_Init(&app->base);

app->palette = Palette_Create();
app->mainWindow = TestWindow_$new(app);
app->mainWindow = TestWindow_Create(app);
}

TestApplication* TestApplication_Create()
Expand Down
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 */
2 changes: 1 addition & 1 deletion src/canvas.c
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@ void Canvas_DrawLine(const Canvas* pCanvas, int x1, int y1, int x2, int y2)
PlotterData* pPlotterData = (PlotterData*)malloc(sizeof(PlotterData));
ASSERT(pPlotterData);
pPlotterData->canvas = pCanvas;
pPlotterData->color = 0xCCFF00CC;
pPlotterData->color = 0xFF0000FF;
plotter.userData = pPlotterData;
plotter.fn = PixelPlotterCallback;

Expand Down
170 changes: 168 additions & 2 deletions src/dockhost.c
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,7 @@ void DockHostWindow_UndockToFloating(DockHostWindow* pDockHostWindow, TreeNode*
FloatingWindowContainer* pFloatingWindowContainer = FloatingWindowContainer_Create();
Window_CreateWindow((Window*)pFloatingWindowContainer, NULL);
FloatingWindowContainer_PinWindow(pFloatingWindowContainer, ((DockData*)pNode->data)->hWnd);

DockHostWindow_Rearrange(pDockHostWindow);

DestroyWindow(g_hWndDragOverlay);
}

Expand Down Expand Up @@ -820,6 +818,174 @@ void DockHostWindow_StartDrag(DockHostWindow* pDockHostWindow, int x, int y)
ReleaseDC(NULL, hdcScreen);
}

void DockHostWindow_StartDrag(DockHostWindow* pDockHostWindow, int x, int y)
{
WNDCLASSEX wcex = { 0 };
if (!GetClassInfoEx(GetModuleHandle(NULL), L"__DragOverlayClass", &wcex))
{
wcex.cbSize = sizeof(wcex);
wcex.lpfnWndProc = (WNDPROC)DragOverlayWndProc;
wcex.hInstance = GetModuleHandle(NULL);
wcex.lpszClassName = L"__DragOverlayClass";
RegisterClassEx(&wcex);
}

HWND g_hWndDragOverlay = CreateWindowEx(WS_EX_LAYERED | WS_EX_TRANSPARENT | WS_EX_TOPMOST, L"__DragOverlayClass", L"DragOverlay", WS_VISIBLE | WS_POPUP, x - 64, y - 64, 128, 128, NULL, NULL, GetModuleHandle(NULL), NULL);

HDC hdcScreen = GetDC(NULL);
HDC hdcMem = CreateCompatibleDC(hdcScreen);

BLENDFUNCTION blendFunction = { 0 };
blendFunction.BlendOp = AC_SRC_OVER;
blendFunction.SourceConstantAlpha = 255;
blendFunction.AlphaFormat = AC_SRC_ALPHA;

BITMAPINFO bmi = { 0 };
bmi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bmi.bmiHeader.biWidth = 128;
bmi.bmiHeader.biHeight = -128;
bmi.bmiHeader.biPlanes = 1;
bmi.bmiHeader.biBitCount = 32;
bmi.bmiHeader.biCompression = BI_RGB;

unsigned int* pBits;

// Create a compatible bitmap with the desired format
HBITMAP hBitmap = CreateDIBSection(hdcScreen, &bmi, DIB_RGB_COLORS, (void**)&pBits, NULL, 0);
HGDIOBJ hOldObj = SelectObject(hdcMem, hBitmap);

// Draw
{
int centerX = 32;
int centerY = 32;
int radius = 32;

unsigned char* pCircle = malloc(64 * 64 * sizeof(unsigned char));

for (int y = 0; y < 64; ++y)
{
for (int x = 0; x < 64; ++x)
{
int dx = x - centerX;
int dy = y - centerY;
float distance = sqrtf((float)(dx * dx + dy * dy));

float dist = distance / (float)radius;

// Calculate alpha based on the distance

float uStripeWidth = 0.1f;
float stripeEdge = 0.5 * (1.0 / uStripeWidth);
BYTE alpha1 = (BYTE)(255.0f * smoothstepf(1.0f, 0.95f, dist));
BYTE alpha2 = (BYTE)(255.0f * (sinf(dist * 24.0f) * 0.5f + 0.5f));
BYTE alpha = min(alpha1, alpha2);
if (alpha > 255)
{
alpha = 255;
}
if (alpha < 0)
{
alpha = 0;
}

pCircle[y * 64 + x] = alpha;
}
}

unsigned int* pData = pBits;
pData += 128 * ((128 - 64) / 2) + ((128 - 64) / 2);
for (int y = 0; y < 64; ++y)
{
for (int x = 0; x < 64; ++x)
{
BYTE alpha = pCircle[y * 64 + x];
unsigned int color = (alpha << 24) | (alpha << 16);
*pData = color;
pData++;
}

pData += 64;
}

free(pCircle);

/*
for (int y = 0; y < 128; ++y)
{
for (int x = 0; x < 128; ++x)
{
unsigned int color = pBits[y * 128 + x];
// Extract RGBA components
BYTE alpha = (color >> 24) & 0xFF;
BYTE red = (color >> 16) & 0xFF;
BYTE green = (color >> 8) & 0xFF;
BYTE blue = (color) & 0xFF;
// Premultiply RGB values by alpha
BYTE premultRed = (BYTE)((red * alpha) / 255);
BYTE premultGreen = (BYTE)((green * alpha) / 255);
BYTE premultBlue = (BYTE)((blue * alpha) / 255);
// Store the premultiplied color back into the bitmap
pBits[y * 128 + x] = (premultRed << 16) | (premultGreen << 8) | premultBlue | (alpha << 24);
}
}
*/

/*
for (int y = 0; y < 128; ++y)
{
pBits[y * 128] = 0xFFFF0000;
pBits[y * 128 + 127] = 0xFFFF0000;
pBits[y] = 0xFFFF0000;
pBits[y + 127 * 128] = 0xFFFF0000;
}
*/

/*
for (int y = 0; y < 128; ++y)
{
for (int x = 0; x < 128; ++x)
{
int dx = x - centerX;
int dy = y - centerY;
float distance = sqrtf((float)(dx * dx + dy * dy));
// Calculate alpha based on the distance
BYTE alpha = (BYTE)(255 * (1.0f - (distance / radius)));
if (alpha > 255)
{
alpha = 255;
}
if (alpha < 0 || distance > radius)
{
alpha = 0;
}
// Set the pixel color (white with varying alpha)
DWORD color = (alpha << 24) | (alpha << 16) | (alpha << 8) | alpha;
pBits[y * 128 + x] = color;
}
}
*/
}

POINT ptPos = { x, y };
SIZE sizeWnd = { 128, 128 };
POINT ptSrc = { 0, 0 };

ClientToScreen(pDockHostWindow->base.hWnd, &ptPos);
ptPos.x -= 64;
ptPos.y -= 64;

UpdateLayeredWindow(g_hWndDragOverlay, hdcScreen, &ptPos, &sizeWnd, hdcMem, &ptSrc, RGB(0, 0, 0), &blendFunction, ULW_ALPHA);

SelectObject(hdcMem, hOldObj);
DeleteDC(hdcMem);
ReleaseDC(NULL, hdcScreen);
}

void DockHostWindow_OnLButtonDown(DockHostWindow* pDockHostWindow, BOOL fDoubleClick, int x, int y, UINT keyFlags)
{
UNREFERENCED_PARAMETER(fDoubleClick);
Expand Down
2 changes: 1 addition & 1 deletion src/floatingwindowcontainer.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ static const WCHAR szClassName[] = L"__FloatingWindowContainer";

/* Private forward declarations */
FloatingWindowContainer* FloatingWindowContainer_Create();
void FloatingWindowContainer_Init(FloatingWindowContainer*, Application* app);
void FloatingWindowContainer_Init(FloatingWindowContainer*);

void FloatingWindowContainer_PreRegister(LPWNDCLASSEX);
void FloatingWindowContainer_PreCreate(LPCREATESTRUCT);
Expand Down
1 change: 0 additions & 1 deletion src/msthemeloader.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ int PntINI_Callback(void* user, PCTSTR section, PCTSTR name, PCTSTR value, int l
DeleteBitmap(hBitmap);
DeleteDC(hdcMem);
}

}
}

Expand Down
Loading

0 comments on commit 5cc20d8

Please sign in to comment.