src/viewport.cpp
branchNewGRF_ports
changeset 10994 cd9968b6f96b
parent 10991 d8811e327d12
equal deleted inserted replaced
10991:d8811e327d12 10994:cd9968b6f96b
    79 	SpriteID image;
    79 	SpriteID image;
    80 	SpriteID pal;
    80 	SpriteID pal;
    81 	const SubSprite *sub;           ///< only draw a rectangular part of the sprite
    81 	const SubSprite *sub;           ///< only draw a rectangular part of the sprite
    82 	int32 x;
    82 	int32 x;
    83 	int32 y;
    83 	int32 y;
    84 	ChildScreenSpriteToDraw *next;
    84 	int next;                       ///< next child to draw (-1 at the end)
    85 };
    85 };
    86 
    86 
    87 struct ParentSpriteToDraw {
    87 struct ParentSpriteToDraw {
    88 	SpriteID image;                 ///< sprite to draw
    88 	SpriteID image;                 ///< sprite to draw
    89 	SpriteID pal;                   ///< palette to use
    89 	SpriteID pal;                   ///< palette to use
   101 	int32 ymax;                     ///< maximal world Y coordinate of bounding box
   101 	int32 ymax;                     ///< maximal world Y coordinate of bounding box
   102 	int zmin;                       ///< minimal world Z coordinate of bounding box
   102 	int zmin;                       ///< minimal world Z coordinate of bounding box
   103 	int zmax;                       ///< maximal world Z coordinate of bounding box
   103 	int zmax;                       ///< maximal world Z coordinate of bounding box
   104 
   104 
   105 	int first_child;                ///< the first child to draw.
   105 	int first_child;                ///< the first child to draw.
   106 	int last_child;                 ///< the last sprite to draw.
       
   107 	bool comparison_done;           ///< Used during sprite sorting: true if sprite has been compared with all other sprites
   106 	bool comparison_done;           ///< Used during sprite sorting: true if sprite has been compared with all other sprites
   108 };
   107 };
   109 
   108 
   110 /* Enumeration of multi-part foundations */
   109 /* Enumeration of multi-part foundations */
   111 enum FoundationPart {
   110 enum FoundationPart {
   675 
   674 
   676 	ps->zmin = z + bb_offset_z;
   675 	ps->zmin = z + bb_offset_z;
   677 	ps->zmax = z + max(bb_offset_z, dz) - 1;
   676 	ps->zmax = z + max(bb_offset_z, dz) - 1;
   678 
   677 
   679 	ps->comparison_done = false;
   678 	ps->comparison_done = false;
   680 	ps->first_child = _vd.child_screen_sprites_to_draw.items;
   679 	ps->first_child = -1;
   681 	ps->last_child  = _vd.child_screen_sprites_to_draw.items;
   680 
   682 
   681 	_vd.last_child = &ps->first_child;
   683 	_vd.last_child = &ps->last_child;
       
   684 
   682 
   685 	if (_vd.combine_sprites == 1) _vd.combine_sprites = 2;
   683 	if (_vd.combine_sprites == 1) _vd.combine_sprites = 2;
   686 }
   684 }
   687 
   685 
   688 void StartSpriteCombine()
   686 void StartSpriteCombine()
   716 	if (transparent) {
   714 	if (transparent) {
   717 		SetBit(image, PALETTE_MODIFIER_TRANSPARENT);
   715 		SetBit(image, PALETTE_MODIFIER_TRANSPARENT);
   718 		pal = PALETTE_TO_TRANSPARENT;
   716 		pal = PALETTE_TO_TRANSPARENT;
   719 	}
   717 	}
   720 
   718 
   721 	/* Append the sprite to the active ChildSprite list.
   719 	*_vd.last_child = _vd.child_screen_sprites_to_draw.items;
   722 	 * If the active ParentSprite is a foundation, update last_foundation_child as well. */
   720 
   723 	ChildScreenSpriteToDraw *cs = _vd.child_screen_sprites_to_draw.Append();
   721 	ChildScreenSpriteToDraw *cs = _vd.child_screen_sprites_to_draw.Append();
   724 	cs->image = image;
   722 	cs->image = image;
   725 	cs->pal = pal;
   723 	cs->pal = pal;
   726 	cs->sub = sub;
   724 	cs->sub = sub;
   727 	cs->x = x;
   725 	cs->x = x;
   728 	cs->y = y;
   726 	cs->y = y;
   729 	cs->next = NULL;
   727 	cs->next = -1;
   730 
   728 
   731 	*_vd.last_child = _vd.child_screen_sprites_to_draw.items;
   729 	/* Append the sprite to the active ChildSprite list.
       
   730 	 * If the active ParentSprite is a foundation, update last_foundation_child as well.
       
   731 	 * Note: ChildSprites of foundations are NOT sequential in the vector, as selection sprites are added at last. */
       
   732 	if (_vd.last_foundation_child[0] == _vd.last_child) _vd.last_foundation_child[0] = &cs->next;
       
   733 	if (_vd.last_foundation_child[1] == _vd.last_child) _vd.last_foundation_child[1] = &cs->next;
       
   734 	_vd.last_child = &cs->next;
   732 }
   735 }
   733 
   736 
   734 /* Returns a StringSpriteToDraw */
   737 /* Returns a StringSpriteToDraw */
   735 void AddStringToDraw(int x, int y, StringID string, uint64 params_1, uint64 params_2, uint16 color, uint16 width)
   738 void AddStringToDraw(int x, int y, StringID string, uint64 params_1, uint64 params_2, uint16 color, uint16 width)
   736 {
   739 {
  1373 	const ParentSpriteToDraw * const *psd_end = psd->End();
  1376 	const ParentSpriteToDraw * const *psd_end = psd->End();
  1374 	for (const ParentSpriteToDraw * const *it = psd->Begin(); it != psd_end; it++) {
  1377 	for (const ParentSpriteToDraw * const *it = psd->Begin(); it != psd_end; it++) {
  1375 		const ParentSpriteToDraw *ps = *it;
  1378 		const ParentSpriteToDraw *ps = *it;
  1376 		if (ps->image != SPR_EMPTY_BOUNDING_BOX) DrawSprite(ps->image, ps->pal, ps->x, ps->y, ps->sub);
  1379 		if (ps->image != SPR_EMPTY_BOUNDING_BOX) DrawSprite(ps->image, ps->pal, ps->x, ps->y, ps->sub);
  1377 
  1380 
  1378 		const ChildScreenSpriteToDraw *last = csstdv->Get(ps->last_child);
  1381 		int child_idx = ps->first_child;
  1379 		for (const ChildScreenSpriteToDraw *cs = csstdv->Get(ps->first_child); cs != last; cs++) {
  1382 		while (child_idx >= 0) {
       
  1383 			const ChildScreenSpriteToDraw *cs = csstdv->Get(child_idx);
       
  1384 			child_idx = cs->next;
  1380 			DrawSprite(cs->image, cs->pal, ps->left + cs->x, ps->top + cs->y, cs->sub);
  1385 			DrawSprite(cs->image, cs->pal, ps->left + cs->x, ps->top + cs->y, cs->sub);
  1381 		}
  1386 		}
  1382 	}
  1387 	}
  1383 }
  1388 }
  1384 
  1389 
  1893 			FOR_ALL_SIGNS(si) {
  1898 			FOR_ALL_SIGNS(si) {
  1894 				if (y >= si->sign.top &&
  1899 				if (y >= si->sign.top &&
  1895 						y <  si->sign.top + 12 &&
  1900 						y <  si->sign.top + 12 &&
  1896 						x >= si->sign.left &&
  1901 						x >= si->sign.left &&
  1897 						x <  si->sign.left + si->sign.width_1) {
  1902 						x <  si->sign.left + si->sign.width_1) {
  1898 					ShowRenameSignWindow(si);
  1903 					HandleClickOnSign(si);
  1899 					return true;
  1904 					return true;
  1900 				}
  1905 				}
  1901 			}
  1906 			}
  1902 			break;
  1907 			break;
  1903 
  1908 
  1907 			FOR_ALL_SIGNS(si) {
  1912 			FOR_ALL_SIGNS(si) {
  1908 				if (y >= si->sign.top &&
  1913 				if (y >= si->sign.top &&
  1909 						y <  si->sign.top + 24 &&
  1914 						y <  si->sign.top + 24 &&
  1910 						x >= si->sign.left &&
  1915 						x >= si->sign.left &&
  1911 						x <  si->sign.left + si->sign.width_1 * 2) {
  1916 						x <  si->sign.left + si->sign.width_1 * 2) {
  1912 					ShowRenameSignWindow(si);
  1917 					HandleClickOnSign(si);
  1913 					return true;
  1918 					return true;
  1914 				}
  1919 				}
  1915 			}
  1920 			}
  1916 			break;
  1921 			break;
  1917 
  1922 
  1923 			FOR_ALL_SIGNS(si) {
  1928 			FOR_ALL_SIGNS(si) {
  1924 				if (y >= si->sign.top &&
  1929 				if (y >= si->sign.top &&
  1925 						y <  si->sign.top + ScaleByZoom(12, vp->zoom) &&
  1930 						y <  si->sign.top + ScaleByZoom(12, vp->zoom) &&
  1926 						x >= si->sign.left &&
  1931 						x >= si->sign.left &&
  1927 						x <  si->sign.left + ScaleByZoom(si->sign.width_2, vp->zoom)) {
  1932 						x <  si->sign.left + ScaleByZoom(si->sign.width_2, vp->zoom)) {
  1928 					ShowRenameSignWindow(si);
  1933 					HandleClickOnSign(si);
  1929 					return true;
  1934 					return true;
  1930 				}
  1935 				}
  1931 			}
  1936 			}
  1932 			break;
  1937 			break;
  1933 
  1938