aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoruruk2013-08-07 23:51:12 +0200
committeruruk2013-08-07 23:51:12 +0200
commit84bf0984b0fc7f2bd18d5f233a001ba311369bd5 (patch)
tree232cd91fe857df09b1d0b0910d6c1b24e31c0693
parent84aac3e49beeeda18a9d08e485e97bf25a961708 (diff)
downloadscummvm-rg350-84bf0984b0fc7f2bd18d5f233a001ba311369bd5.tar.gz
scummvm-rg350-84bf0984b0fc7f2bd18d5f233a001ba311369bd5.tar.bz2
scummvm-rg350-84bf0984b0fc7f2bd18d5f233a001ba311369bd5.zip
AVALANCHE: Introduce Graphics::drawArc(), use it in Scrolls::drawscroll().
-rw-r--r--engines/avalanche/graphics.cpp84
-rw-r--r--engines/avalanche/graphics.h3
-rw-r--r--engines/avalanche/scrolls2.cpp4
3 files changed, 90 insertions, 1 deletions
diff --git a/engines/avalanche/graphics.cpp b/engines/avalanche/graphics.cpp
index 2c266e92c4..158440b017 100644
--- a/engines/avalanche/graphics.cpp
+++ b/engines/avalanche/graphics.cpp
@@ -25,6 +25,8 @@
* Copyright (c) 1994-1995 Mike, Mark and Thomas Thurman.
*/
+#include "math.h"
+
#include "avalanche/avalanche.h"
#include "avalanche/graphics.h"
@@ -117,6 +119,88 @@ void Graphics::drawSprite(const SpriteInfo &sprite, byte picnum, int16 x, int16
}
}
+void Graphics::drawArc(const ::Graphics::Surface &surface, int16 x, int16 y, int16 stAngle, int16 endAngle, uint16 radius, byte color) {
+ const double pi = 3.14;
+ const double convfac = pi / 180.0;
+
+ int32 xRadius = radius;
+ int32 yRadius = radius * kScreenWidth / (8 * kScreenHeight); // Just don't ask why...
+
+ if (xRadius == 0)
+ xRadius ++;
+ if (yRadius == 0)
+ yRadius ++;
+
+ /* check for an ellipse with negligable x and y radius */
+ if ((xRadius <= 1) && (yRadius <= 1))
+ {
+ *(byte *)_scrolls.getBasePtr(x,y) = color;
+ return;
+ }
+
+ /* check if valid angles */
+ stAngle = stAngle % 361;
+ endAngle = endAngle % 361;
+
+ /* if impossible angles then swap them! */
+ if (endAngle < stAngle)
+ {
+ uint16 tmpAngle=endAngle;
+ endAngle=stAngle;
+ stAngle=tmpAngle;
+ }
+
+ /* approximate the number of pixels required by using the circumference */
+ /* equation of an ellipse. */
+ uint16 numOfPixels=floor(sqrt(3.0)*sqrt(pow(float(xRadius), 2)+pow(float(yRadius), 2)) + 0.5);
+
+ /* Calculate the angle precision required */
+ double delta = 90.0 / numOfPixels;
+
+ /* Always just go over the first 90 degrees. Could be optimized a */
+ /* bit if startAngle and endAngle lie in the same quadrant, left as an */
+ /* exercise for the reader :) (JM) */
+ double j = 0;
+
+ /* calculate stop position, go 1 further than 90 because otherwise */
+ /* 1 pixel is sometimes not drawn (JM) */
+ uint16 deltaEnd = 91;
+
+ /* Calculate points */
+ int16 xNext = xRadius;
+ int16 yNext = 0;
+ do {
+ int16 xTemp = xNext;
+ int16 yTemp = yNext;
+ /* this is used by both sin and cos */
+ double tempTerm = (j+delta)*convfac;
+ /* Calculate points */
+ xNext = floor(xRadius*cos(tempTerm) + 0.5);
+ yNext = floor(yRadius*sin(tempTerm + pi) + 0.5);
+
+ int16 xp = x + xTemp;
+ int16 xm = x - xTemp;
+ int16 yp = y + yTemp;
+ int16 ym = y - yTemp;
+ if ((j >= stAngle) && (j <= endAngle))
+ *(byte *)_scrolls.getBasePtr(xp,yp) = color;
+
+ if (((180-j) >= stAngle) && ((180-j) <= endAngle))
+ *(byte *)_scrolls.getBasePtr(xm,yp) = color;
+
+ if (((j+180) >= stAngle) && ((j+180) <= endAngle))
+ *(byte *)_scrolls.getBasePtr(xm,ym) = color;
+
+ if (((360-j) >= stAngle) && ((360-j) <= endAngle))
+ *(byte *)_scrolls.getBasePtr(xp,ym) = color;
+
+ j += delta;
+ } while (j <= deltaEnd);
+}
+
+
+
+
::Graphics::Surface Graphics::loadPictureGraphic(Common::File &file) {
// This function mimics Pascal's getimage().
// The height and the width are stored in 2-2 bytes. We have to add 1 to each because Pascal stores the value of them -1.
diff --git a/engines/avalanche/graphics.h b/engines/avalanche/graphics.h
index 13c6001ef8..56300f480b 100644
--- a/engines/avalanche/graphics.h
+++ b/engines/avalanche/graphics.h
@@ -87,6 +87,9 @@ public:
void drawSprite(const SpriteInfo &sprite, byte picnum, int16 x, int16 y);
+ void drawArc(const ::Graphics::Surface &surface, int16 x, int16 y, int16 stAngle, int16 endAngle, uint16 radius, byte color);
+ // Taken from Free Pascal's Procedure InternalEllipseDefault. Used to replace Pascal's procedure arc.
+
// The caller has to .free() the returned Surfaces!!!
::Graphics::Surface loadPictureGraphic(Common::File &file); // Reads Graphic-planar EGA data.
diff --git a/engines/avalanche/scrolls2.cpp b/engines/avalanche/scrolls2.cpp
index 5087232c98..eeb9b4df4c 100644
--- a/engines/avalanche/scrolls2.cpp
+++ b/engines/avalanche/scrolls2.cpp
@@ -373,7 +373,9 @@ void Scrolls::drawscroll(func2 gotoit) { // This is one of the oldest procs in t
setcolor(4);
arc(mx + lx, my - ly, 360, 90, 15);
arc(mx + lx, my + ly, 270, 360, 15);*/
-
+ _vm->_graphics->drawArc(_vm->_graphics->_scrolls,mx + lx, my - ly, 0, 90, 15, red);
+ _vm->_graphics->drawArc(_vm->_graphics->_scrolls,mx + lx, my + ly, 270, 360, 15, red);
+
_vm->_graphics->_scrolls.fillRect(Common::Rect(mx - lx - 30, my + ly, mx + lx, my + ly + 6), lightgray);
_vm->_graphics->_scrolls.fillRect(Common::Rect(mx - lx - 30, my - ly - 6, mx + lx, my - ly), lightgray);
_vm->_graphics->_scrolls.fillRect(Common::Rect(mx - lx - 15, my - ly, mx + lx + 15, my + ly), lightgray);