~ubuntu-branches/ubuntu/utopic/sikuli/utopic

« back to all changes in this revision

Viewing changes to sikuli-script/src/main/java/org/sikuli/script/UnionScreen.java

  • Committer: Bazaar Package Importer
  • Author(s): Gilles Filippini
  • Date: 2011-01-24 01:07:30 UTC
  • Revision ID: james.westby@ubuntu.com-20110124010730-lzj19enqag94g1ye
Tags: upstream-1.0~x~rc1-dfsg1
ImportĀ upstreamĀ versionĀ 1.0~x~rc1-dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package org.sikuli.script;
 
2
 
 
3
import java.awt.*;
 
4
import java.awt.image.*;
 
5
 
 
6
public class UnionScreen extends Screen {
 
7
   static Rectangle _bounds;
 
8
 
 
9
   public UnionScreen(){
 
10
      super(0);
 
11
   }
 
12
 
 
13
   public int getIdFromPoint(int x, int y){
 
14
      Debug.log(5, "union bound: " + getBounds() );
 
15
      Debug.log(5, "x, y: " + x + "," + y);
 
16
      x += getBounds().x;
 
17
      y += getBounds().y;
 
18
      Debug.log(5, "new x, y: " + x + "," + y);
 
19
      for(int i=0;i<getNumberScreens();i++)
 
20
         if(Screen.getBounds(i).contains(x, y)){
 
21
            return i;
 
22
         }
 
23
      return 0;
 
24
   }
 
25
 
 
26
   public Rectangle getBounds(){
 
27
      if(_bounds == null){
 
28
         _bounds = new Rectangle();
 
29
         for (int i=0; i < Screen.getNumberScreens(); i++) {
 
30
            _bounds = _bounds.union(Screen.getBounds(i));
 
31
         }
 
32
      }
 
33
      return _bounds;
 
34
   }
 
35
 
 
36
 
 
37
   public ScreenImage capture(Rectangle rect) {
 
38
      Debug.log(5, "capture: " + rect);
 
39
 
 
40
      BufferedImage ret = new BufferedImage( rect.width, rect.height, 
 
41
                                             BufferedImage.TYPE_INT_RGB );
 
42
      Graphics2D g2d = ret.createGraphics();
 
43
      for (int i=0; i < Screen.getNumberScreens(); i++) {
 
44
         Rectangle scrBound = Screen.getBounds(i);
 
45
         if(scrBound.intersects(rect)){
 
46
            Rectangle inter = scrBound.intersection(rect);
 
47
            Debug.log(5, "scrBound: " + scrBound + ", inter: " +inter);
 
48
            int ix = inter.x, iy = inter.y;
 
49
            inter.x-=scrBound.x;
 
50
            inter.y-=scrBound.y;
 
51
            BufferedImage img = _robots[i].createScreenCapture(inter);
 
52
            g2d.drawImage(img, ix-rect.x, iy-rect.y, null);
 
53
         }
 
54
      }
 
55
      g2d.dispose();
 
56
      return new ScreenImage(rect, ret);
 
57
   }
 
58
 
 
59
   boolean useFullscreen(){
 
60
      if( Env.getOS() == OS.MAC )
 
61
         return false;
 
62
      if(getNumberScreens()==1)
 
63
         return true;
 
64
      return false;
 
65
   }
 
66
 
 
67