# HG changeset patch # User spq@33b003aa-7bff-0310-803a-e67f0ece8222 # Date 1215394857 0 # Node ID 40a7c9618adea7acd41ceacdc1a9fce67361cc3c # Parent ae46cee19e76fb8af7656b87c990da27d02d1792 * new function which lists instances in a rect diff -r ae46cee19e76 -r 40a7c9618ade engine/core/view/camera.cpp --- a/engine/core/view/camera.cpp Mon Jul 07 00:27:59 2008 +0000 +++ b/engine/core/view/camera.cpp Mon Jul 07 01:40:57 2008 +0000 @@ -323,6 +323,45 @@ } } + void Camera::getMatchingInstances(Rect screen_rect, Layer& layer, std::list& instances) { + instances.clear(); + const std::vector& layer_instances = m_layer_to_instances[&layer]; + std::vector::const_iterator instance_it = layer_instances.end(); + while (instance_it != layer_instances.begin()) { + --instance_it; + Instance* i = (*instance_it); + InstanceVisual* visual = i->getVisual(); + InstanceVisualCacheItem& vc = visual->getCacheItem(this); + if ((vc.dimensions.intersects(screen_rect))) { + assert(vc.image); + Uint8 r, g, b, a; + for(int xx = screen_rect.x; xx < screen_rect.x + screen_rect.w; xx++) { + for(int yy = screen_rect.y; yy < screen_rect.y + screen_rect.h; yy++) { + int x = xx - vc.dimensions.x; + int y = yy - vc.dimensions.y; + if (m_zoom != 1.0) { + double fx = static_cast(x); + double fy = static_cast(y); + double fow = static_cast(vc.image->getWidth()); + double foh = static_cast(vc.image->getHeight()); + double fsw = static_cast(vc.dimensions.w); + double fsh = static_cast(vc.dimensions.h); + x = static_cast(round(fx / fsw * fow)); + y = static_cast(round(fy / fsh * foh)); + } + vc.image->getPixelRGBA(x, y, &r, &b, &g, &a); + // instance is hit with mouse if not totally transparent + if (a != 0) { + instances.push_back(i); + goto found_non_transparent_pixel; + } + } + } + found_non_transparent_pixel:; + } + } + } + void Camera::getMatchingInstances(Location& loc, std::list& instances, bool use_exactcoordinates) { instances.clear(); const std::vector& layer_instances = m_layer_to_instances[loc.getLayer()]; diff -r ae46cee19e76 -r 40a7c9618ade engine/core/view/camera.h --- a/engine/core/view/camera.h Mon Jul 07 00:27:59 2008 +0000 +++ b/engine/core/view/camera.h Mon Jul 07 01:40:57 2008 +0000 @@ -219,6 +219,14 @@ * @param instances list of instances that is filled based on hit test results */ void getMatchingInstances(ScreenPoint screen_coords, Layer& layer, std::list& instances); + + /** Returns instances that match given screen coordinate + * @param screen_point1 top left screen coordinates to be used for hit search + * @param screen_point2 right bottom screen coordinates to be used for hit search + * @param layer layer to use for search + * @param instances list of instances that is filled based on hit test results + */ + void getMatchingInstances(Rect screen_rect, Layer& layer, std::list& instances); /** Returns instances that match given location. Instances are sorted based on camera view, so that "topmost" * instance is first in returned list diff -r ae46cee19e76 -r 40a7c9618ade engine/core/view/camera.i --- a/engine/core/view/camera.i Mon Jul 07 00:27:59 2008 +0000 +++ b/engine/core/view/camera.i Mon Jul 07 01:40:57 2008 +0000 @@ -37,6 +37,7 @@ bool isEnabled(); void getMatchingInstances(ScreenPoint screen_coords, Layer& layer, std::list& instances); + void getMatchingInstances(Rect screen_rect, Layer& layer, std::list& instances); void getMatchingInstances(Location& loc, std::list& instances, bool use_exactcoordinates=false); RendererBase* getRenderer(const std::string& name); void resetRenderers();