/* -*- C++ -*- * Copyright ©2004 Hugo Mills * * This software is distributed under the terms of the GNU GPL v3 * For more information on the GPL, see the file COPYING or * visit http://www.gnu.org/ * * This software is distributed without warranty */ #include "magellan/xfview.h" #include "magellan/plugininfo_viewport.h" #include "magellan/parsertools.h" PluginInfo* XfView::getmodules(int i) { if(i == 0) { PluginInfo_Viewport* pi = new PluginInfo_Viewport(); pi->name = "Viewport Builtin"; pi->author = "Hugo Mills"; pi->version = 0x10000; pi->parser = XfView::parse; return pi; } else return NULL; } XfView* XfView::parse( ConfigLexer* lex, const std::string& type, const std::string& subtype ) { ivec2 tr; ivec2 bl; ivec2 sz; ivec2 cn; tr[0] = -1000000; bl[0] = -1000000; sz[0] = -1000000; cn[0] = -1000000; double scale = 1.0; while(!lex->eos()) { if(readkeyedvalue(lex, "top-right", &tr[0], &tr[1]) || readkeyedvalue(lex, "bottom-left", &bl[0], &bl[1]) || readkeyedvalue(lex, "size", &sz[0], &sz[1]) || readkeyedvalue(lex, "scale", &scale) || readkeyedvalue(lex, "centre", &cn[0], &cn[1]) ) ; else throw(UnknownConfigToken(lex)); } if(tr[0] != -1000000 && bl[0] != -1000000) ; else if(bl[0] != -1000000 && sz[0] != -1000000) { tr[0] = bl[0] + sz[0]; tr[1] = bl[1] + sz[1]; } else if(tr[0] != -1000000 && sz[0] != -1000000) { bl[0] = tr[0] - sz[0]; bl[1] = tr[1] - sz[1]; } else // throw(BadConfiguration) ; if(cn[0] == -1000000) { cn[0] = (tr[0] - bl[0])/2; cn[1] = (tr[1] - bl[1])/2; } return new XfView(bl, tr, cn, scale); } bool XfView::f(ivec2& result, const dvec2& pre) const { result[0] = int(pre[0]*scale); result[1] = int(pre[1]*scale); result += bottom_left; result += centre; if(result[0] < bottom_left[0] || result[0] >= top_right[0] || result[1] < bottom_left[1] || result[1] >= top_right[1]) return false; return true; } bool XfView::g(dvec2& result, const ivec2& post) const { result[0] = (post[0]-centre[0]-bottom_left[0])/scale; result[1] = (post[1]-centre[1]-bottom_left[1])/scale; return true; } void XfView::set_left(int x) { centre[0] -= x - bottom_left[0]; bottom_left[0] = x; } void XfView::set_bottom(int y) { centre[1] -= y - bottom_left[1]; bottom_left[1] = y; }