scroggo | b7e9aee | 2011-03-15 15:15:15 +0000 | [diff] [blame^] | 1 | #include <X11/Xlib.h> |
| 2 | #include <X11/Xatom.h> |
| 3 | #include <X11/keysym.h> |
| 4 | #include <GL/glx.h> |
| 5 | |
| 6 | #include "SkWindow.h" |
| 7 | |
| 8 | #include "SkBitmap.h" |
| 9 | #include "SkColor.h" |
| 10 | #include "SkEvent.h" |
| 11 | |
| 12 | SkOSWindow::SkOSWindow(void* unused) |
| 13 | { |
| 14 | fUnixWindow.fDisplay = NULL; |
| 15 | } |
| 16 | |
| 17 | SkOSWindow::~SkOSWindow() |
| 18 | { |
| 19 | } |
| 20 | |
| 21 | void SkOSWindow::setUnixWindow(Display* dsp, Window win, size_t screenNumber, GC gc) |
| 22 | { |
| 23 | fUnixWindow.fDisplay = dsp; |
| 24 | fUnixWindow.fWin = win; |
| 25 | fUnixWindow.fOSWin = screenNumber; |
| 26 | fUnixWindow.fGc = gc; |
| 27 | } |
| 28 | |
| 29 | bool SkOSWindow::attachGL(const SkBitmap* offscreen) |
| 30 | { |
| 31 | return false; |
| 32 | } |
| 33 | |
| 34 | void SkOSWindow::detachGL() |
| 35 | { |
| 36 | |
| 37 | } |
| 38 | |
| 39 | void SkOSWindow::presentGL() |
| 40 | { |
| 41 | |
| 42 | } |
| 43 | |
| 44 | void SkOSWindow::onSetTitle(const char title[]) |
| 45 | { |
| 46 | if (!fUnixWindow.fDisplay) return; |
| 47 | XTextProperty textProp; |
| 48 | textProp.value = (unsigned char*)title; |
| 49 | textProp.format = 8; |
| 50 | textProp.nitems = strlen((char*)textProp.value); |
| 51 | textProp.encoding = XA_STRING; |
| 52 | XSetWMName(fUnixWindow.fDisplay, fUnixWindow.fWin, &textProp); |
| 53 | } |
| 54 | |
| 55 | void SkOSWindow::onHandleInval(const SkIRect&) |
| 56 | { |
| 57 | SkEvent* evt = new SkEvent("inval-imageview"); |
| 58 | evt->post(getSinkID()); |
| 59 | } |
| 60 | |
| 61 | bool SkOSWindow::onEvent(const SkEvent& evt) |
| 62 | { |
| 63 | if (evt.isType("inval-imageview")) { |
| 64 | update(NULL); |
| 65 | doPaint(); |
| 66 | return true; |
| 67 | } |
| 68 | return INHERITED::onEvent(evt); |
| 69 | } |
| 70 | |
| 71 | void SkOSWindow::doPaint() { |
| 72 | if (!fUnixWindow.fDisplay) return; |
| 73 | // Draw the bitmap to the screen. |
| 74 | const SkBitmap& bitmap = getBitmap(); |
| 75 | for (int i = 0; i < bitmap.width(); i++) { |
| 76 | for (int j = 0; j < bitmap.height(); j++) { |
| 77 | // Get the pixel, put it on the screen. |
| 78 | SkColor color = bitmap.getColor(i, j); |
| 79 | XSetForeground(fUnixWindow.fDisplay, fUnixWindow.fGc, color); |
| 80 | XDrawPoint(fUnixWindow.fDisplay, fUnixWindow.fWin, fUnixWindow.fGc, i, j); |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | bool SkOSWindow::onHandleChar(SkUnichar) |
| 86 | { |
| 87 | return false; |
| 88 | } |
| 89 | |
| 90 | bool SkOSWindow::onHandleKey(SkKey key) |
| 91 | { |
| 92 | return false; |
| 93 | } |
| 94 | |
| 95 | bool SkOSWindow::onHandleKeyUp(SkKey key) |
| 96 | { |
| 97 | return false; |
| 98 | } |