Skip to content

Commit

Permalink
Add PhCustomDrawTreeTimeLine, Update timeline column with darkmode
Browse files Browse the repository at this point in the history
  • Loading branch information
dmex committed Aug 31, 2021
1 parent 28d51d3 commit a0c7292
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 206 deletions.
41 changes: 4 additions & 37 deletions ProcessHacker/modlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -1227,48 +1227,15 @@ BOOLEAN NTAPI PhpModuleTreeNewCallback(
{
case PHMOTLC_TIMELINE:
{
#define PhInflateRect(rect, dx, dy) \
{ (rect)->left -= (dx); (rect)->top -= (dy); (rect)->right += (dx); (rect)->bottom += (dy); }
HBRUSH previousBrush = NULL;
RECT borderRect = customDraw->CellRect;
FLOAT percent = 0;
LARGE_INTEGER systemTime;
LARGE_INTEGER startTime;
LARGE_INTEGER createTime;

if (moduleItem->LoadTime.QuadPart == 0)
break; // nothing to draw

PhQuerySystemTime(&systemTime);
startTime.QuadPart = systemTime.QuadPart - context->ProcessCreateTime.QuadPart;
createTime.QuadPart = systemTime.QuadPart - moduleItem->LoadTime.QuadPart;
percent = (FLOAT)createTime.QuadPart / (FLOAT)startTime.QuadPart * 100.f;
// Prevent overflow from changing the system time to an earlier date.
if (percent > 100.f) percent = 100.f;

FillRect(customDraw->Dc, &rect, GetSysColorBrush(COLOR_WINDOW));
PhInflateRect(&rect, -1, -1);
rect.bottom += 1;
FillRect(customDraw->Dc, &rect, GetSysColorBrush(COLOR_3DFACE));

SetDCBrushColor(customDraw->Dc, RGB(158, 202, 158));
previousBrush = SelectBrush(customDraw->Dc, GetStockBrush(DC_BRUSH));
rect.left = (LONG)(rect.right + ((rect.left - rect.right) * percent / 100));

PatBlt(
PhCustomDrawTreeTimeLine(
customDraw->Dc,
rect.left,
rect.top,
rect.right - rect.left,
rect.bottom - rect.top,
PATCOPY
customDraw->CellRect,
PhEnableThemeSupport,
&moduleItem->LoadTime
);

if (previousBrush) SelectBrush(customDraw->Dc, previousBrush);

PhInflateRect(&borderRect, -1, -1);
borderRect.bottom += 1;
FrameRect(customDraw->Dc, &borderRect, GetStockBrush(GRAY_BRUSH));
}
break;
}
Expand Down
62 changes: 7 additions & 55 deletions ProcessHacker/netlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,9 @@ BOOLEAN NTAPI PhpNetworkTreeNewCallback(
PPH_NETWORK_ITEM networkItem;
RECT rect;

if (!customDraw)
break;

node = (PPH_NETWORK_NODE)customDraw->Node;
networkItem = node->NetworkItem;
rect = customDraw->CellRect;
Expand All @@ -703,66 +706,15 @@ BOOLEAN NTAPI PhpNetworkTreeNewCallback(
{
case PHNETLC_TIMELINE:
{
#define PhInflateRect(rect, dx, dy) \
{ (rect)->left -= (dx); (rect)->top -= (dy); (rect)->right += (dx); (rect)->bottom += (dy); }
HBRUSH previousBrush = NULL;
RECT borderRect = customDraw->CellRect;
FLOAT percent = 0;
static LARGE_INTEGER bootTime = { 0 };
LARGE_INTEGER systemTime;
LARGE_INTEGER startTime;
LARGE_INTEGER createTime;

if (networkItem->CreateTime.QuadPart == 0)
break; // nothing to draw

if (bootTime.QuadPart == 0)
{
SYSTEM_TIMEOFDAY_INFORMATION timeOfDayInfo;

if (NT_SUCCESS(NtQuerySystemInformation(
SystemTimeOfDayInformation,
&timeOfDayInfo,
sizeof(SYSTEM_TIMEOFDAY_INFORMATION),
NULL
)))
{
bootTime.LowPart = timeOfDayInfo.BootTime.LowPart;
bootTime.HighPart = timeOfDayInfo.BootTime.HighPart;
bootTime.QuadPart -= timeOfDayInfo.BootTimeBias;
}
}

PhQuerySystemTime(&systemTime);
startTime.QuadPart = systemTime.QuadPart - bootTime.QuadPart;
createTime.QuadPart = systemTime.QuadPart - networkItem->CreateTime.QuadPart;
percent = (FLOAT)createTime.QuadPart / (FLOAT)startTime.QuadPart * 100.f;
// Prevent overflow from changing the system time to an earlier date.
if (percent > 100.f) percent = 100.f;

FillRect(customDraw->Dc, &rect, GetSysColorBrush(COLOR_WINDOW));
PhInflateRect(&rect, -1, -1);
rect.bottom += 1;
FillRect(customDraw->Dc, &rect, GetSysColorBrush(COLOR_3DFACE));

SetDCBrushColor(customDraw->Dc, RGB(158, 202, 158));
previousBrush = SelectBrush(customDraw->Dc, GetStockBrush(DC_BRUSH));
rect.left = (LONG)(rect.right + ((rect.left - rect.right) * percent / 100));

PatBlt(
PhCustomDrawTreeTimeLine(
customDraw->Dc,
rect.left,
rect.top,
rect.right - rect.left,
rect.bottom - rect.top,
PATCOPY
customDraw->CellRect,
PhEnableThemeSupport,
&networkItem->CreateTime
);

if (previousBrush) SelectBrush(customDraw->Dc, previousBrush);

PhInflateRect(&borderRect, -1, -1);
borderRect.bottom += 1;
FrameRect(customDraw->Dc, &borderRect, GetStockBrush(GRAY_BRUSH));
}
break;
}
Expand Down
93 changes: 16 additions & 77 deletions ProcessHacker/proctree.c
Original file line number Diff line number Diff line change
Expand Up @@ -3614,90 +3614,29 @@ BOOLEAN NTAPI PhpProcessTreeNewCallback(
break;
case PHPRTLC_TIMELINE:
{
#define PhInflateRect(rect, dx, dy) \
{ (rect)->left -= (dx); (rect)->top -= (dy); (rect)->right += (dx); (rect)->bottom += (dy); }
HBRUSH previousBrush = NULL;
RECT borderRect = customDraw->CellRect;
FLOAT percent = 0;

if (PH_IS_REAL_PROCESS_ID(processItem->ProcessId))
{
static LARGE_INTEGER bootTime = { 0 };
LARGE_INTEGER systemTime;
LARGE_INTEGER startTime;
LARGE_INTEGER createTime;

if (bootTime.QuadPart == 0)
{
SYSTEM_TIMEOFDAY_INFORMATION timeOfDayInfo;

if (NT_SUCCESS(NtQuerySystemInformation(
SystemTimeOfDayInformation,
&timeOfDayInfo,
sizeof(SYSTEM_TIMEOFDAY_INFORMATION),
NULL
)))
{
bootTime.LowPart = timeOfDayInfo.BootTime.LowPart;
bootTime.HighPart = timeOfDayInfo.BootTime.HighPart;
bootTime.QuadPart -= timeOfDayInfo.BootTimeBias;
}

//if (NT_SUCCESS(NtQuerySystemInformation(
// SystemTimeOfDayInformation,
// &timeOfDayInfo,
// RTL_SIZEOF_THROUGH_FIELD(SYSTEM_TIMEOFDAY_INFORMATION, CurrentTime),
// NULL
// )))
//{
// startTime.QuadPart = timeOfDayInfo.CurrentTime.QuadPart - timeOfDayInfo.BootTime.QuadPart;
// createTime.QuadPart = timeOfDayInfo.CurrentTime.QuadPart - processItem->CreateTime.QuadPart;
// percent = round((DOUBLE)((FLOAT)createTime.QuadPart / (FLOAT)startTime.QuadPart * 100));
//}
}

PhQuerySystemTime(&systemTime);
startTime.QuadPart = systemTime.QuadPart - bootTime.QuadPart;
createTime.QuadPart = systemTime.QuadPart - processItem->CreateTime.QuadPart;
percent = (FLOAT)createTime.QuadPart / (FLOAT)startTime.QuadPart * 100.f;

// Prevent overflow from changing the system time to an earlier date.
if (percent > 100.f)
percent = 100.f;
PhCustomDrawTreeTimeLine(
customDraw->Dc,
customDraw->CellRect,
PhEnableThemeSupport,
&processItem->CreateTime
);
}
else
{
LARGE_INTEGER createTime;

// DPCs, Interrupts and System Idle Process are always 100%
percent = 100.f;
createTime.QuadPart = 0;

PhCustomDrawTreeTimeLine(
customDraw->Dc,
customDraw->CellRect,
PhEnableThemeSupport,
&createTime
);
}

FillRect(customDraw->Dc, &rect, GetSysColorBrush(COLOR_WINDOW));
PhInflateRect(&rect, -1, -1);
rect.bottom += 1;
FillRect(customDraw->Dc, &rect, GetSysColorBrush(COLOR_3DFACE));

SetDCBrushColor(customDraw->Dc, RGB(158, 202, 158));
previousBrush = SelectBrush(customDraw->Dc, GetStockBrush(DC_BRUSH));

// TODO: This still loses a small fraction of precision compared to PE here causing a 1px difference.
//rect.right = ((LONG)(rect.left + ((rect.right - rect.left) * (LONG)percent) / 100));
//rect.left = ((LONG)(rect.right + ((rect.left - rect.right) * (LONG)percent) / 100));
rect.left = (LONG)(rect.right + ((rect.left - rect.right) * percent / 100));

PatBlt(
customDraw->Dc,
rect.left,
rect.top,
rect.right - rect.left,
rect.bottom - rect.top,
PATCOPY
);

if (previousBrush) SelectBrush(customDraw->Dc, previousBrush);

PhInflateRect(&borderRect, -1, -1);
borderRect.bottom += 1;
FrameRect(customDraw->Dc, &borderRect, GetStockBrush(GRAY_BRUSH));
}
break;
}
Expand Down
44 changes: 7 additions & 37 deletions ProcessHacker/thrdlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -1366,6 +1366,9 @@ BOOLEAN NTAPI PhpThreadTreeNewCallback(
PPH_THREAD_ITEM threadItem;
RECT rect;

if (!customDraw)
break;

node = (PPH_THREAD_NODE)customDraw->Node;
threadItem = node->ThreadItem;
rect = customDraw->CellRect;
Expand All @@ -1377,48 +1380,15 @@ BOOLEAN NTAPI PhpThreadTreeNewCallback(
{
case PH_THREAD_TREELIST_COLUMN_TIMELINE:
{
#define PhInflateRect(rect, dx, dy) \
{ (rect)->left -= (dx); (rect)->top -= (dy); (rect)->right += (dx); (rect)->bottom += (dy); }
HBRUSH previousBrush = NULL;
RECT borderRect = customDraw->CellRect;
FLOAT percent = 0;
LARGE_INTEGER systemTime;
LARGE_INTEGER startTime;
LARGE_INTEGER createTime;

if (threadItem->CreateTime.QuadPart == 0)
break; // nothing to draw

PhQuerySystemTime(&systemTime);
startTime.QuadPart = systemTime.QuadPart - context->ProcessCreateTime.QuadPart;
createTime.QuadPart = systemTime.QuadPart - threadItem->CreateTime.QuadPart;
percent = (FLOAT)createTime.QuadPart / (FLOAT)startTime.QuadPart * 100.f;

FillRect(customDraw->Dc, &rect, GetSysColorBrush(COLOR_WINDOW));
PhInflateRect(&rect, -1, -1);
rect.bottom += 1;
FillRect(customDraw->Dc, &rect, GetSysColorBrush(COLOR_3DFACE));
SetDCBrushColor(customDraw->Dc, percent > 100.f ? RGB(128, 128, 128) : RGB(158, 202, 158));
previousBrush = SelectBrush(customDraw->Dc, GetStockBrush(DC_BRUSH));

// Prevent overflow from changing the system time to an earlier date.
if (percent > 100.f) percent = 100.f;
rect.left = (LONG)(rect.right + ((rect.left - rect.right) * percent / 100));

PatBlt(
PhCustomDrawTreeTimeLine(
customDraw->Dc,
rect.left,
rect.top,
rect.right - rect.left,
rect.bottom - rect.top,
PATCOPY
customDraw->CellRect,
PhEnableThemeSupport,
&threadItem->CreateTime
);

if (previousBrush) SelectBrush(customDraw->Dc, previousBrush);

PhInflateRect(&borderRect, -1, -1);
borderRect.bottom += 1;
FrameRect(customDraw->Dc, &borderRect, GetStockBrush(GRAY_BRUSH));
}
break;
}
Expand Down

0 comments on commit a0c7292

Please sign in to comment.