示例#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;
  }
示例#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);
 }
示例#3
0
 static void setupCursorClipping(long hwnd) throws LWJGLException {
   cursor_clipped = true;
   getGlobalClientRect(hwnd, rect);
   rect.copyToBuffer(rect_buffer);
   clipCursor(rect_buffer);
 }
示例#4
0
 private void updateWidthAndHeight() {
   getClientRect(hwnd, rect_buffer);
   rect.copyFromBuffer(rect_buffer);
   width = rect.right - rect.left;
   height = rect.bottom - rect.top;
 }
示例#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);
 }
示例#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);
  }
示例#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;
 }