int Renderer::Init(shared_ptr<VideoPlugin> plugin) { delete _renderFunc; _renderFunc = NULL; _videoPlugin = plugin; _videoPlugin->SetOption("OpenGLFilter", _videoPluginOpenGLFilter); _videoPlugin->SetOption("Remanency", _monitorRemanency); void *backSurface = _videoPlugin->GetSurface(); switch(_videoPlugin->GetRenderSurfaceBPP()) { case 32: _renderFunc = new Render32BppFunction; break; case 24: _renderFunc = new Render24BppFunction; break; case 16: case 15: _renderFunc = new Render16BppFunction; break; case 8: _renderFunc = new Render8BppFunction; break; default: _renderFunc = new Render0BppFunction; break; } _videoPlugin->TryLock(); // TODO: Seen if need real lock. _scrLineOffset = _videoPlugin->GetRenderSurfacePitch() / 4; _scrPos = _scrBase = 0; // memory address of back buffer _renderFunc->SetBackSurface(backSurface); _renderFunc->SetRenderSurfaceWidth(_videoPlugin->GetRenderSurfaceWidth()); _renderFunc->SetRenderSurfaceHeight(_videoPlugin->GetRenderSurfaceHeight()); _renderFunc->SetScreenPosition(_scrPos); _renderFunc->SetRenderSurfacePitch(_videoPlugin->GetRenderSurfacePitch()); _renderFunc->SetRenderSurfaceBPP(_videoPlugin->GetRenderSurfaceBPP()); Reset(); _videoPlugin->Unlock(); InitPalette(); // init CPC colours return 0; }
static bool CreateMainSurface(uint w, uint h) { SDL_Surface *newscreen, *icon; char caption[50]; int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(); GetAvailableVideoMode(&w, &h); DEBUG(driver, 1, "SDL: using mode %ux%ux%d", w, h, bpp); if (bpp == 0) usererror("Can't use a blitter that blits 0 bpp for normal visuals"); /* Give the application an icon */ icon = SDL_CALL SDL_LoadBMP(ICON_DIR PATHSEP "openttd.32.bmp"); if (icon != NULL) { /* Get the colourkey, which will be magenta */ uint32 rgbmap = SDL_CALL SDL_MapRGB(icon->format, 255, 0, 255); SDL_CALL SDL_SetColorKey(icon, SDL_SRCCOLORKEY, rgbmap); SDL_CALL SDL_WM_SetIcon(icon, NULL); SDL_CALL SDL_FreeSurface(icon); } /* DO NOT CHANGE TO HWSURFACE, IT DOES NOT WORK */ newscreen = SDL_CALL SDL_SetVideoMode(w, h, bpp, SDL_SWSURFACE | SDL_HWPALETTE | (_fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE)); if (newscreen == NULL) { DEBUG(driver, 0, "SDL: Couldn't allocate a window to draw on"); return false; } /* Delay drawing for this cycle; the next cycle will redraw the whole screen */ _num_dirty_rects = 0; _screen.width = newscreen->w; _screen.height = newscreen->h; _screen.pitch = newscreen->pitch / (bpp / 8); _screen.dst_ptr = newscreen->pixels; _sdl_screen = newscreen; BlitterFactoryBase::GetCurrentBlitter()->PostResize(); InitPalette(); snprintf(caption, sizeof(caption), "OpenTTD %s", _openttd_revision); SDL_CALL SDL_WM_SetCaption(caption, caption); SDL_CALL SDL_ShowCursor(0); GameSizeChanged(); return true; }
void cDisplay3BPPHalf::InitOSD() { if (osd) delete osd; osd = cOsdProvider::NewOsd(OsdX0, OsdY0); if (!osd) return; int width=(Width+1)&~1; // Width has to end on byte boundary, so round up tArea Areas[] = { { 0, 0, width - 1, Height - 1, 4 } }; // Try full-size area first while (osd->CanHandleAreas(Areas, sizeof(Areas) / sizeof(tArea)) != oeOk) { // Out of memory, so shrink if (Upper) { // Move up lower border Areas[0].y2=Areas[0].y2-1; } else { // Move down upper border Areas[0].y1=Areas[0].y1+1; } if (Areas[0].y1>Areas[0].y2) { // Area is empty, fail miserably delete osd; osd=NULL; return; } } // Add some backup // CanHandleAreas is not accurate enough if (Upper) { Areas[0].y2=Areas[0].y2-10; } else { Areas[0].y1=Areas[0].y1+10; } osd->SetAreas(Areas, sizeof(Areas) / sizeof(tArea)); InitPalette(); InitScaler(); // In case we switched on the fly, do a full redraw Dirty=true; DirtyAll=true; Flush(); }
static bool CreateMainSurface(uint w, uint h) { int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(); if (bpp == 0) usererror("Can't use a blitter that blits 0 bpp for normal visuals"); set_color_depth(bpp); GetAvailableVideoMode(&w, &h); if (set_gfx_mode(_fullscreen ? GFX_AUTODETECT_FULLSCREEN : GFX_AUTODETECT_WINDOWED, w, h, 0, 0) != 0) { DEBUG(driver, 0, "Allegro: Couldn't allocate a window to draw on '%s'", allegro_error); return false; } /* The size of the screen might be bigger than the part we can actually draw on! * So calculate the size based on the top, bottom, left and right */ _allegro_screen = create_bitmap_ex(bpp, screen->cr - screen->cl, screen->cb - screen->ct); _screen.width = _allegro_screen->w; _screen.height = _allegro_screen->h; _screen.pitch = ((byte*)screen->line[1] - (byte*)screen->line[0]) / (bpp / 8); _screen.dst_ptr = _allegro_screen->line[0]; /* Initialise the screen so we don't blit garbage to the screen */ memset(_screen.dst_ptr, 0, _screen.height * _screen.pitch); /* Set the mouse at the place where we expect it */ poll_mouse(); _cursor.pos.x = mouse_x; _cursor.pos.y = mouse_y; BlitterFactoryBase::GetCurrentBlitter()->PostResize(); InitPalette(); char caption[32]; snprintf(caption, sizeof(caption), "OpenTTD %s", _openttd_revision); set_window_title(caption); enable_hardware_cursor(); select_mouse_cursor(MOUSE_CURSOR_ARROW); show_mouse(_allegro_screen); GameSizeChanged(); return true; }
cDisplay2BPP::cDisplay2BPP(int x0, int y0, int width, int height) : cDisplay(width,height) { // 2BPP display with color mapping osd = cOsdProvider::NewOsd(x0, y0); if (!osd) return; width=(width+3)&~3; // Width has to end on byte boundary, so round up tArea Areas[] = { { 0, 0, width - 1, height - 1, 2 } }; if (osd->CanHandleAreas(Areas, sizeof(Areas) / sizeof(tArea)) != oeOk) { delete osd; osd=NULL; return; } osd->SetAreas(Areas, sizeof(Areas) / sizeof(tArea)); InitPalette(); InitScaler(); }
cDisplay3BPP::cDisplay3BPP(int x0, int y0, int width, int height) : cDisplay(width,height) { // 3BPP display for memory-modded DVB cards and other OSD providers // Actually uses 4BPP, because DVB does not support 3BPP. osd = cOsdProvider::NewOsd(x0, y0); if (!osd) return; width=(width+1)&~1; // Width has to end on byte boundary, so round up tArea Areas[] = { { 0, 0, width - 1, height - 1, 4 } }; if (osd->CanHandleAreas(Areas, sizeof(Areas) / sizeof(tArea)) != oeOk) { delete osd; osd=NULL; return; } osd->SetAreas(Areas, sizeof(Areas) / sizeof(tArea)); InitPalette(); InitScaler(); }
bool VideoDriver_SDL::CreateMainSurface(uint w, uint h) { SDL_Surface *newscreen, *icon; char caption[50]; int bpp = BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(); bool want_hwpalette; GetAvailableVideoMode(&w, &h); DEBUG(driver, 1, "SDL: using mode %ux%ux%d", w, h, bpp); if (bpp == 0) usererror("Can't use a blitter that blits 0 bpp for normal visuals"); char icon_path[MAX_PATH]; if (FioFindFullPath(icon_path, lengthof(icon_path), BASESET_DIR, "openttd.32.bmp") != NULL) { /* Give the application an icon */ icon = SDL_CALL SDL_LoadBMP(icon_path); if (icon != NULL) { /* Get the colourkey, which will be magenta */ uint32 rgbmap = SDL_CALL SDL_MapRGB(icon->format, 255, 0, 255); SDL_CALL SDL_SetColorKey(icon, SDL_SRCCOLORKEY, rgbmap); SDL_CALL SDL_WM_SetIcon(icon, NULL); SDL_CALL SDL_FreeSurface(icon); } } if (_use_hwpalette == 2) { /* Default is to autodetect when to use SDL_HWPALETTE. * In this case, SDL_HWPALETTE is only used for 8bpp * blitters in fullscreen. * * When using an 8bpp blitter on a 8bpp system in * windowed mode with SDL_HWPALETTE, OpenTTD will claim * the system palette, making all other applications * get the wrong colours. In this case, we're better of * trying to approximate the colors we need using system * colors, using a shadow surface (see below). * * On a 32bpp system, SDL_HWPALETTE is ignored, so it * doesn't matter what we do. * * When using a 32bpp blitter on a 8bpp system, setting * SDL_HWPALETTE messes up rendering (at least on X11), * so we don't do that. In this case, SDL takes care of * color approximation using its own shadow surface * (which we can't force in 8bpp on 8bpp mode, * unfortunately). */ want_hwpalette = (bpp == 8 && _fullscreen); } else { /* User specified a value manually */ want_hwpalette = _use_hwpalette; } if (want_hwpalette) DEBUG(driver, 1, "SDL: requesting hardware palete"); /* Free any previously allocated shadow surface */ if (_sdl_screen != NULL && _sdl_screen != _sdl_realscreen) SDL_CALL SDL_FreeSurface(_sdl_screen); if (_sdl_realscreen != NULL) { if (_requested_hwpalette != want_hwpalette) { /* SDL (at least the X11 driver), reuses the * same window and palette settings when the bpp * (and a few flags) are the same. Since we need * to hwpalette value to change (in particular * when switching between fullscreen and * windowed), we restart the entire video * subsystem to force creating a new window. */ DEBUG(driver, 0, "SDL: Restarting SDL video subsystem, to force hwpalette change"); SDL_CALL SDL_QuitSubSystem(SDL_INIT_VIDEO); SDL_CALL SDL_InitSubSystem(SDL_INIT_VIDEO); ClaimMousePointer(); SetupKeyboard(); } } /* Remember if we wanted a hwpalette. We can't reliably query * SDL for the SDL_HWPALETTE flag, since it might get set even * though we didn't ask for it (when SDL creates a shadow * surface, for example). */ _requested_hwpalette = want_hwpalette; /* DO NOT CHANGE TO HWSURFACE, IT DOES NOT WORK */ newscreen = SDL_CALL SDL_SetVideoMode(w, h, bpp, SDL_SWSURFACE | (want_hwpalette ? SDL_HWPALETTE : 0) | (_fullscreen ? SDL_FULLSCREEN : SDL_RESIZABLE)); if (newscreen == NULL) { DEBUG(driver, 0, "SDL: Couldn't allocate a window to draw on"); return false; } _sdl_realscreen = newscreen; if (bpp == 8 && (_sdl_realscreen->flags & SDL_HWPALETTE) != SDL_HWPALETTE) { /* Using an 8bpp blitter, if we didn't get a hardware * palette (most likely because we didn't request one, * see above), we'll have to set up a shadow surface to * render on. * * Our palette will be applied to this shadow surface, * while the real screen surface will use the shared * system palette (which will partly contain our colors, * but most likely will not have enough free color cells * for all of our colors). SDL can use these two * palettes at blit time to approximate colors used in * the shadow surface using system colors automatically. * * Note that when using an 8bpp blitter on a 32bpp * system, SDL will create an internal shadow surface. * This shadow surface will have SDL_HWPALLETE set, so * we won't create a second shadow surface in this case. */ DEBUG(driver, 1, "SDL: using shadow surface"); newscreen = SDL_CALL SDL_CreateRGBSurface(SDL_SWSURFACE, w, h, bpp, 0, 0, 0, 0); if (newscreen == NULL) { DEBUG(driver, 0, "SDL: Couldn't allocate a shadow surface to draw on"); return false; } } /* Delay drawing for this cycle; the next cycle will redraw the whole screen */ _num_dirty_rects = 0; _screen.width = newscreen->w; _screen.height = newscreen->h; _screen.pitch = newscreen->pitch / (bpp / 8); _screen.dst_ptr = newscreen->pixels; _sdl_screen = newscreen; /* When in full screen, we will always have the mouse cursor * within the window, even though SDL does not give us the * appropriate event to know this. */ if (_fullscreen) _cursor.in_window = true; Blitter *blitter = BlitterFactoryBase::GetCurrentBlitter(); blitter->PostResize(); InitPalette(); switch (blitter->UsePaletteAnimation()) { case Blitter::PALETTE_ANIMATION_NONE: case Blitter::PALETTE_ANIMATION_VIDEO_BACKEND: UpdatePalette(); break; case Blitter::PALETTE_ANIMATION_BLITTER: if (_video_driver != NULL) blitter->PaletteAnimate(_local_palette); break; default: NOT_REACHED(); } snprintf(caption, sizeof(caption), "OpenTTD %s", _openttd_revision); SDL_CALL SDL_WM_SetCaption(caption, caption); GameSizeChanged(); return true; }
/* * imgEditInit - initialization */ static BOOL imgEditInit( HANDLE currinst, HANDLE previnst, int cmdshow ) { WNDCLASS wc; HMENU menu; HDC hdc; BOOL maximized; int show_state; hdc = GetDC( NULL ); ColorPlanes = GetDeviceCaps( hdc, PLANES ); BitsPerPixel = GetDeviceCaps( hdc, BITSPIXEL ); ReleaseDC( NULL, hdc ); Instance = currinst; IEInitErrors( currinst ); IEInitGlobalStrings(); if( ImgedIsDDE ) { menu = LoadMenu( Instance, "IMGEDDDEMENU" ); } else { menu = LoadMenu( Instance, "IMGEDMENU" ); } hBitmapIcon = LoadIcon( Instance, "BitmapIcon" ); hIconIcon = LoadIcon( Instance, "IconIcon" ); hCursorIcon = LoadIcon( Instance, "CursorIcon" ); hAccel = LoadAccelerators( Instance, "Accelerators" ); IECtl3dInit( Instance ); #if defined( __NT__ ) hBkBrush = CreateSolidBrush( GetSysColor( COLOR_BTNFACE ) ); #endif /* * set up window class */ if( !previnst ) { wc.style = 0L; wc.lpfnWndProc = ImgEdFrameProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = Instance; wc.hIcon = LoadIcon( Instance, "APPLICON" ); wc.hCursor = LoadCursor( (HANDLE)NULL, IDC_ARROW ); wc.hbrBackground = NULL; wc.lpszMenuName = NULL; wc.lpszClassName = className; if( !RegisterClass( &wc ) ) { return( FALSE ); } } /* * This is the child of the MDI frame window (of it's client window actually). */ if( !previnst ) { wc.style = CS_BYTEALIGNWINDOW | CS_CLASSDC | CS_DBLCLKS; wc.lpfnWndProc = DrawAreaWinProc; wc.cbClsExtra = sizeof( HCURSOR ); wc.cbWndExtra = 0; wc.hInstance = Instance; wc.hIcon = hBitmapIcon; wc.hCursor = LoadCursor( (HANDLE)NULL, IDC_ARROW ); wc.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH ); wc.lpszMenuName = NULL; wc.lpszClassName = DrawAreaClassB; if( !RegisterClass( &wc ) ) { return( FALSE ); } } if( !previnst ) { wc.style = CS_BYTEALIGNWINDOW | CS_CLASSDC | CS_DBLCLKS; wc.lpfnWndProc = DrawAreaWinProc; wc.cbClsExtra = sizeof( HCURSOR ); wc.cbWndExtra = 0; wc.hInstance = Instance; wc.hIcon = hIconIcon; wc.hCursor = LoadCursor( (HANDLE)NULL, IDC_ARROW ); wc.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH ); wc.lpszMenuName = NULL; wc.lpszClassName = DrawAreaClassI; if( !RegisterClass( &wc ) ) { return( FALSE ); } } if( !previnst ) { wc.style = CS_BYTEALIGNWINDOW | CS_CLASSDC | CS_DBLCLKS; wc.lpfnWndProc = DrawAreaWinProc; wc.cbClsExtra = sizeof( HCURSOR ); wc.cbWndExtra = 0; wc.hInstance = Instance; wc.hIcon = hCursorIcon; wc.hCursor = LoadCursor( (HANDLE)NULL, IDC_ARROW ); wc.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH ); wc.lpszMenuName = NULL; wc.lpszClassName = DrawAreaClassC; if( !RegisterClass( &wc ) ) { return( FALSE ); } } if( !previnst ) { wc.style = 0L; wc.lpfnWndProc = ViewWindowProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = Instance; wc.hIcon = LoadIcon( NULL, IDI_APPLICATION ); wc.hCursor = LoadCursor( (HANDLE)NULL, IDC_ARROW ); wc.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH ); wc.lpszMenuName = NULL; wc.lpszClassName = ViewWinClass; if( !RegisterClass( &wc ) ) { return( FALSE ); } } if( !previnst ) { wc.style = 0L; wc.lpfnWndProc = ColorPalWinProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = Instance; wc.hIcon = NULL; wc.hCursor = LoadCursor( (HANDLE)NULL, IDC_ARROW ); #if defined( __NT__ ) wc.hbrBackground = hBkBrush; #else wc.hbrBackground = (HBRUSH)GetStockObject( LTGRAY_BRUSH ); #endif wc.lpszMenuName = NULL; wc.lpszClassName = PaletteClass; if( !RegisterClass( &wc ) ) { return( FALSE ); } } handCursor = LoadCursor( Instance, "HandCursor" ); if( !previnst ) { wc.style = CS_DBLCLKS; wc.lpfnWndProc = ColorsWndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = Instance; wc.hIcon = NULL; wc.hCursor = handCursor; #if defined( __NT__ ) wc.hbrBackground = hBkBrush; #else wc.hbrBackground = (HBRUSH)GetStockObject( LTGRAY_BRUSH ); #endif wc.lpszMenuName = NULL; wc.lpszClassName = "ColorsClass"; if( !RegisterClass( &wc ) ) { return( FALSE ); } } if( !previnst ) { wc.style = CS_DBLCLKS; wc.lpfnWndProc = ScreenWndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = Instance; wc.hIcon = NULL; wc.hCursor = handCursor; #if defined( __NT__ ) wc.hbrBackground = hBkBrush; #else wc.hbrBackground = (HBRUSH)GetStockObject( LTGRAY_BRUSH ); #endif wc.lpszMenuName = NULL; wc.lpszClassName = "ScreenClass"; if( !RegisterClass( &wc ) ) { return( FALSE ); } } if( !previnst ) { wc.style = 0L; wc.lpfnWndProc = CurrentWndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = Instance; wc.hIcon = NULL; wc.hCursor = LoadCursor( (HANDLE)NULL, IDC_ARROW ); #if defined( __NT__ ) wc.hbrBackground = hBkBrush; #else wc.hbrBackground = (HBRUSH)GetStockObject( LTGRAY_BRUSH ); #endif wc.lpszMenuName = NULL; wc.lpszClassName = "CurrentClass"; if( !RegisterClass( &wc ) ) { return( FALSE ); } } if( !previnst ) { wc.style = 0L; wc.lpfnWndProc = BitmapPickProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = Instance; wc.hIcon = NULL; wc.hCursor = NULL; #if defined( __NT__ ) wc.hbrBackground = hBkBrush; #else wc.hbrBackground = (HBRUSH)GetStockObject( LTGRAY_BRUSH ); #endif wc.lpszMenuName = NULL; wc.lpszClassName = BitmapPickClass; if( !RegisterClass( &wc ) ) { return( FALSE ); } } /* * Now make the main window. */ LoadImgedConfig(); maximized = ImgedConfigInfo.ismaximized; InitPalette(); HMainWindow = CreateWindow( className, /* Window class name */ IEAppTitle, /* Window caption */ WS_OVERLAPPEDWINDOW | WS_BORDER | WS_CLIPCHILDREN | WS_CLIPSIBLINGS | WS_DLGFRAME, /* Window style */ ImgedConfigInfo.x_pos, /* Initial X position */ ImgedConfigInfo.y_pos, /* Initial Y position */ ImgedConfigInfo.width, /* Initial X size */ ImgedConfigInfo.height, /* Initial Y size */ (HWND)NULL, /* Parent window handle */ (HMENU)menu, /* Window menu handle */ Instance, /* Program instance handle */ NULL ); /* Create parameters */ if( HMainWindow == NULL ) { return( FALSE ); } if( maximized ) { if( cmdshow == SW_SHOW || cmdshow == SW_SHOWNORMAL ) { show_state = SW_SHOWMAXIMIZED; } else { show_state = cmdshow; } } else { show_state = cmdshow; } ShowWindow( HMainWindow, show_state ); UpdateWindow( HMainWindow ); if( !ImgedIsDDE && !NoTitleScreen ) { DisplayTitleScreen( Instance, HMainWindow, 2000, IEAppTitle ); } CreateColorPal(); InitTools( HMainWindow ); GrayEditOptions(); #ifdef __NT__ DragAcceptFiles( HMainWindow, TRUE ); #endif //SetActiveWindow( HMainWindow ); BringWindowToTop( HMainWindow ); return( TRUE ); } /* imgEditInit */
/* * imgEditInit - initialization */ static BOOL imgEditInit( HAB hab ) { ULONG flags; BOOL maximized; HWND frame; char clientclass[] = { "IMGEDClientClass" }; HWND hwnd; WPI_RECT rect; HMENU hmenu; // Change this to use the querycaps routine ColourPlanes = 1; BitsPerPixel = 4; Instance.hab = hab; Instance.mod_handle = NULL; /* * set up window class */ if (!WinRegisterClass( hab, className, (PFNWP)ImgEdFrameProc, CS_MOVENOTIFY | CS_SIZEREDRAW | CS_CLIPCHILDREN, 0 )) { return( FALSE ); } if (!WinRegisterClass( hab, clientclass, (PFNWP)ClientProc, CS_MOVENOTIFY | CS_SIZEREDRAW | CS_CLIPCHILDREN, 0 )) { return( FALSE ); } if (!WinRegisterClass( hab, PaletteClass, (PFNWP)ColourPalWinProc, CS_MOVENOTIFY | CS_SIZEREDRAW | CS_CLIPCHILDREN, 0 )) { return( FALSE ); } if (!WinRegisterClass( hab, CURRENT_CLASS, (PFNWP)CurrentWndProc, CS_SIZEREDRAW | CS_SYNCPAINT, 0 )) { return( FALSE ); } if (!WinRegisterClass( hab, AVAIL_CLASS, (PFNWP)ColoursWndProc, CS_SIZEREDRAW | CS_SYNCPAINT, 0 )) { return( FALSE ); } if (!WinRegisterClass( hab, SCREEN_CLASS, (PFNWP)ScreenWndProc, CS_SIZEREDRAW, 0 )) { return( FALSE ); } if (!WinRegisterClass( hab, DrawAreaClassB, (PFNWP)DrawAreaWinProc, CS_SIZEREDRAW | CS_SYNCPAINT | CS_CLIPSIBLINGS, 0 )) { return( FALSE ); } if (!WinRegisterClass( hab, DrawAreaClassI, (PFNWP)DrawAreaWinProc, CS_SIZEREDRAW | CS_SYNCPAINT | CS_CLIPSIBLINGS, 0 )) { return( FALSE ); } if (!WinRegisterClass( hab, DrawAreaClassC, (PFNWP)DrawAreaWinProc, CS_SIZEREDRAW | CS_SYNCPAINT | CS_CLIPSIBLINGS, 0 )) { return( FALSE ); } if (!WinRegisterClass( hab, ViewWinClass, (PFNWP)ViewWindowProc, CS_MOVENOTIFY | CS_SIZEREDRAW | CS_CLIPCHILDREN, 0 )) { return( FALSE ); } LoadImgedConfig(); maximized = ImgedConfigInfo.ismaximized; InitPalette(); /* * now make the main window */ flags = FCF_TITLEBAR | FCF_SIZEBORDER | FCF_MINMAX | FCF_SYSMENU | FCF_TASKLIST | FCF_ICON | FCF_MENU; frame = WinCreateStdWindow( HWND_DESKTOP, 0L, &flags, className, ImgEdName, 0L, (HMODULE)0, IMGED_MAIN, &HMainWindow); WinSetWindowPos(frame, HWND_TOP, ImgedConfigInfo.x_pos, ImgedConfigInfo.y_pos, ImgedConfigInfo.width, ImgedConfigInfo.height, SWP_MOVE | SWP_SHOW | SWP_SIZE); _wpi_getclientrect( HMainWindow, &rect ); flags = 0L; /* * N.B. - NOTE that ClientWindow is actually a FRAME WINDOW!!!!! The * name is a bit misleading and it is unlike HMainWindow which * is a client window. */ ClientWindow = WinCreateStdWindow( HMainWindow, 0L, &flags, clientclass, "", 0L, (HMODULE)0, 0, &hwnd); WinSetWindowPos(ClientWindow, HWND_TOP, 0, STATUS_WIDTH, _wpi_getwidthrect( rect ), _wpi_getheightrect(rect) -STATUS_WIDTH -FUNCTIONBAR_WIDTH -1, SWP_MOVE | SWP_SHOW | SWP_SIZE); CreateColourPal(); InitFunctionBar( HMainWindow ); InitTools( _wpi_getframe(HMainWindow) ); hmenu = _wpi_getmenu( frame ); if (ImgedConfigInfo.grid_on) { CheckGridItem(hmenu); } SetHintText("Open Watcom Image Editor."); WinSetFocus( HWND_DESKTOP, _wpi_getframe(HMainWindow) ); return( TRUE ); } /* imgEditInit */
/* * RestoreColorPalette - restore the color palette to the hard-coded colors * in the initialization routine */ void RestoreColorPalette( void ) { int i; COLORREF leftcolor; COLORREF rightcolor; COLORREF color; WPI_PRES pres; int leftindex; int rightindex; wie_clrtype lefttype; wie_clrtype righttype; HMENU hmenu; HWND frame; if( currentPalIndex != COLOR_16 && currentPalIndex != COLOR_256 ) { return; } leftcolor = GetSelectedColor( LMOUSEBUTTON, NULL, &lefttype ); rightcolor = GetSelectedColor( RMOUSEBUTTON, NULL, &righttype ); leftindex = getColorIndex( leftcolor ); rightindex = getColorIndex( rightcolor ); InitPalette(); for( i = 0; i < PALETTE_SIZE - 1; i++ ) { ShowNewColor( i, RGB( palette[currentPalIndex][i].rgbRed, palette[currentPalIndex][i].rgbGreen, palette[currentPalIndex][i].rgbBlue ), FALSE ); } /* * We do the last one separately to invalidate the window. */ ShowNewColor( i, RGB( palette[currentPalIndex][i].rgbRed, palette[currentPalIndex][i].rgbGreen, palette[currentPalIndex][i].rgbBlue ), TRUE ); if( lefttype == NORMAL_CLR ) { color = RGB( palette[currentPalIndex][leftindex].rgbRed, palette[currentPalIndex][leftindex].rgbGreen, palette[currentPalIndex][leftindex].rgbBlue ); pres = _wpi_getpres( HWND_DESKTOP ); _wpi_torgbmode( pres ); SetColor( LMOUSEBUTTON, color, _wpi_getnearestcolor( pres, color ), NORMAL_CLR ); _wpi_releasepres( HWND_DESKTOP, pres ); } if( righttype == NORMAL_CLR ) { color = RGB( palette[currentPalIndex][rightindex].rgbRed, palette[currentPalIndex][rightindex].rgbGreen, palette[currentPalIndex][rightindex].rgbBlue ); pres = _wpi_getpres( HWND_DESKTOP ); _wpi_torgbmode( pres ); SetColor( RMOUSEBUTTON, color, _wpi_getnearestcolor( pres, color ), NORMAL_CLR ); _wpi_releasepres( HWND_DESKTOP, pres ); } PrintHintTextByID( WIE_PALETTERESTORED, NULL ); if( HMainWindow != NULL ) { frame = _wpi_getframe( _wpi_getframe( HMainWindow ) ); hmenu = GetMenu( frame ); _wpi_enablemenuitem( hmenu, IMGED_RCOLOR, FALSE, FALSE ); } } /* RestoreColorPalette */
MoodPalette() { InitPalette(); }
int main(){ int gd=DETECT, gm; int Return=0; char Key, ScanCode; int Counter=0; //Divide total delay & take multiple input initgraph(&gd, &gm,"c:\\tc\\bgi"); //initialize graphics mode randomize(); //Randomize block's shapes & color cleardevice(); //clear screen InitPalette(); //for setting color pallete InitMatrix(); //Initialize Matrix GetImages(); //Saving the images StartScreen(); //for start screen cleardevice(); //clear screen AssignShape(GetRandomShape(), GetRandomColor()); //for the falling block NextShape=GetRandomShape(); NextColor=GetRandomColor(); DisplayScreen(); //Show main screen DisplayNextShape(); //show next brick MoveBlock(LEFT); //keep the block on center & check game over while(kbhit()) getch(); //empty the keyboard input while (!Quit && !GameOver) { //Moving the blocks down if(++Counter >= Speed) //For controling the speed { Counter=0; MoveBlock(DOWN); SoundDrop(); } if(kbhit()) //For the arrow keys { Key = getch(); if(Key == 0) { ScanCode = getch(); if(ScanCode == KEY_UP) RotateBlock(); else if(ScanCode == KEY_LEFT) MoveBlock(LEFT); else if(ScanCode == KEY_RIGHT) MoveBlock(RIGHT); else if(ScanCode == KEY_DOWN) { Score++; //increase score PrintScore(); MoveBlock(DOWN); } if(!Return) SoundDrop(); Return = 0; } else if(Key == KEY_ENTER || Key == KEY_SPACE) //Rotating bricks RotateBlock(); else if(Key == 'P' || Key == 'p') //For pause { MessageBox(" Paused"); while(kbhit()) getch(); //clear the keyboard input for(int x=0; x<COLS; x++) for(int y=0; y<ROWS; y++) PreviousScreenLayout[x][y] -= 1; //Clear the present screen layout to refresh the whole screen UpdateScreen(); //refresh screen } else if(Key == KEY_ESC) //For quit { char ret = MessageBox("Are you sure, you want to Quit?", 563, 2); if(ret == 'y' || ret == 'Y' || ret == KEY_ENTER) { Quit = 1; break; } cleardevice(); //Clear the message box while(kbhit()) getch(); //Clear the keyboard input for(int x=0; x<COLS; x++) for(int y=0; y<ROWS; y++) PreviousScreenLayout[x][y] -= 1; // Clear the present screen layout to refresh the whole screen UpdateScreen(); //refresh screen DisplayScreen(); //show the main screen again DisplayNextShape(); //show next brick box } else if(Key == 's' || Key == 'S') //For sound on/off { SoundOn = !SoundOn; } else if(Key=='a' || Key=='A') //For author { MessageBox("Author: Aguntuk Group",450); cleardevice(); //Clear the message box while(kbhit()) getch(); //Clear the keyboard input for(int x=0;x<COLS;x++) for(int y=0;y<ROWS;y++) PreviousScreenLayout[x][y] -=1; //Clear the present screen layout to refresh the whole screen UpdateScreen(); //refresh screen DisplayScreen(); //show the main screen again DisplayNextShape(); //show next brick box } } delay(6); //For moving down the blocks slowly } if(GameOver) //For game over option { DisplayBlock(6,0); //For display the top most brick ShowGameOver(); //For display game over message box } restorecrtmode(); //For closing graphicg mode return 0; }