Exemplo n.º 1
0
  public void setResizable(boolean resizable) {
    if (this.resizable != resizable) {
      int style = (int) getWindowLongPtr(hwnd, GWL_STYLE);
      int styleex = (int) getWindowLongPtr(hwnd, GWL_EXSTYLE);

      // update frame style
      if (resizable && !Display.isFullscreen()) {
        setWindowLongPtr(hwnd, GWL_STYLE, style |= (WS_THICKFRAME | WS_MAXIMIZEBOX));
      } else {
        setWindowLongPtr(hwnd, GWL_STYLE, style &= ~(WS_THICKFRAME | WS_MAXIMIZEBOX));
      }

      // from the existing client rect, determine the new window rect
      // based on the style changes - using AdjustWindowRectEx.
      getClientRect(hwnd, rect_buffer);
      rect.copyFromBuffer(rect_buffer);
      adjustWindowRectEx(rect_buffer, style, false, styleex);
      rect.copyFromBuffer(rect_buffer);

      // force a frame update and resize accordingly
      setWindowPos(
          hwnd,
          HWND_TOP,
          0,
          0,
          rect.right - rect.left,
          rect.bottom - rect.top,
          SWP_NOMOVE | SWP_NOZORDER | SWP_FRAMECHANGED);

      updateWidthAndHeight();
      resized = false;
    }
    this.resizable = resizable;
  }
Exemplo n.º 2
0
 private static void getGlobalClientRect(long hwnd, Rect rect) {
   rect_buffer.put(0, 0).put(1, 0);
   clientToScreen(hwnd, rect_buffer);
   int offset_x = rect_buffer.get(0);
   int offset_y = rect_buffer.get(1);
   getClientRect(hwnd, rect_buffer);
   rect.copyFromBuffer(rect_buffer);
   rect.offset(offset_x, offset_y);
 }
Exemplo n.º 3
0
 static void setupCursorClipping(long hwnd) throws LWJGLException {
   cursor_clipped = true;
   getGlobalClientRect(hwnd, rect);
   rect.copyToBuffer(rect_buffer);
   clipCursor(rect_buffer);
 }
Exemplo n.º 4
0
 private void updateWidthAndHeight() {
   getClientRect(hwnd, rect_buffer);
   rect.copyFromBuffer(rect_buffer);
   width = rect.right - rect.left;
   height = rect.bottom - rect.top;
 }
Exemplo n.º 5
0
 public static void intersect(Rect r1, Rect r2, Rect dst) {
   dst.top = Math.max(r1.top, r2.top);
   dst.bottom = Math.min(r1.bottom, r2.bottom);
   dst.left = Math.max(r1.left, r2.left);
   dst.right = Math.min(r1.right, r2.right);
 }
