Genericized the popover code to allow pointing in any direction and at any point. This only affects the shaping; everything else needs to be done now.

This commit is contained in:
Pietro Gagliardi 2014-10-10 11:43:12 -04:00
parent 96895004cd
commit 8a74b95fcf
1 changed files with 99 additions and 18 deletions

View File

@ -39,30 +39,111 @@ void xpanic(char *msg, DWORD err)
#define ARROWHEIGHT 8 #define ARROWHEIGHT 8
#define ARROWWIDTH 8 /* should be the same for smooth lines */ #define ARROWWIDTH 8 /* should be the same for smooth lines */
struct popover {
void *gopopover;
// a nice consequence of this design is that it allows four arrowheads to jut out at once; in practice only one will ever be used, but hey — simple implementation!
LONG arrowLeft;
LONG arrowRight;
LONG arrowTop;
LONG arrowBottom;
};
HRGN makePopoverRegion(HDC dc, LONG width, LONG height) HRGN makePopoverRegion(HDC dc, LONG width, LONG height)
{ {
POINT pt[8]; POINT pt[20];
int n;
HRGN region; HRGN region;
struct popover _p = { NULL, -1, -1, 20, -1 };
struct popover *p = &_p;
LONG xmax, ymax;
if (BeginPath(dc) == 0) if (BeginPath(dc) == 0)
xpanic("error beginning path for Popover shape", GetLastError()); xpanic("error beginning path for Popover shape", GetLastError());
pt[0].x = 0; n = 0;
pt[0].y = ARROWHEIGHT;
pt[1].x = pt[0].x; // figure out the xmax and ymax of the box
pt[1].y = pt[0].y + (height - ARROWHEIGHT); xmax = width;
pt[2].x = pt[1].x + width; if (p->arrowRight >= 0)
pt[2].y = pt[1].y; xmax -= ARROWWIDTH;
pt[3].x = pt[2].x; ymax = height;
pt[3].y = pt[2].y - (height - ARROWHEIGHT); if (p->arrowBottom >= 0)
pt[4].x = pt[3].x - ((width / 2) - ARROWWIDTH); ymax -= ARROWHEIGHT;
pt[4].y = pt[3].y;
pt[5].x = pt[4].x - ARROWWIDTH; // the first point is either at (0,0), (0,arrowHeight), (arrowWidth,0), or (arrowWidth,arrowHeight)
pt[5].y = pt[4].y - ARROWHEIGHT; pt[n].x = 0;
pt[6].x = pt[5].x - ARROWWIDTH; if (p->arrowLeft >= 0)
pt[6].y = pt[5].y + ARROWHEIGHT; pt[n].x = ARROWWIDTH;
pt[7].x = pt[0].x; pt[n].y = 0;
pt[7].y = pt[0].y; if (p->arrowTop >= 0)
if (Polyline(dc, pt, 8) == 0) pt[n].y = ARROWHEIGHT;
n++;
// the left side
pt[n].x = pt[n - 1].x;
if (p->arrowLeft >= 0) {
pt[n].y = pt[n - 1].y + p->arrowLeft;
n++;
pt[n].x = pt[n - 1].x - ARROWWIDTH;
pt[n].y = pt[n - 1].y + ARROWHEIGHT;
n++;
pt[n].x = pt[n - 1].x + ARROWWIDTH;
pt[n].y = pt[n - 1].y + ARROWHEIGHT;
n++;
pt[n].x = pt[n - 1].x;
}
pt[n].y = ymax;
n++;
// the bottom side
pt[n].y = pt[n - 1].y;
if (p->arrowBottom >= 0) {
pt[n].x = pt[n - 1].x + p->arrowBottom;
n++;
pt[n].x = pt[n - 1].x + ARROWWIDTH;
pt[n].y = pt[n - 1].y + ARROWHEIGHT;
n++;
pt[n].x = pt[n - 1].x + ARROWWIDTH;
pt[n].y = pt[n - 1].y - ARROWHEIGHT;
n++;
pt[n].y = pt[n - 1].y;
}
pt[n].x = xmax;
n++;
// the right side
pt[n].x = pt[n - 1].x;
if (p->arrowRight >= 0) {
pt[n].y = pt[0].y + p->arrowRight + (ARROWHEIGHT * 2);
n++;
pt[n].x = pt[n - 1].x + ARROWWIDTH;
pt[n].y = pt[n - 1].y - ARROWHEIGHT;
n++;
pt[n].x = pt[n - 1].x - ARROWWIDTH;
pt[n].y = pt[n - 1].y - ARROWHEIGHT;
n++;
pt[n].x = pt[n - 1].x;
}
pt[n].y = pt[0].y;
n++;
// the top side
pt[n].y = pt[n - 1].y;
if (p->arrowTop >= 0) {
pt[n].x = pt[0].x + p->arrowTop + (ARROWWIDTH * 2);
n++;
pt[n].x = pt[n - 1].x - ARROWWIDTH;
pt[n].y = pt[n - 1].y - ARROWHEIGHT;
n++;
pt[n].x = pt[n - 1].x - ARROWWIDTH;
pt[n].y = pt[n - 1].y + ARROWHEIGHT;
n++;
pt[n].y = pt[n - 1].y;
}
pt[n].x = pt[0].x;
n++;
if (Polyline(dc, pt, n) == 0)
xpanic("error drawing lines in Popover shape", GetLastError()); xpanic("error drawing lines in Popover shape", GetLastError());
if (EndPath(dc) == 0) if (EndPath(dc) == 0)
xpanic("error ending path for Popover shape", GetLastError()); xpanic("error ending path for Popover shape", GetLastError());