Example #1
0
bool GUI::Widget::Slider::handleEvent(const sf::Event& e, const sf::RenderWindow& window) {
	if (e.type == sf::Event::MouseButtonPressed && e.mouseButton.button == sf::Mouse::Left) {
		sf::Vector2f mouse(window.mapPixelToCoords(sf::Vector2i(e.mouseButton.x, e.mouseButton.y)));

		if (position.contains(mouse)) {

			float mousePos = (vertical ? mouse.y - position.top : mouse.x - position.left);

			if (mousePos >= sliderPosition && mousePos < sliderPosition + getSliderLength()) {
				//slider pressed
				isDragged = true;
				oldMouseCoordinate = (vertical ? mouse.y : mouse.x);
			}

			return true;
		}
	} else if (e.type == sf::Event::MouseButtonReleased && e.mouseButton.button == sf::Mouse::Left) {
		isDragged = false;
		return false;
	} else if (isDragged && e.type == sf::Event::MouseMoved) {
		sf::Vector2f mouse(window.mapPixelToCoords(sf::Vector2i(e.mouseMove.x, e.mouseMove.y)));

		sliderPosition += (vertical ? mouse.y : mouse.x) - oldMouseCoordinate;
		sliderPosition = std::max(0.0f, std::min(sliderPosition, (vertical ? position.height : position.width) - getSliderLength()));

		oldMouseCoordinate = (vertical ? mouse.y : mouse.x);

		if (action) {
			action(getScrollPosition());
		}

		return true;
	}
	return false;
}
Example #2
0
void ScrollView::setPadding(const Padding &p) {
	if (p != _paddingGlobal) {
		float offset = (isVertical()?_paddingGlobal.top:_paddingGlobal.left);
		float newOffset = (isVertical()?p.top:p.left);
		ScrollViewBase::setPadding(p);

		if (offset != newOffset) {
			setScrollPosition(getScrollPosition() + (offset - newOffset));
		}
	}
}
Example #3
0
///////////////////////////////////////////////////////////
//
// Get the current image's pixel displayed in the center of
//  the window
//
///////////////////////////////////////////////////////////
void view::getCenterPoint(imbxInt32* pCenterPointX, imbxInt32* pCenterPointY)
{
	// Reset the result values
	///////////////////////////////////////////////////////////
	*pCenterPointX = 0;
	*pCenterPointY = 0;

	if(m_originalImage == 0)
	{
		return;
	}

	imbxUint32 imageSizeX, imageSizeY;
	m_originalImage->getSize(&imageSizeX, &imageSizeY);

	// Nothing happens if the image is not valid
	///////////////////////////////////////////////////////////
	if(m_rightPosition - m_leftPosition == 0 || m_bottomPosition - m_topPosition == 0)
	{
		return;
	}

	// Get the window's width
	///////////////////////////////////////////////////////////
	imbxUint32 windowWidth  = 0;
	imbxUint32 windowHeight = 0;
	getWindowSize(&windowWidth, &windowHeight);

	// Get the scroll position
	///////////////////////////////////////////////////////////
	imbxInt32 scrollX = 0;
	imbxInt32 scrollY = 0;
	getScrollPosition(&scrollX, &scrollY);

	// Calculate the actual center point
	///////////////////////////////////////////////////////////
	*pCenterPointX = windowPosToImageX(scrollX + windowWidth / 2);
	*pCenterPointY = windowPosToImageY(scrollY + windowHeight / 2);
}
dim::point2di GUIListGadget::getItemsStartPos() const
{
    dim::point2di ScrollPos(getScrollPosition());
    return dim::point2di(Rect_.Left + 2 + ScrollPos.X, Rect_.Top + 2 + COLUMN_HEIGHT + ScrollPos.Y);
}
Example #5
0
///////////////////////////////////////////////////////////
//
// Invalidate the specified lines
//
///////////////////////////////////////////////////////////
void view::invalidateLines(tCursorLinesList* pLines)
{
	if(pLines->empty() || m_originalImage == 0)
	{
		return;
	}

	imbxInt32 scrollX, scrollY;
	getScrollPosition(&scrollX, &scrollY);

	imbxUint32 windowWidth, windowHeight;
	getWindowSize(&windowWidth, &windowHeight);

	imbxUint32 imageSizeX, imageSizeY;
	m_originalImage->getSize(&imageSizeX, &imageSizeY);

	for(tCursorLinesList::iterator scanLines = pLines->begin(); scanLines != pLines->end(); ++scanLines)
	{
		imbxInt32 lineLeft = scanLines->m_x0 * (m_rightPosition - m_leftPosition) / imageSizeX + m_leftPosition;
		imbxInt32 lineTop = scanLines->m_y0 * (m_bottomPosition - m_topPosition) / imageSizeY + m_topPosition;
		imbxInt32 lineRight = scanLines->m_x1 * (m_rightPosition - m_leftPosition) / imageSizeX + m_leftPosition;
		imbxInt32 lineBottom = scanLines->m_y1 * (m_bottomPosition - m_topPosition) / imageSizeY + m_topPosition;

		if(lineRight < lineLeft)
		{
			imbxInt32 temp = lineLeft;
			lineLeft = lineRight;
			lineRight = temp;
		}

		if(lineBottom < lineTop)
		{
			imbxInt32 temp = lineTop;
			lineTop = lineBottom;
			lineBottom = temp;
		}

		lineLeft   -= scanLines->m_width + 2;
		lineTop    -= scanLines->m_width + 2;
		lineRight  += scanLines->m_width + 2;
		lineBottom += scanLines->m_width + 2;

		lineLeft -= scrollX;
		lineTop -= scrollY;
		lineRight -= scrollX;
		lineBottom -= scrollY;

		if(lineLeft < 0)
		{
			lineLeft = 0;
		}

		if(lineTop < 0)
		{
			lineTop = 0;
		}

		if(lineRight > (imbxInt32)windowWidth)
		{
			lineRight = (imbxInt32)windowWidth;
		}

		if(lineBottom > (imbxInt32)windowHeight)
		{
			lineBottom = (imbxInt32)windowHeight;
		}

		if(lineLeft >= lineRight || lineTop >= lineBottom)
		{
			continue;
		}

		invalidate(lineLeft, lineTop, lineRight, lineBottom);
	}
}
Example #6
0
///////////////////////////////////////////////////////////
//
// End the cursor definition
//
///////////////////////////////////////////////////////////
void view::endCursorDef(imbxInt32 cursorHotSpotX, imbxInt32 cursorHotSpotY)
{
	// Remove the current cursor's lines
	///////////////////////////////////////////////////////////
	invalidateLines(&m_cursorLines);

	// Copy the temporary lines into cursor's lines
	///////////////////////////////////////////////////////////
	m_cursorLines.clear();
	for(tCursorLinesList::iterator copyLines = m_tempCursorLines.begin(); copyLines != m_tempCursorLines.end(); ++copyLines)
	{
		m_cursorLines.push_back(*copyLines);
	}
	m_tempCursorLines.clear();


	// Do we have to scroll the window because the hotspot is
	//  outside the visible area?
	///////////////////////////////////////////////////////////
	if(!isMouseCaptured() || m_originalImage == 0)
	{
		invalidateLines(&m_cursorLines);
		return;
	}

	// Convert the hotspot into window's coordinates
	///////////////////////////////////////////////////////////
	imbxInt32 scrollX, scrollY;
	getScrollPosition(&scrollX, &scrollY);

	imbxUint32 imageSizeX, imageSizeY;
	m_originalImage->getSize(&imageSizeX, &imageSizeY);

	imbxInt32 windowHotSpotX = cursorHotSpotX * (m_rightPosition - m_leftPosition) / imageSizeX +m_leftPosition - scrollX;
	imbxInt32 windowHotSpotY = cursorHotSpotY * (m_bottomPosition - m_topPosition) / imageSizeY +m_topPosition - scrollY;

	// Find the amount of scroll to execute
	///////////////////////////////////////////////////////////
	imbxUint32 windowSizeX, windowSizeY;
	getWindowSize(&windowSizeX, &windowSizeY);

	imbxInt32 limitX = windowSizeX / 10;
	imbxInt32 limitY = windowSizeY / 10;

	imbxInt32 executeScrollX = 0;
	imbxInt32 executeScrollY = 0;

	if(windowHotSpotX < limitX)
	{
		executeScrollX = windowHotSpotX - limitX;
	}
	if(windowHotSpotY < limitY)
	{
		executeScrollY = windowHotSpotY - limitY;
	}
	if(windowHotSpotX > ((imbxInt32)windowSizeX - limitX) )
	{
		executeScrollX = windowHotSpotX - (imbxInt32)windowSizeX + limitX;
	}
	if(windowHotSpotY > ((imbxInt32)windowSizeY - limitY) )
	{
		executeScrollY = windowHotSpotY - (imbxInt32)windowSizeY + limitY;
	}

	if(executeScrollX != 0 && executeScrollY != 0)
	{
		updateWindow();
		setScrollPosition(scrollX + executeScrollX, scrollY + executeScrollY);
	}

	invalidateLines(&m_cursorLines);
}
Example #7
0
///////////////////////////////////////////////////////////
//
// Center the desidered image's pixel in the window
//
///////////////////////////////////////////////////////////
void view::setCenterPoint(imbxInt32 centerPointX, imbxInt32 centerPointY)
{
	if(m_originalImage == 0)
	{
		return;
	}

	// Calculate the size of the area occupied by the image on
	//  the screen
	///////////////////////////////////////////////////////////
	imbxInt32 imageAreaWidth = m_rightPosition - m_leftPosition;
	imbxInt32 imageAreaHeight = m_bottomPosition - m_topPosition;

	// Get the window's width
	///////////////////////////////////////////////////////////
	imbxUint32 windowWidth  = 0;
	imbxUint32 windowHeight = 0;
	getWindowSize(&windowWidth, &windowHeight);

	// Get the scroll position
	///////////////////////////////////////////////////////////
	imbxInt32 oldScrollPosX = 0;
	imbxInt32 oldScrollPosY = 0;
	getScrollPosition(&oldScrollPosX, &oldScrollPosY);

	imbxInt32 newScrollPosX = oldScrollPosX;
	imbxInt32 newScrollPosY = oldScrollPosY;

	// Get the image's size
	///////////////////////////////////////////////////////////
	imbxUint32 imageSizeX, imageSizeY;
	m_originalImage->getSize(&imageSizeX, &imageSizeY);

	// Calculate the new scroll position
	///////////////////////////////////////////////////////////
	if(centerPointX>=0)
	{
		newScrollPosX = imbxInt32((centerPointX * imageAreaWidth)/imageSizeX) + m_leftPosition - windowWidth/2;
	}

	if(centerPointY>=0)
	{
		newScrollPosY = imbxInt32((centerPointY * imageAreaHeight)/imageSizeY) + m_topPosition - windowHeight/2;
	}

	// Check if the scroll position is valid
	///////////////////////////////////////////////////////////
	if(newScrollPosX+(imbxInt32)windowWidth>imageAreaWidth)
	{
		newScrollPosX=imageAreaWidth-(imbxInt32)windowWidth;
	}
	if(newScrollPosY+(imbxInt32)windowHeight>imageAreaHeight)
	{
		newScrollPosY=imageAreaHeight-(imbxInt32)windowHeight;
	}
	if(newScrollPosX < 0)
	{
		newScrollPosX = 0;
	}
	if(newScrollPosY < 0)
	{
		newScrollPosY = 0;
	}
	if(oldScrollPosX!=newScrollPosX || oldScrollPosY!=newScrollPosY)
	{
		setScrollPosition(newScrollPosX, newScrollPosY);
	}

	// Set the new scroll position
	///////////////////////////////////////////////////////////
	if(newScrollPosX != oldScrollPosX || newScrollPosY != oldScrollPosY)
	{
		setScrollPosition(newScrollPosX, newScrollPosY);
	}
}
Example #8
0
///////////////////////////////////////////////////////////
//
// Calculate the rectancle to use to draw the image
//
///////////////////////////////////////////////////////////
void view::updateImageRect(imbxInt32 centerPointX, imbxInt32 centerPointY)
{
	imbxInt32 tempCenterPointX = 0;
	imbxInt32 tempCenterPointY = 0;
	getCenterPoint(&tempCenterPointX, &tempCenterPointY);

	if(centerPointX < 0) centerPointX = tempCenterPointX;
	if(centerPointY < 0) centerPointY = tempCenterPointY;

	imbxInt32 leftPosition, topPosition, rightPosition, bottomPosition;
	leftPosition=
		topPosition=
		rightPosition=
		bottomPosition = 0;

	// Get the window's size
	///////////////////////////////////////////////////////////
	imbxUint32 windowSizeX = 0;
	imbxUint32 windowSizeY = 0;
	getWindowSize(&windowSizeX, &windowSizeY);

	// Get the scroll size
	///////////////////////////////////////////////////////////
	imbxUint32 scrollSizeX = 0;
	imbxUint32 scrollSizeY = 0;
	getScrollSize(&scrollSizeX, &scrollSizeY);

	// Get the scroll position
	///////////////////////////////////////////////////////////
	imbxInt32 scrollPosX = 0;
	imbxInt32 scrollPosY = 0;
	getScrollPosition(&scrollPosX, &scrollPosY);

	// For now, the new scroll size and position are the same
	//  as the old ones
	///////////////////////////////////////////////////////////
	imbxUint32 newScrollSizeX=scrollSizeX;
	imbxUint32 newScrollSizeY=scrollSizeY;

	if(m_originalImage != 0)
	{
		imbxUint32 imageSizeX(0), imageSizeY(0);
		m_originalImage->getSize(&imageSizeX, &imageSizeY);

		// Retrieve the screen's resolution
		///////////////////////////////////////////////////////////
		imbxUint32 screenHorzDPI, screenVertDPI;
		screenHorzDPI=screenVertDPI=75;
		getScreenDPI(&screenHorzDPI, &screenVertDPI);

		// Get the image's size (in mms and pixels)
		///////////////////////////////////////////////////////////
		double imageSizeMmX = 0;
		double imageSizeMmY = 0;
		m_originalImage->getSizeMm(&imageSizeMmX, &imageSizeMmY);

		if(imageSizeMmX == 0)
		{
			imageSizeMmX = (double)imageSizeX * 25.4 / (double)screenHorzDPI;
		}
		if(imageSizeMmY == 0)
		{
			imageSizeMmY = (double)imageSizeY * 25.4 / (double)screenVertDPI;
		}


		// Calculate the area occupied by the image, in screen's
		//  pixels
		///////////////////////////////////////////////////////////
		imbxUint32 displayAreaWidth=(imbxUint32)((double)imageSizeMmX*m_zoom*(double)screenHorzDPI/25.4+0.5);
		imbxUint32 displayAreaHeight=(imbxUint32)((double)imageSizeMmY*m_zoom*(double)screenVertDPI/25.4+0.5);

		if(displayAreaWidth>windowSizeX)
		{
			rightPosition = displayAreaWidth;
		}
		else
		{
			leftPosition = (windowSizeX-displayAreaWidth)>>1;
			rightPosition = leftPosition+displayAreaWidth;
		}

		if(displayAreaHeight>windowSizeY)
		{
			bottomPosition = displayAreaHeight;
		}
		else
		{
			topPosition = (windowSizeY-displayAreaHeight)>>1;
			bottomPosition = topPosition+displayAreaHeight;
		}
		newScrollSizeX = displayAreaWidth;
		newScrollSizeY = displayAreaHeight;
	}