Skip to content

Commit 0a552fa

Browse files
committed
1 parent e1da93a commit 0a552fa

File tree

2 files changed

+58
-10
lines changed

2 files changed

+58
-10
lines changed

litehtmltips/tooltips.cpp

Lines changed: 57 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -203,14 +203,17 @@ void litehtml::tooltips::create( HWND parent )
203203
}
204204
}
205205

206-
void litehtml::tooltips::show( unsigned int id, int top )
206+
void litehtml::tooltips::show( unsigned int id, int top, bool is_update )
207207
{
208208
tool::map::iterator ti = m_tools.find(id);
209209
if(ti != m_tools.end())
210210
{
211211
m_show_tool = id;
212212
m_last_shown_tool = id;
213-
clear_images();
213+
if(!is_update)
214+
{
215+
clear_images();
216+
}
214217
if(m_html)
215218
{
216219
m_html = NULL;
@@ -448,7 +451,44 @@ void litehtml::tooltips::draw_background(tip_layout* layout)
448451
}
449452
break;
450453
}
454+
455+
CTxDIB img;
456+
img._copy(m_dib.bits(), m_dib.width(), m_dib.height(), TRUE);
457+
458+
RGBQUAD* pixels = img.getBits();
459+
int sz = img.getWidth() * img.getHeight();
460+
461+
for(int i=0; i < sz; i++)
462+
{
463+
pixels[i].rgbRed = 0;
464+
pixels[i].rgbGreen = 0;
465+
pixels[i].rgbBlue = 0;
466+
}
467+
468+
// draw shadow at the right side
469+
{
470+
CTxDIB img_shadow;
471+
img.crop(img.getWidth() - shadow_width, 0, img.getWidth(), img.getHeight(), &img_shadow);
472+
img_shadow.resample(img_shadow.getWidth() - 5, img_shadow.getHeight() - 5);
473+
474+
cairo_surface_t* img_sf = cairo_image_surface_create_for_data((unsigned char*) img.getBits(), CAIRO_FORMAT_ARGB32, img.getWidth(), img.getHeight(), img.getWidth() * 4);
475+
476+
simpledib::dib shadow;
477+
shadow.create(m_dib.width(), m_dib.height(), true);
478+
cairo_dev cr_shadow(&shadow);
479+
cairo_set_source_surface(cr_shadow, img_sf, 5, 5);
480+
cairo_paint(cr_shadow);
481+
fastbluralpha(shadow.bits(), shadow.width(), shadow.height(), 5);
482+
483+
cairo_set_operator(m_cr, CAIRO_OPERATOR_DEST_OVER);
484+
485+
cairo_set_source_surface(m_cr, cr_shadow, 0, 0);
486+
cairo_paint(m_cr);
487+
488+
cairo_surface_destroy(img_sf);
489+
}
451490

491+
/*
452492
simpledib::dib shadow;
453493
454494
CTxDIB img;
@@ -480,6 +520,7 @@ void litehtml::tooltips::draw_background(tip_layout* layout)
480520
cairo_paint(m_cr);
481521
482522
cairo_surface_destroy(img_sf);
523+
*/
483524

484525
if(m_alpha != 255)
485526
{
@@ -1234,20 +1275,27 @@ void litehtml::tooltips::update( unsigned int id )
12341275
{
12351276
if(id == m_show_tool && IsWindowVisible(m_hWnd))
12361277
{
1237-
show(id, m_top);
1278+
show(id, m_top, true);
12381279
}
12391280
}
12401281

12411282
void litehtml::tooltips::create_dib( int width, int height )
12421283
{
1243-
if(m_surface) cairo_surface_destroy(m_surface);
1244-
if(m_cr) cairo_destroy(m_cr);
1284+
if(!m_cr || !m_dib.hdc() || m_dib.width() != width || m_dib.height() != height)
1285+
{
1286+
if(m_surface) cairo_surface_destroy(m_surface);
1287+
if(m_cr) cairo_destroy(m_cr);
1288+
1289+
m_dib.clear();
1290+
m_dib.create(width, height, true);
12451291

1246-
m_dib.clear();
1247-
m_dib.create(width, height, true);
1292+
m_surface = cairo_image_surface_create_for_data((unsigned char*) m_dib.bits(), CAIRO_FORMAT_ARGB32, m_dib.width(), m_dib.height(), m_dib.width() * 4);
1293+
m_cr = cairo_create(m_surface);
1294+
} else
1295+
{
1296+
m_dib.clear();
1297+
}
12481298

1249-
m_surface = cairo_image_surface_create_for_data((unsigned char*) m_dib.bits(), CAIRO_FORMAT_ARGB32, m_dib.width(), m_dib.height(), m_dib.width() * 4);
1250-
m_cr = cairo_create(m_surface);
12511299
}
12521300

12531301
void litehtml::tooltips::draw_window(BOOL clr)

litehtmltips/tooltips.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ namespace litehtml
122122
void add_tool(unsigned int id, const wchar_t* text, HWND ctl, LPCRECT rc_tool, UINT options);
123123
void clear();
124124
void create(HWND parent);
125-
void show(unsigned int id, int top = 0);
125+
void show(unsigned int id, int top = 0, bool is_update = false);
126126

127127
void hide();
128128
void set_style(tips_style style) { m_style = style; }

0 commit comments

Comments
 (0)