userCommand.cpp

00001 /*
00002   描画コマンドの処理
00003   Satofumi KAMIMURA
00004   $Id$
00005 */
00006 
00007 #include "screenTask.h"
00008 #include <stdarg.h>
00009 
00010 using namespace std;
00011 
00012 
00013 vector<BasicDrawInterface*> ScreenTask::graphix_groups;
00014 set<unsigned long> ScreenTask::delete_index;
00015 map<unsigned long,BasicDrawInterface*> ScreenTask::text_map;
00016 map<unsigned long,BasicDrawInterface*> ScreenTask::graphix_map;
00017 
00018 
00019 void ScreenTask::clear(unsigned long index) {
00020   win->lock();
00021 
00022   switch (index) {
00023 
00024   case INVALID_LAYER_ID:
00025     break;
00026 
00027   case ALL_LAYER:
00028   case TEXT_LAYER:
00029     // スクロール文字の削除
00030     debug_area_clear = true;
00031 
00032     // 配置文字の削除
00033     for (map<unsigned long,BasicDrawInterface*>::iterator it
00034            = text_map.begin(); it != text_map.end(); ++it) {
00035       delete_index.insert(it->first);
00036     }
00037     if (index == TEXT_LAYER) {
00038       break;
00039     }
00040 
00041   case GRAPHIX_LAYER:
00042     for (map<unsigned long,BasicDrawInterface*>::iterator it
00043            = graphix_map.begin(); it != graphix_map.end(); ++it) {
00044       delete_index.insert(it->first);
00045     }
00046     break;
00047 
00048   default:
00049     delete_index.insert(index);
00050     break;
00051   }
00052   win->unlock();
00053 }
00054 
00055 
00056 unsigned long ScreenTask::setPoints(const vector<VXV::Grid3D>& points,
00057                                     unsigned long color, int width) {
00058   win->lock();
00059   vector<VXV::Grid> points_2d(points.begin(), points.end());
00060   PixelGroupDraw* obj = new PixelGroupDraw(points_2d, color);
00061   graphix_groups.push_back(obj);
00062   graphix_map.insert(pair<unsigned long,BasicDrawInterface*>(layer_index,obj));
00063   win->unlock();
00064 
00065   int ret = layer_index++;
00066   win->unlock();
00067   return ret;
00068 }
00069 
00070 
00071 unsigned long ScreenTask::setLine(const VXV::Grid3D& p0, const VXV::Grid3D& p1,
00072                                   unsigned long color) {
00073   win->lock();
00074   LineDraw* obj = new LineDraw(p0, p1, color);
00075   graphix_groups.push_back(obj);
00076   graphix_map.insert(pair<unsigned long,BasicDrawInterface*>(layer_index,obj));
00077 
00078   int ret = layer_index++;
00079   win->unlock();
00080   return ret;
00081 }
00082 
00083 
00084 unsigned long ScreenTask::setContLine(const std::deque<VXV::Grid3D>& points,
00085                                       unsigned long color) {
00086   win->lock();
00087   deque<VXV::Grid> points_2d(points.begin(), points.end());
00088   ContLineDraw* obj = new ContLineDraw(points_2d, color);
00089   graphix_groups.push_back(obj);
00090   graphix_map.insert(pair<unsigned long,BasicDrawInterface*>(layer_index,obj));
00091 
00092   int ret = layer_index++;
00093   win->unlock();
00094   return ret;
00095 }
00096 
00097 
00098 unsigned long ScreenTask::setCircle(const VXV::Grid& center, int r,
00099                                     unsigned long color) {
00100   win->lock();
00101   CircleDraw* obj = new CircleDraw(center, r, color);
00102   graphix_groups.push_back(obj);
00103   graphix_map.insert(pair<unsigned long,BasicDrawInterface*>(layer_index,obj));
00104 
00105   int ret = layer_index++;
00106   win->unlock();
00107   return ret;
00108 }
00109 
00110 
00111 unsigned long ScreenTask::setText(const char* text, const VXV::Grid& pos,
00112                                   int pxSize, bool pin, unsigned long color,
00113                                   unsigned long back) {
00114   win->lock();
00115   TextDraw* obj = new TextDraw(*ttf, text, pos, pxSize, pin, color, back);
00116   graphix_groups.push_back(obj);
00117   graphix_map.insert(pair<unsigned long,BasicDrawInterface*>(layer_index,obj));
00118 
00119   int ret = layer_index++;
00120   win->unlock();
00121   return ret;
00122 }
00123 
00124 
00125 void ScreenTask::drawObjects(void) {
00126 
00127   if (debug_area_clear) {
00128     debug_area_clear = false;
00129     debug_area->clear();
00130   }
00131 
00132   for (vector<BasicDrawInterface*>::iterator it = graphix_groups.begin();
00133        it != graphix_groups.end(); ++it) {
00134     user_view->add(*it);
00135   }
00136   graphix_groups.clear();
00137 
00138   for (set<unsigned long>::iterator it = delete_index.begin();
00139        it != delete_index.end(); ++it) {
00140     map<unsigned long,BasicDrawInterface*>::iterator p = text_map.find(*it);
00141     if (p != text_map.end()) {
00142       user_view->del(p->second);
00143       text_map.erase(*it);
00144 
00145     } else {
00146       p = graphix_map.find(*it);
00147       if (p != graphix_map.end()) {
00148         user_view->del(p->second);
00149         graphix_map.erase(*it);
00150       }
00151     }
00152   }
00153   delete_index.clear();
00154 }
00155 
00156 
00157 int ScreenTask::printf(ScrollAreaComponent* area,
00158                        const char* fmt, va_list ap) {
00159   win->lock();
00160   int n = area->printf(fmt, ap);
00161   win->unlock();
00162 
00163   return n;
00164 }
00165 
00166 
00167 int ScreenTask::consolePrintf(const char* fmt, va_list ap) {
00168   return printf(debug_area, fmt, ap);
00169 }
00170 
00171 
00172 int ScreenTask::commandLogPrintf(const char* fmt, ...) {
00173   va_list ap;
00174   va_start(ap, fmt);
00175   return printf(command_log, fmt, ap);
00176 }
00177 

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