Skip to content

Commit

Permalink
improvement: semi-hilite with half alpha color of hilite candidate.
Browse files Browse the repository at this point in the history
fix: semi-hilite hover not clear when moving out of candidate window, after once click select a candidate.
  • Loading branch information
fxliang committed May 27, 2024
1 parent b1aebe8 commit 772145c
Showing 1 changed file with 29 additions and 21 deletions.
50 changes: 29 additions & 21 deletions WeaselUI/WeaselPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#define GDPCOLOR_FROM_COLORREF(color) \
Gdiplus::Color::MakeARGB(((color >> 24) & 0xff), GetRValue(color), \
GetGValue(color), GetBValue(color))
#define HALF_ALPHA_COLOR(color) \
((((color & 0xff000000) >> 25) & 0xff) << 24) | (color & 0x00ffffff)

#pragma comment(lib, "Shcore.lib")

Expand Down Expand Up @@ -266,6 +268,7 @@ LRESULT WeaselPanel::OnLeftClickedUp(UINT uMsg,
if (rect.PtInRect(point)) {
size_t i = m_ctx.cinfo.highlighted;
if (_UICallback) {
m_mouse_entry = false;
_UICallback(&i, NULL, NULL, NULL);
if (!m_status.composing)
DestroyWindow();
Expand Down Expand Up @@ -360,14 +363,15 @@ LRESULT WeaselPanel::OnLeftClickedDown(UINT uMsg,
}
}
}
// select by click
// select by click relative actions
for (size_t i = 0; i < m_candidateCount && i < MAX_CANDIDATES_COUNT; ++i) {
CRect rect = m_layout->GetCandidateRect((int)i);
if (m_istorepos)
rect.OffsetRect(0, m_offsetys[i]);
rect.InflateRect(m_style.hilite_padding_x, m_style.hilite_padding_y);
if (rect.PtInRect(point)) {
bar_scale_ = 0.8f;
// modify highlighted
if (i != m_ctx.cinfo.highlighted) {
if (_UICallback)
_UICallback(NULL, &i, NULL, NULL);
Expand Down Expand Up @@ -728,7 +732,7 @@ bool WeaselPanel::_DrawCandidates(CDCHandle& dc, bool back) {
// if candidate_shadow_color not transparent, draw candidate shadow first
if (COLORNOTTRANSPARENT(m_style.candidate_shadow_color)) {
for (auto i = 0; i < m_candidateCount && i < MAX_CANDIDATES_COUNT; ++i) {
if (i == m_ctx.cinfo.highlighted)
if (i == m_ctx.cinfo.highlighted || i == m_hoverIndex)
continue; // draw non hilited candidates only
rect = m_layout->GetCandidateRect((int)i);
IsToRoundStruct rd = m_layout->GetRoundInfo(i);
Expand All @@ -744,10 +748,9 @@ bool WeaselPanel::_DrawCandidates(CDCHandle& dc, bool back) {
}
// draw non highlighted candidates, without shadow
if ((COLORNOTTRANSPARENT(m_style.candidate_back_color) ||
COLORNOTTRANSPARENT(m_style.candidate_border_color)) ||
m_style.hover_type == UIStyle::HoverType::SEMI_HILITE) {
COLORNOTTRANSPARENT(m_style.candidate_border_color))) {
for (auto i = 0; i < m_candidateCount && i < MAX_CANDIDATES_COUNT; ++i) {
if (i == m_ctx.cinfo.highlighted)
if (i == m_ctx.cinfo.highlighted || i == m_hoverIndex)
continue;
rect = m_layout->GetCandidateRect((int)i);
IsToRoundStruct rd = m_layout->GetRoundInfo(i);
Expand All @@ -756,25 +759,28 @@ bool WeaselPanel::_DrawCandidates(CDCHandle& dc, bool back) {
ReconfigRoundInfo(rd, i, m_candidateCount);
}
rect.InflateRect(m_style.hilite_padding_x, m_style.hilite_padding_y);
if (i != m_hoverIndex)
_HighlightText(dc, rect, m_style.candidate_back_color, 0x00000000,
m_style.round_corner, bkType, rd,
m_style.candidate_border_color);
else {
int color = ((m_style.hilited_candidate_back_color >> 25) & 0xff)
<< 24;
color = (m_style.hilited_candidate_back_color & 0x00ffffff) | color;
int border_color =
((m_style.hilited_candidate_border_color >> 25) & 0xff) << 24;
border_color = (m_style.hilited_candidate_border_color & 0x00ffffff) |
border_color;
_HighlightText(dc, rect, color, 0x00000000, m_style.round_corner,
bkType, rd, border_color);
}
_HighlightText(dc, rect, m_style.candidate_back_color, 0x00000000,
m_style.round_corner, bkType, rd,
m_style.candidate_border_color);
drawn = true;
}
}
// draw highlighted back ground and shadow
// draw semi-hilite background and shadow
if (m_hoverIndex > 0) {
rect = m_layout->GetCandidateRect(m_hoverIndex);
IsToRoundStruct rd = m_layout->GetRoundInfo(m_hoverIndex);
if (m_istorepos) {
rect.OffsetRect(0, m_offsetys[m_hoverIndex]);
ReconfigRoundInfo(rd, m_hoverIndex, m_candidateCount);
}
rect.InflateRect(m_style.hilite_padding_x, m_style.hilite_padding_y);
_HighlightText(dc, rect,
HALF_ALPHA_COLOR(m_style.hilited_candidate_back_color),
HALF_ALPHA_COLOR(m_style.hilited_candidate_shadow_color),
m_style.round_corner, bkType, rd,
HALF_ALPHA_COLOR(m_style.hilited_candidate_border_color));
}
// draw highlighted background and shadow
{
rect = m_layout->GetHighlightRect();
bool markSt = bar_scale_ == 1.0 || (!m_style.mark_text.empty());
Expand Down Expand Up @@ -1047,6 +1053,8 @@ LRESULT WeaselPanel::OnCreate(UINT uMsg,
WPARAM wParam,
LPARAM lParam,
BOOL& bHandled) {
m_mouse_entry = false;
m_hoverIndex = -1;
GetWindowRect(&m_inputPos);
Refresh();
return TRUE;
Expand Down

0 comments on commit 772145c

Please sign in to comment.