X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgbase%2Fwindow.cpp;h=fbcbd519f99dbe01a49f70490b4f6de259d6c87b;hb=dce7552c5e2f64fcf5f58b0c934bb4a01f6cbcf7;hp=0b59a110c964f9073382432b93004492ce1ec2c7;hpb=c9626e6953c16efc66575eff80c4c0de2f739041;p=libs%2Fgui.git diff --git a/source/gbase/window.cpp b/source/gbase/window.cpp index 0b59a11..fbcbd51 100644 --- a/source/gbase/window.cpp +++ b/source/gbase/window.cpp @@ -23,16 +23,16 @@ LRESULT CALLBACK wndproc_(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam) { if(msg==WM_CREATE) { - CREATESTRUCT *cs=reinterpret_cast(lparam); + CREATESTRUCT *cs = reinterpret_cast(lparam); SetWindowLong(hwnd, 0, reinterpret_cast(cs->lpCreateParams)); } else { - Msp::Graphics::Window *wnd=reinterpret_cast(GetWindowLong(hwnd, 0)); + Msp::Graphics::Window *wnd = reinterpret_cast(GetWindowLong(hwnd, 0)); Msp::Graphics::Window::Event ev; - ev.msg=msg; - ev.wparam=wparam; - ev.lparam=lparam; + ev.msg = msg; + ev.wparam = wparam; + ev.lparam = lparam; if(wnd && wnd->event(ev)) return 0; } @@ -62,9 +62,9 @@ WindowOptions::WindowOptions(): Window::Window(Display &dpy, unsigned w, unsigned h, bool fs): display(dpy) { - options.width=w; - options.height=h; - options.fullscreen=fs; + options.width = w; + options.height = h; + options.fullscreen = fs; init(); } @@ -78,47 +78,47 @@ Window::Window(Display &dpy, const WindowOptions &opts): void Window::init() { - visible=false; - kbd_autorepeat=true; - resizing=false; - priv=new Private; + visible = false; + kbd_autorepeat = true; + resizing = false; + priv = new Private; #ifdef WIN32 - static bool wndclass_created=false; + static bool wndclass_created = false; if(!wndclass_created) { WNDCLASSEX wndcl; - wndcl.cbSize=sizeof(WNDCLASSEX); - wndcl.style=0; - wndcl.lpfnWndProc=&wndproc_; - wndcl.cbClsExtra=0; - wndcl.cbWndExtra=sizeof(Window *); - wndcl.hInstance=reinterpret_cast(Application::get_data()); - wndcl.hIcon=0; - wndcl.hCursor=LoadCursor(0, IDC_ARROW); - wndcl.hbrBackground=0; - wndcl.lpszMenuName=0; - wndcl.lpszClassName="mspgbase"; - wndcl.hIconSm=0; + wndcl.cbSize = sizeof(WNDCLASSEX); + wndcl.style = 0; + wndcl.lpfnWndProc = &wndproc_; + wndcl.cbClsExtra = 0; + wndcl.cbWndExtra = sizeof(Window *); + wndcl.hInstance = reinterpret_cast(Application::get_data()); + wndcl.hIcon = 0; + wndcl.hCursor = LoadCursor(0, IDC_ARROW); + wndcl.hbrBackground = 0; + wndcl.lpszMenuName = 0; + wndcl.lpszClassName = "mspgbase"; + wndcl.hIconSm = 0; if(!RegisterClassEx(&wndcl)) throw Exception("Couldn't register window class"); - wndclass_created=true; + wndclass_created = true; } RECT rect; SetRect(&rect, 0, 0, options.width, options.height); - int style=(options.fullscreen ? WS_POPUP : WS_OVERLAPPEDWINDOW); + int style = (options.fullscreen ? WS_POPUP : WS_OVERLAPPEDWINDOW); if(!options.resizable) - style&=~WS_THICKFRAME; - int exstyle=(options.fullscreen ? WS_EX_APPWINDOW : WS_EX_OVERLAPPEDWINDOW); + style &= ~WS_THICKFRAME; + int exstyle = (options.fullscreen ? WS_EX_APPWINDOW : WS_EX_OVERLAPPEDWINDOW); AdjustWindowRectEx(&rect, style, false, exstyle); - priv->window=CreateWindowEx(exstyle, + priv->window = CreateWindowEx(exstyle, "mspgbase", "Window", style, @@ -132,16 +132,16 @@ void Window::init() throw Exception("CreateWindowEx failed"); #else - ::Display *dpy=display.get_private().display; + ::Display *dpy = display.get_private().display; - priv->wm_delete_window=XInternAtom(dpy, "WM_DELETE_WINDOW", true); - priv->invisible_cursor=0; + priv->wm_delete_window = XInternAtom(dpy, "WM_DELETE_WINDOW", true); + priv->invisible_cursor = 0; XSetWindowAttributes attr; - attr.override_redirect=options.fullscreen; - attr.event_mask=ButtonPressMask|ButtonReleaseMask|PointerMotionMask|KeyPressMask|KeyReleaseMask|StructureNotifyMask|EnterWindowMask; + attr.override_redirect = options.fullscreen; + attr.event_mask = ButtonPressMask|ButtonReleaseMask|PointerMotionMask|KeyPressMask|KeyReleaseMask|StructureNotifyMask|EnterWindowMask; - priv->window=XCreateWindow(dpy, + priv->window = XCreateWindow(dpy, DefaultRootWindow(dpy), 0, 0, options.width, options.height, @@ -156,9 +156,9 @@ void Window::init() if(!options.resizable) { XSizeHints hints; - hints.flags=PMinSize|PMaxSize; - hints.min_width=hints.max_width=options.width; - hints.min_height=hints.max_height=options.height; + hints.flags = PMinSize|PMaxSize; + hints.min_width=hints.max_width = options.width; + hints.min_height=hints.max_height = options.height; XSetWMNormalHints(dpy, priv->window, &hints); } @@ -195,10 +195,10 @@ void Window::set_title(const string &title) #else vector buf(title.begin(), title.end()); XTextProperty prop; - prop.value=&buf[0]; - prop.encoding=XA_STRING; - prop.format=8; - prop.nitems=title.size(); + prop.value = &buf[0]; + prop.encoding = XA_STRING; + prop.format = 8; + prop.nitems = title.size(); XSetWMName(display.get_private().display, priv->window, &prop); display.check_error(); #endif @@ -206,19 +206,19 @@ void Window::set_title(const string &title) void Window::reconfigure(const WindowOptions &opts) { - bool fullscreen_changed=(opts.fullscreen!=options.fullscreen); - resizing=(opts.width!=options.width || opts.height!=options.height); + bool fullscreen_changed = (opts.fullscreen!=options.fullscreen); + resizing = (opts.width!=options.width || opts.height!=options.height); - options=opts; + options = opts; #ifdef WIN32 RECT rect; SetRect(&rect, 0, 0, options.width, options.height); - int style=(options.fullscreen ? WS_POPUP : WS_OVERLAPPEDWINDOW); + int style = (options.fullscreen ? WS_POPUP : WS_OVERLAPPEDWINDOW); if(!options.resizable) - style&=~WS_THICKFRAME; - int exstyle=(options.fullscreen ? WS_EX_APPWINDOW : WS_EX_OVERLAPPEDWINDOW); + style &= ~WS_THICKFRAME; + int exstyle = (options.fullscreen ? WS_EX_APPWINDOW : WS_EX_OVERLAPPEDWINDOW); AdjustWindowRectEx(&rect, style, false, exstyle); if(fullscreen_changed) @@ -234,9 +234,9 @@ void Window::reconfigure(const WindowOptions &opts) else SetWindowPos(priv->window, 0, 0, 0, rect.right-rect.left, rect.bottom-rect.top, SWP_NOMOVE|SWP_NOZORDER); #else - ::Display *dpy=display.get_private().display; + ::Display *dpy = display.get_private().display; - bool was_visible=visible; + bool was_visible = visible; if(fullscreen_changed) { if(was_visible) @@ -245,23 +245,23 @@ void Window::reconfigure(const WindowOptions &opts) // Wait for the window to be unmapped. This makes window managers happy. XEvent ev; - int ev_type=UnmapNotify; + int ev_type = UnmapNotify; XPeekIfEvent(dpy, &ev, match_event_type, reinterpret_cast(&ev_type)); } XSetWindowAttributes attr; - attr.override_redirect=options.fullscreen; + attr.override_redirect = options.fullscreen; XChangeWindowAttributes(dpy, priv->window, CWOverrideRedirect, &attr); } XSizeHints hints; if(options.resizable) - hints.flags=0; + hints.flags = 0; else { - hints.flags=PMinSize|PMaxSize; - hints.min_width=hints.max_width=options.width; - hints.min_height=hints.max_height=options.height; + hints.flags = PMinSize|PMaxSize; + hints.min_width=hints.max_width = options.width; + hints.min_height=hints.max_height = options.height; } XSetWMNormalHints(dpy, priv->window, &hints); @@ -288,7 +288,7 @@ void Window::reconfigure(const WindowOptions &opts) void Window::set_keyboard_autorepeat(bool r) { - kbd_autorepeat=r; + kbd_autorepeat = r; } void Window::show_cursor(bool s) @@ -296,7 +296,7 @@ void Window::show_cursor(bool s) #ifdef WIN32 ShowCursor(s); #else - ::Display *dpy=display.get_private().display; + ::Display *dpy = display.get_private().display; if(s) XUndefineCursor(dpy, priv->window); @@ -304,19 +304,19 @@ void Window::show_cursor(bool s) { if(!priv->invisible_cursor) { - int screen=DefaultScreen(dpy); + int screen = DefaultScreen(dpy); - Pixmap pm=XCreatePixmap(dpy, priv->window, 1, 1, 1); - GC gc=XCreateGC(dpy, pm, 0, 0); + Pixmap pm = XCreatePixmap(dpy, priv->window, 1, 1, 1); + GC gc = XCreateGC(dpy, pm, 0, 0); XSetFunction(dpy, gc, GXclear); XDrawPoint(dpy, pm, gc, 0, 0); XFreeGC(dpy, gc); XColor black; - black.pixel=BlackPixel(dpy, screen); + black.pixel = BlackPixel(dpy, screen); XQueryColor(dpy, DefaultColormap(dpy, screen), &black); - priv->invisible_cursor=XCreatePixmapCursor(dpy, pm, pm, &black, &black, 0, 0); + priv->invisible_cursor = XCreatePixmapCursor(dpy, pm, pm, &black, &black, 0, 0); XFreePixmap(dpy, pm); } @@ -342,7 +342,7 @@ void Window::show() #else XMapRaised(display.get_private().display, priv->window); #endif - visible=true; + visible = true; if(options.fullscreen) { @@ -360,7 +360,7 @@ void Window::hide() #else XUnmapWindow(display.get_private().display, priv->window); #endif - visible=false; + visible = false; if(options.fullscreen) display.restore_mode(); @@ -369,8 +369,8 @@ void Window::hide() bool Window::event(const Event &evnt) { #ifdef WIN32 - WPARAM wp=evnt.wparam; - LPARAM lp=evnt.lparam; + WPARAM wp = evnt.wparam; + LPARAM lp = evnt.lparam; switch(evnt.msg) { case WM_KEYDOWN: @@ -408,8 +408,8 @@ bool Window::event(const Event &evnt) signal_pointer_motion.emit(GET_X_LPARAM(lp), GET_Y_LPARAM(lp)); break; case WM_SIZE: - options.width=LOWORD(lp); - options.height=HIWORD(lp); + options.width = LOWORD(lp); + options.height = HIWORD(lp); signal_resize.emit(options.width, options.height); break; case WM_CLOSE: @@ -419,7 +419,7 @@ bool Window::event(const Event &evnt) return false; } #else - const XEvent &ev=evnt.xevent; + const XEvent &ev = evnt.xevent; switch(ev.type) { case ButtonPress: @@ -445,16 +445,16 @@ bool Window::event(const Event &evnt) case ConfigureNotify: if((ev.xconfigure.width==static_cast(options.width) && ev.xconfigure.height==static_cast(options.height)) == resizing) { - options.width=ev.xconfigure.width; - options.height=ev.xconfigure.height; - resizing=false; + options.width = ev.xconfigure.width; + options.height = ev.xconfigure.height; + resizing = false; signal_resize.emit(options.width, options.height); } #ifdef WITH_XF86VIDMODE if(options.fullscreen) { - ::Display *dpy=display.get_private().display; - int screen=DefaultScreen(dpy); + ::Display *dpy = display.get_private().display; + int screen = DefaultScreen(dpy); XF86VidModeSetViewPort(dpy, screen, ev.xconfigure.x, ev.xconfigure.y); } #endif