comparison engine/core/view/camera.cpp @ 18:40a7c9618ade

* new function which lists instances in a rect
author spq@33b003aa-7bff-0310-803a-e67f0ece8222
date Mon, 07 Jul 2008 01:40:57 +0000
parents ab09325f901e
children 1e3b68c260a6
comparison
equal deleted inserted replaced
17:ae46cee19e76 18:40a7c9618ade
321 } 321 }
322 } 322 }
323 } 323 }
324 } 324 }
325 325
326 void Camera::getMatchingInstances(Rect screen_rect, Layer& layer, std::list<Instance*>& instances) {
327 instances.clear();
328 const std::vector<Instance*>& layer_instances = m_layer_to_instances[&layer];
329 std::vector<Instance*>::const_iterator instance_it = layer_instances.end();
330 while (instance_it != layer_instances.begin()) {
331 --instance_it;
332 Instance* i = (*instance_it);
333 InstanceVisual* visual = i->getVisual<InstanceVisual>();
334 InstanceVisualCacheItem& vc = visual->getCacheItem(this);
335 if ((vc.dimensions.intersects(screen_rect))) {
336 assert(vc.image);
337 Uint8 r, g, b, a;
338 for(int xx = screen_rect.x; xx < screen_rect.x + screen_rect.w; xx++) {
339 for(int yy = screen_rect.y; yy < screen_rect.y + screen_rect.h; yy++) {
340 int x = xx - vc.dimensions.x;
341 int y = yy - vc.dimensions.y;
342 if (m_zoom != 1.0) {
343 double fx = static_cast<double>(x);
344 double fy = static_cast<double>(y);
345 double fow = static_cast<double>(vc.image->getWidth());
346 double foh = static_cast<double>(vc.image->getHeight());
347 double fsw = static_cast<double>(vc.dimensions.w);
348 double fsh = static_cast<double>(vc.dimensions.h);
349 x = static_cast<int>(round(fx / fsw * fow));
350 y = static_cast<int>(round(fy / fsh * foh));
351 }
352 vc.image->getPixelRGBA(x, y, &r, &b, &g, &a);
353 // instance is hit with mouse if not totally transparent
354 if (a != 0) {
355 instances.push_back(i);
356 goto found_non_transparent_pixel;
357 }
358 }
359 }
360 found_non_transparent_pixel:;
361 }
362 }
363 }
364
326 void Camera::getMatchingInstances(Location& loc, std::list<Instance*>& instances, bool use_exactcoordinates) { 365 void Camera::getMatchingInstances(Location& loc, std::list<Instance*>& instances, bool use_exactcoordinates) {
327 instances.clear(); 366 instances.clear();
328 const std::vector<Instance*>& layer_instances = m_layer_to_instances[loc.getLayer()]; 367 const std::vector<Instance*>& layer_instances = m_layer_to_instances[loc.getLayer()];
329 std::vector<Instance*>::const_iterator instance_it = layer_instances.end(); 368 std::vector<Instance*>::const_iterator instance_it = layer_instances.end();
330 while (instance_it != layer_instances.begin()) { 369 while (instance_it != layer_instances.begin()) {