Exemplo n.º 6
0
  private long doHandleMessage(long hwnd, int msg, long wParam, long lParam, long millis) {
    /*switch ( msg ) {
    	case 0x0:
    	case 0x0020:
    	case 0x0084:
    	case WM_MOUSEMOVE:
    		break;
    	default:
    		WindowsEventDebug.printMessage(msg, wParam, lParam);
    }*/

    if (parent != null && !isFocused) {
      switch (msg) {
        case WM_LBUTTONDOWN:
        case WM_RBUTTONDOWN:
        case WM_MBUTTONDOWN:
        case WM_XBUTTONDOWN:
          sendMessage(parent_hwnd, msg, wParam, lParam);
      }
    }

    switch (msg) {
        // disable screen saver and monitor power down messages which wreak havoc
      case WM_ACTIVATE:
        /*switch ((int)wParam) {
        	case WA_ACTIVE:
        	case WA_CLICKACTIVE:
        		appActivate(true);
        		break;
        	case WA_INACTIVE:
        		appActivate(false);
        		break;
        }*/
        return 0L;
      case WM_SIZE:
        switch ((int) wParam) {
          case SIZE_RESTORED:
          case SIZE_MAXIMIZED:
            maximized = ((int) wParam) == SIZE_MAXIMIZED;
            resized = true;
            updateWidthAndHeight();
            setMinimized(false);
            break;
          case SIZE_MINIMIZED:
            setMinimized(true);
            break;
        }
        break;
      case WM_SIZING:
        resized = true;
        updateWidthAndHeight();
        break;
      case WM_SETCURSOR:
        if ((lParam & 0xFFFF) == HTCLIENT) {
          // if the cursor is inside the client area, reset it
          // to the current LWJGL-cursor
          updateCursor();
          return -1; // TRUE
        } else {
          // let Windows handle cursors outside the client area for resizing, etc.
          return defWindowProc(hwnd, msg, wParam, lParam);
        }
      case WM_KILLFOCUS:
        appActivate(false);
        return 0L;
      case WM_SETFOCUS:
        appActivate(true);
        return 0L;
      case WM_MOUSEACTIVATE:
        if (parent != null) {
          if (!isFocused) grabFocus();
          return 3L; // MA_NOACTIVATE
        }
        break;
      case WM_MOUSEMOVE:
        int xPos = (int) (short) (lParam & 0xFFFF);
        int yPos = transformY(getHwnd(), (int) (short) ((lParam >> 16) & 0xFFFF));
        handleMouseMoved(xPos, yPos, millis);
        checkCursorState();
        mouseInside = true;
        if (!trackingMouse) {
          trackingMouse = nTrackMouseEvent(hwnd);
        }
        return 0L;
      case WM_MOUSEWHEEL:
        int dwheel = (int) (short) ((wParam >> 16) & 0xFFFF);
        handleMouseScrolled(dwheel, millis);
        return 0L;
      case WM_LBUTTONDOWN:
        handleMouseButton(0, 1, millis);
        return 0L;
      case WM_LBUTTONUP:
        handleMouseButton(0, 0, millis);
        return 0L;
      case WM_RBUTTONDOWN:
        handleMouseButton(1, 1, millis);
        return 0L;
      case WM_RBUTTONUP:
        handleMouseButton(1, 0, millis);
        return 0L;
      case WM_MBUTTONDOWN:
        handleMouseButton(2, 1, millis);
        return 0L;
      case WM_MBUTTONUP:
        handleMouseButton(2, 0, millis);
        return 0L;
      case WM_XBUTTONUP:
        if ((wParam >> 16) == XBUTTON1) {
          handleMouseButton(3, 0, millis);
        } else {
          handleMouseButton(4, 0, millis);
        }
        return 1;
      case WM_XBUTTONDOWN:
        if ((wParam & 0xFF) == MK_XBUTTON1) {
          handleMouseButton(3, 1, millis);
        } else {
          handleMouseButton(4, 1, millis);
        }
        return 1;
      case WM_SYSCHAR:
      case WM_CHAR:
        handleChar(wParam, lParam, millis);
        return 0L;
      case WM_SYSKEYUP:
        /* Fall through */
      case WM_KEYUP:
        // SysRq apparently only generates WM_KEYUP, so we'll fake a WM_KEYDOWN
        if (wParam == WindowsKeycodes.VK_SNAPSHOT
            && keyboard != null
            && !keyboard.isKeyDown(org.lwjgl.input.Keyboard.KEY_SYSRQ)) {
          // Set key state to pressed
          long fake_lparam = lParam & ~(1 << 31);
          // Set key previous state to released
          fake_lparam &= ~(1 << 30);
          handleKeyButton(wParam, fake_lparam, millis);
        }
        /* Fall through */
      case WM_SYSKEYDOWN:
        /* Fall through */
      case WM_KEYDOWN:
        handleKeyButton(wParam, lParam, millis);
        break;
      case WM_QUIT:
        close_requested = true;
        return 0L;
      case WM_SYSCOMMAND:
        switch ((int) (wParam & 0xfff0)) {
          case SC_KEYMENU:
          case SC_MOUSEMENU:
          case SC_SCREENSAVE:
          case SC_MONITORPOWER:
            return 0L;
          case SC_CLOSE:
            close_requested = true;
            return 0L;
          default:
            break;
        }
        break;
      case WM_PAINT:
        is_dirty = true;
        break;
      case WM_MOUSELEAVE:
        mouseInside = false;
        trackingMouse = false;
        break;
      case WM_CANCELMODE:
        nReleaseCapture();
        /* fall through */
      case WM_CAPTURECHANGED:
        if (captureMouse != -1) {
          handleMouseButton(captureMouse, 0, millis);
          captureMouse = -1;
        }
        return 0L;
      case WM_WINDOWPOSCHANGED:
        if (getWindowRect(hwnd, rect_buffer)) {
          rect.copyFromBuffer(rect_buffer);
          x = rect.top;
          y = rect.bottom;
        } else {
          LWJGLUtil.log("WM_WINDOWPOSCHANGED: Unable to get window rect");
        }
        break;
      case WM_GETICON:
        iconsLoaded = true;
        break;
    }

    return defWindowProc(hwnd, msg, wParam, lParam);
  }
