add pen and cap support to pen-list%

This commit is contained in:
Matthew Flatt 2010-07-21 15:49:18 -06:00
parent 90ec44f65c
commit fa68e23c37
9 changed files with 66 additions and 28 deletions

View File

@ -25,19 +25,24 @@ Creates an empty pen list.
[style (one-of/c 'transparent 'solid 'xor 'hilite
'dot 'long-dash 'short-dash 'dot-dash
'xor-dot 'xor-long-dash 'xor-short-dash
'xor-dot-dash)])
'xor-dot-dash)]
[cap (one-of/c 'round 'projecting 'butt) 'round]
[join (one-of/c 'round 'bevel 'miter) 'round])
(is-a?/c pen%)]
[(find-or-create-pen [color-name string?]
[width (real-in 0 255)]
[style (one-of/c 'transparent 'solid 'xor 'hilite
'dot 'long-dash 'short-dash 'dot-dash
'xor-dot 'xor-long-dash 'xor-short-dash
'xor-dot-dash)])
'xor-dot-dash)]
[cap (one-of/c 'round 'projecting 'butt) 'round]
[join (one-of/c 'round 'bevel 'miter) 'round])
(or/c (is-a?/c pen%) false/c)])]{
Finds a pen of the given specification, or creates one and adds it to
the list. The arguments are the same as for creating a @scheme[pen%]
instance. When @scheme[color-name] is provided, however, the return
instance plus a cap and join style as for @method[pen% set-cap] and
@method[pen% set-join]. When @scheme[color-name] is provided, however, the return
value is @scheme[#f] when no color matching @scheme[color-name] can be
found in @scheme[the-color-database].

View File

@ -3235,6 +3235,8 @@ static Scheme_Object *os_wxPenListFindOrCreatePen(int n, Scheme_Object *p[])
class wxColour* x0 INIT_NULLED_OUT;
double x1;
int x2;
int x3;
int x4;
SETUP_VAR_STACK_PRE_REMEMBERED(3);
VAR_STACK_PUSH(0, p);
@ -3242,14 +3244,22 @@ static Scheme_Object *os_wxPenListFindOrCreatePen(int n, Scheme_Object *p[])
VAR_STACK_PUSH(2, x0);
if (n != (POFFSET+3))
WITH_VAR_STACK(scheme_wrong_count_m("find-or-create-pen in pen-list% (color% case)", POFFSET+3, POFFSET+3, n, p, 1));
if ((n < (POFFSET+3)) || (n > (POFFSET+5)))
WITH_VAR_STACK(scheme_wrong_count_m("find-or-create-pen in pen-list% (color% case)", POFFSET+3, POFFSET+5, n, p, 1));
x0 = WITH_VAR_STACK(objscheme_unbundle_wxColour(p[POFFSET+0], "find-or-create-pen in pen-list% (color% case)", 0));
x1 = WITH_VAR_STACK(objscheme_unbundle_double_in(p[POFFSET+1], 0, 255, "find-or-create-pen in pen-list% (color% case)"));
x2 = WITH_VAR_STACK(unbundle_symset_penStyle(p[POFFSET+2], "find-or-create-pen in pen-list% (color% case)"));
if (n > (POFFSET+3)) {
x3 = WITH_VAR_STACK(unbundle_symset_cap(p[POFFSET+3], "find-or-create-pen in pen-list% (color% case)"));
} else
x3 = wxCAP_ROUND;
if (n > (POFFSET+4)) {
x4 = WITH_VAR_STACK(unbundle_symset_join(p[POFFSET+4], "find-or-create-pen in pen-list% (color% case)"));
} else
x4 = wxJOIN_ROUND;
r = WITH_VAR_STACK(((wxPenList *)((Scheme_Class_Object *)p[0])->primdata)->FindOrCreatePen(x0, x1, x2));
r = WITH_VAR_STACK(((wxPenList *)((Scheme_Class_Object *)p[0])->primdata)->FindOrCreatePen(x0, x1, x2, x3, x4));
@ -3258,6 +3268,8 @@ static Scheme_Object *os_wxPenListFindOrCreatePen(int n, Scheme_Object *p[])
string x0 INIT_NULLED_OUT;
double x1;
int x2;
int x3;
int x4;
SETUP_VAR_STACK_PRE_REMEMBERED(3);
VAR_STACK_PUSH(0, p);
@ -3265,14 +3277,22 @@ static Scheme_Object *os_wxPenListFindOrCreatePen(int n, Scheme_Object *p[])
VAR_STACK_PUSH(2, x0);
if (n != (POFFSET+3))
WITH_VAR_STACK(scheme_wrong_count_m("find-or-create-pen in pen-list% (color name case)", POFFSET+3, POFFSET+3, n, p, 1));
if ((n < (POFFSET+3)) || (n > (POFFSET+5)))
WITH_VAR_STACK(scheme_wrong_count_m("find-or-create-pen in pen-list% (color name case)", POFFSET+3, POFFSET+5, n, p, 1));
x0 = (string)WITH_VAR_STACK(objscheme_unbundle_string(p[POFFSET+0], "find-or-create-pen in pen-list% (color name case)"));
x1 = WITH_VAR_STACK(objscheme_unbundle_double_in(p[POFFSET+1], 0, 255, "find-or-create-pen in pen-list% (color name case)"));
x2 = WITH_VAR_STACK(unbundle_symset_penStyle(p[POFFSET+2], "find-or-create-pen in pen-list% (color name case)"));
if (n > (POFFSET+3)) {
x3 = WITH_VAR_STACK(unbundle_symset_cap(p[POFFSET+3], "find-or-create-pen in pen-list% (color name case)"));
} else
x3 = wxCAP_ROUND;
if (n > (POFFSET+4)) {
x4 = WITH_VAR_STACK(unbundle_symset_join(p[POFFSET+4], "find-or-create-pen in pen-list% (color name case)"));
} else
x4 = wxJOIN_ROUND;
r = WITH_VAR_STACK(((wxPenList *)((Scheme_Class_Object *)p[0])->primdata)->FindOrCreatePen(x0, x1, x2));
r = WITH_VAR_STACK(((wxPenList *)((Scheme_Class_Object *)p[0])->primdata)->FindOrCreatePen(x0, x1, x2, x3, x4));
@ -3321,7 +3341,7 @@ void objscheme_setup_wxPenList(Scheme_Env *env)
os_wxPenList_class = WITH_VAR_STACK(objscheme_def_prim_class(env, "pen-list%", "object%", (Scheme_Method_Prim *)os_wxPenList_ConstructScheme, 1));
WITH_VAR_STACK(scheme_add_method_w_arity(os_wxPenList_class, "find-or-create-pen" " method", (Scheme_Method_Prim *)os_wxPenListFindOrCreatePen, 3, 3));
WITH_VAR_STACK(scheme_add_method_w_arity(os_wxPenList_class, "find-or-create-pen" " method", (Scheme_Method_Prim *)os_wxPenListFindOrCreatePen, 3, 5));
WITH_VAR_STACK(scheme_made_class(os_wxPenList_class));

View File

@ -202,8 +202,8 @@
@CREATOR ();
@ "find-or-create-pen" : wxPen! FindOrCreatePen(wxColour!,rdouble[0|255],SYM[penStyle]); <> color%
@ "find-or-create-pen" : wxPen^ FindOrCreatePen(string,rdouble[0|255],SYM[penStyle]); <> color name
@ "find-or-create-pen" : wxPen! FindOrCreatePen(wxColour!,rdouble[0|255],SYM[penStyle],SYM[cap]=wxCAP_ROUND,SYM[join]=wxJOIN_ROUND); <> color%
@ "find-or-create-pen" : wxPen^ FindOrCreatePen(string,rdouble[0|255],SYM[penStyle],SYM[cap]=wxCAP_ROUND,SYM[join]=wxJOIN_ROUND); <> color name
@END

View File

@ -274,8 +274,8 @@ class wxPenList: public wxObject
wxPenList(void);
~wxPenList(void);
void AddPen(wxPen *pen);
wxPen *FindOrCreatePen(wxColour *colour, double width, int style);
wxPen *FindOrCreatePen(char *colour, double width, int style);
wxPen *FindOrCreatePen(wxColour *colour, double width, int style, int cap = wxCAP_ROUND, int join = wxJOIN_ROUND);
wxPen *FindOrCreatePen(char *colour, double width, int style, int cap = wxCAP_ROUND, int join = wxJOIN_ROUND);
};
class wxBrushList: public wxObject

View File

@ -644,7 +644,7 @@ void wxPenList::AddPen (wxPen * pen)
pen->Lock(1);
}
wxPen *wxPenList::FindOrCreatePen (wxColour * colour, double width, int style)
wxPen *wxPenList::FindOrCreatePen (wxColour * colour, double width, int style, int cap, int join)
{
wxPen *pen;
wxChildNode *node;
@ -661,6 +661,8 @@ wxPen *wxPenList::FindOrCreatePen (wxColour * colour, double width, int style)
c = each_pen->GetColour();
if (each_pen->GetWidthF() == width &&
each_pen->GetStyle() == style &&
each_pen->GetCap() == cap &&
each_pen->GetJoin() == join &&
c->Red () == colour->Red () &&
c->Green () == colour->Green () &&
c->Blue () == colour->Blue ())
@ -668,16 +670,18 @@ wxPen *wxPenList::FindOrCreatePen (wxColour * colour, double width, int style)
}
}
pen = new WXGC_PTRS wxPen (colour, width, style);
if (cap != wxCAP_ROUND) pen->SetCap(cap);
if (join != wxJOIN_ROUND) pen->SetJoin(join);
AddPen(pen);
return pen;
}
wxPen *wxPenList::FindOrCreatePen (char *colour, double width, int style)
wxPen *wxPenList::FindOrCreatePen (char *colour, double width, int style, int cap, int join)
{
wxColour *the_colour;
the_colour = wxTheColourDatabase->FindColour(colour);
if (the_colour)
return FindOrCreatePen (the_colour, width, style);
return FindOrCreatePen (the_colour, width, style, cap, join);
else
return NULL;
}

View File

@ -262,8 +262,8 @@ class wxPenList: public wxObject
wxPenList(void);
~wxPenList(void);
void AddPen(wxPen *pen);
wxPen *FindOrCreatePen(wxColour *colour, double width, int style);
wxPen *FindOrCreatePen(char *colour, double width, int style);
wxPen *FindOrCreatePen(wxColour *colour, double width, int style, int cap = wxCAP_ROUND, int join = wxJOIN_ROUND);
wxPen *FindOrCreatePen(char *colour, double width, int style, int cap = wxCAP_ROUND, int join = wxJOIN_ROUND);
};
class wxBrushList: public wxObject

View File

@ -511,7 +511,7 @@ void wxPenList::AddPen (wxPen * pen)
list->Show(pen, -1); /* so it can be collected */
}
wxPen *wxPenList::FindOrCreatePen (wxColour * colour, double width, int style)
wxPen *wxPenList::FindOrCreatePen (wxColour * colour, double width, int style, int cap, int join)
{
wxPen *pen;
int i = 0;
@ -525,7 +525,9 @@ wxPen *wxPenList::FindOrCreatePen (wxColour * colour, double width, int style)
each_pen = (wxPen *) node->Data ();
if (each_pen &&
each_pen->GetWidthF() == width &&
each_pen->GetStyle() == style) {
each_pen->GetStyle() == style &&
each_pen->GetCap() == cap &&
each_pen->GetJoin() == join) {
wxColour *col;
col = each_pen->GetColour();
if (col->Red () == colour->Red () &&
@ -537,6 +539,9 @@ wxPen *wxPenList::FindOrCreatePen (wxColour * colour, double width, int style)
}
pen = new wxPen (colour, width, style, FALSE);
if (cap != wxCAP_ROUND) pen->SetCap(cap);
if (join != wxJOIN_ROUND) pen->SetJoin(join);
pen->Lock(1);
AddPen(pen);
@ -544,12 +549,12 @@ wxPen *wxPenList::FindOrCreatePen (wxColour * colour, double width, int style)
return pen;
}
wxPen *wxPenList::FindOrCreatePen (char *colour, double width, int style)
wxPen *wxPenList::FindOrCreatePen (char *colour, double width, int style, int cap, int join)
{
wxColour *the_colour;
the_colour = wxTheColourDatabase->FindColour (colour);
if (the_colour)
return FindOrCreatePen (the_colour, width, style);
return FindOrCreatePen (the_colour, width, style, cap, join);
else
return NULL;
}

View File

@ -204,7 +204,7 @@ void wxPenList::AddPen(wxPen *Pen)
list->Show(Pen, -1); /* so it can be collected */
}
wxPen *wxPenList::FindOrCreatePen(wxColour *colour, double w, int style)
wxPen *wxPenList::FindOrCreatePen(wxColour *colour, double w, int style, int cap, int join)
{
wxPen *pen;
wxChildNode *node;
@ -221,6 +221,8 @@ wxPen *wxPenList::FindOrCreatePen(wxColour *colour, double w, int style)
if (each_pen &&
each_pen->GetWidthF() == w &&
each_pen->GetStyle() == style &&
each_pen->GetCap() == cap &&
each_pen->GetJoin() == join &&
pc->Red() == colour->Red() &&
pc->Green() == colour->Green() &&
pc->Blue() == colour->Blue())
@ -228,18 +230,20 @@ wxPen *wxPenList::FindOrCreatePen(wxColour *colour, double w, int style)
}
pen = new wxPen(colour, w, style);
if (cap != wxCAP_ROUND) pen->SetCap(cap);
if (join != wxJOIN_ROUND) pen->SetJoin(join);
pen->Lock(1);
AddPen(pen);
return pen;
}
wxPen *wxPenList::FindOrCreatePen(char *colour, double width, int style)
wxPen *wxPenList::FindOrCreatePen(char *colour, double width, int style, int cap, int join)
{
wxColour *the_colour;
the_colour = wxTheColourDatabase->FindColour(colour);
if (the_colour)
return FindOrCreatePen(the_colour, width, style);
return FindOrCreatePen(the_colour, width, style, cap, join);
return NULL;
}

View File

@ -121,8 +121,8 @@ public:
~wxPenList(void);
void AddPen(wxPen *pen);
wxPen *FindOrCreatePen(wxColour *colour, double width, int style);
wxPen *FindOrCreatePen(char *colour, double width, int style);
wxPen *FindOrCreatePen(wxColour *colour, double width, int style, int cap = wxCAP_ROUND, int join = wxJOIN_ROUND);
wxPen *FindOrCreatePen(char *colour, double width, int style, int cap = wxCAP_ROUND, int join = wxJOIN_ROUND);
};
#endif // PenBrush_h