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