Exemplo n.º 7
0
 private static int transformY(long hwnd, int y) {
   getClientRect(hwnd, rect_buffer);
   rect.copyFromBuffer(rect_buffer);
   return (rect.bottom - rect.top) - 1 - y;
 }
Exemplo n.º 8
0
  private Element generateGraphicsNode(Document doc, ClassGraphics gr) {

    Element graphicsEl = doc.createElement(EL_GRAPHICS);

    Element bounds = doc.createElement(EL_BOUNDS);
    graphicsEl.appendChild(bounds);
    bounds.setAttribute(ATR_X, Integer.toString(gr.getBoundX()));
    bounds.setAttribute(ATR_Y, Integer.toString(gr.getBoundY()));
    bounds.setAttribute(ATR_WIDTH, Integer.toString(gr.getBoundWidth()));
    bounds.setAttribute(ATR_HEIGHT, Integer.toString(gr.getBoundHeight()));

    for (Shape shape : gr.getShapes()) {

      if (shape instanceof Rect) {
        Rect rect = (Rect) shape;
        Element rectEl = doc.createElement(EL_RECT);
        graphicsEl.appendChild(rectEl);
        rectEl.setAttribute(ATR_X, Integer.toString(rect.getX()));
        rectEl.setAttribute(ATR_Y, Integer.toString(rect.getY()));
        rectEl.setAttribute(ATR_WIDTH, Integer.toString(rect.getWidth()));
        rectEl.setAttribute(ATR_HEIGHT, Integer.toString(rect.getHeight()));
        rectEl.setAttribute(ATR_COLOUR, Integer.toString(rect.getColor().getRGB()));
        rectEl.setAttribute(ATR_FILLED, Boolean.toString(rect.isFilled()));
        rectEl.setAttribute(ATR_FIXED, Boolean.toString(rect.isFixed()));
        rectEl.setAttribute(ATR_STROKE, Float.toString(rect.getStroke().getLineWidth()));
        rectEl.setAttribute(ATR_LINETYPE, Float.toString(rect.getLineType()));
        rectEl.setAttribute(ATR_TRANSPARENCY, Integer.toString(rect.getTransparency()));
      } else if (shape instanceof Text) {
        Text text = (Text) shape;
        Element textEl = doc.createElement(EL_TEXT);
        textEl.setAttribute(ATR_STRING, text.getText());
        textEl.setAttribute(ATR_X, Integer.toString(text.getX()));
        textEl.setAttribute(ATR_Y, Integer.toString(text.getY()));
        textEl.setAttribute(ATR_FONTNAME, text.getFont().getName());
        textEl.setAttribute(ATR_FONTSIZE, Integer.toString(text.getFont().getSize()));
        textEl.setAttribute(ATR_FONTSTYLE, Integer.toString(text.getFont().getStyle()));
        textEl.setAttribute(ATR_TRANSPARENCY, Integer.toString(text.getTransparency()));
        textEl.setAttribute(ATR_COLOUR, Integer.toString(text.getColor().getRGB()));
        graphicsEl.appendChild(textEl);
      } // TODO handle the rest of shapes
    }

    return graphicsEl;
  }