Changeset - r21250:73db1c02a3c0
[Not reviewed]
master
0 2 0
fonsinchen - 10 years ago 2014-02-15 12:19:46
fonsinchen@openttd.org
(svn r26338) -Fix [FS#5908]: Don't redraw the link graph overlay if it's empty (MJP)
2 files changed with 23 insertions and 15 deletions:
0 comments (0 inline, 0 general)
src/main_gui.cpp
Show inline comments
 
@@ -232,53 +232,59 @@ enum {
 
};
 

	
 
struct MainWindow : Window
 
{
 
	uint refresh;
 

	
 
	static const uint LINKGRAPH_REFRESH_PERIOD = 0xff;
 
	static const uint LINKGRAPH_DELAY = 0xf;
 

	
 
	MainWindow(WindowDesc *desc) : Window(desc)
 
	{
 
		this->InitNested(0);
 
		CLRBITS(this->flags, WF_WHITE_BORDER);
 
		ResizeWindow(this, _screen.width, _screen.height);
 

	
 
		NWidgetViewport *nvp = this->GetWidget<NWidgetViewport>(WID_M_VIEWPORT);
 
		nvp->InitializeViewport(this, TileXY(32, 32), ZOOM_LVL_VIEWPORT);
 

	
 
		this->viewport->overlay = new LinkGraphOverlay(this, WID_M_VIEWPORT, 0, 0, 3);
 
		this->refresh = LINKGRAPH_DELAY;
 
	}
 

	
 
	virtual void OnTick()
 
	{
 
		if (--refresh == 0) {
 
			this->viewport->overlay->RebuildCache();
 
			this->GetWidget<NWidgetBase>(WID_M_VIEWPORT)->SetDirty(this);
 
			this->refresh = LINKGRAPH_REFRESH_PERIOD;
 
		if (--this->refresh > 0) return;
 

	
 
		this->refresh = LINKGRAPH_REFRESH_PERIOD;
 

	
 
		if (this->viewport->overlay->GetCargoMask() == 0 ||
 
				this->viewport->overlay->GetCompanyMask() == 0) {
 
			return;
 
		}
 

	
 
		this->viewport->overlay->RebuildCache();
 
		this->GetWidget<NWidgetBase>(WID_M_VIEWPORT)->SetDirty(this);
 
	}
 

	
 
	virtual void OnPaint()
 
	{
 
		this->DrawWidgets();
 
		if (_game_mode == GM_MENU) {
 
			static const SpriteID title_sprites[] = {SPR_OTTD_O, SPR_OTTD_P, SPR_OTTD_E, SPR_OTTD_N, SPR_OTTD_T, SPR_OTTD_T, SPR_OTTD_D};
 
			static const uint LETTER_SPACING = 10;
 
			int name_width = (lengthof(title_sprites) - 1) * LETTER_SPACING;
 

	
 
			for (uint i = 0; i < lengthof(title_sprites); i++) {
 
				name_width += GetSpriteSize(title_sprites[i]).width;
 
			}
 
			int off_x = (this->width - name_width) / 2;
 

	
 
			for (uint i = 0; i < lengthof(title_sprites); i++) {
 
				DrawSprite(title_sprites[i], PAL_NONE, off_x, 50);
 
				off_x += GetSpriteSize(title_sprites[i]).width + LETTER_SPACING;
 
			}
 
		}
 
	}
 

	
 
	virtual EventState OnHotkey(int hotkey)
 
	{
src/viewport.cpp
Show inline comments
 
@@ -1456,59 +1456,61 @@ void ViewportDoDraw(const ViewPort *vp, 
 
	ViewportAddSigns(&_vd.dpi);
 

	
 
	DrawTextEffects(&_vd.dpi);
 

	
 
	if (_vd.tile_sprites_to_draw.Length() != 0) ViewportDrawTileSprites(&_vd.tile_sprites_to_draw);
 

	
 
	ParentSpriteToDraw *psd_end = _vd.parent_sprites_to_draw.End();
 
	for (ParentSpriteToDraw *it = _vd.parent_sprites_to_draw.Begin(); it != psd_end; it++) {
 
		*_vd.parent_sprites_to_sort.Append() = it;
 
	}
 

	
 
	_vp_sprite_sorter(&_vd.parent_sprites_to_sort);
 
	ViewportDrawParentSprites(&_vd.parent_sprites_to_sort, &_vd.child_screen_sprites_to_draw);
 

	
 
	if (_draw_bounding_boxes) ViewportDrawBoundingBoxes(&_vd.parent_sprites_to_sort);
 
	if (_draw_dirty_blocks) ViewportDrawDirtyBlocks();
 

	
 
	DrawPixelInfo dp = _vd.dpi;
 
	ZoomLevel zoom = _vd.dpi.zoom;
 
	dp.zoom = ZOOM_LVL_NORMAL;
 
	dp.width = UnScaleByZoom(dp.width, zoom);
 
	dp.height = UnScaleByZoom(dp.height, zoom);
 
	_cur_dpi = &dp;
 

	
 
	/* translate to window coordinates */
 
	dp.left = x;
 
	dp.top = y;
 

	
 
	if (vp->overlay != NULL) vp->overlay->Draw(&dp);
 

	
 
	/* translate back to world coordinates */
 
	dp.left = UnScaleByZoom(_vd.dpi.left, zoom);
 
	dp.top = UnScaleByZoom(_vd.dpi.top, zoom);
 

	
 
	if (_vd.string_sprites_to_draw.Length() != 0) ViewportDrawStrings(zoom, &_vd.string_sprites_to_draw);
 
	if (vp->overlay != NULL && vp->overlay->GetCargoMask() != 0 && vp->overlay->GetCompanyMask() != 0) {
 
		/* translate to window coordinates */
 
		dp.left = x;
 
		dp.top = y;
 
		vp->overlay->Draw(&dp);
 
	}
 

	
 
	if (_vd.string_sprites_to_draw.Length() != 0) {
 
		/* translate to world coordinates */
 
		dp.left = UnScaleByZoom(_vd.dpi.left, zoom);
 
		dp.top = UnScaleByZoom(_vd.dpi.top, zoom);
 
		ViewportDrawStrings(zoom, &_vd.string_sprites_to_draw);
 
	}
 

	
 
	_cur_dpi = old_dpi;
 

	
 
	_vd.string_sprites_to_draw.Clear();
 
	_vd.tile_sprites_to_draw.Clear();
 
	_vd.parent_sprites_to_draw.Clear();
 
	_vd.parent_sprites_to_sort.Clear();
 
	_vd.child_screen_sprites_to_draw.Clear();
 
}
 

	
 
/**
 
 * Make sure we don't draw a too big area at a time.
 
 * If we do, the sprite memory will overflow.
 
 */
 
static void ViewportDrawChk(const ViewPort *vp, int left, int top, int right, int bottom)
 
{
 
	if (ScaleByZoom(bottom - top, vp->zoom) * ScaleByZoom(right - left, vp->zoom) > 180000 * ZOOM_LVL_BASE * ZOOM_LVL_BASE) {
 
		if ((bottom - top) > (right - left)) {
 
			int t = (top + bottom) >> 1;
 
			ViewportDrawChk(vp, left, top, right, t);
 
			ViewportDrawChk(vp, left, t, right, bottom);
 
		} else {
 
			int t = (left + right) >> 1;
 
			ViewportDrawChk(vp, left, top, t, bottom);
0 comments (0 inline, 0 general)