void Design::drawRoundRect(Graphics::ManagedSurface *surface, Common::ReadStream &in, Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType) { int16 y1 = in.readSint16BE(); int16 x1 = in.readSint16BE(); int16 y2 = in.readSint16BE(); int16 x2 = in.readSint16BE(); int16 arc = in.readSint16BE(); if (x1 > x2) SWAP(x1, x2); if (y1 > y2) SWAP(y1, y2); Common::Rect r(x1, y1, x2, y2); PlotData pd(surface, &patterns, fillType, 1, this); if (fillType <= patterns.size()) Graphics::drawRoundRect(r, arc / 2, kColorBlack, true, drawPixel, &pd); pd.fillType = borderFillType; pd.thickness = borderThickness; if (borderThickness > 0 && borderFillType <= patterns.size()) Graphics::drawRoundRect(r, arc / 2, kColorBlack, false, drawPixel, &pd); }
void Design::drawOval(Graphics::ManagedSurface *surface, Common::ReadStream &in, Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType) { int16 y1 = in.readSint16BE(); int16 x1 = in.readSint16BE(); int16 y2 = in.readSint16BE(); int16 x2 = in.readSint16BE(); PlotData pd(surface, &patterns, fillType, 1, this); if (fillType <= patterns.size()) Graphics::drawEllipse(x1, y1, x2-1, y2-1, kColorBlack, true, drawPixel, &pd); pd.fillType = borderFillType; pd.thickness = borderThickness; if (borderThickness > 0 && borderFillType <= patterns.size()) Graphics::drawEllipse(x1, y1, x2-1, y2-1, kColorBlack, false, drawPixel, &pd); }
static Scanner Do(const Patterns& patterns, bool surround) { if (patterns.size() != 1) throw std::runtime_error("Only one regexp is allowed for this scanner"); Pire::Fsm fsm = Pire::Lexer(patterns[0]).Parse(); if (surround) fsm.Surround(); return fsm.Compile<Scanner>(); }
void Search::readStrGraph(Patterns &patterns,StrGraph &desc) { clear(); map<StrGraph::Node*,Node*> recollect; for(StrGraph::node_iter ni = desc.nodes().begin(); ni!=desc.nodes().end(); ++ni) { Node *n = create_node(gd<Name>(*ni)); recollect[*ni] = n; SearchStage &stage = gd<SearchStage>(n); DString limit = gd<StrAttrs>(*ni).look("limit","50"); stage.limit = atoi(limit.c_str()); DString action = gd<StrAttrs>(*ni).look("action","union"); if(action=="union") stage.type = UnionInquiry; else if(action=="intersection") stage.type = IntersectionInquiry; else if(action=="pattern") { stage.type = PatternInquiry; DString pattern = gd<StrAttrs>(*ni).look("pattern",""); Patterns::iterator pi = patterns.find(pattern); if(pi==patterns.end()) throw UndefinedPattern(pattern); stage.pattern = &pi->second; } else if(action=="path") { stage.type = PathInquiry; DString ways = gd<StrAttrs>(*ni)["ways"]; if(ways=="in") stage.goIn = true, stage.goOut = false; else if(ways=="both") stage.goIn = stage.goOut = true; else // ways=="out" default stage.goIn = false, stage.goOut = true; stage.firstOnly = gd<StrAttrs>(*ni)["firstonly"]=="true"; stage.shortest = gd<StrAttrs>(*ni)["shortest"]=="true"; stage.weightattr = gd<StrAttrs>(*ni).look("weightattr","weight"); } else throw UnknownAction(action); } for(StrGraph::graphedge_iter ei = desc.edges().begin(); ei!=desc.edges().end(); ++ei) { Edge *e = create_edge(recollect[(*ei)->tail],recollect[(*ei)->head]).first; DString input = gd<StrAttrs>(*ei).look("input",""); gd<Name>(e) = input; } }
static Pire::CountingScanner Do(const Patterns& patterns, bool /*surround*/) { Pire::CountingScanner sc; for (Patterns::const_iterator i = patterns.begin(), ie = patterns.end(); i != ie; ++i) { Pire::CountingScanner tsc = Pire::CountingScanner( Pire::Lexer(*i).Parse(), Pire::Lexer(".*").Parse()); if (i == patterns.begin()) tsc.Swap(sc); else { sc = Pire::CountingScanner::Glue(sc, tsc); if (sc.Empty()) { std::ostringstream msg; msg << "Scanner gluing failed at regexp " << *i << " - pattern too complicated"; throw std::runtime_error(msg.str()); } } } return sc; }
static Pire::Impl::Scanner<Relocation, Shortcutting> Do(const Patterns& patterns, bool surround) { typedef Pire::Impl::Scanner<Relocation, Shortcutting> Sc; Sc sc; for (Patterns::const_iterator i = patterns.begin(), ie = patterns.end(); i != ie; ++i) { Pire::Fsm fsm = Pire::Lexer(*i).Parse(); if (surround) fsm.Surround(); Sc tsc = fsm.Compile<Sc>(); if (i == patterns.begin()) tsc.Swap(sc); else { sc = Sc::Glue(sc, tsc); if (sc.Empty()) { std::ostringstream msg; msg << "Scanner gluing failed at regexp " << *i << " - pattern too complicated"; throw std::runtime_error(msg.str()); } } } return sc; }
void Design::drawPolygon(Graphics::ManagedSurface *surface, Common::ReadStream &in, Patterns &patterns, byte fillType, byte borderThickness, byte borderFillType) { byte ignored = in.readSint16BE(); // ignored if (ignored) warning("Ignored: %d", ignored); int numBytes = in.readSint16BE(); // #bytes used by polygon data, including the numBytes int16 by1 = in.readSint16BE(); int16 bx1 = in.readSint16BE(); int16 by2 = in.readSint16BE(); int16 bx2 = in.readSint16BE(); Common::Rect bbox(bx1, by1, bx2, by2); numBytes -= 8; int y1 = in.readSint16BE(); int x1 = in.readSint16BE(); Common::Array<int> xcoords; Common::Array<int> ycoords; numBytes -= 6; while (numBytes > 0) { int y2 = y1; int x2 = x1; int b = in.readSByte(); if (b == -128) { y2 = in.readSint16BE(); numBytes -= 3; } else { y2 += b; numBytes -= 1; } b = in.readSByte(); if (b == -128) { x2 = in.readSint16BE(); numBytes -= 3; } else { x2 += b; numBytes -= 1; } xcoords.push_back(x1); ycoords.push_back(y1); x1 = x2; y1 = y2; } xcoords.push_back(x1); ycoords.push_back(y1); int npoints = xcoords.size(); int *xpoints = (int *)calloc(npoints, sizeof(int)); int *ypoints = (int *)calloc(npoints, sizeof(int)); for (int i = 0; i < npoints; i++) { xpoints[i] = xcoords[i]; ypoints[i] = ycoords[i]; } PlotData pd(surface, &patterns, fillType, 1, this); if (fillType <= patterns.size()) { Graphics::drawPolygonScan(xpoints, ypoints, npoints, bbox, kColorBlack, drawPixel, &pd); } pd.fillType = borderFillType; pd.thickness = borderThickness; if (borderThickness > 0 && borderFillType <= patterns.size()) { for (int i = 1; i < npoints; i++) Graphics::drawLine(xpoints[i-1], ypoints[i-1], xpoints[i], ypoints[i], kColorBlack, drawPixel, &pd); } free(xpoints); free(ypoints); }