Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

displaycard_win32compatible.cpp

Go to the documentation of this file.
00001 /*
00002         $Id: displaycard_win32compatible.cpp,v 1.2 2001/03/06 19:45:24 japj Exp $
00003 
00004         ------------------------------------------------------------------------
00005         ClanLib, the platform independent game SDK.
00006 
00007         This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00008         version 2. See COPYING for details.
00009 
00010         For a total list of contributers see CREDITS.
00011 
00012         ------------------------------------------------------------------------
00013 */
00014 
00015 #include "Core/precomp.h"
00016 #include <windows.h>
00017 #include "displaycard_win32compatible.h"
00018 #include "Core/System/Win32/init_win32.h"
00019 #include "API/Core/Math/rect.h"
00020 #include "API/Application.h"
00021 
00022 CL_DisplayCard_Win32Compatible::CL_DisplayCard_Win32Compatible(int card_no)
00023 : CL_DisplayCard_Generic(card_no)
00024 {
00025         hwnd = NULL;
00026         
00027         CL_System_Win32::add_listener(this);
00028 }
00029 
00030 CL_DisplayCard_Win32Compatible::~CL_DisplayCard_Win32Compatible()
00031 {
00032         CL_System_Win32::remove_listener(this);
00033 
00034         destroy_window();
00035 }
00036 
00037 void CL_DisplayCard_Win32Compatible::destroy_window()
00038 {
00039         if (hwnd == NULL) return;
00040 
00041         BOOL res = DestroyWindow(hwnd);
00042         cl_assert(res == TRUE);
00043         hwnd = NULL;
00044 }
00045 
00046 extern LONG WINAPI MainMessageHandler(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
00047 
00048 void CL_DisplayCard_Win32Compatible::create_window(
00049         int width,
00050         int height,
00051         int bpp,
00052         bool full_screen,
00053         bool allow_resize)
00054 {
00055         WNDCLASS wndclass;
00056 
00057         wndclass.style = 0;
00058         wndclass.lpfnWndProc = (WNDPROC) MainMessageHandler;
00059         wndclass.cbClsExtra = 0;
00060         wndclass.cbWndExtra = 0;
00061         wndclass.hInstance = CL_System_Win32::hInstance;
00062         wndclass.hIcon = NULL;
00063         wndclass.hCursor = LoadCursor (NULL,IDC_ARROW);
00064         wndclass.hbrBackground = (HBRUSH)(COLOR_WINDOW+1);
00065         wndclass.lpszMenuName = "ClanApplication";
00066         wndclass.lpszClassName = "ClanApplication";
00067 
00068         RegisterClass(&wndclass);
00069 
00070         int x = 0;
00071         int y = 0;
00072 
00073         if (full_screen)
00074         {
00075                 width = GetSystemMetrics(SM_CXSCREEN);
00076                 height = GetSystemMetrics(SM_CYSCREEN);
00077         }
00078         else
00079         {
00080                 int scr_width = GetSystemMetrics(SM_CXSCREEN);
00081                 int scr_height = GetSystemMetrics(SM_CYSCREEN);
00082 
00083                 x = scr_width/2 - width/2;
00084                 y = scr_height/2 - height/2;
00085         }
00086 
00087         int style;
00088         if (full_screen)
00089         {
00090                 style = WS_POPUP;
00091         }
00092         else if (allow_resize)
00093         {
00094                 style = WS_POPUP | WS_SYSMENU | WS_CAPTION | WS_SIZEBOX | WS_MAXIMIZEBOX /* | WS_MINIMIZEBOX*/;
00095         }
00096         else
00097         {
00098                 style = WS_POPUPWINDOW | WS_CAPTION /*| WS_MINIMIZEBOX*/;
00099         }
00100 
00101         char *title = CL_ClanApplication::app->get_title();
00102 
00103         hwnd = CreateWindow(
00104                 "ClanApplication",
00105                 title,
00106                 style,
00107                 x,
00108                 y,
00109                 width,
00110                 height,
00111                 NULL,
00112                 NULL,
00113                 CL_System_Win32::hInstance,
00114                 NULL);
00115 
00116         cl_assert(hwnd != NULL);
00117 
00118         // Ok. Thanks to microsoft, the titlebar is part of the window!
00119         // I havn't been able to find a function that gets the size of the titlebar (probably just me),
00120         // so I do some clientrect calcing. Someone please fix this, and in the flip_display()
00121         // function too.
00122 
00123         if (!full_screen)
00124         {
00125                 RECT client_rect;
00126                 GetClientRect(hwnd, &client_rect);
00127 
00128                 POINT Pt;
00129                 Pt.x=0;
00130                 Pt.y=0;
00131                 ClientToScreen(hwnd,&Pt);
00132 
00133                 RECT dest_rect;
00134                 GetWindowRect(hwnd, &dest_rect);
00135 
00136                 // Add windows title bar height and the +3 is for the windows bottom border
00137                 // I don't think there's another way of doing it
00138                 dest_rect.bottom += (Pt.y-dest_rect.top)+3;
00139 
00140                 // Add window left/right borders width
00141                 dest_rect.right   += (Pt.x-dest_rect.left)*2;
00142 
00143                 SetWindowPos(
00144                         hwnd,
00145                         HWND_TOP,
00146                         dest_rect.left,
00147                         dest_rect.top,
00148                         dest_rect.right - dest_rect.left,
00149                         dest_rect.bottom - dest_rect.top,
00150                         SWP_NOZORDER | SWP_FRAMECHANGED);
00151         }
00152 
00153         ShowWindow(hwnd, SW_SHOW);
00154         UpdateWindow(hwnd);
00155 }
00156 
00157 void CL_DisplayCard_Win32Compatible::show_system_cursor()
00158 {
00159         ShowCursor(TRUE);
00160 }
00161 
00162 void CL_DisplayCard_Win32Compatible::hide_system_cursor()
00163 {
00164         ShowCursor(FALSE);
00165 }
00166 
00167 bool CL_DisplayCard_Win32Compatible::received_event(UINT uMsg, WPARAM wParam, LPARAM lParam)
00168 {
00169         switch (uMsg)
00170         {
00171         case WM_SIZE:
00172                 set_resize(LOWORD(lParam), HIWORD(lParam));
00173                 return true;
00174 
00175         case WM_PAINT:
00176                 {
00177                         HDC hdc = (HDC) wParam;
00178                         RECT rect;
00179                         if (GetUpdateRect(hwnd, &rect, FALSE))
00180                         {
00181                                 PAINTSTRUCT paint;
00182                                 BeginPaint(hwnd, &paint);
00183 
00184                                 CL_Rect cl_rect;
00185                                 cl_rect.x1 = rect.left;
00186                                 cl_rect.y1 = rect.top;
00187                                 cl_rect.x2 = rect.right;
00188                                 cl_rect.y2 = rect.bottom;
00189 
00190                                 get_sig_paint()(cl_rect);
00191 
00192                                 EndPaint(hwnd, &paint);
00193                         }
00194                         else
00195                         {
00196                                 CL_Rect cl_rect(0, 0, get_width(), get_height());
00197                                 get_sig_paint()(cl_rect);
00198                         }
00199                 }
00200                 return true;
00201 
00202         default:
00203                 return false;
00204         }
00205 }

Generated at Wed Apr 4 19:54:00 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001