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

clanwindowscreen.cpp

Go to the documentation of this file.
00001 /*
00002         $Id: clanwindowscreen.cpp,v 1.1 2001/03/06 15:09:17 mbn 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 <Display/Input/Be/keyboard_be.h>
00017 #include <API/Core/System/error.h>
00018 #include <API/Display/Input/input.h>
00019 #include <API/Core/System/system.h>
00020 #include "Core/System/Generic/string_asm.h"
00021 
00022 #include "clanwindowscreen.h"
00023 
00024 #include <Screen.h>
00025 #include <AppDefs.h>
00026 
00027 ClanWindowScreen::ClanWindowScreen(status_t* ret) : BWindowScreen("ClanWindowScreen",B_16_BIT_640x480,ret)
00028 {
00029         if (*ret < B_OK)
00030         {
00031                 throw CL_Error("Could not create BWindowScreen");
00032         }
00033         
00034         if (!CanControlFrameBuffer())
00035         {
00036                 throw CL_Error("We have no control over the framebuffer");
00037         }
00038         
00039         save_buffer = NULL;
00040         connected = false;
00041 }
00042 
00043 void ClanWindowScreen::ScreenConnected(bool is_connected)
00044 {
00045         connected = is_connected;
00046         
00047         if (connected)
00048         {
00049                 uint32 space = find_space();
00050                 if (!space)
00051                 {
00052                         throw CL_Error("No valid mode found");
00053                 }
00054                 if (SetSpace(space)<B_OK)
00055                 {
00056                         throw CL_Error("Could not set mode");
00057                 }
00058 
00059                 frames = 2;
00060                 if (SetFrameBuffer(width,height*frames)<B_OK)
00061                 {
00062                         throw CL_Error("Could not set framebuffer dimensions");
00063                 }
00064 
00065                 frame_buffer = (uint8*)(CardInfo()->frame_buffer);
00066                 line_length = FrameBufferInfo()->bytes_per_row;
00067                 write_frame = 1;
00068                 
00069                 sync=(sync_hook)CardHookAt(7);
00070                 if (sync)
00071                 {
00072 //                      std::cout << "ClanWindowScreen: Using sync after clear_dislay" << std::endl;
00073                 }
00074 
00075                 init_accelerations();
00076 
00077                 memset( frame_buffer, 0, line_length*height*frames );
00078 
00079                 if (save_buffer)
00080                 {
00081                         fast_memmove( frame_buffer, save_buffer, line_length*height*frames );
00082                 } else
00083                 {
00084                         save_buffer = new uint8[line_length*height*frames];
00085                 }
00086         } else
00087         {
00088                 CL_System::suspend_time();
00089                 fast_memmove( save_buffer, frame_buffer, line_length*height*frames );
00090         }
00091 }
00092 
00093 void ClanWindowScreen::init_accelerations()
00094 {
00095         fill_rect8 = NULL;
00096         fill_rect16 = NULL;
00097         fill_rect32 = NULL;
00098         acc_fill_rect = false;
00099         switch (bpp)
00100         {
00101                 case 8:
00102                         fill_rect8=(rect8_hook)CardHookAt(5);
00103                         if (fill_rect8)
00104                         {
00105                                 std::cout << "ClanWindowScreen: Using accelerated fill_rect" << std::endl;
00106                                 acc_fill_rect = true;
00107                         }
00108                         break;
00109                 case 16:
00110                         fill_rect16=(rect16_hook)CardHookAt(13);
00111                         if (fill_rect16)
00112                         {
00113                                 std::cout << "ClanWindowScreen: Using accelerated fill_rect" << std::endl;
00114                                 acc_fill_rect = true;
00115                         }
00116                         break;
00117                 case 32:
00118                         fill_rect32=(rect32_hook)CardHookAt(6);
00119                         if (fill_rect32)
00120                         {
00121                                 std::cout << "ClanWindowScreen: Using accelerated fill_rect" << std::endl;
00122                                 acc_fill_rect = true;
00123                         }
00124                         break;
00125         }
00126 }
00127 
00128 bool ClanWindowScreen::fill_rect_accelerated()
00129 {
00130         return acc_fill_rect;
00131 }
00132 
00133 void ClanWindowScreen::set_videomode(int _width, int _height, int _bpp, bool _fullscreen, bool _allow_resize, bool _video_memory)
00134 {
00135         width = _width;
00136         height = _height;
00137         bpp = _bpp;
00138         fullscreen = _fullscreen;
00139         allow_resize = _allow_resize;
00140         
00141         Show();
00142 }
00143 
00144 void ClanWindowScreen::flip_display()
00145 {
00146         if (connected)
00147         {
00148                 MoveDisplayArea(0,height*write_frame);
00149                 BScreen(this).WaitForRetrace();
00150                 write_frame = !write_frame;
00151         } else
00152         {
00153                 while(!connected)
00154                 {
00155                         snooze(5000);
00156                 }
00157                 CL_System::resume_time();
00158                 write_frame = !write_frame;
00159         }
00160 }
00161 
00162 void ClanWindowScreen::put_display(const CL_Rect &rect)
00163 {
00164         // this is not implemented! Someone with BeOS knowledge, please do so. :)
00165         // mbn -- 21. nov 2000
00166         cl_assert(false); 
00167 }
00168 
00169 uint8* ClanWindowScreen::get_data()
00170 {
00171         if (!connected)
00172         {
00173                 return save_buffer + line_length*height*write_frame;
00174         }
00175         return frame_buffer + line_length*height*write_frame;
00176 }
00177 
00178 uint32 ClanWindowScreen::find_space()
00179 {
00180         if ((width==640) && (height==480) && (bpp==8))
00181                 return B_8_BIT_640x480;
00182         if ((width==640) && (height==480) && (bpp==16))
00183                 return B_16_BIT_640x480;
00184         if ((width==640) && (height==480) && (bpp==32))
00185                 return B_32_BIT_640x480;
00186         
00187         if ((width==800) && (height==600) && (bpp==8))
00188                 return B_8_BIT_800x600;
00189         if ((width==800) && (height==600) && (bpp==16))
00190                 return B_16_BIT_800x600;
00191         if ((width==800) && (height==600) && (bpp==32))
00192                 return B_32_BIT_800x600;
00193 
00194         if ((width==1024) && (height==768) && (bpp==8))
00195                 return B_8_BIT_1024x768;
00196         if ((width==1024) && (height==768) && (bpp==16))
00197                 return B_16_BIT_1024x768;
00198         if ((width==1024) && (height==768) && (bpp==32))
00199                 return B_32_BIT_1024x768;
00200 
00201         return 0;
00202 }
00203 
00204 void ClanWindowScreen::MessageReceived(BMessage *message)
00205 {
00206         switch ( message->what )
00207         {
00208                 case B_KEY_DOWN:
00209                         ((CL_BeKeyboard*)(CL_Input::keyboards[0]))->handle_key( message, true );
00210                         break;
00211                 case B_KEY_UP:
00212                         ((CL_BeKeyboard*)(CL_Input::keyboards[0]))->handle_key( message, false );
00213                         break;
00214                 case B_MODIFIERS_CHANGED:
00215                         ((CL_BeKeyboard*)(CL_Input::keyboards[0]))->handle_modifiers( message );
00216                         break;
00217                 default:
00218                         BWindowScreen::MessageReceived(message);
00219                         break;
00220         }
00221 }

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