替换 NIM 为独立 TTUI 引擎并完善窗口交互
移除 NIM 源码及主题依赖,加入 Win32、Direct2D、DirectWrite UI 静态库。迁移主页面、添加任务及外观设置,完善虚拟列表、统一窗口透明度和首次显示初始化。增加 Windows 7 API 回退与回归测试,在 AGENTS.md 记录后续控件体系和布局系统计划。
This commit is contained in:
1 parent
7c0ee5d964
commit
db38ec5c03
408 files changed
+1575
-55735
No files matched your search
@@ -0,0 +1,34 @@
|
||||
#pragma once
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
namespace ttui {
|
||||
|
||||
class AeroBackdrop
|
||||
{
|
||||
public:
|
||||
AeroBackdrop() = default;
|
||||
~AeroBackdrop();
|
||||
|
||||
AeroBackdrop(const AeroBackdrop&) = delete;
|
||||
AeroBackdrop& operator=(const AeroBackdrop&) = delete;
|
||||
|
||||
bool Create(HWND owner);
|
||||
void Sync(HWND owner);
|
||||
void Refresh();
|
||||
void Hide();
|
||||
void Destroy();
|
||||
bool IsValid() const { return hwnd_ != nullptr; }
|
||||
|
||||
private:
|
||||
static LRESULT CALLBACK WndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
||||
void ApplyGlass(int width, int height);
|
||||
|
||||
HWND hwnd_ = nullptr;
|
||||
int blur_width_ = 0;
|
||||
int blur_height_ = 0;
|
||||
bool blur_enabled_ = false;
|
||||
bool visible_ = false;
|
||||
};
|
||||
|
||||
} // namespace ttui
|
||||
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
#include <functional>
|
||||
namespace ttui {
|
||||
// Initializes COM/OLE and per-monitor DPI, creates windows, then runs Win32 messages.
|
||||
// Return false from create_windows on startup failure. Invoke once on the UI thread.
|
||||
int RunApplication(const std::function<bool()>& create_windows);
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
#include <algorithm>
|
||||
#include <cstddef>
|
||||
#include <utility>
|
||||
namespace ttui {
|
||||
// Data-only viewport. Rendering visits visible rows, never allocates per-row controls.
|
||||
class VirtualList {
|
||||
public:
|
||||
void Configure(size_t count, int page) {
|
||||
count_=static_cast<int>((std::min)(count, static_cast<size_t>(0x7fffffff)));
|
||||
page_=(std::max)(1,page); ScrollTo(first_);
|
||||
if (selected_>=count_) selected_=count_-1;
|
||||
}
|
||||
void ScrollTo(int row) { first_=std::clamp(row,0,(std::max)(0,count_-page_)); }
|
||||
void Select(int row) { selected_=row>=0 && row<count_ ? row : -1; }
|
||||
void RevealSelection() {
|
||||
if (selected_<0) return;
|
||||
if (selected_<first_) ScrollTo(selected_);
|
||||
if (selected_>=first_+page_) ScrollTo(selected_-page_+1);
|
||||
}
|
||||
std::pair<int,int> Visible() const { return {first_,(std::min)(count_,first_+page_+1)}; }
|
||||
int First() const { return first_; }
|
||||
int Selected() const { return selected_; }
|
||||
int Count() const { return count_; }
|
||||
int Page() const { return page_; }
|
||||
private:
|
||||
int count_=0,page_=1,first_=0,selected_=-1;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,87 @@
|
||||
#pragma once
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
#include <windows.h>
|
||||
#include <d2d1.h>
|
||||
#include <dwrite.h>
|
||||
#include <wrl/client.h>
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
namespace ttui {
|
||||
struct Rect {
|
||||
float left=0, top=0, right=0, bottom=0;
|
||||
bool Contains(float x, float y) const { return x>=left && x<right && y>=top && y<bottom; }
|
||||
D2D1_RECT_F Native() const { return D2D1::RectF(left,top,right,bottom); }
|
||||
};
|
||||
class Canvas {
|
||||
public:
|
||||
Canvas(ID2D1HwndRenderTarget* target, IDWriteFactory* text) : target_(target), text_(text) {}
|
||||
void Fill(Rect rect, unsigned rgb, float opacity=1);
|
||||
void Text(const std::wstring& text, Rect rect, unsigned rgb=0x273449, float size=14, bool bold=false, DWRITE_TEXT_ALIGNMENT alignment=DWRITE_TEXT_ALIGNMENT_LEADING);
|
||||
void Progress(Rect rect, double fraction);
|
||||
void Clip(Rect rect) { target_->PushAxisAlignedClip(rect.Native(), D2D1_ANTIALIAS_MODE_PER_PRIMITIVE); }
|
||||
void Unclip() { target_->PopAxisAlignedClip(); }
|
||||
ID2D1HwndRenderTarget* Target() const { return target_; }
|
||||
private:
|
||||
ID2D1HwndRenderTarget* target_;
|
||||
IDWriteFactory* text_;
|
||||
};
|
||||
// Owns a native top-level window; business code owns the C++ object.
|
||||
// Destroy the native window before destroying members used by virtual callbacks.
|
||||
class Window {
|
||||
public:
|
||||
Window();
|
||||
virtual ~Window();
|
||||
Window(const Window&)=delete;
|
||||
Window& operator=(const Window&)=delete;
|
||||
bool Create(HWND owner, const wchar_t* class_name, const wchar_t* title, int width, int height, bool main_window=false, bool resizable=false);
|
||||
HWND GetHWND() const { return hwnd_; }
|
||||
bool IsOpen() const { return hwnd_ && IsWindow(hwnd_); }
|
||||
void ShowWindow(int command=SW_SHOWNORMAL);
|
||||
void CenterWindow();
|
||||
void ActiveWindow();
|
||||
void Close();
|
||||
void Invalidate(); // coalesced to at most 30 paints per second
|
||||
void Preview(); // refresh during interactive control tracking, limited to 30Hz
|
||||
float Scale() const { return dpi_/96.f; }
|
||||
float Width() const;
|
||||
float Height() const;
|
||||
void Place(HWND child, Rect rect);
|
||||
HWND CreateEdit(int id, const wchar_t* cue);
|
||||
static std::wstring EditText(HWND edit);
|
||||
void FocusContent();
|
||||
void ClearButtons();
|
||||
void Button(int id, std::wstring label, Rect rect, bool primary=false);
|
||||
bool SetOpacity(int percent); // Uniform window alpha, clamped to 30..100.
|
||||
void SetBackgroundImage(const std::wstring& path);
|
||||
bool HasBackgroundImage() const;
|
||||
void SetBackgroundImageOpacity(float opacity);
|
||||
void DrawBackground(Canvas& canvas, float opacity);
|
||||
protected:
|
||||
virtual void OnCreate() {}
|
||||
virtual void OnLayout() {}
|
||||
virtual void OnPaint(Canvas&) {}
|
||||
virtual void OnCommand(int) {}
|
||||
virtual std::optional<LRESULT> OnMessage(UINT, WPARAM, LPARAM) { return {}; }
|
||||
private:
|
||||
struct Impl;
|
||||
std::unique_ptr<Impl> impl_;
|
||||
static LRESULT CALLBACK WndProc(HWND,UINT,WPARAM,LPARAM);
|
||||
static LRESULT CALLBACK EditProc(HWND,UINT,WPARAM,LPARAM,UINT_PTR,DWORD_PTR);
|
||||
LRESULT Dispatch(UINT,WPARAM,LPARAM);
|
||||
bool EnsureTarget();
|
||||
void Paint();
|
||||
void RefreshFont();
|
||||
HBRUSH ControlBackground(HDC dc);
|
||||
void DiscardControlBackground();
|
||||
HWND hwnd_=nullptr;
|
||||
float dpi_=96;
|
||||
int opacity_percent_=100;
|
||||
bool main_=false, dirty_=false, resizable_=false, initialized_=false, opacity_applied_=false;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
#include <windows.h>
|
||||
#ifndef WM_DPICHANGED
|
||||
#define WM_DPICHANGED 0x02E0
|
||||
#endif
|
||||
namespace ttui::compat {
|
||||
inline UINT Dpi(HWND window=nullptr) {
|
||||
HMODULE user=GetModuleHandleW(L"user32.dll");
|
||||
if (window) {
|
||||
using Function=UINT(WINAPI*)(HWND);
|
||||
auto get=reinterpret_cast<Function>(GetProcAddress(user,"GetDpiForWindow"));
|
||||
if (get) { UINT value=get(window); if (value) return value; }
|
||||
}
|
||||
using Function=UINT(WINAPI*)();
|
||||
auto get=reinterpret_cast<Function>(GetProcAddress(user,"GetDpiForSystem"));
|
||||
if (get) { UINT value=get(); if (value) return value; }
|
||||
HDC dc=GetDC(nullptr); int value=dc?GetDeviceCaps(dc,LOGPIXELSX):96;
|
||||
if (dc) ReleaseDC(nullptr,dc);
|
||||
return value>0?static_cast<UINT>(value):96;
|
||||
}
|
||||
inline void EnableDpiAwareness() {
|
||||
using Function=BOOL(WINAPI*)(HANDLE);
|
||||
auto set=reinterpret_cast<Function>(GetProcAddress(GetModuleHandleW(L"user32.dll"),"SetProcessDpiAwarenessContext"));
|
||||
if (set && (set(reinterpret_cast<HANDLE>(static_cast<INT_PTR>(-4))) || set(reinterpret_cast<HANDLE>(static_cast<INT_PTR>(-3))))) return;
|
||||
SetProcessDPIAware();
|
||||
}
|
||||
inline void AdjustWindow(RECT& rect,DWORD style,UINT dpi) {
|
||||
using Function=BOOL(WINAPI*)(LPRECT,DWORD,BOOL,DWORD,UINT);
|
||||
auto adjust=reinterpret_cast<Function>(GetProcAddress(GetModuleHandleW(L"user32.dll"),"AdjustWindowRectExForDpi"));
|
||||
if (adjust && adjust(&rect,style,FALSE,0,dpi)) return;
|
||||
AdjustWindowRectEx(&rect,style,FALSE,0);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user