yum-archive/TaSTT-Whisper

High-performance GPGPU inference of OpenAI's Whisper automatic speech recognition (ASR) model

git clone https://git.yummers.dev/yum-archive/TaSTT-Whisper

KonstantinSource codes8c4603c

master
2.8 KiB118 linesraw
1#include "stdafx.h"
2#include "CircleIndicator.h"
3#include <atltypes.h>
4#include "AppState.h"
5
6namespace
7{
8	static const LPCTSTR windowClassName = L"CircleIndicator";
9
10	// Font with these symbols, shipped with Windows since forever:
11	// https://learn.microsoft.com/en-us/typography/font-list/segoe-ui-symbol
12	static const LPCTSTR fontName = L"Segoe UI Symbol";
13
14	// Outlined circle
15	static const LPCTSTR circleOutline = L"⚪";
16	// Filled circle
17	static const LPCTSTR circleFilled = L"⚫";
18
19	// Font size for that symbol font, in points
20	constexpr int fontSizePoints = 14;
21
22	// Default active color for the indicator
23	constexpr uint32_t defaultActiveColor = 0x7FFF7F;
24}
25
26CircleIndicator::CircleIndicator() :
27	activeColor( defaultActiveColor )
28{ }
29
30ATL::CWndClassInfo& CircleIndicator::GetWndClassInfo()
31{
32	// Use custom class style with CS_PARENTDC, and COLOR_3DFACE for the background
33	static ATL::CWndClassInfo wc = 
34	{
35		{ sizeof( WNDCLASSEX ),
36		CS_HREDRAW | CS_VREDRAW | CS_PARENTDC,
37		StartWindowProc,
38		0, 0, NULL, NULL, NULL, (HBRUSH)( COLOR_3DFACE + 1 ), NULL, windowClassName, NULL },
39		NULL, NULL, IDC_ARROW, TRUE, 0, _T( "" )
40	};
41	return wc;
42}
43
44// Class registration
45HRESULT CircleIndicator::registerClass()
46{
47	WNDPROC pUnusedWndSuperProc = nullptr;
48	ATOM a = GetWndClassInfo().Register( &pUnusedWndSuperProc );
49	if( 0 != a )
50		return S_OK;
51	return getLastHr();
52}
53
54HRESULT CircleIndicator::createFont( int height )
55{
56	LOGFONT logFont;
57	memset( &logFont, 0, sizeof( logFont ) );
58	logFont.lfHeight = height;
59	logFont.lfCharSet = ANSI_CHARSET;
60	logFont.lfOutPrecision = OUT_TT_PRECIS;
61	logFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
62	wcsncpy_s( logFont.lfFaceName, fontName, _TRUNCATE );
63	font.CreateFontIndirect( &logFont );
64	if( font )
65		return S_OK;
66	return E_FAIL;
67}
68
69void CircleIndicator::onDestroy()
70{
71	if( font )
72		font.DeleteObject();
73}
74
75void CircleIndicator::onPaint( CDCHandle dc )
76{
77	CRect rectInt32;
78	GetClientRect( &rectInt32 );
79
80	CPaintDC pdc( m_hWnd );
81
82	const int logPixels = pdc.GetDeviceCaps( LOGPIXELSY );
83	int fontSize = -MulDiv( fontSizePoints, logPixels, 72 );
84	if( !font || fontHeight != fontSize )
85	{
86		if( font )
87			font.DeleteObject();
88		HRESULT hr = createFont( fontSize );
89		if( FAILED( hr ) )
90			return;
91		fontHeight = fontSize;
92	}
93
94	pdc.SetBkColor( GetSysColor( COLOR_3DFACE ) );
95	pdc.SelectFont( font );
96	pdc.SetBkMode( OPAQUE );
97	constexpr UINT textFormat = DT_CENTER | DT_VCENTER;
98
99	if( isActive )
100	{
101		pdc.SetTextColor( activeColor );
102		pdc.DrawText( circleFilled, 1, rectInt32, textFormat );
103		pdc.SetBkMode( TRANSPARENT );
104	}
105
106	pdc.SetTextColor( 0 );
107	pdc.DrawText( circleOutline, 1, rectInt32, textFormat );
108}
109
110void CircleIndicator::setActive( bool nowActive )
111{
112	if( nowActive == isActive )
113		return;
114
115	// Repaint the control
116	isActive = nowActive;
117	InvalidateRect( nullptr );
118}