@@ -109,7 +109,8 @@ TileGenerator::TileGenerator():
109
109
m_drawAlpha(false ),
110
110
m_shading(true ),
111
111
m_backend(" " ),
112
- m_border(0 ),
112
+ m_xBorder(0 ),
113
+ m_yBorder(0 ),
113
114
m_db(NULL ),
114
115
m_image(NULL ),
115
116
m_xMin(INT_MAX),
@@ -122,7 +123,8 @@ TileGenerator::TileGenerator():
122
123
m_geomY(-2048 ),
123
124
m_geomX2(2048 ),
124
125
m_geomY2(2048 ),
125
- m_zoom(1 )
126
+ m_zoom(1 ),
127
+ m_scales(SCALE_LEFT | SCALE_TOP)
126
128
{
127
129
}
128
130
@@ -159,6 +161,11 @@ void TileGenerator::setZoom(int zoom)
159
161
m_zoom = zoom;
160
162
}
161
163
164
+ void TileGenerator::setScales (uint flags)
165
+ {
166
+ m_scales = flags;
167
+ }
168
+
162
169
Color TileGenerator::parseColor (const std::string &color)
163
170
{
164
171
Color parsed;
@@ -190,9 +197,6 @@ void TileGenerator::setDrawPlayers(bool drawPlayers)
190
197
void TileGenerator::setDrawScale (bool drawScale)
191
198
{
192
199
m_drawScale = drawScale;
193
- if (m_drawScale) {
194
- m_border = 40 ;
195
- }
196
200
}
197
201
198
202
void TileGenerator::setDrawAlpha (bool drawAlpha)
@@ -359,9 +363,16 @@ void TileGenerator::createImage()
359
363
{
360
364
m_mapWidth = (m_xMax - m_xMin + 1 ) * 16 ;
361
365
m_mapHeight = (m_zMax - m_zMin + 1 ) * 16 ;
366
+ if (m_drawScale) {
367
+ m_xBorder = (m_scales & SCALE_LEFT) ? 40 : 0 ;
368
+ m_yBorder = (m_scales & SCALE_TOP) ? 40 : 0 ;
369
+ }
370
+
362
371
int image_width, image_height;
363
- image_width = (m_mapWidth * m_zoom) + m_border;
364
- image_height = (m_mapHeight * m_zoom) + m_border;
372
+ image_width = (m_mapWidth * m_zoom) + m_xBorder;
373
+ image_width += m_drawScale && (m_scales & SCALE_RIGHT) ? 40 : 0 ;
374
+ image_height = (m_mapHeight * m_zoom) + m_yBorder;
375
+ image_height += m_drawScale && (m_scales & SCALE_BOTTOM) ? 40 : 0 ;
365
376
if (image_width > 4096 || image_height > 4096 )
366
377
std::cerr << " Warning: The width or height of the image to be created exceeds 4096 pixels!"
367
378
<< " (Dimensions: " << image_width << " x" << image_height << " )"
@@ -633,36 +644,66 @@ inline void TileGenerator::renderShading(int zPos)
633
644
void TileGenerator::renderScale ()
634
645
{
635
646
int color = color2int (m_scaleColor);
636
- gdImageString (m_image, gdFontGetMediumBold (), 24 , 0 , reinterpret_cast <unsigned char *>(const_cast <char *>(" X" )), color);
637
- gdImageString (m_image, gdFontGetMediumBold (), 2 , 24 , reinterpret_cast <unsigned char *>(const_cast <char *>(" Z" )), color);
638
647
639
648
string scaleText;
640
649
641
- for (int i = (m_xMin / 4 ) * 4 ; i <= m_xMax; i += 4 ) {
642
- stringstream buf;
643
- buf << i * 16 ;
644
- scaleText = buf.str ();
650
+ if (m_scales & SCALE_TOP) {
651
+ gdImageString (m_image, gdFontGetMediumBold (), 24 , 0 , reinterpret_cast <unsigned char *>(const_cast <char *>(" X" )), color);
652
+ for (int i = (m_xMin / 4 ) * 4 ; i <= m_xMax; i += 4 ) {
653
+ stringstream buf;
654
+ buf << i * 16 ;
655
+ scaleText = buf.str ();
645
656
646
- int xPos = (m_xMin * -16 + i * 16 )*m_zoom + m_border;
647
- gdImageString (m_image, gdFontGetMediumBold (), xPos + 2 , 0 , reinterpret_cast <unsigned char *>(const_cast <char *>(scaleText.c_str ())), color);
648
- gdImageLine (m_image, xPos, 0 , xPos, m_border - 1 , color);
657
+ int xPos = (m_xMin * -16 + i * 16 )*m_zoom + m_xBorder;
658
+ gdImageString (m_image, gdFontGetMediumBold (), xPos + 2 , 0 , reinterpret_cast <unsigned char *>(const_cast <char *>(scaleText.c_str ())), color);
659
+ gdImageLine (m_image, xPos, 0 , xPos, m_yBorder - 1 , color);
660
+ }
649
661
}
650
662
651
- for (int i = (m_zMax / 4 ) * 4 ; i >= m_zMin; i -= 4 ) {
652
- stringstream buf;
653
- buf << i * 16 ;
654
- scaleText = buf.str ();
663
+ if (m_scales & SCALE_LEFT) {
664
+ gdImageString (m_image, gdFontGetMediumBold (), 2 , 24 , reinterpret_cast <unsigned char *>(const_cast <char *>(" Z" )), color);
665
+ for (int i = (m_zMax / 4 ) * 4 ; i >= m_zMin; i -= 4 ) {
666
+ stringstream buf;
667
+ buf << i * 16 ;
668
+ scaleText = buf.str ();
655
669
656
- int yPos = (m_mapHeight - 1 - (i * 16 - m_zMin * 16 ))*m_zoom + m_border;
657
- gdImageString (m_image, gdFontGetMediumBold (), 2 , yPos, reinterpret_cast <unsigned char *>(const_cast <char *>(scaleText.c_str ())), color);
658
- gdImageLine (m_image, 0 , yPos, m_border - 1 , yPos, color);
670
+ int yPos = (m_mapHeight - 1 - (i * 16 - m_zMin * 16 ))*m_zoom + m_yBorder;
671
+ gdImageString (m_image, gdFontGetMediumBold (), 2 , yPos, reinterpret_cast <unsigned char *>(const_cast <char *>(scaleText.c_str ())), color);
672
+ gdImageLine (m_image, 0 , yPos, m_xBorder - 1 , yPos, color);
673
+ }
674
+ }
675
+
676
+ if (m_scales & SCALE_BOTTOM) {
677
+ for (int i = (m_xMin / 4 ) * 4 ; i <= m_xMax; i += 4 ) {
678
+ stringstream buf;
679
+ buf << i * 16 ;
680
+ scaleText = buf.str ();
681
+
682
+ int xPos = (m_xMin * -16 + i * 16 )*m_zoom + m_xBorder;
683
+ int yPos = m_yBorder + m_mapHeight;
684
+ gdImageString (m_image, gdFontGetMediumBold (), xPos + 2 , yPos, reinterpret_cast <unsigned char *>(const_cast <char *>(scaleText.c_str ())), color);
685
+ gdImageLine (m_image, xPos, yPos, xPos, yPos + 39 , color);
686
+ }
687
+ }
688
+
689
+ if (m_scales & SCALE_RIGHT) {
690
+ for (int i = (m_zMax / 4 ) * 4 ; i >= m_zMin; i -= 4 ) {
691
+ stringstream buf;
692
+ buf << i * 16 ;
693
+ scaleText = buf.str ();
694
+
695
+ int xPos = m_xBorder + m_mapWidth;
696
+ int yPos = (m_mapHeight - 1 - (i * 16 - m_zMin * 16 ))*m_zoom + m_yBorder;
697
+ gdImageString (m_image, gdFontGetMediumBold (), xPos + 2 , yPos, reinterpret_cast <unsigned char *>(const_cast <char *>(scaleText.c_str ())), color);
698
+ gdImageLine (m_image, xPos, yPos, xPos + 39 , yPos, color);
699
+ }
659
700
}
660
701
}
661
702
662
703
void TileGenerator::renderOrigin ()
663
704
{
664
- int imageX = (-m_xMin * 16 )*m_zoom + m_border ;
665
- int imageY = (m_mapHeight - m_zMin * -16 )*m_zoom + m_border ;
705
+ int imageX = (-m_xMin * 16 )*m_zoom + m_xBorder ;
706
+ int imageY = (m_mapHeight - m_zMin * -16 )*m_zoom + m_yBorder ;
666
707
gdImageArc (m_image, imageX, imageY, 12 , 12 , 0 , 360 , color2int (m_originColor));
667
708
}
668
709
@@ -672,8 +713,8 @@ void TileGenerator::renderPlayers(const std::string &inputPath)
672
713
673
714
PlayerAttributes players (inputPath);
674
715
for (PlayerAttributes::Players::iterator player = players.begin (); player != players.end (); ++player) {
675
- int imageX = (player->x / 10 - m_xMin * 16 )*m_zoom + m_border ;
676
- int imageY = (m_mapHeight - (player->z / 10 - m_zMin * 16 ))*m_zoom + m_border ;
716
+ int imageX = (player->x / 10 - m_xMin * 16 )*m_zoom + m_xBorder ;
717
+ int imageY = (m_mapHeight - (player->z / 10 - m_zMin * 16 ))*m_zoom + m_yBorder ;
677
718
678
719
gdImageArc (m_image, imageX, imageY, 5 , 5 , 0 , 360 , color);
679
720
gdImageString (m_image, gdFontGetMediumBold (), imageX + 2 , imageY + 2 , reinterpret_cast <unsigned char *>(const_cast <char *>(player->name .c_str ())), color);
@@ -718,19 +759,19 @@ void TileGenerator::printUnknown()
718
759
719
760
inline int TileGenerator::getImageX (int val) const
720
761
{
721
- return (m_zoom*val) + m_border ;
762
+ return (m_zoom*val) + m_xBorder ;
722
763
}
723
764
724
765
inline int TileGenerator::getImageY (int val) const
725
766
{
726
- return (m_zoom*val) + m_border ;
767
+ return (m_zoom*val) + m_yBorder ;
727
768
}
728
769
729
770
inline void TileGenerator::setZoomed (gdImagePtr image, int y, int x, int color) {
730
771
int xx,yy;
731
772
for (xx = 0 ; xx < m_zoom; xx++) {
732
773
for (yy = 0 ; yy < m_zoom; yy++) {
733
- image->tpixels [m_border + (y*m_zoom) + xx][m_border + (x*m_zoom) + yy] = color;
774
+ image->tpixels [m_yBorder + (y*m_zoom) + xx][m_xBorder + (x*m_zoom) + yy] = color;
734
775
}
735
776
}
736
777
}
0 commit comments