Пример #1
0
void Widget::setGeometry(const Rect<int>& geometry)
{
	if(!geometry.size().isValid())
		return;

	if(!parent_) {
		ws_->moveWindow(handle_, geometry.topLeft());
		ws_->resizeWindow(handle_, geometry.size());
		ws_->sync();
	}
	else {
		// Calculate invalidated rectangle
		int x = minOf(pos_.x(), geometry.x());
		int y = minOf(pos_.y(), geometry.y());
		int width = maxOf(size_.width(), geometry.size().width());
		int height = maxOf(size_.height(), geometry.size().height());
		Rect<int> rect(x, y, width, height);

		// Send events
		MoveEvent me;
		me.setOldPos(pos_, {});
		me.setPos(geometry.topLeft(), {});
		processEvent(&me, {});

		ResizeEvent re;
		re.setOldSize(size_, {});
		re.setSize(geometry.size(), {});
		processEvent(&re, {});

		rect.intersect(parent_->rect());
		parent_->repaint();
	}
}
Пример #2
0
void Widget::move(const Point<int>& pos)
{
	if(pos_ == pos)
		return;

	if(!parent_) {
		ws_->moveWindow(handle_, pos);
		ws_->sync();
	}
	else {
		// Calculate invalidated rectangle
		Rect<int> rect = geometry();
		Point<int> diff = pos - pos_;

		if(diff.x() > 0) {
			rect.setWidth(rect.width() + diff.x());
		}
		else if(diff.x() < 0) {
			rect.setX(rect.x() + diff.x());
			rect.setWidth(rect.width() - diff.x());
		}

		if(diff.y() > 0) {
			rect.setHeight(rect.height() + diff.y());
		}
		else if(diff.y() < 0) {
			rect.setY(rect.y() + diff.y());
			rect.setHeight(rect.height() - diff.y());
		}

		// Send event
		MoveEvent e;
		e.setOldPos(pos_, {});
		e.setPos(pos, {});
		processEvent(&e, {});

		rect.intersect(parent_->rect());
		parent_->repaint();
	}
}