Ejemplo n.º 1
0
QImage InnerDropdown::grabForPanelAnimation() {
	SendPendingMoveResizeEvents(this);
	auto result = QImage(size() * cIntRetinaFactor(), QImage::Format_ARGB32_Premultiplied);
	result.setDevicePixelRatio(cRetinaFactor());
	result.fill(Qt::transparent);
	{
		Painter p(&result);
		App::roundRect(p, rect().marginsRemoved(_st.padding), _st.bg, ImageRoundRadius::Small);
		for (const auto child : children()) {
			if (const auto widget = qobject_cast<QWidget*>(child)) {
				RenderWidget(p, widget, widget->pos());
			}
		}
	}
	return result;
}
Ejemplo n.º 2
0
QPixmap Shadow::grab(
		not_null<TWidget*> target,
		const style::Shadow &shadow,
		RectParts sides) {
	SendPendingMoveResizeEvents(target);
	auto rect = target->rect();
	auto extend = QMargins(
		(sides & RectPart::Left) ? shadow.extend.left() : 0,
		(sides & RectPart::Top) ? shadow.extend.top() : 0,
		(sides & RectPart::Right) ? shadow.extend.right() : 0,
		(sides & RectPart::Bottom) ? shadow.extend.bottom() : 0
	);
	auto full = QRect(0, 0, extend.left() + rect.width() + extend.right(), extend.top() + rect.height() + extend.bottom());
	auto result = QPixmap(full.size() * cIntRetinaFactor());
	result.setDevicePixelRatio(cRetinaFactor());
	result.fill(Qt::transparent);
	{
		Painter p(&result);
		Ui::Shadow::paint(p, full.marginsRemoved(extend), full.width(), shadow);
		RenderWidget(p, target, QPoint(extend.left(), extend.top()));
	}
	return result;
}
Ejemplo n.º 3
0
void TextBox::Render( Point pos, bool selected ) {
	
	const Rect& rect = this->GetRect();
	const Point r = rect.Offset(pos);
	Control::RenderBase(pos, selected);
	
	int w,h;
	Drawing().GetResolution(w,h);
	
	// TODO: tweak clip region a little
	Drawing().PushClipRegion( r.x+2, r.y, m_text_area.w-5, m_text_area.h );
	
	int j;
	
	int sz=0;
	
	if(!m_lines.empty()) {
		// selection
		std::string piece = m_lines[m_cursor.y].text.utf8_substr(0, m_position.x, m_password);
		if(m_update_viewport) {
			sz = m_style.font->GetTextSize(piece);
			m_viewport_offset.x = sz;
			m_update_viewport = false;
		} else {
			sz = m_viewport_offset.x;
		}
		
		
		// draw selection if there is one
		if(m_anchor.x != -1) {
			j=0;
			Point p1,p2;
			sortPoints(p1,p2);
			int yy=m_position.y;
			for( auto i = m_lines.begin()+yy; i != m_lines.end(); i++,j++,yy++) {
				if(5+j*m_line_height+i->h > rect.h) break;
				if(yy < p1.y || yy > p2.y) continue;
				
				if(yy == p1.y && p1.y == p2.y) {
					std::string pd = m_lines[yy].text.utf8_substr(p1.x, p2.x-p1.x, m_password);
					std::string pd1 = m_lines[yy].text.utf8_substr(0, p1.x, m_password);
					
					int selw = m_style.font->GetTextSize( pd );
					int selw1 = m_style.font->GetTextSize( pd1 );
					
					Drawing().FillRect( r.x-sz+5+selw1, r.y+5+j*m_line_height, selw, i->h, m_selection_color);
				} else if(yy == p1.y) {
					std::string pd = m_lines[yy].text.utf8_substr(p1.x, std::string::npos, m_password);
					int selw = m_style.font->GetTextSize( pd );
					Drawing().FillRect( r.x-sz+5+i->w-selw, r.y+5+j*m_line_height, selw, i->h, m_selection_color);
				} else if(yy == p2.y) {
					std::string pd = m_lines[yy].text.utf8_substr(0, p2.x, m_password);
					int selw = m_style.font->GetTextSize( pd );
					Drawing().FillRect( r.x-sz+5, r.y+5+j*m_line_height, selw, i->h, m_selection_color);
				} else {
					Drawing().FillRect( r.x-sz+5, r.y+5+j*m_line_height, i->w, i->h, m_selection_color);
				}
			}
		}
		
		// placeholder or text
		if(!isActive() && m_lines.size() == 1 && !m_placeholder.text.empty() && m_lines[0].text.empty() ) {
			Drawing().TexRect( r.x+5, r.y+5, m_placeholder.w, m_placeholder.h, m_placeholder.tex);
		} else {
			j=0;
			if(m_position.y < m_lines.size()) {
				for( auto i = m_lines.begin()+m_position.y; i != m_lines.end(); i++,j++) {
					if(5+j*m_line_height+i->h > rect.h) break;
					if(i->h <= 1) continue;
					Drawing().TexRect( r.x-sz+5, r.y+5+j*m_line_height, i->w, i->h, i->tex);
				}
			}
		}
	}
	
	
	
	// cursor
	if(isActive() && !m_readonly && (m_cursor_blink_counter += getDeltaTime()) > m_cursor_blinking_rate && 
		m_cursor.y >= m_position.y && m_cursor.y-m_position.y < rect.h/m_line_height) {
		
		if(m_cursor_blink_counter > 2*m_cursor_blinking_rate) {
			m_cursor_blink_counter = 0;
		}
			
		if(m_cursor.x >= m_position.x && m_cursor.x <= m_lines[m_cursor.y].text.utf8_size()) {
			// std::string piece = m_lines[m_cursor.y].text.utf8_substr(m_position.x, m_cursor.x-m_position.x, m_password);
			std::string piece = m_lines[m_cursor.y].text.utf8_substr(0, m_cursor.x, m_password);
			Drawing().Rect(m_style.font->GetTextSize( piece )+r.x-sz+5, 
				(m_cursor.y-m_position.y)*m_line_height+r.y+5, 1, m_line_height, 0xffffffff);
		}
	}
	
	Drawing().PopClipRegion();
	
	RenderWidget(pos,selected);
	
}