1 /* === S I N F G =========================================================== */
2 /*! \file checkerboard.cpp
3 ** \brief Template Header
5 ** $Id: checkerboard.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
31 #include "checkerboard.h"
33 #include <sinfg/string.h>
34 #include <sinfg/time.h>
35 #include <sinfg/context.h>
36 #include <sinfg/paramdesc.h>
37 #include <sinfg/renddesc.h>
38 #include <sinfg/surface.h>
39 #include <sinfg/value.h>
40 #include <sinfg/valuenode.h>
41 #include <sinfg/segment.h>
45 using namespace sinfg;
49 /* === M A C R O S ========================================================= */
51 /* === G L O B A L S ======================================================= */
53 SINFG_LAYER_INIT(CheckerBoard);
54 SINFG_LAYER_SET_NAME(CheckerBoard,"checker_board");
55 SINFG_LAYER_SET_LOCAL_NAME(CheckerBoard,_("CheckerBoard"));
56 SINFG_LAYER_SET_CATEGORY(CheckerBoard,_("Geometry"));
57 SINFG_LAYER_SET_VERSION(CheckerBoard,"0.1");
58 SINFG_LAYER_SET_CVS_ID(CheckerBoard,"$Id: checkerboard.cpp,v 1.1.1.1 2005/01/04 01:23:10 darco Exp $");
60 /* === P R O C E D U R E S ================================================= */
62 /* === M E T H O D S ======================================================= */
64 CheckerBoard::CheckerBoard():
65 Layer_Composite (1.0,Color::BLEND_STRAIGHT),
66 color (Color::black()),
67 pos (Point(0.125,0.125)),
68 size (Point(0.25,0.25))
71 set_blend_method(Color::BLEND_STRAIGHT);
75 CheckerBoard::point_test(const sinfg::Point& getpos)const
77 int val=((int)((getpos[0]-pos[0])/size[0])+(int)((getpos[1]-pos[1])/size[1]));
78 if(getpos[0]-pos[0] < 0.0)
80 if(getpos[1]-pos[1] < 0.0)
86 CheckerBoard::set_param(const String ¶m, const ValueBase &value)
94 return Layer_Composite::set_param(param,value);
98 CheckerBoard::get_param(const String ¶m)const
108 return Layer_Composite::get_param(param);
112 CheckerBoard::get_param_vocab()const
114 Layer::Vocab ret(Layer_Composite::get_param_vocab());
116 ret.push_back(ParamDesc("color")
117 .set_local_name(_("Color"))
118 .set_description(_("Color of checkers"))
120 ret.push_back(ParamDesc("pos")
121 .set_local_name(_("Offset"))
123 ret.push_back(ParamDesc("size")
124 .set_local_name(_("Size"))
125 .set_description(_("Size of checkers"))
133 CheckerBoard::hit_check(sinfg::Context context, const sinfg::Point &getpos)const
135 if(get_amount()!=0.0 && point_test(getpos))
137 sinfg::Layer::Handle tmp;
138 if(get_blend_method()==Color::BLEND_BEHIND && (tmp=context.hit_check(getpos)))
140 if(Color::is_onto(get_blend_method()) && !(tmp=context.hit_check(getpos)))
142 return const_cast<CheckerBoard*>(this);
145 return context.hit_check(getpos);
149 CheckerBoard::get_color(Context context, const Point &getpos)const
151 if(get_amount()!=0.0 && point_test(getpos))
153 if(get_amount()==1.0 && get_blend_method()==Color::BLEND_STRAIGHT)
156 return Color::blend(color,context.get_color(getpos),get_amount(),get_blend_method());
159 return context.get_color(getpos);
163 CheckerBoard::accelerated_render(Context context,Surface *surface,int quality, const RendDesc &renddesc, ProgressCallback *cb)const
165 SuperCallback supercb(cb,0,9500,10000);
167 if(!context.accelerated_render(surface,quality,renddesc,&supercb))
174 const Point tl(renddesc.get_tl());
176 const int w(surface->get_w());
177 const int h(surface->get_h());
178 const Real pw(renddesc.get_pw()),ph(renddesc.get_ph());
180 Surface::alpha_pen apen(surface->begin());
182 apen.set_alpha(get_amount());
183 apen.set_blend_method(get_blend_method());
184 apen.set_value(color);
186 for(y=0,pos[1]=tl[1];y<h;y++,apen.inc_y(),apen.dec_x(x),pos[1]+=ph)
187 for(x=0,pos[0]=tl[0];x<w;x++,apen.inc_x(),pos[0]+=pw)
191 // Mark our progress as finished
192 if(cb && !cb->amount_complete(10000,10000))