src/smallmap_gui.cpp
changeset 6937 40c760fcf1f6
parent 6878 5cefd3ac59c7
child 7266 b16e67e992b4
equal deleted inserted replaced
6936:3ea055cc4957 6937:40c760fcf1f6
    23 #include "player.h"
    23 #include "player.h"
    24 #include "vehicle.h"
    24 #include "vehicle.h"
    25 #include "town.h"
    25 #include "town.h"
    26 #include "sound.h"
    26 #include "sound.h"
    27 #include "variables.h"
    27 #include "variables.h"
       
    28 #include "blitter/factory.hpp"
    28 
    29 
    29 static const Widget _smallmap_widgets[] = {
    30 static const Widget _smallmap_widgets[] = {
    30 {  WWT_CLOSEBOX,   RESIZE_NONE,    13,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW},
    31 {  WWT_CLOSEBOX,   RESIZE_NONE,    13,     0,    10,     0,    13, STR_00C5,                STR_018B_CLOSE_WINDOW},
    31 {   WWT_CAPTION,  RESIZE_RIGHT,    13,    11,   433,     0,    13, STR_00B0_MAP,            STR_018C_WINDOW_TITLE_DRAG_THIS},
    32 {   WWT_CAPTION,  RESIZE_RIGHT,    13,    11,   433,     0,    13, STR_00B0_MAP,            STR_018C_WINDOW_TITLE_DRAG_THIS},
    32 { WWT_STICKYBOX,     RESIZE_LR,    13,   434,   445,     0,    13, 0x0,                     STR_STICKY_BUTTON},
    33 { WWT_STICKYBOX,     RESIZE_LR,    13,   434,   445,     0,    13, 0x0,                     STR_STICKY_BUTTON},
   167 	_legend_land_owners,
   168 	_legend_land_owners,
   168 };
   169 };
   169 
   170 
   170 static inline void WRITE_PIXELS(void *d, uint32 val)
   171 static inline void WRITE_PIXELS(void *d, uint32 val)
   171 {
   172 {
       
   173 	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
   172 	uint8 *val8 = (uint8 *)&val;
   174 	uint8 *val8 = (uint8 *)&val;
   173 	_screen.renderer->SetPixel(d, 0, 0, val8[0]);
   175 
   174 	_screen.renderer->SetPixel(d, 1, 0, val8[1]);
   176 	blitter->SetPixel(d, 0, 0, val8[0]);
   175 	_screen.renderer->SetPixel(d, 2, 0, val8[2]);
   177 	blitter->SetPixel(d, 1, 0, val8[1]);
   176 	_screen.renderer->SetPixel(d, 3, 0, val8[3]);
   178 	blitter->SetPixel(d, 2, 0, val8[2]);
       
   179 	blitter->SetPixel(d, 3, 0, val8[3]);
   177 }
   180 }
   178 
   181 
   179 static inline void WRITE_PIXELS_OR(void *d, uint32 val)
   182 static inline void WRITE_PIXELS_OR(void *d, uint32 val)
   180 {
   183 {
       
   184 	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
   181 	uint8 *val8 = (uint8 *)&val;
   185 	uint8 *val8 = (uint8 *)&val;
   182 	_screen.renderer->SetPixelIfEmpty(d, 0, 0, val8[0]);
   186 
   183 	_screen.renderer->SetPixelIfEmpty(d, 1, 0, val8[1]);
   187 	blitter->SetPixelIfEmpty(d, 0, 0, val8[0]);
   184 	_screen.renderer->SetPixelIfEmpty(d, 2, 0, val8[2]);
   188 	blitter->SetPixelIfEmpty(d, 1, 0, val8[1]);
   185 	_screen.renderer->SetPixelIfEmpty(d, 3, 0, val8[3]);
   189 	blitter->SetPixelIfEmpty(d, 2, 0, val8[2]);
       
   190 	blitter->SetPixelIfEmpty(d, 3, 0, val8[3]);
   186 }
   191 }
   187 
   192 
   188 #define MKCOLOR(x) TO_LE32X(x)
   193 #define MKCOLOR(x) TO_LE32X(x)
   189 
   194 
   190 /* Height encodings; 16 levels XXX - needs updating for more/finer heights! */
   195 /* Height encodings; 16 levels XXX - needs updating for more/finer heights! */
   278  * @param proc Pointer to the colour function
   283  * @param proc Pointer to the colour function
   279  * @see GetSmallMapPixels(TileIndex)
   284  * @see GetSmallMapPixels(TileIndex)
   280  */
   285  */
   281 static void DrawSmallMapStuff(void *dst, uint xc, uint yc, int pitch, int reps, uint32 mask, GetSmallMapPixels *proc)
   286 static void DrawSmallMapStuff(void *dst, uint xc, uint yc, int pitch, int reps, uint32 mask, GetSmallMapPixels *proc)
   282 {
   287 {
   283 	void *dst_ptr_end = _screen.renderer->MoveTo(_screen.dst_ptr, _screen.width, _screen.height - 1);
   288 	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
       
   289 	void *dst_ptr_end = blitter->MoveTo(_screen.dst_ptr, _screen.width, _screen.height - 1);
   284 
   290 
   285 	do {
   291 	do {
   286 		/* check if the tile (xc,yc) is within the map range */
   292 		/* check if the tile (xc,yc) is within the map range */
   287 		if (xc < MapMaxX() && yc < MapMaxY()) {
   293 		if (xc < MapMaxX() && yc < MapMaxY()) {
   288 			/* check if the dst pointer points to a pixel inside the screen buffer */
   294 			/* check if the dst pointer points to a pixel inside the screen buffer */
   289 			if (dst > _screen.dst_ptr && dst < dst_ptr_end)
   295 			if (dst > _screen.dst_ptr && dst < dst_ptr_end)
   290 				WRITE_PIXELS_OR(dst, proc(TileXY(xc, yc)) & mask);
   296 				WRITE_PIXELS_OR(dst, proc(TileXY(xc, yc)) & mask);
   291 		}
   297 		}
   292 	/* switch to next tile in the column */
   298 	/* switch to next tile in the column */
   293 	} while (xc++, yc++, dst = _screen.renderer->MoveTo(dst, pitch, 0), --reps != 0);
   299 	} while (xc++, yc++, dst = blitter->MoveTo(dst, pitch, 0), --reps != 0);
   294 }
   300 }
   295 
   301 
   296 
   302 
   297 static inline TileType GetEffectiveTileType(TileIndex tile)
   303 static inline TileType GetEffectiveTileType(TileIndex tile)
   298 {
   304 {
   508  * @param type type of map requested (vegetation, owners, routes, etc)
   514  * @param type type of map requested (vegetation, owners, routes, etc)
   509  * @param show_towns true if the town names should be displayed, false if not.
   515  * @param show_towns true if the town names should be displayed, false if not.
   510  */
   516  */
   511 static void DrawSmallMap(DrawPixelInfo *dpi, Window *w, int type, bool show_towns)
   517 static void DrawSmallMap(DrawPixelInfo *dpi, Window *w, int type, bool show_towns)
   512 {
   518 {
       
   519 	Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter();
   513 	DrawPixelInfo *old_dpi;
   520 	DrawPixelInfo *old_dpi;
   514 	int dx,dy, x, y, x2, y2;
   521 	int dx,dy, x, y, x2, y2;
   515 	void *ptr;
   522 	void *ptr;
   516 	int tile_x;
   523 	int tile_x;
   517 	int tile_y;
   524 	int tile_y;
   562 			tile_x--;
   569 			tile_x--;
   563 			tile_y++;
   570 			tile_y++;
   564 		}
   571 		}
   565 	}
   572 	}
   566 
   573 
   567 	ptr = _screen.renderer->MoveTo(dpi->dst_ptr, -dx - 4, 0);
   574 	ptr = blitter->MoveTo(dpi->dst_ptr, -dx - 4, 0);
   568 	x = - dx - 4;
   575 	x = - dx - 4;
   569 	y = 0;
   576 	y = 0;
   570 
   577 
   571 	for (;;) {
   578 	for (;;) {
   572 		uint32 mask = 0xFFFFFFFF;
   579 		uint32 mask = 0xFFFFFFFF;
   596 
   603 
   597 skip_column:
   604 skip_column:
   598 		if (y == 0) {
   605 		if (y == 0) {
   599 			tile_y++;
   606 			tile_y++;
   600 			y++;
   607 			y++;
   601 			ptr = _screen.renderer->MoveTo(ptr, 0, 1);
   608 			ptr = blitter->MoveTo(ptr, 0, 1);
   602 		} else {
   609 		} else {
   603 			tile_x--;
   610 			tile_x--;
   604 			y--;
   611 			y--;
   605 			ptr = _screen.renderer->MoveTo(ptr, 0, -1);
   612 			ptr = blitter->MoveTo(ptr, 0, -1);
   606 		}
   613 		}
   607 		ptr = _screen.renderer->MoveTo(ptr, 2, 0);
   614 		ptr = blitter->MoveTo(ptr, 2, 0);
   608 		x += 2;
   615 		x += 2;
   609 	}
   616 	}
   610 
   617 
   611 	/* draw vehicles? */
   618 	/* draw vehicles? */
   612 	if (type == 0 || type == 1) {
   619 	if (type == 0 || type == 1) {
   648 
   655 
   649 				/* Calculate pointer to pixel and the color */
   656 				/* Calculate pointer to pixel and the color */
   650 				color = (type == 1) ? _vehicle_type_colors[v->type] : 0xF;
   657 				color = (type == 1) ? _vehicle_type_colors[v->type] : 0xF;
   651 
   658 
   652 				/* And draw either one or two pixels depending on clipping */
   659 				/* And draw either one or two pixels depending on clipping */
   653 				_screen.renderer->SetPixel(dpi->dst_ptr, x, y, color);
   660 				blitter->SetPixel(dpi->dst_ptr, x, y, color);
   654 				if (!skip) _screen.renderer->SetPixel(dpi->dst_ptr, x + 1, y, color);;
   661 				if (!skip) blitter->SetPixel(dpi->dst_ptr, x + 1, y, color);
   655 			}
   662 			}
   656 		}
   663 		}
   657 	}
   664 	}
   658 
   665 
   659 	if (show_towns) {
   666 	if (show_towns) {