Skip to content

Commit

Permalink
Added extra pen style flags for miniwindows
Browse files Browse the repository at this point in the history
  • Loading branch information
nickgammon committed Aug 29, 2010
1 parent cd7549d commit 3de68fa
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 9 deletions.
63 changes: 55 additions & 8 deletions miniwindow.cpp
Expand Up @@ -86,6 +86,29 @@ static int BytesPerLine (int nWidth, int nBitsPerPixel)
return ( (nWidth * nBitsPerPixel + 31) & (~31) ) / 8;
}

// helper function to make normal/geometric pens
// legacy behaviour is to do what we always did
// however if an endcap or join mask bit is on we juse the ExtCreatePen function
static void MakeAPen (CPen & pen, long PenColour, long PenStyle, long PenWidth)
{

// legacy behaviour
if ((PenStyle & PS_ENDCAP_MASK) == 0 &&
(PenStyle & PS_JOIN_MASK) == 0)
{
pen.CreatePen (PenStyle, PenWidth, PenColour);
}
else
{
LOGBRUSH logbrush;
logbrush.lbStyle = BS_SOLID;
logbrush.lbColor = PenColour;
logbrush.lbHatch = 0; // not applicable

pen.Attach (::ExtCreatePen (PenStyle | PS_GEOMETRIC, PenWidth, &logbrush, 0, NULL));
}
} // end of MakeAPen

// a negative or zero value for the bottom of a rectange is considered offset from the bottom edge
long CMiniWindow::FixBottom (const long Bottom)
{
Expand Down Expand Up @@ -308,7 +331,7 @@ long CMiniWindow::RectOp (short Action, long Left, long Top, long Right, long B
static long ValidatePenStyle (const long PenStyle, const long PenWidth)
{

switch (PenStyle)
switch (PenStyle & PS_STYLE_MASK)
{
// must be one of these flags
case PS_SOLID: // 0
Expand All @@ -327,6 +350,28 @@ static long ValidatePenStyle (const long PenStyle, const long PenWidth)
default: return ePenStyleNotValid;
}

switch (PenStyle & PS_ENDCAP_MASK)
{
// must be one of these flags
case PS_ENDCAP_ROUND: // 0x000
case PS_ENDCAP_SQUARE: // 0x100
case PS_ENDCAP_FLAT: // 0x200
break;

default: return ePenStyleNotValid;
}

switch (PenStyle & PS_JOIN_MASK)
{
// must be one of these flags
case PS_JOIN_ROUND: // 0x0000
case PS_JOIN_BEVEL: // 0x1000
case PS_JOIN_MITER: // 0x2000
break;

default: return ePenStyleNotValid;
}

return eOK;
}

Expand Down Expand Up @@ -476,8 +521,8 @@ long CMiniWindow::CircleOp (short Action,

// create requested pen
CPen pen;
pen.CreatePen (PenStyle, PenWidth, PenColour);
MakeAPen (pen, PenColour, PenStyle, PenWidth);

// select into DC
CPen* oldPen = dc.SelectObject(&pen);
CBrush* oldBrush = dc.SelectObject(&br);
Expand Down Expand Up @@ -885,7 +930,8 @@ long CMiniWindow::Line (long x1, long y1, long x2, long y2,

// create requested pen
CPen pen;
pen.CreatePen (PenStyle, PenWidth, PenColour);
MakeAPen (pen, PenColour, PenStyle, PenWidth);

CPen* oldPen = dc.SelectObject(&pen);

dc.MoveTo (x1, y1);
Expand Down Expand Up @@ -913,7 +959,8 @@ long CMiniWindow::Arc (long Left, long Top, long Right, long Bottom,

// create requested pen
CPen pen;
pen.CreatePen (PenStyle, PenWidth, PenColour);
MakeAPen (pen, PenColour, PenStyle, PenWidth);

CPen* oldPen = dc.SelectObject(&pen);

dc.Arc(Left, Top, FixRight (Right), FixBottom (Bottom),
Expand Down Expand Up @@ -1480,7 +1527,7 @@ long CMiniWindow::Bezier(LPCTSTR Points, long PenColour, long PenStyle, long Pen

// create requested pen
CPen pen;
pen.CreatePen (PenStyle, PenWidth, PenColour);
MakeAPen (pen, PenColour, PenStyle, PenWidth);
CPen* oldPen = dc.SelectObject(&pen);

dc.PolyBezier(&points [0], iCount);
Expand Down Expand Up @@ -1545,7 +1592,7 @@ long CMiniWindow::Polygon(LPCTSTR Points,

// create requested pen
CPen pen;
pen.CreatePen (PenStyle, PenWidth, PenColour);
MakeAPen (pen, PenColour, PenStyle, PenWidth);

// select pen and brush into device context
CPen* oldPen = dc.SelectObject(&pen);
Expand Down Expand Up @@ -1836,7 +1883,7 @@ long CMiniWindow::ImageOp(short Action,

// create requested pen
CPen pen;
pen.CreatePen (PenStyle, PenWidth, PenColour);
MakeAPen (pen, PenColour, PenStyle, PenWidth);

// select into DC
CPen* oldPen = dc.SelectObject(&pen);
Expand Down
12 changes: 11 additions & 1 deletion scripting/lua_methods.cpp
Expand Up @@ -7173,14 +7173,24 @@ static flags_pair miniwindow_flags [] =

// pen styles for drawing shapes

{ "pen_solid", PS_SOLID }, // solid pen
{ "pen_solid", PS_SOLID }, // solid pen (0)
{ "pen_dash", PS_DASH }, // -------
{ "pen_dot", PS_DOT }, // .......
{ "pen_dash_dot", PS_DASHDOT }, // _._._._
{ "pen_dash_dot_dot", PS_DASHDOTDOT }, // _.._.._
{ "pen_null", PS_NULL }, // no pen
{ "pen_inside_frame", PS_INSIDEFRAME }, // solid, inside the shape

// end style ('OR' in one of these)
{ "pen_endcap_round", PS_ENDCAP_ROUND }, // rounded ends (default)
{ "pen_endcap_square",PS_ENDCAP_SQUARE }, // square ends
{ "pen_endcap_flat", PS_ENDCAP_FLAT }, // flat end (does not extend past end)

// join style ('OR' in one of these)
{ "pen_join_round", PS_JOIN_ROUND }, // rounded join (default)
{ "pen_join_bevel", PS_JOIN_BEVEL }, // bevelled join
{ "pen_join_miter", PS_JOIN_MITER }, // mitered join

// brush styles for drawing shapes

{ "brush_solid", 0 },
Expand Down

0 comments on commit 3de68fa

Please sign in to comment.