From fa68e23c37c1a68bf3fcc7d344057a170fa83df3 Mon Sep 17 00:00:00 2001 From: Matthew Flatt Date: Wed, 21 Jul 2010 15:49:18 -0600 Subject: [PATCH] add pen and cap support to pen-list% --- collects/scribblings/gui/pen-list-class.scrbl | 11 ++++-- src/gracket/wxs/wxs_gdi.cxx | 34 +++++++++++++++---- src/gracket/wxs/wxs_gdi.xc | 4 +-- src/wxmac/include/base/wb_gdi.h | 4 +-- src/wxmac/src/base/wb_gdi.cc | 10 ++++-- src/wxwindow/include/base/wb_gdi.h | 4 +-- src/wxwindow/src/base/wb_gdi.cxx | 13 ++++--- src/wxxt/src/GDI-Classes/Pen+Brush.cc | 10 ++++-- src/wxxt/src/GDI-Classes/Pen+Brush.h | 4 +-- 9 files changed, 66 insertions(+), 28 deletions(-) diff --git a/collects/scribblings/gui/pen-list-class.scrbl b/collects/scribblings/gui/pen-list-class.scrbl index 86380b2397..6cb46596cb 100644 --- a/collects/scribblings/gui/pen-list-class.scrbl +++ b/collects/scribblings/gui/pen-list-class.scrbl @@ -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]. diff --git a/src/gracket/wxs/wxs_gdi.cxx b/src/gracket/wxs/wxs_gdi.cxx index d8b04b72ff..ee3b6d0486 100644 --- a/src/gracket/wxs/wxs_gdi.cxx +++ b/src/gracket/wxs/wxs_gdi.cxx @@ -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)); diff --git a/src/gracket/wxs/wxs_gdi.xc b/src/gracket/wxs/wxs_gdi.xc index 3179b43e20..cfaea1883b 100644 --- a/src/gracket/wxs/wxs_gdi.xc +++ b/src/gracket/wxs/wxs_gdi.xc @@ -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 diff --git a/src/wxmac/include/base/wb_gdi.h b/src/wxmac/include/base/wb_gdi.h index e3637d01d0..3e1189ea1e 100644 --- a/src/wxmac/include/base/wb_gdi.h +++ b/src/wxmac/include/base/wb_gdi.h @@ -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 diff --git a/src/wxmac/src/base/wb_gdi.cc b/src/wxmac/src/base/wb_gdi.cc index 8ef201cebb..c86a58a44c 100644 --- a/src/wxmac/src/base/wb_gdi.cc +++ b/src/wxmac/src/base/wb_gdi.cc @@ -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; } diff --git a/src/wxwindow/include/base/wb_gdi.h b/src/wxwindow/include/base/wb_gdi.h index 74cd93bdc4..3bed83ca4f 100644 --- a/src/wxwindow/include/base/wb_gdi.h +++ b/src/wxwindow/include/base/wb_gdi.h @@ -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 diff --git a/src/wxwindow/src/base/wb_gdi.cxx b/src/wxwindow/src/base/wb_gdi.cxx index e5d08e1f05..b0e5203b01 100644 --- a/src/wxwindow/src/base/wb_gdi.cxx +++ b/src/wxwindow/src/base/wb_gdi.cxx @@ -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; } diff --git a/src/wxxt/src/GDI-Classes/Pen+Brush.cc b/src/wxxt/src/GDI-Classes/Pen+Brush.cc index 4eb6e80f87..f4184ced2a 100644 --- a/src/wxxt/src/GDI-Classes/Pen+Brush.cc +++ b/src/wxxt/src/GDI-Classes/Pen+Brush.cc @@ -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; } diff --git a/src/wxxt/src/GDI-Classes/Pen+Brush.h b/src/wxxt/src/GDI-Classes/Pen+Brush.h index a49aa89cd2..d6a359f04c 100644 --- a/src/wxxt/src/GDI-Classes/Pen+Brush.h +++ b/src/wxxt/src/GDI-Classes/Pen+Brush.h @@ -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