labelComponent.cpp

00001 /*
00002   ラベル表示のコンポーネント
00003   Satofumi KAMIMURA
00004   $Id$
00005 */
00006 
00007 #include "labelComponent.h"
00008 
00009 
00010 LabelComponent::LabelComponent(SurfaceInterface* obj) : surface(obj) {
00011   if (surface) {
00012     w = surface->w;
00013     h = surface->h;
00014   } else {
00015     w = 0;
00016     h = 0;
00017   }
00018   position = VXV::Grid(0, 0);
00019 }
00020 
00021 
00022 bool LabelComponent::draw(unsigned long ticks, const UserInput& ui) {
00023   if (!surface) {
00024     return false;
00025 
00026   } else {
00027     surface->draw(VXV::Rect(surface->w, surface->h), position, ticks);
00028     return true;
00029   }
00030 }
00031 
00032 
00033 bool LabelComponent::draw(const VXV::Grid& view_pos,
00034                           const VXV::Rect& view_range, double view_magnify,
00035                           const VXV::Grid& draw_pos, bool pined) {
00036   VXV::Grid pos;
00037   if (pined) {
00038     // 位置計算
00039     pos.x = static_cast<int>(rint((draw_pos.x - view_range.x) * view_magnify))
00040       + view_pos.x;
00041     pos.y = static_cast<int>(rint((-draw_pos.y - view_range.y) * view_magnify))
00042       + view_pos.y;
00043   } else {
00044     pos = draw_pos;
00045   }
00046   pos += view_pos;
00047 
00048   // 範囲計算
00049   VXV::Rect draw_range;
00050   draw_range.x = view_pos.x;
00051   draw_range.y = view_pos.y;
00052   draw_range.w = draw_range.x + view_range.w;
00053   draw_range.h = draw_range.y + view_range.h;
00054 
00055   if ((pos.x > draw_range.w) || (pos.x + surface->w < draw_range.x) ||
00056       (pos.y > draw_range.h) || (pos.y + surface->h < draw_range.y)) {
00057     return true;
00058   }
00059 
00060   VXV::Rect draw_rect = VXV::Rect(0, 0, surface->w, surface->h);
00061   if (pos.x < draw_range.x) {
00062     draw_rect.x = draw_range.x - pos.x;
00063   }
00064   if (pos.y < draw_range.y) {
00065     draw_rect.y = draw_range.y - pos.y;
00066   }
00067   if (pos.x + surface->w > draw_range.w) {
00068     draw_rect.w -= pos.x + surface->w - draw_range.w;
00069   }
00070   if (pos.y + surface->h > draw_range.h) {
00071     draw_rect.h -= pos.y + surface->h - draw_range.h;
00072   }
00073   surface->draw(draw_rect, pos, 0);
00074   return true;
00075 }
00076 

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