viewComponent.cpp

00001 /*
00002   拡大率を指定して再描画するビュー
00003   Satofumi KAMIMURA
00004   $Id$
00005 */
00006 
00007 #include "viewComponent.h"
00008 #include "deleteObjects.h"
00009 
00010 
00011 ViewComponent::ViewComponent(const VXV::Rect& range, double magnify) {
00012   w = range.w;
00013   h = range.h;
00014   position = VXV::Grid(0, 0);
00015 
00016   draw_range = range;
00017   draw_magnify = magnify;
00018 }
00019 
00020 
00021 ViewComponent::~ViewComponent(void) {
00022   clear();
00023 }
00024 
00025 
00026 bool ViewComponent::draw(unsigned long ticks, const UserInput& ui) {
00027 
00028   BasicDrawInterface::setDrawPosition(position, draw_range, draw_magnify);
00029   for (std::list<BasicDrawInterface*>::iterator it = objs.begin();
00030        it != objs.end(); ++it) {
00031     if (*it) {
00032       (*it)->draw();
00033     }
00034   }
00035   return true;
00036 }
00037 
00038 
00039 ViewComponent& ViewComponent::updateMagnify(double magnify) {
00040   draw_magnify = magnify;
00041 
00042   return *this;
00043 }
00044 
00045 
00046 ViewComponent& ViewComponent::setViewToRangeGrid(const VXV::Grid& view_grid,
00047                                                  const VXV::Grid& range_grid) {
00048   int left = static_cast<int>(rint(view_grid.x - range_grid.x / draw_magnify));
00049   int top = static_cast<int>(rint(view_grid.y - range_grid.y / draw_magnify));
00050   updateViewPosition(VXV::Grid(left, top));
00051 
00052   return *this;
00053 }
00054 
00055 
00056 ViewComponent& ViewComponent::updateViewPosition(const VXV::Grid& pos) {
00057   draw_range.x = pos.x;
00058   draw_range.y = pos.y;
00059 
00060   return *this;
00061 }
00062 
00063 
00064 ViewComponent& ViewComponent::updateViewSize(const VXV::Rect& size) {
00065   draw_range.w = size.w;
00066   draw_range.h = size.h;
00067 
00068   return *this;
00069 }
00070 
00071 
00072 ViewComponent& ViewComponent::clear(void) {
00073   for_each(objs.begin(), objs.end(), DeleteObjects());
00074   objs.clear();
00075 
00076   return *this;
00077 }
00078 
00079 
00080 ViewComponent& ViewComponent::add(BasicDrawInterface* obj) {
00081   objs.push_back(obj);
00082 
00083   return *this;
00084 }
00085 
00086 
00087 void ViewComponent::del(BasicDrawInterface* obj) {
00088   std::list<BasicDrawInterface*>::iterator it = find(objs.begin(),
00089                                                      objs.end(), obj);
00090   if (it != objs.end()) {
00091     delete *it;
00092     *it = NULL;
00093     objs.erase(it);
00094   }
00095 }
00096 

Generated on Mon Apr 13 22:52:02 2009 by  doxygen 1.5.7.1