int executeCutCPU(SDL_Renderer *ren, Board *B){ if (determineWinner(B)) return 1; // Nothing to do int i, j; minmaxImplementation(B, &i, &j, minMaxDepth, 1); // Estimate position of desired I and J starting with Cut // The rest is the same as in Basic Execute Cut B->edges[i][j] = noArc; B->edges[j][i] = noArc; eraseArc(ren, B->Vertices[findIndex(B, i)].x, B->Vertices[findIndex(B, i)].y, B->Vertices[findIndex(B, j)].x, B->Vertices[findIndex(B, j)].y); if (B->Vertices[findIndex(B, i)].locked > 0){ endNode(ren, B->Vertices[findIndex(B, i)].x, B->Vertices[findIndex(B, i)].y); } else{ drawNode(ren, B->Vertices[findIndex(B, i)].x, B->Vertices[findIndex(B, i)].y); } if (B->Vertices[findIndex(B, j)].locked > 0){ endNode(ren, B->Vertices[findIndex(B, j)].x, B->Vertices[findIndex(B, j)].y); } else{ drawNode(ren, B->Vertices[findIndex(B, j)].x, B->Vertices[findIndex(B, j)].y); } //the next two lines rotate the turn display...you should not need to chagne this stringColor(ren, 5, 5, "Cut's Turn:", white); stringColor(ren, 5, 5, "Short's Turn:", black); return 1; }
void draw_legend(SDL_Surface *ecran)//, SDL_Surface *rectangle, int x, int y) { rectangleColor(ecran, 1150, 400, 950, 500, 0xffffffff); stringColor(ecran, 1000, 430, "densite", 0xff3a2aff); stringColor(ecran, 1000, 460, "repartition", 0x3a3affff); SDL_Flip(ecran); }
static void draw_sound(SDL_Surface *surface, int size, int16_t * left_channel, int16_t * right_channel, int v_position, int height, Uint32 pixel) { int i; float step; /* Here as in the other plotting functions we need to compute the step for each data, the only * problem was that, if we computed it as an integer then, for higher value of size (That are the * frames for each period) then all the values would have collapsed, since the "step" would have * been 0. */ step = (((float)surface->w / 2) / size); stringColor(surface, 10, v_position - height + (height / 10), "Amplitude", 0xffffffff); stringColor(surface, (surface->w / 2) - 20, v_position - height + (height / 10), "L", 0xffffffff); stringColor(surface, (surface->w / 2) + 10, v_position - height + (height / 10), "R", 0xffffffff); hlineColor(surface, 0, surface->w, v_position, 0xffffffff); // We plot directly both channels, by going from left to right. for (i=1; i<size; i++) { aalineColor(surface, (int)((surface->w / 2) + ((i-1)*step)), ((int)(right_channel[i-1] * height / (float)DAMP_FACTOR) + v_position), (int)((surface->w / 2) + (i*step)), ((int)(right_channel[i] * height / (float)DAMP_FACTOR) + v_position), pixel); aalineColor(surface, (int)((surface->w / 2) - ((i-1)*step)), ((int)(left_channel[i-1] * height / (float)DAMP_FACTOR) + v_position), (int)((surface->w / 2) - (i*step)), ((int)(left_channel[i] * height / (float)DAMP_FACTOR) + v_position), pixel); } }
void TFont::surf_string_tr(SDL_Surface *surf,int x, int y, const char *s, int color,int w) { if (loaded_font) gfxPrimitivesSetFont(loaded_font,charWidth,charHeight); if (charWidth*strlen(s) > (unsigned)w) { int len = w/charWidth; char *dup = strdup(s); dup[len+1] = 0; stringColor(surf,x,y,dup,color); free(dup); } else stringColor(surf,x,y,s,color); }
/* Here we draw the histogram statistice for the summ of the frames */ void make_histogram_stat(int peak_y, int peak_u, int peak_v, int x_off, int y_off) { char framestat[25]; sprintf(framestat, "Peak Y at : %i", peak_y); stringColor(screen, x_off+10, y_off+10, framestat, white); sprintf(framestat, "Peak U at : %i", peak_u); stringColor(screen, x_off+10, y_off+25, framestat, white); sprintf(framestat, "Peak V at : %i", peak_v); stringColor(screen, x_off+10, y_off+40, framestat, white); }
/* Here we draw the vectorscope layout */ void make_vectorscope_layout() { int i, p1_x, p1_y, p2_x, p2_y; double temp; char text[4]; boxColor(screen, vector_x-130, vector_y+130, vector_x+130, vector_y-130, black); hlineColor(screen, vector_x-20, vector_x-128, vector_y, white); hlineColor(screen, vector_x+20, vector_x+128, vector_y, white); vlineColor(screen, vector_x, vector_y-20, vector_y-128, white); vlineColor(screen, vector_x, vector_y+20, vector_y+128, white); circleColor(screen,vector_x, vector_y, 20, white); circleColor(screen,vector_x, vector_y, 50, white); circleColor(screen,vector_x, vector_y, 80, white); circleColor(screen,vector_x, vector_y,112, white); for (i =0; i<36; i++) { /* Here we draw the degree scale */ temp = 112* cos (i*(10/57.3)) ; /* sin & cos only accept radiant */ p1_x = round(temp); /* and not degree input */ temp = 112* sin (i*(10/57.3) ); p1_y = round(temp); temp = 117* cos (i*(10/57.3) ); p2_x = round(temp); temp = 117* sin (i*(10/57.3) ); p2_y = round(temp); lineColor(screen, vector_x + p1_x, vector_y + p1_y, vector_x + p2_x, vector_y + p2_y, white); } sprintf(text, "0"); /* Creating the grad description */ stringColor(screen, vector_x + 135 , vector_y - 3, text, white); sprintf(text, "90"); stringColor(screen, vector_x - 7 , vector_y - 145, text, white); sprintf(text, "180"); stringColor(screen, vector_x - 155 , vector_y - 3, text, white); sprintf(text, "270"); stringColor(screen, vector_x - 10 , vector_y + 135, text, white); makepoint( 90, 60); /* length, arc, for purple */ makepoint( 96, 104); /* length, arc, for red */ makepoint( 67, 166); /* length, arc, for yellow */ makepoint( 90, 241); /* length, arc, for green */ makepoint( 96, 283); /* length, arc, for cyan */ makepoint( 67, 346); /* length, arc, for blue */ }
static void draw_real_spectrum(SDL_Surface *surface, int size, fftw_complex * spectrum, int v_position, int height, const char * title, Uint32 pixel) { int i; float step; char spectrum_title[255]; step = (((float)surface->w / 2) / (size)); sprintf(spectrum_title, "%s Real Spectrum", title); stringColor(surface, 10, v_position - height + (height / 10), spectrum_title, 0xffffffff); hlineColor(surface, 0, surface->w, v_position, 0xffffffff); for (i=1; i < size; i++) { aalineColor(surface, (int)((surface->w / 2) + ((i-1)*step)), ((int)(spectrum[0][i-1] * height) + v_position), (int)((surface->w / 2) + (i*step)), ((int)(spectrum[0][i] * height) + v_position), pixel); aalineColor(surface, (int)((surface->w / 2) - ((i-1)*step)), ((int)(spectrum[0][i-1] * height) + v_position), (int)((surface->w / 2) - (i*step)), ((int)(spectrum[0][i] * height) + v_position), pixel); } }
void Maze::drawValues(Draw * xwin,int ra,int ga, int ba,int rb, int gb, int bb) { for (int h=1;h<wall.height;h++) { for (int w=1;w<=wall.width;w++) { // std::cout<<values[w][h]<<std::endl; double ratio = (float)values[w][h]/(float)(totalblocks+1); ratio+=0.0000000001; int rc,gc,bc; rc=(ra*ratio)+(rb*(1.0-ratio)); gc=(ga*ratio)+(gb*(1.0-ratio)); bc=(ba*ratio)+(bb*(1.0-ratio)); std::string tmp=stringColor(rc,gc,bc); char *color = new char[6]; color=strcpy(color,tmp.c_str()); drawBlock(w,h,xwin,this,color); } } }
void draw_lgd_x(SDL_Surface *ecran, SDL_Surface *rectangle, int pos_x) { int a, b, af; SDL_Rect position; char buff[4]; memset(buff, '\0', 4); for ((af = 0, a = 50); a < WIN_WIDTH; (a += (50 * OFFSET_W), af += 50)) { position.x = a; for (b = pos_x - 6; b < pos_x; b++) { position.y = b; SDL_FillRect(rectangle, NULL, SDL_MapRGB(ecran->format, 255, 255, 255)); SDL_BlitSurface(rectangle, NULL, ecran, &position); } sprintf(buff, "%d", af); stringColor(ecran, a - 5, (WIN_HEIGHT - 45), buff, 0xffffffff); memset(buff, '\0', 4); } a -= (50 *OFFSET_W); draw_axe_y(ecran, rectangle, a); draw_lgd_y(ecran, rectangle, a, a + 25); draw_fleche_y(ecran, rectangle, a); SDL_Flip(ecran); }
void CLasagneText::Render( SDL_Surface *surface //!< The surface to blit our text surface too ) { if (!m_visible) return; stringColor(surface, m_position.x(), m_position.y(), m_text.c_str(), 0xFFFFFFFF); }
/* Here we draw the layout of the histogram */ void draw_histogram_layout(int x_off, int y_off) { int i, offset; char text[3]; hlineColor(screen, x_off, x_off+257, y_off+101 , white); vlineColor(screen, x_off-1, y_off, y_off+101, white); vlineColor(screen, x_off+257,y_off,y_off+101, white); if (scalepercent == 0) { for (i = 0; i < 15; i++) { offset = i*16+ 16; vlineColor(screen, x_off+offset, y_off+101, y_off+105, white); } vlineColor(screen, x_off+128, y_off+106, y_off+110, white); /* Description of the axis */ stringColor(screen, x_off-5 +16 , y_off+115, "16", white); stringColor(screen, x_off-9 +128, y_off+115, "128", white); stringColor(screen, x_off-9 +240, y_off+115, "240", white); } else { for (i =0; i< 11;i++) { offset = (int)i*21.9 + 16; vlineColor(screen, x_off+offset, y_off+101, y_off+105, white); } } for (i = 0; i < 6; i++) /*Labeling the y axis in percent */ { hlineColor(screen, x_off-5, x_off, y_off+ i*20, white); offset = 100- i*20; sprintf(text, "%i", offset); stringColor(screen, x_off-30 , y_off+ i*20 -3 , text, white); } }
static void draw(SDL_Surface *screen) { int i, j; unsigned char tmps[255]; if (SDL_MUSTLOCK(screen) && SDL_LockSurface(screen) < 0) return; boxColor(screen, 0, 0, screen->w, screen->h, 0x000000ff); /* scena */ for (i = 0; i < 20; i++) { for (j = 0; j < 12; j++) { if (mapa[j][i] < 100) drawImg(screen, stena, i, j, mapa[j][i], 0); else if (mapa[j][i] < 1000) drawImg(screen, vecivagony, i, j, anim, mapa[j][i] - 100); else if (mapa[j][i] < 10000) drawImg(screen, vrata, i, j, vrataanim, 0); else if (mapa[j][i] == 10000) { mapa[j][i] = 0; lokox = i; lokoy = j; }; } } /* naklad */ for (i = 0; i < pocet_vagonov; i++) { drawImg(screen, vecivagony, vagony[i].x, vagony[i].y, vagony[i].smer + 3, vagony[i].naklad); } /* loko */ if (lokobumanim == 100) { drawImg(screen, loko, lokox, lokoy, anim, lokodir); } else { drawImg(screen, lokobum, lokox, lokoy, lokobumanim, 0); } if (kolook) { sprintf(tmps, "HESLO: %s", hesla[aktualnaScena]); stringColor(screen, 33, 9, tmps, 0xffffffff); } sprintf(tmps, "%s", heslo); stringColor(screen, 33, 21, tmps, 0xffffffff); SDL_Flip(screen); if (SDL_MUSTLOCK(screen)) SDL_UnlockSurface(screen); printf("onTime\n"); }
int executeShort(SDL_Renderer *ren, SDL_MouseButtonEvent e, Board *B){ //determine if mouse click was on an unlocked arc. //if so lock the arc //else return 1 to sustain turn; int success = 0; for (int i = 0; i < B->num; i++) { for (int j = 0; j < B->num; j++) { if ((B->edges[i][j] == stdArc) || (B->edges[j][i] == stdArc)) //if edge exists test distance { if (arcClicked(B->Vertices[findIndex(B, i)].x, B->Vertices[findIndex(B, i)].y, B->Vertices[findIndex(B, j)].x, B->Vertices[findIndex(B, j)].y, e)){ B->edges[i][j] = lockedArc; B->edges[j][i] = lockedArc; lockArc(ren, B->Vertices[findIndex(B, i)].x, B->Vertices[findIndex(B, i)].y, B->Vertices[findIndex(B, j)].x, B->Vertices[findIndex(B, j)].y); if (B->Vertices[findIndex(B, i)].locked>0){ endNode(ren, B->Vertices[findIndex(B, i)].x, B->Vertices[findIndex(B, i)].y); } else{ drawNode(ren, B->Vertices[findIndex(B, i)].x, B->Vertices[findIndex(B, i)].y); } if (B->Vertices[findIndex(B, j)].locked>0){ endNode(ren, B->Vertices[findIndex(B, j)].x, B->Vertices[findIndex(B, j)].y); } else{ drawNode(ren, B->Vertices[findIndex(B, j)].x, B->Vertices[findIndex(B, j)].y); } success = 1; j = B->num; i = B->num; } } } } //the next two lines rotate the turn display...you should not need to chagne this if (success){ stringColor(ren, 5, 5, "Short's Turn:", white); stringColor(ren, 5, 5, "Cut's Turn:", black); return 0; } else{ return 1; } }
CAMLprim value ml_stringColor(value dst,value p,value c,value color) { SDL_Surface *sur= SDL_SURFACE(dst); SDL_Rect rect; int r; SDLRect_of_value(&rect,p); r=stringColor(sur,rect.x,rect.y,String_val(c),Int32_val(color)); return Val_bool(r); }
void draw_lgd(SDL_Surface *ecran) { char buff[12]; int i; memset(buff, '\0', 12); sprintf(buff, "Probabilite"); for (i = 0; i < 11; i++) { characterColor(ecran, 8, (220 + (i * 20)), buff[i], 0xffffffff); } i += 4; stringColor(ecran, 4, (210 + (i * 15)), "(%)", 0xffffffff); }
/********** 枠を描画 ***********/ void Prot_Frame(SDL_Surface *window) { char num[5],num2[5],num3[5]; lineColor(window, 0, WINDOW_Y/2, WINDOW_X, WINDOW_Y/2, 0x000000ff); /*Y軸*/ lineColor(window, 1, 1, 1, WINDOW_Y, 0x000000ff); /*内枠X軸上側*/ lineColor(window, 1, 1, WINDOW_X, 1, 0x000000ff); /*Y軸*/ lineColor(window, WINDOW_X-1, 1, WINDOW_X-1, WINDOW_Y-1, 0x000000ff); /*内枠X軸上側*/ lineColor(window, 1, WINDOW_Y-1, WINDOW_X-1, WINDOW_Y-1, 0x000000ff); lineColor(window, WINDOW_X/2, 0, WINDOW_X/2, WINDOW_Y, 0x000000ff); sprintf(num,"0"); sprintf(num2,"-100"); sprintf(num3,"100"); stringColor(window, center[0],center[1], num, 0x000000ff); stringColor(window, 0,WINDOW_Y/2, num2, 0x000000ff); stringColor(window, WINDOW_X-25,WINDOW_Y/2, num3, 0x000000ff); stringColor(window, WINDOW_X/2,0, num3, 0x000000ff); stringColor(window, WINDOW_X/2,WINDOW_Y-10, num2, 0x000000ff); char num4[10]; sprintf(num4,"%d",end_count); stringColor(window, 50,50, num4, 0x000000ff); }
/*************** 敵集団をプロット ***************/ void Opponent_Prot(Indiv pop[], SDL_Surface *window) { int i; char tmp_n[5]; /*個体を描画*/ for(i=0;i<Ns;i++){ sprintf(tmp_n,"%d",pop[i].nitch); stringColor(window, (pop[i].n[0]*2)+center[0]-5, (pop[i].n[1]*2)+center[1]-3, tmp_n, 0x0000ffff); /* trigonColor(window, (Opponent[i].n[0]*2)+center[0], (Opponent[i].n[1]*2)+center[1]-5, (Opponent[i].n[0]*2)+center[0]+6, (Opponent[i].n[1]*2)+center[1]+6, (Opponent[i].n[0]*2)+center[0]-5, (Opponent[i].n[1]*2)+center[1]+6, 0x0000ffff); // 三角形を描画 */ } }
void draw_lgd_y(SDL_Surface *ecran, SDL_Surface *rectangle, int pos_y, int py) { int a, b, af; SDL_Rect position; char buff[4]; memset(buff, '\0', 4); for ((af = 100, a = (50)); a < WIN_WIDTH; (a += (20 * OFFSET_H), af -= 20)) { position.y = a; for (b = pos_y ; b < pos_y + 6; b++) { position.x = b; SDL_FillRect(rectangle, NULL, SDL_MapRGB(ecran->format, 255, 255, 255)); SDL_BlitSurface(rectangle, NULL, ecran, &position); } sprintf(buff, "%d", af); stringColor(ecran, (py), a - 3, buff, 0xffffffff); memset(buff, '\0', 4); } SDL_Flip(ecran); }
void Popup(const char *text, Uint32 txtColor, Uint32 backColor, Uint32 time){ SDLTimer timer; SDL_Event SDLEvent; bool run = true; Uint16 textLen = strlen(text); SDLSetVideo(800,200,false); SDL_ShowCursor(SDL_ENABLE); timer.Reset(); while(run){ while(SDL_PollEvent(&SDLEvent)){ switch(SDLEvent.type){ case SDL_QUIT: run = false; break; case SDL_KEYDOWN: if(SDLEvent.key.keysym.sym == SDLK_ESCAPE)run = false; break; } } timer.Frame(15); if(time > 0)if(timer.total > time)run = false; boxColor(screen,0,0,screen->w,screen->h,backColor); stringColor(screen,(screen->w/2)-(textLen*4),screen->h/2 - 4,text,txtColor); SDL_Flip(screen); } }
int main ( int argc, char** argv ) { // initialize SDL video if ( SDL_Init( SDL_INIT_VIDEO ) < 0 ) { printf( "Unable to init SDL: %s\n", SDL_GetError() ); return 1; } // make sure SDL cleans up before exit atexit(SDL_Quit); // create a new window SDL_Surface* screen = SDL_SetVideoMode(800, 600, 24, SDL_SWSURFACE); if ( !screen ) { printf("Unable to set 640x480 video: %s\n", SDL_GetError()); return 1; } SDL_WM_SetCaption("Raw Viewer","Raw Viewer"); // load an image SDL_Surface* buffer = SDL_CreateRGBSurface(SDL_SWSURFACE,600,524,32,0,0,0,0); fl=fopen(argv[1],"rb"); fseek(fl,0,SEEK_END); Max=ftell(fl); Render(buffer,rejim,WIDT,HIGH,DX); // program main loop bool done = false; while (!done) { // message processing loop FlushHits(); SDL_Event event; while (SDL_PollEvent(&event)) { // check for messages switch (event.type) { // exit if the window is closed case SDL_QUIT: done = true; break; // check for keypresses case SDL_KEYDOWN: { SetHit(event.key.keysym.sym); break; } } // end switch } // end of message processing UpdateKeyboard(); // DRAWING STARTS HERE if (KeyDown(SDLK_ESCAPE)) done=true; // clear screen SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 0, 0, 0)); SDL_BlitSurface(buffer,0,screen,0); lineColor(screen,0,524,600,524,0xFFFFFFFF); lineColor(screen,600,0,600,524,0xFFFFFFFF); char buf[255]; sprintf(buf,"Offset:%X",Offs); stringColor(screen,700,10,buf,0xFFFFFFFF); sprintf(buf,"Width:%d",WIDT); stringColor(screen,700,20,buf,0xFFFFFFFF); rectangleColor(screen,663,7,670,509,0xFF0000FF); FillRect(screen,665,9,4,501*(Offs/(float)Max),0x00FF00);//rectangleColor(screen,664,8,669,8+500*Offs/Max,0x00FF00FF); if (WIDT>150) { rectangleColor(screen,9,549,511,556,0xFF0000FF); //Rect 9,549,502,7,0 FillRect(screen,10,550,500*DX/(WIDT-150),5,0x00FF00);// Rect 10,550,500*(Float(DX)/Float(widt-150)),5,1 } switch (rejim) { case 1: sprintf(buf,"1 Bit mode"); break; case 2: sprintf(buf,"2 Bit mode"); break; case 3: sprintf(buf,"4 Bit mode"); break; case 4: sprintf(buf,"8 Bit mode"); break; case 5: sprintf(buf,"16 Bit mode RGBA5551"); break; case 6: sprintf(buf,"16 Bit mode RGBA4444"); break; case 7: sprintf(buf,"16 Bit mode RGB565"); break; case 8: sprintf(buf,"16 Bit mode BGRA5551"); break; case 9: sprintf(buf,"16 Bit mode BGRA4444"); break; case 10: sprintf(buf,"16 Bit mode BGR565"); break; case 11: sprintf(buf,"24 Bit mode RGB"); break; case 12: sprintf(buf,"24 Bit mode BGR"); break; } stringColor(screen,5,580,buf,0xFFFFFFFF); if (KeyHit(SDLK_SPACE)) { setka=!setka; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_PERIOD)) { WIDT++; DX=0; if (WIDT<1) WIDT =1; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_COMMA)) { WIDT--; DX=0; if (WIDT<1) WIDT =1; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_SEMICOLON)) { WIDT+=10; DX=0; if (WIDT<1) WIDT =1; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_l)) { WIDT-=10; DX=0; if (WIDT<1) WIDT =1; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_LEFTBRACKET)) { WIDT+=100; DX=0; if (WIDT<1) WIDT =1; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_p)) { WIDT-=100; DX=0; if (WIDT<1) WIDT =1; Render(buffer,rejim,WIDT,HIGH,DX); } if (MouseDown(1)) { if (MouseX()>663 && MouseX()<670 && MouseY()>7 && MouseY()<507) { Offs=(float)Max*((MouseY()-8.0))/500.0; Render(buffer,rejim,WIDT,HIGH,DX); } if (WIDT>150) { if (MouseX()>9 && MouseX()<511 && MouseY()>549 && MouseY()<556) { DX=(WIDT -150)*((MouseX()-10)/500.0); Render(buffer,rejim,WIDT,HIGH,DX); } } } if (MouseDown(3)) { HIGH=MouseY()/4; if (HIGH<1) HIGH=1; if (HIGH> 130) HIGH=130; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyHit(SDLK_1)) { rejim=1; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyHit(SDLK_2)) { rejim=2; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyHit(SDLK_3)) { rejim=3; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyHit(SDLK_4)) { rejim=4; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyHit(SDLK_5)) { rejim=5; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyHit(SDLK_6)) { rejim=6; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyHit(SDLK_7)) { rejim=7; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyHit(SDLK_8)) { rejim=8; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyHit(SDLK_9)) { rejim=9; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyHit(SDLK_0)) { rejim=10; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyHit(SDLK_MINUS)) { rejim=11; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyHit(SDLK_EQUALS)) { rejim=12; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_RIGHT)) { Offs++; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_LEFT)) { Offs--; Render(buffer,rejim,WIDT,HIGH,DX); } if (rejim<5) { if (KeyDown(SDLK_DOWN)) { Offs+=WIDT; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_UP)) { Offs-=WIDT; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_PAGEUP)) { Offs-=WIDT*10; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_PAGEDOWN)) { Offs+=WIDT*10; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_HOME)) { Offs-=WIDT*100; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_END)) { Offs+=WIDT*100; Render(buffer,rejim,WIDT,HIGH,DX); } } else if (rejim < 11) { if (KeyDown(SDLK_DOWN)) { Offs+=WIDT*2; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_UP)) { Offs-=WIDT*2; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_PAGEUP)) { Offs-=WIDT*20; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_PAGEDOWN)) { Offs+=WIDT*20; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_HOME)) { Offs-=WIDT*200; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_END)) { Offs+=WIDT*200; Render(buffer,rejim,WIDT,HIGH,DX); } } else if (rejim < 13) { if (KeyDown(SDLK_DOWN)) { Offs+=WIDT*3; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_UP)) { Offs-=WIDT*3; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_PAGEUP)) { Offs-=WIDT*30; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_PAGEDOWN)) { Offs+=WIDT*30; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_HOME)) { Offs-=WIDT*300; Render(buffer,rejim,WIDT,HIGH,DX); } if (KeyDown(SDLK_END)) { Offs+=WIDT*300; Render(buffer,rejim,WIDT,HIGH,DX); } } // DRAWING ENDS HERE // finally, update the screen :) SDL_Flip(screen); SDL_Delay(10); } // end main loop fclose(fl); return 0; }
int main(int argc, char **argv) { SDL_Window *win = NULL; SDL_Renderer *ren = NULL; SDL_Event e; Board B; B.num = numNodes; int quit = GAME_UNDERWAY; int turn = rand() % 2; // TODO!!! // Add a simple menu here that shows up in the black console window to choose PvP or Computer vs. Player int isCutCPU, isShortCPU; //THE MENU NEED IMPROVEMENT. iT TESTS FOR INPUT BUT IT EXITS IF WRONG. //A LOOP IS NEEDED TO GET INPUTS UNTIL SOMETHING VALID // Main menu printf("Make a choice:\n"); printf("1) Player versus player\n"); printf("2) Player versus CPU (Player as Short)\n"); printf("3) Player versus CPU (Player as Cut)\n"); printf("4) CPU versus CPU\n"); printf("Enter your choice: "); //I found this one while looking for minimax algortihm. //I tought it was interesting so I gave it a try int choice; if (scanf_s("%i", &choice) != 1 || choice < 1 || choice > 4) { printf("Unable to read your input.\n"); return 1; } choice--; isCutCPU = choice & 0x1; isShortCPU = (choice & 0x02) >> 1; // Probably don't need to modify anything else below initializeGraphicsWindow(&win, &ren); SDL_SetRenderDrawColor(ren, 255, 255, 255, 255); // creates a white background for the board SDL_RenderClear(ren); //clears the game board to ensure it is plain white SDL_RenderPresent(ren); //renders the gameboard to the screen if (turn){ stringColor(ren, 5, 5, "Short's Turn:", white); } //displays initial turn else{ stringColor(ren, 5, 5, "Cut's Turn:", black); } createAndDrawBoard(ren,&B);//generates random planar graph and draws it //This is the main loop. //It calls executeTurn once per mouse click until the user quits or someone wins while (quit==GAME_UNDERWAY){ while (SDL_PollEvent(&e) != 0) //Loops through event queue { //User requests quit if (e.type == SDL_QUIT) //allows user to x out of program { quit = USER_QUIT; } if (e.type == SDL_MOUSEBUTTONDOWN) //handles mouse button events { turn = executeTurn(turn, ren, e.button, &B); quit = determineWinner(&B); //returns 0,2,or 3 as defined above inline with the declaration of quit } } SDL_RenderPresent(ren); //presents changes to the screen that result from the execution of one turn if (isCutCPU && turn == 0) { executeCutCPU(ren, &B); turn = 1; if (quit = determineWinner(&B)) break; SDL_RenderPresent(ren); SDL_Delay(1000); } else if (isShortCPU && turn == 1) { executeShortCPU(ren, &B); turn = 0; if (quit = determineWinner(&B)) break; SDL_RenderPresent(ren); SDL_Delay(1000); } } // Display who won displayWinBanner(ren, quit); while ((quit == CUT_WINS) || (quit == SHORT_WINS)) //if there was a winner hold the screen until the game window is closed. { SDL_RenderPresent(ren); //present changes to the screen // wait until the user closes the window while (SDL_PollEvent(&e) != 0) { //User requests quit if (e.type == SDL_QUIT) { quit = USER_QUIT; } } } freeGraphicsWindow(&win, &ren);//Terminate SDL and end program deleteBoard(&B); //deallocates dynamic memory return 0; }
/** * Draws a text string on the surface. * @param x X coordinate in pixels. * @param y Y coordinate in pixels. * @param s Character string to draw. * @param color Color of string. */ void Surface::drawString(Sint16 x, Sint16 y, const char *s, Uint8 color) { stringColor(_surface, x, y, s, Palette::getRGBA(getPalette(), color)); }
/***************************************************************** 関数名 : InitWindows 機能 : メインウインドウの表示,設定を行う 引数 : int clientID : クライアント番号 int num : 全クライアント数 出力 : 正常に設定できたとき0,失敗したとき-1 *****************************************************************/ int InitWindows(int clientID,int num,char name[][MAX_NAME_SIZE]) { int i; //SDL_Surface *image; ////////////////////////////////////////////////////////////////////////////////////// /*変更点 画像のファイル名を変更してグー、チョキ、パーが表示できるようにした*/ char clientButton[4][6]={"0.jpg","1.jpg","2.jpg"}; char endButton[]="END.jpg"; char allButton[]="ALL.jpg"; char *s,title[10]; /* 引き数チェック */ assert(0<num && num<=MAX_CLIENTS); SDL_EnableKeyRepeat(0,1); /* SDLの初期化 */ if(SDL_Init(SDL_INIT_VIDEO) < 0) { printf("failed to initialize SDL.\n"); return -1; } /* メインのウインドウを作成する */ if((gMainWindow = SDL_SetVideoMode(600,400, 32, SDL_SWSURFACE)) == NULL) { printf("failed to initialize videomode.\n"); return -1; } SDL_FillRect(gMainWindow, NULL, 0x000000ff); //to blue stringColor(gMainWindow, 0, 0, "Press buttons 1 and 2 on the wiimote now to connect.\n", 0xffffffff); SDL_Flip(gMainWindow); /* ウインドウのタイトルをセット */ sprintf(title,"Battle of Soft Character %d",clientID); SDL_WM_SetCaption(title,NULL); // ***** Wiiリモコン処理 ***** wiimote_t wiimote = WIIMOTE_INIT; data.wiimote=wiimote; wiimote_report_t report = WIIMOTE_REPORT_INIT; // Wiiリモコンの接続(1つのみ) if(strcmp(wiiName,"key") !=0){ if (wiimote_connect(&data.wiimote, wiiName) < 0) { // コマンド引数に指定したWiiリモコン識別情報を渡して接続 printf("unable to open wiimote: %s\n", wiimote_get_error()); exit(1); } } //Wiiリモコンのレポートタイプを指定する if (wiimote_report(&data.wiimote, &report, sizeof(report.status)) < 0) { wiimote_disconnect(&data.wiimote); } data.wiimote.led.one = 1; data.wiimote.mode.acc = 1;//加速度センサをオンにする /* 背景を白にする */ SDL_FillRect(gMainWindow,NULL,0xffffff); /* ボタンの作成 */ /////////////////////////////////////////////////////////////////////////////////// /*変更点 クライアントの数だけボタンが作成されるが、ここで3つしかボタンをつくらないことにする。 (選択用のボタン3つと終了用のボタン1つ) */ // for(i=0;i<4;i++){ /* if (i < 3){ /gButtonRect[i].x=20+150*i; gButtonRect[i].y=10; gButtonRect[i].w=135; gButtonRect[i].h=135;/ gButtonRect[i].x=20+150*i; gButtonRect[i].y=10; gButtonRect[i].w=135; gButtonRect[i].h=135; }else{ gButtonRect[i].x=400; gButtonRect[i].y=260; gButtonRect[i].w=70; gButtonRect[i].h=20; }*/ /*if(i==3){ s=endButton; }else{ s=clientButton[i]; } s = endButton; image = IMG_Load(s); SDL_BlitSurface(image,NULL,gMainWindow,&(gButtonRect[i])); SDL_FreeSurface(image); */ // } SDL_Flip(gMainWindow); return 0; }
void Decorator::basicText(Picture& dstpic, const Point& pos, const std::string& text, NColor color) { stringColor( dstpic.surface(), pos.x(), pos.y(), text.c_str(), color.color ); dstpic.update(); }
void Draw(SDL_Surface *screen) { int rate,x,y,s; SDL_Rect dest,clip; SDL_Surface *texture_image; SDL_Surface *texture_target1; SDL_Surface *texture_target2; FPSmanager fpsm; Uint32 rmask, gmask, bmask, amask; int width_half = screen->w/2; int height_half = screen->h/2; Uint32 text_color = 0xffffffff; /* Define masks for 32bit surface */ #if SDL_BYTEORDER == SDL_BIG_ENDIAN rmask = 0xff000000; gmask = 0x00ff0000; bmask = 0x0000ff00; amask = 0x000000ff; #else rmask = 0x000000ff; gmask = 0x0000ff00; bmask = 0x00ff0000; amask = 0xff000000; #endif /* Create semi-transparent textured surface */ s=64; texture_image = SDL_DisplayFormatAlpha(SDL_CreateRGBSurface(SDL_SWSURFACE, s, s, 32, rmask, gmask, bmask, amask)); /* Add some color */ boxRGBA(texture_image, 0, 0, s/2, s/2, 255, 0, 0, 255); boxRGBA(texture_image, s/2, 0, s, s/2, 0, 255, 0, 255); boxRGBA(texture_image, 0, s/2, s/2, s, 0, 0, 255, 255); boxRGBA(texture_image, s/2, s/2, s, s, 255, 255, 255, 255); /* Make 75%-transparent */ SDL_gfxSetAlpha(texture_image, 96); /* Set alpha channel use to per-pixel blending */ SDL_SetAlpha(texture_image, SDL_SRCALPHA, 255); /* Create an all transparent surface */ texture_target1 = SDL_DisplayFormatAlpha(SDL_CreateRGBSurface(SDL_SWSURFACE, 256, 256, 32, rmask, gmask, bmask, amask)); /* Make 75%-transparent */ SDL_gfxSetAlpha(texture_target1, 64); /* Set alpha channel use to per-pixel blending */ SDL_SetAlpha(texture_target1, SDL_SRCALPHA, 255); /* Create an all transparent surface (2) */ texture_target2 = SDL_DisplayFormatAlpha(SDL_CreateRGBSurface(SDL_SWSURFACE, 256, 256, 32, rmask, gmask, bmask, amask)); /* Make 75%-transparent */ SDL_gfxSetAlpha(texture_target2, 64); /* Set alpha channel use to per-pixel blending */ SDL_SetAlpha(texture_target2, SDL_SRCALPHA, 255); /* Define clipping region for left box */ clip.x = width_half-256-10 ; clip.y = height_half-256/2 ; clip.w = 256; clip.h = 256; /* Initialize Framerate manager */ SDL_initFramerate(&fpsm); /* Set/switch framerate */ rate=5; SDL_setFramerate(&fpsm,rate); /* --- Drawing loop */ while (1) { /* Event handler */ HandleEvent(); /* Black screen */ ClearScreen(screen); /* Random position of new texture */ x=(rand() % (256+2*s))-s; y=(rand() % (256+2*s))-s; /* Same for comparison texture */ dest.x = x; dest.y = y; dest.w = texture_image->w; dest.h = texture_image->h; SDL_BlitSurface(texture_image, NULL, texture_target1, &dest); /* Blit image into the target using custom Blit function. */ dest.x = x; dest.y = y; dest.w = texture_image->w; dest.h = texture_image->h; SDL_gfxBlitRGBA(texture_image, NULL, texture_target2, &dest); /* Draw comparison target on screen (left) */ dest.x = width_half-256-10; dest.y = height_half-256/2; dest.w = 256; dest.h = 256; SDL_BlitSurface(texture_target1, NULL, screen, &dest); /* Draw combiner target on screen (right) */ dest.x = width_half+10; dest.y = height_half-256/2; dest.w = 256; dest.h = 256; SDL_BlitSurface(texture_target2, NULL, screen, &dest); /* Draw some frames with titles */ rectangleColor(screen, width_half-256-10-1, height_half-256/2-1, width_half-256-10-1+257, height_half-256/2-1+257, text_color); rectangleColor(screen, width_half+10-1, height_half-256/2-1, width_half+10-1+257, height_half-256/2-1+257, text_color); stringColor(screen, width_half-256-10-1, height_half-256/2-1-36, " SDL Standard Blitter ", text_color); stringColor(screen, width_half-256-10-1, height_half-256/2-1-24, "Image --sdlBlit--> Target1", text_color); stringColor(screen, width_half-256-10-1, height_half-256/2-1-12, "Target1 --sdlBlit--> Screen", text_color); stringColor(screen, width_half+10-1, height_half-256/2-1-36, " SDL_gfx Compositing Blitter", text_color); stringColor(screen, width_half+10-1, height_half-256/2-1-24, "Image --gfxBlit--> Target2", text_color); stringColor(screen, width_half+10-1, height_half-256/2-1-12, "Target2 --sdlBlit--> Screen", text_color); stringColor(screen, width_half-256-10-1, height_half-256/2-1-60, "gfxBlitRGBA Demo: Target1/2 A=64 (25%), Image A=96 (37%)", text_color); /* Display by flipping screens */ SDL_Flip(screen); /* Delay to fix rate */ SDL_framerateDelay(&fpsm); } }
void make_text(int x_off, int y_off, char text[25]) { boxColor(screen, x_off, y_off-20, x_off+256, y_off-5, black); stringColor(screen, x_off+10, y_off-12, text, white); }
int init() { printf("Starting Forester "VERSION_STR"...\n"); ParseCfgFile(CFG_FN); if(SDL_Init(SDL_INIT_EVERYTHING)) { printf("SDL_Init() fail.\n"); return 1; } screen = SDL_SetVideoMode(scr_w_?scr_w_:SCRW_D, scr_h_?scr_h_:SCRH_D, 32, SDL_HWSURFACE|SDL_DOUBLEBUF); if(screen == NULL) { printf("Couldn`t create screen.\n"); return 1; } SDL_WM_SetCaption("Forester "VERSION_STR, NULL); stringColor(screen, 2, 2, "Starting...", 0xccddeeff); SDL_Flip(screen); if(TTF_Init()) printf("Warning: couldn`t initialize TTF.\n"); else { ui_font = TTF_OpenFont(FONT_FN, UI_FONT_SIZE); if(ui_font == NULL) { printf("Fatal: font file has failed to load.\n"); return 1; } } buttons_total = TOOLBUTTON; struct SCHbtnInfo btn_in = { 0, 0, 50, _1ST_LINE_H, 0x4488cc66, BTNV_BODY|BTNV_TEXT, "New", FONT_FN, NULL, NULL }; buttons[BUTTON_NEW] = SCHbtnCreate(btn_in); btn_in.text = "Load"; btn_in.x = 51; btn_in.col = 0x5566cc66; buttons[BUTTON_LOAD] = SCHbtnCreate(btn_in); btn_in.text = "Save"; btn_in.x = 102; btn_in.col = 0x6655cc66; buttons[BUTTON_SAVE] = SCHbtnCreate(btn_in); btn_in.text = "Resize"; btn_in.x = 153; btn_in.col = 0x7766cc66; buttons[BUTTON_RESIZE] = SCHbtnCreate(btn_in); btn_in.text = "Quit"; btn_in.x = scr_w_-51; btn_in.col = 0x88110066; buttons[BUTTON_QUIT] = SCHbtnCreate(btn_in); btn_in.flags = BTNV_BODY|BTNV_GLYPH; btn_in.glyphFN = ICN_ERASE; btn_in.x = 0; btn_in.y = 17; btn_in.w = 32; btn_in.h = 32; btn_in.col = 0x3344cc66; buttons[BUTTON_TOOL_ERASE] = SCHbtnCreate(btn_in); if(WSinit()) return 1; int toolc = WSgetToolsCount(); if(toolc == -1) return 1; /* Tool buttons */ #define TBTN_OFFSET 4 #define TBTN_W tile_w_+TBTN_OFFSET #define TBTN_H tile_h_+TBTN_OFFSET btn_in.col = 0x22773366; btn_in.w = TBTN_W; btn_in.h = TBTN_H; btn_in.x = -TBTN_W-9; /* WHY 9 ?!? */ btn_in.y = 50; int id; for(id = 0; id < toolc; id++) { if(buttons_total >= BTN_MAX-1) { printf("Too much buttons!\n"); break; } btn_in.surfptr = tiles[id].tile; btn_in.x += TBTN_W+1; if(btn_in.x+btn_in.w > scr_w_) { btn_in.y += TBTN_H+1; btn_in.x = 0; } buttons[id+TOOLBUTTON] = SCHbtnCreate(btn_in); buttons_total++; } printf("Alright.\n"); return 0; }