Back to index

plt-scheme  4.2.1
Pen+Brush.cc
Go to the documentation of this file.
00001 /*                                                      -*- C++ -*-
00002  *
00003  * Purpose: pen and brush classes needed for drawing
00004  *
00005  * Authors: Markus Holzem and Julian Smart
00006  *
00007  * Copyright: (C) 2004-2009 PLT Scheme Inc.
00008  * Copyright: (C) 1995, AIAI, University of Edinburgh (Julian)
00009  * Copyright: (C) 1995, GNU (Markus)
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00024  * 02110-1301 USA.
00025  */
00026 
00027 #ifdef __GNUG__
00028 #pragma implementation "Pen+Brush.h"
00029 #pragma implementation "Region.h"
00030 #endif
00031 
00032 #define  Uses_XLib
00033 #define  Uses_wxPenBrush
00034 #define  Uses_wxBitmap
00035 #define  Uses_wxPostScriptDC
00036 #include "wx.h"
00037 
00038 #include "../wx_cairo.h"
00039 
00040 #include <math.h>
00041 
00042 //-----------------------------------------------------------------------------
00043 // wxPen create and destroy
00044 //-----------------------------------------------------------------------------
00045 
00046 wxPen::wxPen(void)
00047 {
00048     wxColour *c;
00049 
00050     __type = wxTYPE_PEN;
00051 
00052     stipple = NULL;
00053     c = new wxColour(wxBLACK);
00054     c->Lock(1);
00055     colour  = c;
00056     style   = wxSOLID;
00057     join    = wxJOIN_ROUND;
00058     cap     = wxCAP_ROUND;
00059     nb_dash = 0;
00060     dash    = NULL;
00061     width   = 1;
00062     locked = 0;
00063 }
00064 
00065 wxPen::wxPen(wxColour *col, double Width, int Style)
00066 {
00067     wxColour *c;
00068 
00069     __type = wxTYPE_PEN;
00070 
00071     c = new wxColour(col);
00072     c->Lock(1);
00073     colour  = c;
00074     width   = Width;
00075     style   = Style;
00076     stipple = NULL;
00077     join    = wxJOIN_ROUND;
00078     cap     = wxCAP_ROUND;
00079     nb_dash = 0;
00080     dash    = NULL;
00081     locked = 0;
00082 }
00083 
00084 wxPen::wxPen(const char *col, double Width, int Style)
00085 {
00086     wxColour *c;
00087 
00088     __type = wxTYPE_PEN;
00089 
00090     c = new wxColour(col);
00091     c->Lock(1);
00092     colour  = c;
00093     width   = Width;
00094     style   = Style;
00095     stipple = NULL;
00096     join    = wxJOIN_ROUND;
00097     cap     = wxCAP_ROUND;
00098     nb_dash = 0;
00099     dash    = NULL;
00100     locked = 0;
00101 }
00102 
00103 wxPen::~wxPen(void)
00104 {
00105   if (stipple)
00106     --stipple->selectedIntoDC;
00107 }
00108 
00109 void wxPen::SetStipple(wxBitmap *s)
00110 {
00111   if (s && (!s->Ok() || (s->selectedIntoDC < 0)))
00112     return;
00113 
00114   if (s)
00115     s->selectedIntoDC++;
00116   if (stipple)
00117     --stipple->selectedIntoDC;
00118 
00119   stipple = s;
00120 }
00121 
00122 //-----------------------------------------------------------------------------
00123 // wxBrush
00124 //-----------------------------------------------------------------------------
00125 
00126 wxBrush::wxBrush(void)
00127 {
00128     wxColour *c;
00129 
00130     __type = wxTYPE_BRUSH;
00131 
00132     c = new wxColour(wxWHITE);
00133     c->Lock(1);
00134     colour  = c;
00135     stipple = NULL;
00136     style   = wxSOLID;
00137     locked  = 0;
00138 }
00139 
00140 wxBrush::wxBrush(wxColour *col, int Style)
00141 {
00142     wxColour *c;
00143 
00144     __type = wxTYPE_BRUSH;
00145 
00146     c = new wxColour(col);
00147     c->Lock(1);
00148     colour  = c;
00149     style   = Style;
00150     stipple = NULL;
00151     locked  = 0;
00152 }
00153 
00154 wxBrush::wxBrush(const char *col, int Style)
00155 {
00156     wxColour *c;
00157 
00158     __type = wxTYPE_BRUSH;
00159 
00160     c = new wxColour(col);
00161     c->Lock(1);
00162     colour  = c;
00163     style   = Style;
00164     stipple = NULL;
00165     locked  = 0;
00166 }
00167 
00168 wxBrush::~wxBrush(void)
00169 {
00170   if (stipple)
00171     --stipple->selectedIntoDC;
00172 }
00173 
00174 void wxBrush::SetStipple(wxBitmap *s)
00175 {
00176   if (s && (!s->Ok() || (s->selectedIntoDC < 0)))
00177     return;
00178 
00179   if (s)
00180     s->selectedIntoDC++;
00181   if (stipple)
00182     --stipple->selectedIntoDC;
00183 
00184   stipple = s;
00185 }
00186 
00187 //-----------------------------------------------------------------------------
00188 // wxPenList
00189 //-----------------------------------------------------------------------------
00190 
00191 wxPenList::wxPenList(void)
00192 : wxObject(WXGC_NO_CLEANUP)
00193 {
00194   list = new wxChildList;
00195 }
00196 
00197 wxPenList::~wxPenList(void)
00198 {
00199 }
00200 
00201 void wxPenList::AddPen(wxPen *Pen) 
00202 { 
00203   list->Append(Pen); 
00204   list->Show(Pen, -1); /* so it can be collected */
00205 } 
00206 
00207 wxPen *wxPenList::FindOrCreatePen(wxColour *colour, double w, int style)
00208 {
00209   wxPen *pen;
00210   wxChildNode *node;
00211   int i = 0;
00212   
00213   if (!colour)
00214     return NULL;
00215   
00216   while ((node = list->NextNode(i))) {
00217     wxPen *each_pen;
00218     wxColour *pc;
00219     each_pen = (wxPen*)node->Data();
00220     pc = each_pen->GetColour();
00221     if (each_pen &&
00222        each_pen->GetWidthF() == w &&
00223        each_pen->GetStyle() == style &&
00224        pc->Red() == colour->Red() &&
00225        pc->Green() == colour->Green() &&
00226        pc->Blue() == colour->Blue())
00227       return each_pen;
00228   }
00229   
00230   pen = new wxPen(colour, w, style);
00231   pen->Lock(1);
00232   AddPen(pen);
00233   
00234   return pen;
00235 }
00236 
00237 wxPen *wxPenList::FindOrCreatePen(char *colour, double width, int style)
00238 {
00239   wxColour *the_colour;
00240   the_colour = wxTheColourDatabase->FindColour(colour);
00241   if (the_colour)
00242     return FindOrCreatePen(the_colour, width, style);
00243   return NULL;
00244 }
00245 
00246 //-----------------------------------------------------------------------------
00247 // wxBrushList
00248 //-----------------------------------------------------------------------------
00249 
00250 wxBrushList::wxBrushList(void)
00251 : wxObject(WXGC_NO_CLEANUP)
00252 {
00253   list = new wxChildList;
00254 }
00255 
00256 wxBrushList::~wxBrushList(void)
00257 {
00258 }
00259 
00260 void wxBrushList::AddBrush(wxBrush *Brush) 
00261 { 
00262   list->Append(Brush); 
00263   list->Show(Brush, -1); /* so it can be collected */
00264 } 
00265 
00266 wxBrush *wxBrushList::FindOrCreateBrush(wxColour *colour, int style)
00267 {
00268   wxBrush *brush;
00269   wxChildNode *node;
00270   int i = 0;
00271 
00272   if (!colour)
00273     return NULL;
00274 
00275   while ((node = list->NextNode(i))) {
00276     wxBrush *each_brush;
00277     wxColour *bc;
00278     each_brush = (wxBrush*)node->Data();
00279     bc = each_brush->GetColour();
00280     if (each_brush &&
00281        each_brush->GetStyle() == style &&
00282        bc->Red() == colour->Red() &&
00283        bc->Green() == colour->Green() &&
00284        bc->Blue() == colour->Blue())
00285       return each_brush;
00286   }
00287 
00288   brush = new wxBrush(colour, style);
00289   brush->Lock(1);
00290   AddBrush(brush);
00291   
00292   return brush;
00293 }
00294 
00295 wxBrush *wxBrushList::FindOrCreateBrush(char *colour, int style)
00296 {
00297   wxColour *the_colour;
00298   the_colour = wxTheColourDatabase->FindColour(colour);
00299   if (the_colour)
00300     return FindOrCreateBrush(the_colour, style);
00301   return NULL;
00302 }
00303 
00304 //-----------------------------------------------------------------------------
00305 // wxEllipseToPolygon
00306 //-----------------------------------------------------------------------------
00307 
00308 static XPoint *wxEllipseToPolygon(double width, double height, double x, double y, int *_npoints)
00309      /* Makes a polygon with the resolution determined by width */
00310 {
00311   int iwidth = (int)width + 2;
00312   int is_odd = iwidth & 0x1;
00313   int x_extent = (int)((iwidth + 1) / 2) + is_odd, i;
00314   double w2 = (x_extent - 1) * (x_extent - 1), dx, dy;
00315   XPoint *p;
00316   int npoints;
00317 
00318   npoints = (4 * x_extent) - (2 * is_odd);
00319   *_npoints = npoints;
00320 
00321 #ifdef MZ_PRECISE_GC
00322   p = (XPoint *)GC_malloc_atomic(sizeof(XPoint) * npoints);
00323 #else
00324   p = new WXGC_ATOMIC XPoint[npoints];
00325 #endif
00326 
00327   dx = x + width / 2;
00328   dy = y + height / 2;
00329   
00330   for (i = 0; i < x_extent; i++) {
00331     double y = (height / width) * sqrt(w2 - (i * i));
00332     p[i].x = (int)floor(i + dx);
00333     p[i].y = (int)floor(y + dy);
00334     p[2 * x_extent - i - 1].x = (int)floor(i + dx);
00335     p[2 * x_extent - i - 1].y = (int)floor(-y + dy);
00336     p[2 * x_extent + i - is_odd].x = (int)floor(-i + dx);
00337     p[2 * x_extent + i - is_odd].y = (int)floor(-y + dy);
00338     if (i || !is_odd) {
00339       p[4 * x_extent - i - 1 - 2 * is_odd].x = (int)floor(-i + dx);
00340       p[4 * x_extent - i - 1 - 2 * is_odd].y = (int)floor(y + dy);
00341     }
00342   }
00343 
00344   return p;
00345 }
00346 
00347 //-----------------------------------------------------------------------------
00348 // wxRegion
00349 //-----------------------------------------------------------------------------
00350 
00351 #define UseXtRegions
00352 #include "../../../wxcommon/Region.h"
00353 #include "wx_types.h"
00354 
00355 #include "../../../wxcommon/Region.cxx"