From 7b358424ebad9349421acd533c2fa1cbf6cf3e3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rg=20Frings-F=C3=BCrst?= Date: Wed, 28 Dec 2016 16:52:56 +0100 Subject: Initial import of xtrkcad version 1:4.0.2-2 --- app/wlib/mswlib/mswlines.c | 98 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 app/wlib/mswlib/mswlines.c (limited to 'app/wlib/mswlib/mswlines.c') diff --git a/app/wlib/mswlib/mswlines.c b/app/wlib/mswlib/mswlines.c new file mode 100644 index 0000000..be1330d --- /dev/null +++ b/app/wlib/mswlib/mswlines.c @@ -0,0 +1,98 @@ +#include +#include +#include +#include +#include +#include +#include "mswint.h" + +/* + ***************************************************************************** + * + * Lines + * + ***************************************************************************** + */ + +struct wLine_t { + WOBJ_COMMON + int count; + wLines_t * lines; + }; + +static void repaintLines( HWND hWnd, wControl_p b ) +{ + int lastWidth; + HDC hDc; + wLine_p bl = (wLine_p)(b); + wLines_p lp; + HPEN oldPen, newPen; + + lastWidth = -1; + hDc = GetDC( hWnd ); + for (lp=bl->lines; lp<&bl->lines[bl->count]; lp++) { + if (lastWidth != lp->width) { + lastWidth = lp->width; + newPen = CreatePen( PS_SOLID, lastWidth, RGB(0,0,0) ); + oldPen = SelectObject( hDc, newPen ); + DeleteObject( oldPen ); + } + MoveTo( hDc, lp->x0, lp->y0 ); + LineTo( hDc, lp->x1, lp->y1 ); + } + ReleaseDC( hWnd, hDc ); +} + + +static callBacks_t linesCallBacks = { + repaintLines, + NULL, + NULL }; + + +wLine_p wLineCreate( + wWin_p parent, + const char * labelStr, + int count, + wLines_t * lines ) +{ + wLine_p b; + wLines_p lp; + POS_T minX, maxX, minY, maxY; + int index; + + if (count <= 0) + return NULL; + b = (wLine_p)mswAlloc( parent, B_LINES, labelStr, sizeof *b, NULL, &index ); + b->count = count; + b->lines = lines; + + lp = lines; + minX = maxX = lp->x0; + minY = maxY = lp->y0; + for (lp=lines; lp<&b->lines[count]; lp++) { + if (minX > lp->x0) + minX = lp->x0; + if (maxX < lp->x0) + maxX = lp->x0; + if (minY > lp->y0) + minY = lp->y0; + if (maxY < lp->y0) + maxY = lp->y0; + if (minX > lp->x1) + minX = lp->x1; + if (maxX < lp->x1) + maxX = lp->x1; + if (minY > lp->y1) + minY = lp->y1; + if (maxY < lp->y1) + maxY = lp->y1; + } + b->x = minX; + b->y = minY; + b->w = maxX-minX; + b->h = maxY-minY; + mswAddButton( (wControl_p)b, FALSE, NULL ); + mswCallBacks[B_LINES] = &linesCallBacks; + return b; +} -- cgit v1.2.3