soui 5.0.0.1
Soui5 Doc
 
Loading...
Searching...
No Matches
SCaret.cpp
1#include "souistd.h"
2#include "core/SCaret.h"
3#include "animation/SInterpolatorImpl.h"
4#include <core/SWindowMgr.h>
5#include <core/SWnd.h>
6
7SNSBEGIN
8
10 : m_pContainer(pContainer)
11 , m_bDrawCaret(true)
12 , m_bVisible(FALSE)
13 , m_iFrame(0)
14 , m_byAlpha(0xFF)
15 , m_crCaret(RGBA(0, 0, 0, 255))
16 , m_nAniFrames(20)
17 , m_nShowFrames(20)
18 , m_bAniCaret(FALSE)
19 , m_hOwner(0)
20{
21 m_AniInterpolator.Attach(CREATEINTERPOLATOR(SAccelerateInterpolator::GetClassName()));
22}
23
25{
26 m_pContainer->UnregisterTimelineHandler(this);
27}
28
29BOOL SCaret::Init(HBITMAP hBmp, int nWid, int nHei)
30{
31 ::CreateCaret(m_pContainer->GetHostHwnd(), hBmp, nWid, nHei);
32 ::HideCaret(m_pContainer->GetHostHwnd());
33
34 m_bDrawCaret = true;
36 GETRENDERFACTORY->CreateRenderTarget(&pRT, nWid, nHei);
37 m_bmpCaret = (IBitmapS *)pRT->GetCurrentObject(OT_BITMAP);
38 if (hBmp)
39 {
40// todo:hjx
41#ifdef _WIN32
42 //以拉伸方式创建一个插入符位图
43 HDC hdc = pRT->GetDC(0);
44 HDC hdc2 = CreateCompatibleDC(hdc);
45 SelectObject(hdc2, hBmp);
46
47 BITMAP bm;
48 GetObject(hBmp, sizeof(bm), &bm);
49 StretchBlt(hdc, 0, 0, nWid, nHei, hdc2, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY);
50 DeleteDC(hdc2);
51 pRT->ReleaseDC(hdc, NULL);
52#endif
53 }
54 else
55 {
56 //创建一个黑色插入符的位图
57 CRect rc(0, 0, nWid, nHei);
58 pRT->BeginDraw();
59 pRT->FillSolidRect(&rc, m_crCaret);
60 pRT->EndDraw();
61 }
62
63 return TRUE;
64}
65
67{
68 if (!m_bVisible)
69 return;
70 if (!m_bDrawCaret)
71 return;
72 if (!m_bmpCaret)
73 return;
74 CRect rcCaret = GetRect();
75 pRT->DrawBitmap(rcCaret, m_bmpCaret, 0, 0, m_byAlpha);
76}
77
79{
80 if (!m_bVisible)
81 return;
82
83 m_iFrame++;
84 int nFrameCount = (m_nShowFrames + m_nAniFrames * 2);
85 if (m_iFrame % nFrameCount == 0)
86 m_iFrame = 0;
87
88 if (m_bAniCaret)
89 {
91 m_byAlpha = 255; // visible
93 { // fadeout
94 int iFrame = m_iFrame - m_nShowFrames;
95 m_byAlpha = (BYTE)(255 * m_AniInterpolator->getInterpolation(1.0f - iFrame * 1.0f / m_nAniFrames));
96 }
97 else
98 { // fadein
99 int iFrame = m_iFrame - m_nShowFrames - m_nAniFrames;
100 m_byAlpha = (BYTE)(255 * m_AniInterpolator->getInterpolation(iFrame * 1.0f / m_nAniFrames));
101 }
102 Invalidate();
103 }
104 else
105 {
106 if (m_iFrame == 0)
107 {
108 m_bDrawCaret = true;
109 m_byAlpha = 255;
110 Invalidate();
111 }
112 else if (m_iFrame == m_nShowFrames)
113 {
114 m_bDrawCaret = false;
115 Invalidate();
116 }
117 }
118}
119
120void SCaret::SetPosition(int x, int y)
121{
122 m_ptCaret.x = x;
123 m_ptCaret.y = y;
124 m_iFrame = 0;
125 if (m_bVisible)
126 {
127 m_bDrawCaret = TRUE;
128 }
129 RECT rc = { 0 };
130 m_pContainer->FrameToHost(&rc);
131 ::SetCaretPos(rc.left + x, rc.top + y);
132}
133
134BOOL SCaret::SetVisible(BOOL bVisible, SWND owner)
135{
136 if (m_hOwner == owner && bVisible == m_bVisible)
137 return FALSE;
138 m_hOwner = owner;
139 m_bVisible = bVisible;
140
141 m_iFrame = 0;
142 if (m_bVisible)
143 {
144 m_bDrawCaret = TRUE;
145 }
146 if (bVisible)
147 m_pContainer->RegisterTimelineHandler(this);
148 else
149 m_pContainer->UnregisterTimelineHandler(this);
150 return TRUE;
151}
152
154{
155 return m_bVisible;
156}
157
158RECT SCaret::GetRect() const
159{
160 CSize szCaret;
161 if (m_bmpCaret)
162 szCaret = m_bmpCaret->Size();
163 return CRect(m_ptCaret, szCaret);
164}
165
167{
168 if (m_hOwner)
169 {
171 if (pOwner)
172 {
173 RECT rcCaret = GetRect();
174 pOwner->InvalidateRect(&rcCaret);
175 }
176 }
177}
178
179SNSEND
SOUI系统中的DUI窗口管理模块
SOUI基础DUI窗口模块
Smart pointer class for managing COM-style reference-counted objects.
bool m_bDrawCaret
Definition SCaret.h:128
void Draw(IRenderTarget *pRT) OVERRIDE
Draws the caret.
Definition SCaret.cpp:66
CPoint m_ptCaret
Definition SCaret.h:126
COLORREF m_crCaret
Definition SCaret.h:133
SAutoRefPtr< IInterpolator > m_AniInterpolator
Definition SCaret.h:136
ISwndContainer * m_pContainer
Definition SCaret.h:137
int m_iFrame
Definition SCaret.h:129
SCaret(ISwndContainer *pContainer)
Constructor.
Definition SCaret.cpp:9
BOOL m_bAniCaret
Definition SCaret.h:132
void OnNextFrame() OVERRIDE
Handles the next frame in the timeline.
Definition SCaret.cpp:78
BOOL SetVisible(BOOL bVisible, SWND owner) OVERRIDE
Sets the visibility of the caret.
Definition SCaret.cpp:134
BOOL m_bVisible
Definition SCaret.h:125
~SCaret()
Destructor.
Definition SCaret.cpp:24
SWND m_hOwner
Definition SCaret.h:138
BYTE m_byAlpha
Definition SCaret.h:130
SAutoRefPtr< IBitmapS > m_bmpCaret
Definition SCaret.h:127
BOOL IsVisible() SCONST OVERRIDE
Checks if the caret is visible.
Definition SCaret.cpp:153
int m_nAniFrames
Definition SCaret.h:134
void Invalidate()
Invalidates the caret area.
Definition SCaret.cpp:166
BOOL Init(HBITMAP hBmp, int nWid, int nHei) OVERRIDE
Initializes the caret.
Definition SCaret.cpp:29
RECT GetRect() SCONST OVERRIDE
Gets the rectangle of the caret.
Definition SCaret.cpp:158
void SetPosition(int x, int y) OVERRIDE
Sets the position of the caret.
Definition SCaret.cpp:120
int m_nShowFrames
Definition SCaret.h:135
Base class for SOUI DUI windows.
Definition SWnd.h:286
void InvalidateRect(LPCRECT lprect) OVERRIDE
Invalidates a specific rectangle area of the window.
Definition Swnd.cpp:1444
static SWindow * GetWindow(SWND swnd)
Retrieves the SWindow pointer from a given handle.
Bitmap object interface.
Definition SRender-i.h:420
Interface for rendering target objects.
Definition SRender-i.h:1440
HRESULT DrawBitmap(LPCRECT pRcDest, const IBitmapS *pBitmap, int xSrc, int ySrc, BYTE byAlpha=0xFF) PURE
Draw a bitmap.
SOUI Window Container Interface.