File: Display.java

package info (click to toggle)
libcaca 0.99.beta20-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,264 kB
  • sloc: ansic: 25,091; php: 2,763; python: 2,637; cs: 1,213; cpp: 1,127; java: 916; objc: 836; makefile: 543; perl: 505; sh: 472; asm: 297; ruby: 215; xml: 33
file content (168 lines) | stat: -rw-r--r-- 4,367 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/**
 *  libcaca       Java bindings for libcaca
 *  Copyright (c) 2009 Adrien Grand <jpountz@dinauz.org>
 *
 *  This library is free software. It comes without any warranty, to
 *  the extent permitted by applicable law. You can redistribute it
 *  and/or modify it under the terms of the Do What the Fuck You Want
 *  to Public License, Version 2, as published by Sam Hocevar. See
 *  http://www.wtfpl.net/ for more details.
 */

package org.zoy.caca;

public class Display extends NativeObject {

  static {
    Caca.load();
  }

  private static native long createDisplayAndCanvas();
  private static native long createDisplay(long canvasPtr);
  private static native long createDisplayAndCanvasWithDriver(String driver);
  private static native long createDisplayWithDriver(long canvasPtr, String driver);

  // Keep a reference to the canvas so that it does not get collected before this.
  private Canvas canvas;

  public Display() {
    ptr = createDisplayAndCanvas();
    long canvasPtr = getDisplayCanvas(ptr);
    // Create a managed canvas
    canvas = new Canvas(canvasPtr);
  }

  public Display(Canvas canvas) {
    this.canvas = canvas;
    ptr = createDisplay(canvas.ptr);
  }

  public Display(String driver) {
    ptr = createDisplayAndCanvasWithDriver(driver);
    long canvasPtr = getDisplayCanvas(ptr);
    // Create a managed canvas
    canvas = new Canvas(canvasPtr);
  }

  public Display(Canvas canvas, Driver driver) {
    ptr = createDisplayWithDriver(canvas.ptr, driver.code);
  }

  public static class Driver extends CacaObject {
    public Driver(String code, String desc) {
      super(code, desc);
    }
    public static Driver forCode(String code) {
      for (Driver driver : getDriverList()) {
        if (driver.code.equals(code)) {
          return driver;
        }
      }
      return null;
    }
  }

  private static native String[] getDisplayDriverList();

  public static Driver[] getDriverList() {
    String[] tmp = getDisplayDriverList();
    Driver[] drivers = new Driver[tmp.length / 2];
    for (int i = 0; 2*i < tmp.length; i++) {
      drivers[i] = new Driver(tmp[2*i], tmp[2*i+1]);
    }
    return drivers;
  }

  private static native void setDisplayDriver(long displayPtr, String driver);

  public void setDriver(Driver driver) {
    setDisplayDriver(ptr, driver.code);
  }

  private static native String getDisplayDriver(long displayPtr);

  public Driver getDriver() {
    return Driver.forCode(getDisplayDriver(ptr));
  }

  private static native long getDisplayCanvas(long displayPtr);

  public Canvas getCanvas() {
    return canvas;
  }

  private static native void displayRefresh(long displayPtr);

  public void refresh() {
    displayRefresh(ptr);
  }

  private static native void setDisplayTime(long displayPtr, int time);

  public void setTime(int time) {
    setDisplayTime(ptr, time);
  }

  private static native int getDisplayTime(long displayPtr);

  public int getTime() {
    return getDisplayTime(ptr);
  }

  private static native int getDisplayWidth(long displayPtr);

  public int getWidth() {
    return getDisplayWidth(ptr);
  }

  private static native int getDisplayHeight(long displayPtr);

  public int getHeight() {
    return getDisplayHeight(ptr);
  }

  private static native void setDisplayTitle(long displayPtr, String title);

  public void setTitle(String title) {
    setDisplayTitle(ptr, title);
  }

  private static native void setDisplayMouse(long displayPtr, boolean status);

  public void setMouse(boolean status) {
    setDisplayMouse(ptr, status);
  }

  private static native void setDisplayCursor(long displayPtr, boolean status);

  public void setCursor(boolean status) {
    setDisplayCursor(ptr, status);
  }

  private static native long getDisplayEvent(long displayPtr, int eventMask, int timeout);

  public Event getEvent(Event.Type type, int timeout) {
    return new Event(getDisplayEvent(ptr, type.code, timeout));
  }

  private static native int getDisplayMouseX(long eventPtr);

  public int getMouseX() {
    return getDisplayMouseX(ptr);
  }

  private static native int getDisplayMouseY(long eventPtr);

  public int getMouseY() {
    return getDisplayMouseY(ptr);
  }

  private static native void freeDisplay(long displayPtr);

  @Override
  public void finalize() throws Throwable {
    freeDisplay(ptr);
    super.finalize();
  }

}