diff options
Diffstat (limited to 'src/graphics')
| -rw-r--r-- | src/graphics/Graphics.cpp | 13 | ||||
| -rw-r--r-- | src/graphics/Graphics.h | 2 |
2 files changed, 6 insertions, 9 deletions
diff --git a/src/graphics/Graphics.cpp b/src/graphics/Graphics.cpp index d4e2956..c70344b 100644 --- a/src/graphics/Graphics.cpp +++ b/src/graphics/Graphics.cpp @@ -67,13 +67,10 @@ void VideoBuffer::Resize(int width, int height, bool resample, bool fixedRatio) else if(fixedRatio) { //Force proportions - float scaleFactor = 1.0f; - if(Height > newHeight) - scaleFactor = ((float)newHeight)/((float)Height); - if(Width > newWidth) - scaleFactor = ((float)newWidth)/((float)Width); - newWidth = ((float)Width)*scaleFactor; - newHeight = ((float)Height)*scaleFactor; + if(newWidth*Height > newHeight*Width) // same as nW/W > nH/H + newWidth = (int)(Width * (newHeight/(float)Height)); + else + newHeight = (int)(Height * (newWidth/(float)Width)); } if(resample) newBuffer = Graphics::resample_img(Buffer, Width, Height, newWidth, newHeight); @@ -589,7 +586,7 @@ int Graphics::textwidth(const char *s) return x-1; } -int Graphics::CharWidth(char c) +int Graphics::CharWidth(unsigned char c) { return font_data[font_ptrs[(int)c]]; } diff --git a/src/graphics/Graphics.h b/src/graphics/Graphics.h index 580f2c0..de1c2e8 100644 --- a/src/graphics/Graphics.h +++ b/src/graphics/Graphics.h @@ -203,7 +203,7 @@ public: //Font/text metrics static int CharIndexAtPosition(char *s, int positionX, int positionY); static int PositionAtCharIndex(char *s, int charIndex, int & positionX, int & positionY); - static int CharWidth(char c); + static int CharWidth(unsigned char c); static int textnwidth(char *s, int n); static void textnpos(char *s, int n, int w, int *cx, int *cy); static int textwidthx(char *s, int w); |
