void TetrisPiece::draw(SDL_Surface* screen, int x, int y, int w) { Draw_FillRect(screen, x, y, w*4, w*4, 0); x += -w/2*getDim() + 2*w; y += w; Uint32 c_white = SDL_MapRGB(screen->format, 255,255,255); Uint32 c_cyan = SDL_MapRGB(screen->format, 32,255,255); Uint32 c_yellow = SDL_MapRGB(screen->format, 255,255, 32); Uint32 c_purple = SDL_MapRGB(screen->format, 255, 32,255); Uint32 c_green = SDL_MapRGB(screen->format, 32,255, 32); Uint32 c_red = SDL_MapRGB(screen->format, 255, 32, 32); Uint32 c_blue = SDL_MapRGB(screen->format, 32, 32,255); Uint32 c_orange = SDL_MapRGB(screen->format, 255,128, 32); Uint32 c_drkRed = SDL_MapRGB(screen->format, 225, 16, 16); Uint32 c_gray = SDL_MapRGB(screen->format, 150,150,150); Uint32 c_drkGray = SDL_MapRGB(screen->format, 100,100,100); Uint32 c_black = SDL_MapRGB(screen->format, 0, 0, 0); for(int i = 0; i < getDim(); i++) { for(int j = 0; j < getDim(); j++) { Uint32 temp; switch(this->getShape()[i][j] * getCol()) { case -1: temp = c_gray; break; case 1: temp = c_cyan; break; case 2: temp = c_yellow; break; case 3: temp = c_purple; break; case 4: temp = c_green; break; case 5: temp = c_red; break; case 6: temp = c_blue; break; case 7: temp = c_orange; break; default: temp = c_black; break; } Draw_FillRect(screen, x + w*j, y + w*(i), w - 2, w - 2, temp); } } }
//--------------------------------------------------------- void CVIEW_ScatterPlot::_Draw_Legend(wxDC &dc, wxRect r) { CSG_Colors Colors(*m_Options("DENSITY_PAL")->asColors()); Colors.Set_Count(r.GetHeight()); for(int i=0, y=r.GetBottom(); i<Colors.Get_Count(); i++, y--) { Draw_FillRect(dc, Get_Color_asWX(Colors.Get_Color(i)), r.GetLeft(), y, r.GetRight(), y + 1); } // r.Offset(0, -r.GetHeight()); Draw_Edge(dc, EDGE_STYLE_SIMPLE, r); Draw_Text(dc, TEXTALIGN_BOTTOMLEFT, 2 + r.GetRight(), r.GetBottom(), "0"); Draw_Text(dc, TEXTALIGN_TOPLEFT , 2 + r.GetRight(), r.GetTop (), wxString::Format("%d", (int)m_Count.Get_Max())); }
int DrawRectangle(SDL_Surface * screen, T_Rectangle *rectangle_info,T_Screen *screen_info) { int x = 0; int y = 0; int height = 0; int width = 0; int color = 0; //checking input parameters assert(NULL!=screen); assert(NULL!=rectangle_info); assert(NULL != screen_info); x = rectangle_info->start_point.x; y = rectangle_info->start_point.y; height = rectangle_info->height; width = rectangle_info->width; if ((x+width)>screen_info->width) { printf("warnning:the rectangle's stop x-accordate exceeds the screen's width!\n"); width = screen_info->width - x; } if ((y+height)>screen_info->height) { printf("warnning:the rectangle's stop y-accordate exceeds the screen's height!\n"); height = screen_info->height - y; } color = rectangle_info->color; //drawing the rectangle on the screen if ( 1== rectangle_info->fill) { Draw_FillRect(screen, x, y, width, height, color); } else { Draw_Rect(screen, x, y, width, height, color); } return 0; }
//--------------------------------------------------------- void CWKSP_Layer_Legend::_Draw_Continuum_H(wxDC &dc, int y, double yToDC, double zMin, double zMax, double zFactor, double dz, int dyFont) { int i, iy, jy, yTick, yText, sx, sy; double z; wxString s; yTick = y + m_dxBox; yText = y + m_dxBox + m_dxTick; //----------------------------------------------------- for(i=0, z=m_xBox; i<m_pClassify->Get_Class_Count(); i++, z+=yToDC) { Draw_FillRect(dc, Get_Color_asWX(m_pClassify->Get_Class_Color(i)), (int)(z), y, (int)(z + yToDC), yTick); } Draw_Edge(dc, EDGE_STYLE_SIMPLE, m_xBox, y, m_xBox + METRIC_HEIGHT, yTick); //----------------------------------------------------- switch( m_pClassify->Get_Metric_Mode() ) { case METRIC_MODE_NORMAL: default: jy = METRIC_POS_H(zMin) - METRIC_HEIGHT; z = dz * floor(zMin / dz); if( z < zMin ) z += dz; for(; z<=zMax; z+=dz) { iy = METRIC_POS_H(z); dc.DrawLine(iy, yTick, iy, yText); s = METRIC_GET_STRING(z, dz); dc.GetTextExtent(s, &sx, &sy); if( abs(jy - iy) >= (int)(1.25 * sx) ) { jy = iy; Draw_Text(dc, TEXTALIGN_TOPCENTER, iy, yText, s); } } break; case METRIC_MODE_LOGUP: jy = METRIC_POS_H(zMax) + METRIC_HEIGHT; z = dz * floor(zMax / dz); if( z > zMax ) z -= dz; for(; z>=zMin; z-=dz) { iy = METRIC_POS_H(z); dc.DrawLine(iy, yTick, iy, yText); s = METRIC_GET_STRING(z, dz); dc.GetTextExtent(s, &sx, &sy); if( abs(jy - iy) >= (int)(1.25 * sx) ) { jy = iy; Draw_Text(dc, TEXTALIGN_TOPCENTER, iy, yText, s); } while( abs(iy - METRIC_POS_H(z - dz)) > 2 * sx ) dz *= 0.1; } break; case METRIC_MODE_LOGDOWN: jy = METRIC_POS_H(zMin) - METRIC_HEIGHT; z = dz * floor(zMin / dz); if( z < zMin ) z += dz; for(; z<=zMax; z+=dz) { iy = METRIC_POS_H(z); dc.DrawLine(iy, yTick, iy, yText); s = METRIC_GET_STRING(z, dz); dc.GetTextExtent(s, &sx, &sy); if( abs(jy - iy) >= (int)(1.25 * sx) ) { jy = iy; Draw_Text(dc, TEXTALIGN_TOPCENTER, iy, yText, s); } while( abs(iy - METRIC_POS_H(z + dz)) > 2 * sx ) dz *= 0.1; } break; } //----------------------------------------------------- _Set_Size(METRIC_HEIGHT, yText + dyFont); }
//--------------------------------------------------------- void CWKSP_Layer_Legend::_Draw_Continuum_V(wxDC &dc, int y, double yToDC, double zMin, double zMax, double zFactor, double dz, int dyFont) { int i, iy, jy; double z; //----------------------------------------------------- for(i=0, z=y+METRIC_HEIGHT; i<m_pClassify->Get_Class_Count(); i++, z-=yToDC) { Draw_FillRect(dc, Get_Color_asWX(m_pClassify->Get_Class_Color(i)), m_xBox, (int)(z), m_xTick, (int)(z - yToDC)); } Draw_Edge(dc, EDGE_STYLE_SIMPLE, m_xBox, y, m_xTick, y + METRIC_HEIGHT); //----------------------------------------------------- switch( m_pClassify->Get_Metric_Mode() ) { case METRIC_MODE_NORMAL: default: z = dz * floor(zMin / dz); if( z < zMin ) z += dz; for(; z<=zMax; z+=dz) { iy = METRIC_POS_V(z); dc.DrawLine(m_xTick, iy, m_xText, iy); _Draw_Label(dc, iy, METRIC_GET_STRING(z, dz), TEXTALIGN_YCENTER); } break; case METRIC_MODE_LOGUP: jy = METRIC_POS_V(zMax) + (1 + dyFont); z = dz * floor(zMax / dz); if( z > zMax ) z -= dz; for(; z>=zMin; z-=dz) { iy = METRIC_POS_V(z); dc.DrawLine(m_xTick, iy, m_xText, iy); if( abs(jy - iy) >= (int)(0.75 * dyFont) ) { jy = iy; _Draw_Label(dc, iy, METRIC_GET_STRING(z, dz), TEXTALIGN_YCENTER); } while( abs(iy - METRIC_POS_V(z - dz)) > 2 * dyFont ) dz *= 0.1; } break; case METRIC_MODE_LOGDOWN: jy = METRIC_POS_V(zMin) - (1 + dyFont); z = dz * floor(zMin / dz); if( z < zMin ) z += dz; for(; z<=zMax; z+=dz) { iy = METRIC_POS_V(z); dc.DrawLine(m_xTick, iy, m_xText, iy); if( abs(jy - iy) >= (int)(0.75 * dyFont) ) { jy = iy; _Draw_Label(dc, iy, METRIC_GET_STRING(z, dz), TEXTALIGN_YCENTER); } while( abs(iy - METRIC_POS_V(z + dz)) > 2 * dyFont ) dz *= 0.1; } break; } //----------------------------------------------------- _Set_Size(0, METRIC_HEIGHT + dc.GetFont().GetPointSize()); }
void Manager::play() { SDL_Event event; SDLSound sound; std::stringstream strm; std::string msg; bool showMenu = true; bool done = false; bool keyCatch = false; bool giveHelp = false; int shootflag=0; bool returnKey = false; int bar_length = LENGTH; unsigned totalTime = 60; unsigned ticks=100; unsigned timepau = 1000; int ff=0; ticks += clock.getElapsedTicks(); static_cast<MultiSprite*>(pter)->velocityX(0); static_cast<MultiSprite*>(pter)->velocityY(0); static_cast<MultiSprite*>(pterleft)->velocityX(0); static_cast<MultiSprite*>(pterleft)->velocityY(0); const Uint32 BLUE = SDL_MapRGB(screen->format, 0x00, 0x00, 0xcd); const Uint32 WHITE = SDL_MapRGB(screen->format, 255, 255, 255); while ( not done ) { if(showMenu) { ghostbcknd.draw(); gui.draw(); SDL_Flip(screen); if(ff==0) { timepau = clock.getSeconds(); } if(remainingTime==0) { done = true; } SDL_PollEvent(&event); if (event.type == SDL_QUIT) { break; } if(event.type == SDL_KEYDOWN) { switch ( event.key.keysym.sym ) { case SDLK_ESCAPE : done = false; returnKey=false; break; case SDLK_q : done = true; break; case SDLK_RETURN : { if ( !keyCatch ) { gui.lightOn(); returnKey = true; } break; } case SDLK_DOWN : { if ( !keyCatch ) { gui.increment(); } break; } case SDLK_UP : { if ( !keyCatch ) { gui.decrement(); } break; } default: break; } //end of switch keyCatch = true; } // end of keydown if(event.type == SDL_KEYUP) { keyCatch = false; if ( returnKey ) { //cout << "Chosen: " << gui.getIconClicked() << endl; if(gui.getIconClicked()=="Help") { done=true; } SDL_Delay(1000); showMenu = false; } gui.lightOff(); //break; } //end of keyUp } if(!showMenu) { remainingTime = (totalTime+timepau) - clock.getSeconds(); draw(); Draw_FillRect(screen, 110, 60, bar_length, 10, WHITE); int getHealthBar = orbs.getBarLength(); Draw_FillRect(screen, 110, 85, getHealthBar, 10, BLUE); SDL_Flip(screen); update(); if(remainingTime==0 || getHealthBar <= 0) { clock.isPaused(); strm << "Final Score is : " << orbs.getScore() << std::ends; msg = strm.str(); io->printMessageAt(msg, 100, 200); done = true; } static int tempv=60; if (not clock.isPaused() && remainingTime >= 0 && bar_length > 0) { if (tempv==(remainingTime+1)){ tempv=remainingTime; //cout<<"enter here"<<bar_length<<endl; bar_length=bar_length-7; } } SDL_Flip(screen); if ( clock.isPaused() ) clock.unpause(); SDL_PollEvent(&event); if (event.type == SDL_QUIT) { break; } if(event.type == SDL_KEYUP) { keyCatch = false; if(var1==0) view->setObjectToTrack(pter); else view->setObjectToTrack(pterleft); keyCatch = false; static_cast<MultiSprite*>(pter)->velocityX(0); static_cast<MultiSprite*>(pter)->velocityY(0); static_cast<MultiSprite*>(pterleft)->velocityX(0); static_cast<MultiSprite*>(pterleft)->velocityY(0); } //sdl-keyup if(event.type == SDL_KEYDOWN) { switch ( event.key.keysym.sym ) { case SDLK_ESCAPE : { if(!keyCatch) { showMenu = true; if ( clock.isPaused() ) clock.unpause(); else clock.pause(); keyCatch = false; ff=1; } keyCatch = true; break; } case SDLK_q : done = true; break; case SDLK_RETURN : { if ( !keyCatch ) { } break; } case SDLK_SPACE : { if (!keyCatch) { keyCatch = true; static int i = 0; i = (i + 1) % 2; if ( i ) orbs.setOrbToTrack(0); else view->setObjectToTrack(pter); } break; } case SDLK_p : { if (!keyCatch) { keyCatch = true; if ( clock.isPaused() ) clock.unpause(); else clock.pause(); } break; } case SDLK_0 : case SDLK_1 : case SDLK_2 : case SDLK_3 : case SDLK_4 : case SDLK_5 : case SDLK_6 : case SDLK_7 : { if (!keyCatch) { keyCatch = true; io->clearString(); io->buildString(event); int n = event.key.keysym.sym - SDLK_0; sound[n]; break; } } case SDLK_r : { if(shootflag==0) orbs.shoot(pter->X()+60,pter->Y()+20,0); else orbs.shoot(pterleft->X()-60,pterleft->Y()+20,1); } break; case SDLK_LEFT : { var1=1; shootflag=1; view->setObjectToTrack(pterleft); static_cast<MultiSprite*>(pterleft)->left(); //cout<< " flag is "<<shootflag<<endl; } break; case SDLK_RIGHT: { view->setObjectToTrack(pter); var1=0; shootflag=0; if (var2==1){ pter->X(pterleft->X()); pter->Y(pterleft->Y()); var2=0; } static_cast<MultiSprite*>(pter)->right(); break; } case SDLK_UP: if (var1==1) { view->setObjectToTrack(pterleft); static_cast<MultiSprite*>(pterleft)->up(); break ; } static_cast<MultiSprite*>(pter)->up(); break; case SDLK_DOWN: if (var1==1){ view->setObjectToTrack(pterleft); static_cast<MultiSprite*>(pterleft)->down();break; } static_cast<MultiSprite*>(pter)->down(); break; case SDLK_F1: { if(!keyCatch) { toggleTheStupidHud(); giveHelp = true; if ( clock.isPaused() ) clock.unpause(); else clock.pause(); keyCatch = false; } keyCatch = true; break; } default : break; } } } } //end while }// finc
//--------------------------------------------------------- void CDLG_Colors_Control::Draw_Box(wxDC &dc, int BoxID) { int i, r, g, b, s, ax, ay, bx, by; double xStep, yStep; wxRect rBox; //----------------------------------------------------- Get_BoxRect(rBox, BoxID); rBox.Inflate(1); Draw_FillRect(dc, SYS_Get_Color(wxSYS_COLOUR_WINDOW), rBox); Draw_Edge(dc, EDGE_STYLE_SUNKEN, rBox); rBox.Deflate(1); //----------------------------------------------------- xStep = (double)rBox.GetWidth() / (double)m_pColors->Get_Count(); yStep = (double)rBox.GetHeight() / 255.0; ax = rBox.GetLeft(); ay = rBox.GetBottom() + 1; r = g = b = 0; s = 255; //----------------------------------------------------- for(i=0; i<m_pColors->Get_Count(); i++) { switch( BoxID ) { case 0: r = s = m_pColors->Get_Red (i); break; case 1: g = s = m_pColors->Get_Green(i); break; case 2: b = s = m_pColors->Get_Blue (i); break; case 3: r = m_pColors->Get_Red (i); g = m_pColors->Get_Green(i); b = m_pColors->Get_Blue (i); s = (r + g + b) / 3; break; case 4: r = m_pColors->Get_Red (i); g = m_pColors->Get_Green(i); b = m_pColors->Get_Blue (i); break; } bx = ax; ax = rBox.GetLeft() + (int)(xStep * (i + 1.0)); by = ay - (int)(yStep * (double)s); Draw_FillRect(dc, wxColour(r, g, b), ax, ay, bx, by); } }
/*----------------------------------------------------------------------*/ int main(int argc, char *argv[]) { SDL_Surface *screen; int width, height; Uint8 video_bpp; Uint32 videoflags; int done; SDL_Event event; Uint32 then, now, frames; if ( SDL_Init(SDL_INIT_VIDEO) < 0 ) { fprintf(stderr, "SDL_Init problem: %s", SDL_GetError()); exit(1); } atexit(SDL_Quit); videoflags = SDL_SWSURFACE | SDL_ANYFORMAT; width = 640; height = 480; video_bpp = 0; while ( argc > 1 ) { --argc; if ( strcmp(argv[argc-1], "-width") == 0 ) { width = atoi(argv[argc]); --argc; } else if ( strcmp(argv[argc-1], "-height") == 0 ) { height = atoi(argv[argc]); --argc; } else if ( strcmp(argv[argc-1], "-bpp") == 0 ) { video_bpp = atoi(argv[argc]); videoflags &= ~SDL_ANYFORMAT; --argc; } else if ( strcmp(argv[argc], "-fast") == 0 ) { videoflags = FastestFlags(videoflags, width, height, video_bpp); } else if ( strcmp(argv[argc], "-hw") == 0 ) { videoflags ^= SDL_HWSURFACE; } else if ( strcmp(argv[argc], "-flip") == 0 ) { videoflags ^= SDL_DOUBLEBUF; } else if ( strcmp(argv[argc], "-fullscreen") == 0 ) { videoflags ^= SDL_FULLSCREEN; } else { fprintf(stderr, "Use: %s [-bpp N] [-hw] [-flip] [-fast] [-fullscreen]\n", argv[0]); exit(1); } }/*while*/ /*Video mode activation*/ screen = SDL_SetVideoMode(width, height, video_bpp, videoflags); if (!screen) { fprintf(stderr, "I can not activate video mode: %dx%d: %s\n", width, height, SDL_GetError()); exit(2); } {/*BEGIN*/ Uint32 c_white = SDL_MapRGB(screen->format, 255,255,255); Uint32 c_gray = SDL_MapRGB(screen->format, 200,200,200); Uint32 c_dgray= SDL_MapRGB(screen->format, 64,64,64); Uint32 c_cyan = SDL_MapRGB(screen->format, 32,255,255); //SDL_Rect r = {100,300,50,50}; //SDL_SetClipRect(screen, &r); //Test of clipping code Draw_Line(screen, 100,100, 30,0, c_white); Draw_Line(screen, 30,0, 100,100, c_white); Draw_Line(screen, 100,100, 30,0, c_white); Draw_Line(screen, 30,0, 100,100, c_white); Draw_Line(screen, 0,0, 100,100, c_white); Draw_Line(screen, 100,100, 300,200, c_white); Draw_Line(screen, 200,300, 250,400, SDL_MapRGB(screen->format, 128,128,255)); Draw_Line(screen, 500,50, 600,70, SDL_MapRGB(screen->format, 128,255,128)); Draw_Line(screen, 500,50, 600,70, SDL_MapRGB(screen->format, 128,255,128)); Draw_Circle(screen, 100,100, 50, c_white); /*-------------*/ Draw_Circle(screen, 150,150, 5, c_white); Draw_Circle(screen, 150,150, 4, SDL_MapRGB(screen->format, 64,64,64)); Draw_Circle(screen, 150,150, 3, SDL_MapRGB(screen->format, 255,0,0)); Draw_Circle(screen, 150,150, 2, SDL_MapRGB(screen->format, 0,255,0)); Draw_Circle(screen, 150,150, 1, SDL_MapRGB(screen->format, 0,0,255)); /*-------------*/ Draw_Line(screen, 500,100, 600,120, SDL_MapRGB(screen->format, 128,255,128)); Draw_Circle(screen, 601,121, 2, c_white); Draw_Circle(screen, 400,200, 2, c_white); Draw_Line(screen, 400,200, 409,200, c_white); Draw_Circle(screen, 409,200, 2, c_white); Draw_Line(screen, 400,200, 400,250, c_white); Draw_Circle(screen, 400,250, 2, c_white); Draw_Line(screen, 409,200, 400,250, c_white); Draw_Line(screen, 400,300, 409,300, c_gray); Draw_Line(screen, 400,300, 400,350, c_gray); Draw_Line(screen, 409,300, 400,350, c_dgray); Draw_Rect(screen, 398,298, 4,4, c_cyan); Draw_Rect(screen, 407,298, 4,4, c_cyan); Draw_Rect(screen, 398,348, 4,4, c_cyan); Draw_HLine(screen, 10,400, 50, c_white); Draw_VLine(screen, 60,400, 360, c_white); Draw_Rect(screen, 500,400, 50,50, c_white); Draw_Pixel(screen, 510,410, c_white); Draw_Pixel(screen, 520,420, SDL_MapRGB(screen->format, 255,0,0)); Draw_Pixel(screen, 530,430, SDL_MapRGB(screen->format, 0,255,0)); Draw_Pixel(screen, 540,440, SDL_MapRGB(screen->format, 0,0,255)); Draw_Ellipse(screen, 100,300, 60,30, c_white); Draw_FillEllipse(screen, 300,300, 30,60, SDL_MapRGB(screen->format, 64,64,200)); Draw_Ellipse(screen, 300,300, 30,60, SDL_MapRGB(screen->format, 255,0,0)); Draw_Round(screen, 200,20, 70,50, 10, c_white); Draw_Round(screen, 300,20, 70,50, 20, SDL_MapRGB(screen->format, 255,0,0)); Draw_FillRound(screen, 390,20, 70,50, 20, SDL_MapRGB(screen->format, 255,0,0)); Draw_Round(screen, 390,20, 70,50, 20, c_cyan); /*Draw_Round(screen, 500,400, 5,3, 4, c_cyan);*/ Draw_Rect(screen, 499,199, 52,72, SDL_MapRGB(screen->format, 255,255,0)); Draw_FillRect(screen, 500,200, 50,70, SDL_MapRGB(screen->format, 64,200,64)); Draw_FillCircle(screen, 500,330, 30, c_cyan); SDL_UpdateRect(screen, 0, 0, 0, 0); frames = 0; then = SDL_GetTicks(); done = 0; while( !done ) { ++frames; while ( SDL_PollEvent(&event) ) { switch (event.type) { case SDL_KEYDOWN: /*break;*/ case SDL_QUIT: done = 1; break; default: break; } }/*while*/ }/*while(!done)*/ }/*END*/ now = SDL_GetTicks(); if ( now > then ) { printf("%2.2f frames per second\n", ((double)frames*1000)/(now-then)); } fprintf(stderr, "[END]\n"); return 0; }/*main*/