summaryrefslogtreecommitdiff
path: root/app/wlib/mswlib/mswdraw.c
diff options
context:
space:
mode:
Diffstat (limited to 'app/wlib/mswlib/mswdraw.c')
-rw-r--r--app/wlib/mswlib/mswdraw.c409
1 files changed, 206 insertions, 203 deletions
diff --git a/app/wlib/mswlib/mswdraw.c b/app/wlib/mswlib/mswdraw.c
index c2739e6..be5bcd6 100644
--- a/app/wlib/mswlib/mswdraw.c
+++ b/app/wlib/mswlib/mswdraw.c
@@ -29,13 +29,8 @@
#include <math.h>
#include <winuser.h>
-#ifdef WIN32
#define wFont_t tagLOGFONTA
-#else
-#define wFont_t tagLOGFONT
-#endif
-#include "misc.h"
#include "mswint.h"
#include <FreeImage.h>
@@ -48,9 +43,9 @@ wBool_t wDrawDoTempDraw = TRUE;
*****************************************************************************
*/
-static wBool_t initted = FALSE;
+#define M_PI 3.14159265358979323846
-long wDebugFont;
+static wBool_t initted = FALSE;
static FARPROC oldDrawProc;
@@ -59,69 +54,53 @@ static long tmpOp = 0x990066;
static long setOp = 0x8800c6;
static long clrOp = 0xbb0226;
-#define CENTERMARK_LENGTH 6
+#define CENTERMARK_LENGTH 4
-bool bDrawMainBM = 0;
+static bool bDrawMainBM = 0;
+
+typedef struct {
+ double x, y;
+} coOrd;
#ifdef SLOW
-static wPos_t XPIX2INCH( wDraw_p d, int ix )
+static wDrawPix_t XWINPIX2DRAWPIX( wDraw_p d, wWinPix_t ix )
{
- return (wPos_t)ix;
+ return (wDrawPix_t)ix;
}
-static wPos_t YPIX2INCH( wDraw_p d, int iy )
+static wDrawPix_t YWINPIX2DRAWPIX( wDraw_p d, wWinPix_t iy )
{
- wPos_t y;
- y = (wPos_t)(d->h-2-iy);
+ wWinPix_t y;
+ y = (wDrawPix_t)(d->h-2-iy);
return y;
}
-static int XINCH2PIX( wDraw_p d, wPos_t xx )
+static wWinPix_t XDRAWPIX2WINPIX( wDraw_p d, wDrawPix_t xx )
{
- int ix;
- ix = (int)(xx);
+ wWinPix_t ix;
+ ix = (wWinPix_t)(xx);
return ix;
}
-static int YINCH2PIX( wDraw_p d, wPos_t y )
+static wWinPix_t YDRAWPIX2WINPIX( wDraw_p d, wDrawPix_t y )
{
- int iy;
- iy = d->h-2 - (int)(y);
+ wWinPix_t iy;
+ iy = (d->h)-2 - (wWinPix_t)(y);
return iy;
}
-
-static wPos_t XPIXELSTOINCH( wDraw_p d, int ix )
-{
- return (wPos_t)ix;
-}
-
-
-static wPos_t YPIXELSTOINCH( wDraw_p d, int iy )
-{
- return (wPos_t)iy;
-}
#else
-#define XPIX2INCH( d, ix ) \
- ((wPos_t)ix)
-
-#define YPIX2INCH( d, iy ) \
- ((wPos_t)(d->h-2-iy))
-
-#define XINCH2PIX( d, xx ) \
- ((int)(xx))
-
-#define YINCH2PIX( d, y ) \
- (d->h-2 - (int)(y))
+#define XWINPIX2DRAWPIX( d, ix ) \
+ ((wDrawPix_t)ix)
+#define YWINPIX2DRAWPIX( d, iy ) \
+ ((wDrawPix_t)(d->h-2-iy))
-#define XPIXELSTOINCH( d, ix ) \
- ((wPos_t)ix)
-
-
-#define YPIXELSTOINCH( d, iy ) \
- ((wPos_t)iy)
+#define XDRAWPIX2WINPIX( d, xx ) \
+ ((wWinPix_t)(xx))
+#define YDRAWPIX2WINPIX( d, y ) \
+ (d->h - 2 - (wWinPix_t)(y))
#endif
/*
@@ -134,7 +113,9 @@ static wPos_t YPIXELSTOINCH( wDraw_p d, int iy )
+/** @prefs [msw tweak] NoNegDrawArgs=1 Suppress drawing if x < 0 or y < 0 (-1 value causes preference read) */
static long noNegDrawArgs = -1;
+/** @prefs [msw tweak] NoFlatEndCaps=1 Suppress EndCap Flat pen style */
static long noFlatEndCaps = 0;
void wDrawDelayUpdate(
@@ -323,10 +304,10 @@ static int clip0( POINT * p0, POINT * p1, wDraw_p d )
void wDrawLine(
wDraw_p d,
- wPos_t p0x,
- wPos_t p0y,
- wPos_t p1x,
- wPos_t p1y,
+ wDrawPix_t p0x,
+ wDrawPix_t p0y,
+ wDrawPix_t p1x,
+ wDrawPix_t p1y,
wDrawWidth dw,
wDrawLineType_e lt,
wDrawColor dc,
@@ -335,10 +316,10 @@ void wDrawLine(
POINT p0, p1;
RECT rect;
setDrawMode( d, dw, lt, dc, dopt );
- p0.x = XINCH2PIX(d,p0x);
- p0.y = YINCH2PIX(d,p0y);
- p1.x = XINCH2PIX(d,p1x);
- p1.y = YINCH2PIX(d,p1y);
+ p0.x = XDRAWPIX2WINPIX(d,p0x);
+ p0.y = YDRAWPIX2WINPIX(d,p0y);
+ p1.x = XDRAWPIX2WINPIX(d,p1x);
+ p1.y = YDRAWPIX2WINPIX(d,p1y);
if ( noNegDrawArgs>0 && !clip0( &p0, &p1, d ) )
return;
MoveTo( d->hDc, p0.x, p0.y );
@@ -365,6 +346,12 @@ void wDrawLine(
}
}
+static double d2r(double angle)
+{
+ angle *= (M_PI / 180.0);
+ return angle;
+}
+
static double mswsin( double angle )
{
while (angle < 0.0) angle += 360.0;
@@ -406,12 +393,12 @@ static double mswasin( double x, double h )
void wDrawArc(
wDraw_p d,
- wPos_t px,
- wPos_t py,
- wPos_t r,
+ wDrawPix_t px,
+ wDrawPix_t py,
+ wDrawPix_t r,
double a0,
double a1,
- int drawCenter,
+ int sizeCenter,
wDrawWidth dw,
wDrawLineType_e lt,
wDrawColor dc,
@@ -419,19 +406,16 @@ void wDrawArc(
{
int i, cnt;
POINT p0, p1, ps, pe, pp0, pp1, pp2, pc;
- double psx, psy, pex, pey, len, aa;
+ wDrawPix_t psx, psy, pex, pey;
+ double len, aa, ai;
RECT rect;
int needMoveTo;
wBool_t fakeArc = FALSE;
- len = a1/360.0 * (2 * M_PI) * r;
- if (len < 3)
- return;
-
- p0.x = XINCH2PIX(d,px-r);
- p0.y = YINCH2PIX(d,py+r)+1;
- p1.x = XINCH2PIX(d,px+r);
- p1.y = YINCH2PIX(d,py-r)+1;
+ p0.x = XDRAWPIX2WINPIX(d,px-r);
+ p0.y = YDRAWPIX2WINPIX(d,py+r);
+ p1.x = XDRAWPIX2WINPIX(d,px+r);
+ p1.y = YDRAWPIX2WINPIX(d,py-r);
pex = px + r * mswsin(a0);
pey = py + r * mswcos(a0);
@@ -440,17 +424,18 @@ void wDrawArc(
/*pointOnCircle( &pe, p, r, a0 );
pointOnCircle( &ps, p, r, a0+a1 );*/
- ps.x = XINCH2PIX(d,(wPos_t)psx);
- ps.y = YINCH2PIX(d,(wPos_t)psy);
- pe.x = XINCH2PIX(d,(wPos_t)pex);
- pe.y = YINCH2PIX(d,(wPos_t)pey);
+ ps.x = XDRAWPIX2WINPIX(d,psx);
+ ps.y = YDRAWPIX2WINPIX(d,psy);
+ pe.x = XDRAWPIX2WINPIX(d,pex);
+ pe.y = YDRAWPIX2WINPIX(d,pey);
setDrawMode( d, dw, lt, dc, dopt );
if (dw == 0)
dw = 1;
- if (r>4096) {
+ /* Windows drawing will overshoot the end of the arc for large radius */
+ if (r > 500) {
/* The book says 32K but experience says otherwise */
fakeArc = TRUE;
}
@@ -459,21 +444,23 @@ void wDrawArc(
fakeArc = TRUE;
}
if ( fakeArc ) {
- cnt = (int)a1;
+ cnt = (int)(a1 / 2);
if ( cnt <= 0 ) cnt = 1;
- if ( cnt > 360 ) cnt = 360;
- aa = a1 / cnt;
- psx = px + r * mswsin(a0);
- psy = py + r * mswcos(a0);
- pp0.x = XINCH2PIX( d, (wPos_t)psx );
- pp0.y = YINCH2PIX( d, (wPos_t)psy );
+ if ( cnt > 180 ) cnt = 180;
+ // Convert a0 and a1 to radians here
+ ai = d2r(a1) / cnt;
+ aa = d2r(a0);
+ psx = px + r * sin(aa);
+ psy = py + r * cos(aa);
+ pp0.x = XDRAWPIX2WINPIX( d, psx );
+ pp0.y = YDRAWPIX2WINPIX( d, psy );
needMoveTo = TRUE;
for ( i=0; i<cnt; i++ ) {
- a0 += aa;
- psx = px + r * mswsin(a0);
- psy = py + r * mswcos(a0);
- pp2.x = pp1.x = XINCH2PIX( d, (wPos_t)psx );
- pp2.y = pp1.y = YINCH2PIX( d, (wPos_t)psy );
+ aa += ai;
+ psx = px + r * sin(aa);
+ psy = py + r * cos(aa);
+ pp2.x = pp1.x = XDRAWPIX2WINPIX( d, psx );
+ pp2.y = pp1.y = YDRAWPIX2WINPIX( d, psy );
if ( clip0( &pp0, &pp1, d ) ) {
if (needMoveTo) {
MoveTo( d->hDc, pp0.x, pp0.y );
@@ -487,30 +474,30 @@ void wDrawArc(
}
} else {
if ( a0 == 0.0 && a1 == 360.0 ) {
- Arc( d->hDc, p0.x, p1.y, p1.x, p0.y, ps.x, p0.y-1, pe.x, p1.y-1 );
- Arc( d->hDc, p0.x, p1.y, p1.x, p0.y, ps.x, p1.y-1, pe.x, p0.y-1 );
+ Arc( d->hDc, p0.x, p1.y, p1.x, p0.y, ps.x, p0.y, pe.x, p1.y );
+ Arc( d->hDc, p0.x, p1.y, p1.x, p0.y, ps.x, p1.y, pe.x, p0.y );
} else {
Arc( d->hDc, p0.x, p1.y, p1.x, p0.y, ps.x, ps.y, pe.x, pe.y );
}
}
// should the center of the arc be drawn?
- if( drawCenter ) {
+ if( sizeCenter ) {
// calculate the center coordinates
- pc.x = XINCH2PIX( d, px );
- pc.y = YINCH2PIX( d, py );
+ pc.x = XDRAWPIX2WINPIX( d, px );
+ pc.y = YDRAWPIX2WINPIX( d, py );
// now draw the crosshair
- MoveTo( d->hDc, pc.x - CENTERMARK_LENGTH/2, pc.y );
- LineTo( d->hDc, pc.x + CENTERMARK_LENGTH/2, pc.y );
- MoveTo( d->hDc, pc.x, pc.y - CENTERMARK_LENGTH/2 );
- LineTo( d->hDc, pc.x, pc.y + CENTERMARK_LENGTH/2 );
+ MoveTo( d->hDc, pc.x - CENTERMARK_LENGTH*sizeCenter, pc.y );
+ LineTo( d->hDc, pc.x + CENTERMARK_LENGTH*sizeCenter, pc.y );
+ MoveTo( d->hDc, pc.x, pc.y - CENTERMARK_LENGTH*sizeCenter );
+ LineTo( d->hDc, pc.x, pc.y + CENTERMARK_LENGTH*sizeCenter );
// invalidate the area of the crosshair
- rect.top = pc.y - CENTERMARK_LENGTH / 2 - 1;
- rect.bottom = pc.y + CENTERMARK_LENGTH / 2 + 1;
- rect.left = pc.x - CENTERMARK_LENGTH / 2 - 1;
- rect.right = pc.x + CENTERMARK_LENGTH / 2 + 1;
+ rect.top = pc.y - CENTERMARK_LENGTH*sizeCenter - 1;
+ rect.bottom = pc.y + CENTERMARK_LENGTH*sizeCenter + 1;
+ rect.left = pc.x - CENTERMARK_LENGTH*sizeCenter - 1;
+ rect.right = pc.x + CENTERMARK_LENGTH*sizeCenter + 1;
myInvalidateRect( d, &rect );
}
@@ -544,16 +531,16 @@ void wDrawArc(
void wDrawPoint(
wDraw_p d,
- wPos_t px,
- wPos_t py,
+ wDrawPix_t px,
+ wDrawPix_t py,
wDrawColor dc,
wDrawOpts dopt )
{
POINT p0;
RECT rect;
- p0.x = XINCH2PIX(d,px);
- p0.y = YINCH2PIX(d,py);
+ p0.x = XDRAWPIX2WINPIX(d,px);
+ p0.y = YDRAWPIX2WINPIX(d,py);
if ( p0.x < 0 || p0.y < 0 )
return;
@@ -707,7 +694,9 @@ void mswFontInit( void )
{
const char * face;
long size;
+ /** @prefs [msw window font] face=FontName */
face = wPrefGetString( "msw window font", "face" );
+ /** @prefs [msw window font] size=-24 */
wPrefGetInteger( "msw window font", "size", &size, -24 );
if (face) {
strncpy( logFont.lfFaceName, face, LF_FACESIZE );
@@ -750,16 +739,16 @@ static int computeFontSize( wDraw_p d, double siz )
}
void wDrawGetTextSize(
- wPos_t *w,
- wPos_t *h,
- wPos_t *d,
- wPos_t *a,
+ wDrawPix_t *w,
+ wDrawPix_t *h,
+ wDrawPix_t *d,
+ wDrawPix_t *a,
wDraw_p bd,
const char * text,
wFont_p fp,
double siz )
{
- int x, y;
+ wWinPix_t x, y;
HFONT newFont, prevFont;
DWORD extent;
int oldLfHeight;
@@ -773,16 +762,16 @@ void wDrawGetTextSize(
fp->lfWidth = 0;
newFont = CreateFontIndirect( fp );
prevFont = SelectObject( bd->hDc, newFont );
- extent = GetTextExtent( bd->hDc, CAST_AWAY_CONST text, strlen(text) );
+ extent = GetTextExtent( bd->hDc, CAST_AWAY_CONST text, (int)(strlen(text)) );
GetTextMetrics(bd->hDc, &textMetric);
x = LOWORD(extent);
y = HIWORD(extent);
- *w = XPIXELSTOINCH( bd, x );
- *h = YPIXELSTOINCH( bd, y );
- *d = YPIXELSTOINCH(bd, textMetric.tmDescent );
- *a = YPIXELSTOINCH(bd, textMetric.tmAscent );
+ *w = (wDrawPix_t)x;
+ *h = (wDrawPix_t)y;
+ *d = (wDrawPix_t)textMetric.tmDescent;
+ *a = (wDrawPix_t)textMetric.tmAscent;
SelectObject( bd->hDc, prevFont );
DeleteObject( newFont );
@@ -803,8 +792,8 @@ void wDrawGetTextSize(
*/
void wDrawString(
wDraw_p d,
- wPos_t px,
- wPos_t py,
+ wDrawPix_t px,
+ wDrawPix_t py,
double angle,
const char * text,
wFont_p fp,
@@ -828,8 +817,8 @@ void wDrawString(
fp->lfHeight = computeFontSize(d, siz);
fp->lfWidth = 0;
newFont = CreateFontIndirect(fp);
- x = XINCH2PIX(d,px) + (int)(mswsin(angle)*fp->lfHeight-0.5);
- y = YINCH2PIX(d,py) + (int)(mswcos(angle)*fp->lfHeight-0.5);
+ x = XDRAWPIX2WINPIX(d,px) + (int)(mswsin(angle)*fp->lfHeight-0.5);
+ y = YDRAWPIX2WINPIX(d,py) + (int)(mswcos(angle)*fp->lfHeight-0.5);
if (noNegDrawArgs > 0 && (x < 0 || y < 0)) {
DeleteObject(newFont);
@@ -843,7 +832,7 @@ void wDrawString(
if (dopts & wDrawOutlineFont) {
HPEN oldPen;
BeginPath(d->hDc);
- TextOut(d->hDc, x, y, text, strlen(text));
+ TextOut(d->hDc, x, y, text, (int)strlen(text));
EndPath(d->hDc);
// Now draw outline text
@@ -857,11 +846,11 @@ void wDrawString(
old = SetTextColor(d->hDc, mswGetColor(d->hasPalette,
dc));
- TextOut(d->hDc, x, y, text, strlen(text));
+ TextOut(d->hDc, x, y, text, (int)(strlen(text)));
SetTextColor(d->hDc, old);
}
- extent = GetTextExtent(d->hDc, CAST_AWAY_CONST text, strlen(text));
+ extent = GetTextExtent(d->hDc, CAST_AWAY_CONST text, (int)(strlen(text)));
SelectObject(d->hDc, prevFont);
w = LOWORD(extent);
h = HIWORD(extent);
@@ -925,10 +914,10 @@ void wSetSelectedFontSize(wFontSize_t size)
void wDrawFilledRectangle(
wDraw_p d,
- wPos_t px,
- wPos_t py,
- wPos_t sx,
- wPos_t sy,
+ wDrawPix_t px,
+ wDrawPix_t py,
+ wDrawPix_t sx,
+ wDrawPix_t sy,
wDrawColor color,
wDrawOpts opts )
{
@@ -944,10 +933,10 @@ void wDrawFilledRectangle(
mode = R2_COPYPEN;
}
SetROP2(d->hDc, mode);
- rect.left = XINCH2PIX(d,px);
- rect.right = XINCH2PIX(d,px+sx);
- rect.top = YINCH2PIX(d,py+sy);
- rect.bottom = YINCH2PIX(d,py);
+ rect.left = XDRAWPIX2WINPIX(d,px);
+ rect.right = XDRAWPIX2WINPIX(d,px+sx);
+ rect.top = YDRAWPIX2WINPIX(d,py+sy);
+ rect.bottom = YDRAWPIX2WINPIX(d,py);
if ( rect.right < 0 ||
rect.bottom < 0 )
return;
@@ -1000,8 +989,8 @@ static void addPoint(
BYTE type, RECT * pr)
{
POINT p;
- p.x = XINCH2PIX(d, pp->x);
- p.y = YINCH2PIX(d, pp->y);
+ p.x = XDRAWPIX2WINPIX(d, pp->x);
+ p.y = YDRAWPIX2WINPIX(d, pp->y);
#ifdef DRAWFILLPOLYLOG
fprintf(logF, " q[%d] = {%d,%d}\n", pk, p.x, p.y);
@@ -1042,7 +1031,7 @@ static void addPoint(
void wDrawPolygon(
wDraw_p d,
- wPos_t node[][2],
+ wDrawPix_t node[][2],
wPolyLine_e type[],
wIndex_t cnt,
wDrawColor color,
@@ -1088,8 +1077,8 @@ void wDrawPolygon(
setDrawMode(d, dw, lt, color, opts);
}
- rect.left = rect.right = XINCH2PIX(d,node[cnt-1][0]-1);
- rect.top = rect.bottom = YINCH2PIX(d,node[cnt-1][1]+1);
+ rect.left = rect.right = XDRAWPIX2WINPIX(d,node[cnt-1][0]-1);
+ rect.top = rect.bottom = YDRAWPIX2WINPIX(d,node[cnt-1][1]+1);
#ifdef DRAWFILLPOLYLOG
logF = fopen("log.txt", "a");
@@ -1110,10 +1099,10 @@ void wDrawPolygon(
nextNode = (i == cnt - 1) ? 0 : i + 1;
// calculate distance to neighboring nodes
- int prevXDistance = node[i][0] - node[prevNode][0];
- int prevYDistance = node[i][1] - node[prevNode][1];
- int nextXDistance = node[nextNode][0]-node[i][0];
- int nextYDistance = node[nextNode][1]-node[i][1];
+ int prevXDistance = (wWinPix_t)(node[i][0] - node[prevNode][0]);
+ int prevYDistance = (wWinPix_t)(node[i][1] - node[prevNode][1]);
+ int nextXDistance = (wWinPix_t)(node[nextNode][0]-node[i][0]);
+ int nextYDistance = (wWinPix_t)(node[nextNode][1]-node[i][1]);
// distance from node to endpoints of curve is half the line length
endPoint0.x = (prevXDistance/2)+node[prevNode][0];
@@ -1202,29 +1191,29 @@ void wDrawPolygon(
#define MAX_FILLCIRCLE_POINTS (30)
void wDrawFilledCircle(
wDraw_p d,
- wPos_t x,
- wPos_t y,
- wPos_t r,
+ wDrawPix_t x,
+ wDrawPix_t y,
+ wDrawPix_t r,
wDrawColor color,
wDrawOpts opts )
{
POINT p0, p1;
RECT rect;
- static wPos_t circlePts[MAX_FILLCIRCLE_POINTS][2];
+ static wDrawPix_t circlePts[MAX_FILLCIRCLE_POINTS][2];
int inx, cnt;
double dang;
- p0.x = XINCH2PIX(d,x-r);
- p0.y = YINCH2PIX(d,y+r)+1;
- p1.x = XINCH2PIX(d,x+r);
- p1.y = YINCH2PIX(d,y-r)+1;
+ p0.x = XDRAWPIX2WINPIX(d,x-r);
+ p0.y = YDRAWPIX2WINPIX(d,y+r);
+ p1.x = XDRAWPIX2WINPIX(d,x+r);
+ p1.y = YDRAWPIX2WINPIX(d,y-r);
setDrawBrush( d, color, opts );
if ( noNegDrawArgs > 0 && ( p0.x < 0 || p0.y < 0 ) ) {
if ( r > MAX_FILLCIRCLE_POINTS )
cnt = MAX_FILLCIRCLE_POINTS;
else if ( r > 8 )
- cnt = r;
+ cnt = XDRAWPIX2WINPIX(d,r);
else
cnt = 8;
dang = 360.0/cnt;
@@ -1308,8 +1297,8 @@ void wDrawClear( wDraw_p d )
void wDrawSetSize(
wDraw_p d,
- wPos_t width,
- wPos_t height, void * redraw)
+ wWinPix_t width,
+ wWinPix_t height, void * redraw)
{
d->w = width;
d->h = height;
@@ -1323,8 +1312,8 @@ void wDrawSetSize(
void wDrawGetSize(
wDraw_p d,
- wPos_t * width,
- wPos_t * height )
+ wWinPix_t * width,
+ wWinPix_t * height )
{
*width = d->w-2;
*height = d->h-2;
@@ -1349,17 +1338,17 @@ double wDrawGetMaxRadius( wDraw_p d )
void wDrawClip(
wDraw_p d,
- wPos_t x,
- wPos_t y,
- wPos_t w,
- wPos_t h )
+ wDrawPix_t x,
+ wDrawPix_t y,
+ wDrawPix_t w,
+ wDrawPix_t h )
{
- int ix0, iy0, ix1, iy1;
+ wWinPix_t ix0, iy0, ix1, iy1;
HRGN hRgnClip;
- ix0 = XINCH2PIX(d,x);
- iy0 = YINCH2PIX(d,y);
- ix1 = XINCH2PIX(d,x+w);
- iy1 = YINCH2PIX(d,y+h);
+ ix0 = XDRAWPIX2WINPIX(d,x);
+ iy0 = YDRAWPIX2WINPIX(d,y);
+ ix1 = XDRAWPIX2WINPIX(d,x+w);
+ iy1 = YDRAWPIX2WINPIX(d,y+h);
/* Note: Ydim is upside down so iy1<iy0 */
hRgnClip = CreateRectRgn( ix0, iy1, ix1, iy0 );
SelectClipRgn( d->hDc, hRgnClip );
@@ -1384,22 +1373,24 @@ void wRedraw( wDraw_p d )
struct wDrawBitMap_t {
wDrawBitMap_p next;
- wPos_t x;
- wPos_t y;
- wPos_t w;
- wPos_t h;
+ wDrawPix_t x;
+ wDrawPix_t y;
+ wDrawPix_t w;
+ wDrawPix_t h;
char * bmx;
wDrawColor color;
HBITMAP bm;
};
-wDrawBitMap_p bmRoot = NULL;
+static wDrawBitMap_p bmRoot = NULL;
+extern wDrawColor drawColorWhite;
+extern wDrawColor drawColorBlack;
void wDrawBitMap(
wDraw_p d,
wDrawBitMap_p bm,
- wPos_t px,
- wPos_t py,
+ wDrawPix_t px,
+ wDrawPix_t py,
wDrawColor dc,
wDrawOpts dopt )
{
@@ -1409,15 +1400,15 @@ void wDrawBitMap(
int x0, y0;
RECT rect;
- x0 = XINCH2PIX(d,px-bm->x);
- y0 = YINCH2PIX(d,py-bm->y+bm->h);
+ x0 = XDRAWPIX2WINPIX(d,px-bm->x);
+ y0 = YDRAWPIX2WINPIX(d,py-bm->y+bm->h);
#ifdef LATER
if ( noNegDrawArgs > 0 && ( x0 < 0 || y0 < 0 ) )
return;
#endif
- if (dc == wDrawColorWhite) {
+ if (dc == drawColorWhite) {
mode = clrOp;
- dc = wDrawColorBlack;
+ dc = drawColorBlack;
} else {
mode = setOp;
}
@@ -1426,21 +1417,21 @@ void wDrawBitMap(
if ( bm->bm )
DeleteObject( bm->bm );
bm->bm = mswCreateBitMap( mswGetColor(d->hasPalette,dc) /*colorPalette.palPalEntry[dc]*/, RGB( 255, 255, 255 ),
- RGB( 255, 255, 255 ), bm->w, bm->h, bm->bmx );
+ RGB( 255, 255, 255 ), (wWinPix_t)bm->w, (wWinPix_t)bm->h, bm->bmx );
bm->color = dc;
}
bmDc = CreateCompatibleDC( d->hDc );
setDrawMode( d, 0, wDrawLineSolid, dc, dopt );
oldBm = SelectObject( bmDc, bm->bm );
- BitBlt( d->hDc, x0, y0, bm->w, bm->h, bmDc, 0, 0, mode );
+ BitBlt( d->hDc, x0, y0, (wWinPix_t)bm->w, (wWinPix_t)bm->h, bmDc, 0, 0, mode );
SelectObject( bmDc, oldBm );
DeleteDC( bmDc );
if (d->hWnd) {
rect.top = y0-1;
- rect.bottom = rect.top+bm->h+1;
+ rect.bottom = rect.top+ (wWinPix_t)bm->h+1;
rect.left = x0-1;
- rect.right = rect.left+bm->w+1;
+ rect.right = rect.left+ (wWinPix_t)bm->w+1;
myInvalidateRect( d, &rect );
}
}
@@ -1484,22 +1475,18 @@ wDrawBitMap_p wDrawBitMapCreate(
*****************************************************************************
*/
-int doSetFocus = 1;
+static int doSetFocus = 1;
-long FAR PASCAL XEXPORT mswDrawPush(
+LRESULT FAR PASCAL XEXPORT mswDrawPush(
HWND hWnd,
UINT message,
- UINT wParam,
- LONG lParam )
+ WPARAM wParam,
+ LPARAM lParam )
{
-#ifdef WIN32
- long inx = GetWindowLong( hWnd, GWL_ID );
-#else
- short inx = GetWindowWord( hWnd, GWW_ID );
-#endif
+ wIndex_t inx = (wIndex_t)GetWindowLongPtr( hWnd, GWL_ID );
wDraw_p b;
- short int ix, iy;
- wPos_t x, y;
+ wWinPix_t ix, iy;
+ wDrawPix_t x, y;
HDC hDc;
PAINTSTRUCT ps;
wAction_t action;
@@ -1529,7 +1516,10 @@ long FAR PASCAL XEXPORT mswDrawPush(
}
b->wFactor = (double)GetDeviceCaps( b->hDc, LOGPIXELSX );
b->hFactor = (double)GetDeviceCaps( b->hDc, LOGPIXELSY );
- b->DPI = 96.0; /*min( b->wFactor, b->hFactor );*/
+ double dpi;
+ /** @prefs [Preference] ScreenDPI=96.0 Sets DPI of screen */
+ wPrefGetFloat(PREFSECTION, DPISET, &dpi, 96.0);
+ b->DPI = dpi;
b->hWnd = hWnd;
SetROP2( b->hDc, R2_WHITE );
Rectangle( b->hDc, 0, 0, b->w, b->h );
@@ -1564,7 +1554,7 @@ long FAR PASCAL XEXPORT mswDrawPush(
b->drawResize( b, b->size );*/
if (b->drawRepaint)
b->drawRepaint( b, b->data, 0, 0 );
- return 0;
+ return (LRESULT)0;
case WM_MOUSEMOVE:
activeWnd = GetActiveWindow();
focusWnd = GetFocus();
@@ -1613,15 +1603,15 @@ long FAR PASCAL XEXPORT mswDrawPush(
}
ix = LOWORD( lParam );
iy = HIWORD( lParam );
- x = XPIX2INCH( b, ix );
- y = YPIX2INCH( b, iy );
+ x = XWINPIX2DRAWPIX( b, ix );
+ y = YWINPIX2DRAWPIX( b, iy );
b->lastX = x;
b->lastY = y;
if (b->action)
b->action( b, b->data, action, x, y );
if (b->hWnd)
UpdateWindow(b->hWnd);
- return 0;
+ return (LRESULT)0;
case WM_CHAR:
b = (wDraw_p)mswMapIndex( inx );
extChar = wAccelKey_None;
@@ -1655,9 +1645,9 @@ long FAR PASCAL XEXPORT mswDrawPush(
if (extChar != wAccelKey_None)
b->action( b, b->data, wActionExtKey + ( (int)extChar << 8 ), b->lastX, b->lastY );
else
- b->action( b, b->data, wActionText + ( wParam << 8 ), b->lastX, b->lastY );
+ b->action( b, b->data, wActionText + ( (int)wParam << 8 ), b->lastX, b->lastY );
}
- return 0;
+ return (LRESULT)0;
case WM_PAINT:
b = (wDraw_p)mswMapIndex( inx );
@@ -1740,7 +1730,7 @@ static LRESULT drawMsgProc( wDraw_p b, HWND hWnd, UINT message, WPARAM wParam, L
}
if (b->action)
b->action( b, b->data, action, b->lastX, b->lastY );
- return 0;
+ return (LRESULT)0;
case WM_MOUSEHWHEEL:
if ( GET_KEYSTATE_WPARAM(wParam) & (MK_SHIFT|MK_MBUTTON)) {
if ( GET_WHEEL_DELTA_WPARAM(wParam) > 0 ) {
@@ -1751,7 +1741,7 @@ static LRESULT drawMsgProc( wDraw_p b, HWND hWnd, UINT message, WPARAM wParam, L
}
if (b->action)
b->action( b, b->data, action, b->lastX, b->lastY );
- return 0;
+ return (LRESULT)0;
}
return DefWindowProc( hWnd, message, wParam, lParam );
@@ -1799,7 +1789,7 @@ static callBacks_t drawCallBacks = {
drawDoneProc,
(messageCallback_p)drawMsgProc };
-wDraw_p drawList = NULL;
+static wDraw_p drawList = NULL;
void mswRedrawAll( void )
@@ -1841,12 +1831,12 @@ void mswRepaintAll( void )
wDraw_p wDrawCreate(
wWin_p parent,
- wPos_t x,
- wPos_t y,
+ wWinPix_t x,
+ wWinPix_t y,
const char * helpStr,
long option,
- wPos_t w,
- wPos_t h,
+ wWinPix_t w,
+ wWinPix_t h,
void * data,
wDrawRedrawCallBack_p redrawProc,
wDrawActionCallBack_p action )
@@ -1872,7 +1862,7 @@ wDraw_p wDrawCreate(
d->hWnd = CreateWindow( mswDrawWindowClassName, NULL,
WS_CHILDWINDOW|WS_VISIBLE|WS_BORDER,
d->x, d->y, w, h,
- ((wControl_p)parent)->hWnd, (HMENU)index, mswHInst, NULL );
+ ((wControl_p)parent)->hWnd, (HMENU)(UINT_PTR)index, mswHInst, NULL );
if (d->hWnd == (HWND)0) {
mswFail( "CreateWindow(DRAW)" );
@@ -1909,7 +1899,7 @@ wDraw_p wDrawCreate(
*****************************************************************************
*/
-wDraw_p wBitMapCreate( wPos_t w, wPos_t h, int planes )
+wDraw_p wBitMapCreate( wWinPix_t w, wWinPix_t h, int planes )
{
wDraw_p d;
HDC hDc;
@@ -1934,11 +1924,13 @@ wDraw_p wBitMapCreate( wPos_t w, wPos_t h, int planes )
d->hBmMain = CreateCompatibleBitmap( hDc, d->w, d->h );
if ( d->hBmMain == (HBITMAP)0 ) {
wNoticeEx( NT_ERROR, "CreateBitMap: CreateBM Main fails", "Ok", NULL );
+ ReleaseDC(mswHWnd, hDc);
return FALSE;
}
d->hBmTemp = CreateCompatibleBitmap( hDc, d->w, d->h );
if ( d->hBmTemp == (HBITMAP)0 ) {
wNoticeEx( NT_ERROR, "CreateBitMap: CreateBM Temp fails", "Ok", NULL );
+ ReleaseDC(mswHWnd, hDc);
return FALSE;
}
d->hasPalette = (GetDeviceCaps(hDc,RASTERCAPS ) & RC_PALETTE) != 0;
@@ -2043,8 +2035,19 @@ wBitMapWriteFile(wDraw_p d, const char * fileName)
}
if (bCanSave) {
- bSuccess = FreeImage_Save(fif, dib2, fileName, PNG_DEFAULT);
- return bSuccess;
+ int flags;
+
+ switch (fif) {
+ case FIF_JPEG:
+ flags = JPEG_QUALITYNORMAL;
+ break;
+ case FIF_PNG:
+ flags = PNG_DEFAULT;
+ break;
+ default:
+ flags = 0; // whatver the default is for the file format
+ }
+ bSuccess = FreeImage_Save(fif, dib2, fileName, flags);
}
}
FreeImage_Unload(dib2);