src/viewport.cpp
branchNewGRF_ports
changeset 10274 b3c58f3df92b
parent 10242 52b4a9006029
child 10310 c8b1eafc56bd
equal deleted inserted replaced
10243:e9066a148720 10274:b3c58f3df92b
   157 {
   157 {
   158 	w->viewport->width = 0;
   158 	w->viewport->width = 0;
   159 	w->viewport = NULL;
   159 	w->viewport = NULL;
   160 }
   160 }
   161 
   161 
   162 void AssignWindowViewport(Window *w, int x, int y,
   162 /**
       
   163  * Initialize viewport of the window for use.
       
   164  * @param w Window to use/display the viewport in
       
   165  * @param x Offset of left edge of viewport with respect to left edge window \a w
       
   166  * @param y Offset of top edge of viewport with respect to top edge window \a w
       
   167  * @param width Width of the viewport
       
   168  * @param height Height of the viewport
       
   169  * @param follow_flags Flags controlling the viewport.
       
   170  *        - If bit 31 is set, the lower 16 bits are the vehicle that the viewport should follow.
       
   171  *        - If bit 31 is clear, it is a tile position.
       
   172  * @param zoom Zoomlevel to display
       
   173  */
       
   174 void InitializeWindowViewport(Window *w, int x, int y,
   163 	int width, int height, uint32 follow_flags, ZoomLevel zoom)
   175 	int width, int height, uint32 follow_flags, ZoomLevel zoom)
   164 {
   176 {
   165 	assert(w->viewport == NULL);
   177 	assert(w->viewport == NULL);
   166 
   178 
   167 	ViewPort *vp = &(WP(w, vp_d).vp_data);
   179 	ViewPort *vp = &(WP(w, vp_d).vp_data);
   323 
   335 
   324 		if (height > 0) DoSetViewportPosition(FindWindowZPosition(w) + 1, left, top, width, height);
   336 		if (height > 0) DoSetViewportPosition(FindWindowZPosition(w) + 1, left, top, width, height);
   325 	}
   337 	}
   326 }
   338 }
   327 
   339 
   328 
   340 /**
       
   341  * Is a xy position inside the viewport of the window?
       
   342  * @param w Window to examine its viewport
       
   343  * @param x X coordinate of the xy position
       
   344  * @param y Y coordinate of the xy position
       
   345  * @return Pointer to the viewport if the xy position is in the viewport of the window,
       
   346  *         otherwise \c NULL is returned.
       
   347  */
   329 ViewPort *IsPtInWindowViewport(const Window *w, int x, int y)
   348 ViewPort *IsPtInWindowViewport(const Window *w, int x, int y)
   330 {
   349 {
   331 	ViewPort *vp = w->viewport;
   350 	ViewPort *vp = w->viewport;
   332 
   351 
   333 	if (vp != NULL &&
   352 	if (vp != NULL &&
  1615 		SetViewportPosition(w, WP(w, vp_d).scrollpos_x, WP(w, vp_d).scrollpos_y);
  1634 		SetViewportPosition(w, WP(w, vp_d).scrollpos_x, WP(w, vp_d).scrollpos_y);
  1616 	}
  1635 	}
  1617 }
  1636 }
  1618 
  1637 
  1619 /**
  1638 /**
  1620  * Marks a viewport as dirty for repaint.
  1639  * Marks a viewport as dirty for repaint if it displays (a part of) the area the needs to be repainted.
  1621  *
  1640  * @param vp     The viewport to mark as dirty
  1622  * @param vp The viewport to mark as dirty
  1641  * @param left   Left edge of area to repaint
  1623  * @todo documents the missing parameters @c left, @c top, @c right and @c bottom
  1642  * @param top    Top edge of area to repaint
  1624  * @todo detailed description missing
  1643  * @param right  Right edge of area to repaint
       
  1644  * @param bottom Bottom edge of area to repaint
  1625  * @ingroup dirty
  1645  * @ingroup dirty
  1626  */
  1646  */
  1627 static void MarkViewportDirty(const ViewPort *vp, int left, int top, int right, int bottom)
  1647 static void MarkViewportDirty(const ViewPort *vp, int left, int top, int right, int bottom)
  1628 {
  1648 {
  1629 	right -= vp->virtual_left;
  1649 	right -= vp->virtual_left;
  1646 		UnScaleByZoom(right, vp->zoom) + vp->left,
  1666 		UnScaleByZoom(right, vp->zoom) + vp->left,
  1647 		UnScaleByZoom(bottom, vp->zoom) + vp->top
  1667 		UnScaleByZoom(bottom, vp->zoom) + vp->top
  1648 	);
  1668 	);
  1649 }
  1669 }
  1650 
  1670 
       
  1671 /**
       
  1672  * Mark all viewports that display an area as dirty (in need of repaint).
       
  1673  * @param left   Left edge of area to repaint
       
  1674  * @param top    Top edge of area to repaint
       
  1675  * @param right  Right edge of area to repaint
       
  1676  * @param bottom Bottom edge of area to repaint
       
  1677  * @ingroup dirty
       
  1678  */
  1651 void MarkAllViewportsDirty(int left, int top, int right, int bottom)
  1679 void MarkAllViewportsDirty(int left, int top, int right, int bottom)
  1652 {
  1680 {
  1653 	Window **wz;
  1681 	Window **wz;
  1654 
  1682 
  1655 	FOR_ALL_WINDOWS(wz) {
  1683 	FOR_ALL_WINDOWS(wz) {