void Scene::renderDbg( Graphics2D& g , Vec2f const& pos , int index ) { bool isEven = mLevel.isEvenLayer( index ); Vec2f cPos = mLevel.calcCellCenterPos( index ); g.setBrush( ColorKey3( 0 , 0 , 255 ) ); g.drawCircle( pos + cPos , int( g_BubbleRadius - 10) ); g.setBrush( ColorKey3( 255 , 255 , 0 ) ); for( int i = 0 ; i < NUM_LINK_DIR ; ++i ) { int linkIdx = mLevel.getLinkCellIndex( index , LinkDir(i) , isEven ); //BubbleCell& linkCell = mLevel.getCell( linkIdx ); Vec2f cPos = mLevel.calcCellCenterPos( linkIdx ); g.drawCircle( pos + cPos , int( g_BubbleRadius -10) ); } //g.setBrush( ColorKey3( 255 , 0 , 0 ) ); //for( int i = 0 ; i < mLevel.mNumFallCell ; ++i ) //{ // Vec2f cPos = mLevel.calcCellCenterPos( mLevel.mIndexFallCell[i] ); // g.drawCircle( pos + cPos , g_BubbleRadius - 5 ); //} }
void Scene::renderBubble( Graphics2D& g , Vec2f const& pos , int color ) { RenderUtility::setPen( g , Color::eBlack ); RenderUtility::setBrush( g , color , COLOR_NORMAL); g.drawCircle( pos , int( g_BubbleRadius ) ); RenderUtility::setBrush( g , color , COLOR_DEEP ); RenderUtility::setPen( g , Color::eNull ); g.drawCircle( pos , int( g_BubbleRadius - 5.0 ) ); RenderUtility::setBrush( g , color , COLOR_LIGHT ); g.drawCircle( pos + Vec2f( 5 , -5 ) , 5 ); }
void SnakeGameView::render(Graphics2D& g) { #if 0 g.clearScreen(g.makeRGB(0xFF,0xFF,0xFF)); for(int y = 0; y < mBoard.height(); ++y) { for(int x = 0; x < mBoard.width(); ++x) { GameBoard::BoardState st = mBoard.boardStateAt(x,y); switch (st) { case GameBoard::BoardStateSnake: g.fillRect(x << 3, y << 3, 8, 8, g.makeRGB(0, 255, 0)); break; case GameBoard::BoardStateFood: g.fillRect(x << 3, y << 3, 8, 8, g.makeRGB(0, 0, 255)); break; case GameBoard::BoardStateBlock: g.fillRect(x << 3, y << 3, 8, 8, g.makeRGB(0, 0, 0)); break; default: break; } } } #endif }
void Scene::render( Graphics2D& g ) { if ( mScale != 1.0f ) { g.beginXForm(); g.translateXForm( getSurfacePos().x , getSurfacePos().y ); g.scaleXForm( mScale , mScale ); render( g , Vec2i(0,0) ); g.finishXForm(); } else { render( g , getSurfacePos() ); } }
void WireframeActor::drawActor(Graphics2D& g,long gameTime,float x1, float y1,double scale) { if(relative) { if(visible) { g.setColor(color); if(filled) { g.fillRect((x1 - View::x),(y1 - View::y),(float)(width*scale),(float)(height*scale)); } else { g.drawRect((x1 - View::x),(y1 - View::y),(float)(width*scale),(float)(height*scale)); } } } else { if(visible) { g.setColor(color); if(filled) { g.fillRect((x1),(y1),(float)(width*scale),(float)(height*scale)); } else { g.drawRect((x1),(y1),(float)(width*scale),(float)(height*scale)); } } } }
void Menu::draw(Graphics2D& g) { g.drawWallpaper( Vector2D(0, 0), SCREEN_SIZE ); // model::Project& proj = getOwner().getProject(); // model::DataBase& ldb = proj.getLDB(); // model::SaveData& lsd = proj.getLSD(); if( cursorNum() == 1 ) drawMainMenu(g); else switch( cursor(0) ) { case MENU_SKILL: case MENU_EQUIP: drawMainMenu(g, true); break; case MENU_QUIT: g.drawWindow( Vector2D( (SCREEN_SIZE[0]-quitMessageW_-16)/2, 72 ), Size2D(quitMessageW_+16, 32) ); g.drawString(quitMessage_, Vector2D( (SCREEN_SIZE[0]-quitMessageW_)/2, 82 ), font::FNT_NORMAL); g.drawWindow( Vector2D( (SCREEN_SIZE[0]-yesNoW_-16)/2, 120 ), Size2D(yesNoW_+16, 48) ); g.drawCursor( Vector2D( (SCREEN_SIZE[0]-yesNoW_-8)/2, cursor()*CURSOR_H + 128 ) + cursorMove(), Size2D(yesNoW_+8, 16) ); g.drawString(yes_, Vector2D( (SCREEN_SIZE[0]-yesNoW_)/2, 130 ), font::FNT_NORMAL); g.drawString(no_ , Vector2D( (SCREEN_SIZE[0]-yesNoW_)/2, 146 ), font::FNT_NORMAL); break; default: break; } }
void Scene::renderBubbleList( Graphics2D& g , Vec2f const& pos , BubbleList& bList ) { for( BubbleList::iterator iter = bList.begin() ,iterEnd = bList.end() ; iter != iterEnd ; ++iter ) { SceneBubble* bubble = *iter; Vec2f bPos = pos + bubble->pos; if ( bubble->alpha != 1.0f ) { g.beginBlend( bPos - Vec2f( g_BubbleRadius , g_BubbleRadius ) , Vec2f( g_BubbleDiameter , g_BubbleDiameter ) , bubble->alpha ); renderBubble( g , pos + bubble->pos , bubble->color ); g.endBlend(); } else { renderBubble( g , pos + bubble->pos , bubble->color ); } } }
void Scene::renderLauncher( Graphics2D& g , Vec2f const& pos ) { RenderUtility::setBrush( g , mLevel.mShootBubbleColor ); RenderUtility::setPen( g , mLevel.mShootBubbleColor ); Vec2f bPos = pos + mLevel.mLauncherPos; Vec2f startPos = bPos + 10 * mLevel.mLauncherDir; Vec2f offset = 15 * mLevel.mLauncherDir; int idx = ( mTimeCount / 120 ) % 13 - 4; for( int i = 0 ; i < 5 ; ++ i ) { int r = std::max( 1 , 5 - abs( idx - i ) ); startPos += offset; g.drawCircle( startPos , r ); } //g.drawLine( bPos , bPos + 60 * mLevel.mLauncherDir ); renderBubble( g , bPos , mLevel.mShootBubbleColor ); }
void Item::draw(Graphics2D& g) { model::Project& proj = getOwner().getProject(); model::SaveData& lsd = proj.getLSD(); model::DataBase& ldb = proj.getLDB(); std::ostringstream ss; switch( cursorNum() ) { case 1: { // select item std::map< uint16_t, model::SaveData::Item >& itemList = lsd.item(); structure::Array2D const& item = ldb[13]; g.drawWindow( Vector2D(0, 0), Size2D(SCREEN_SIZE[0], 32) ); g.drawWindow( Vector2D(0, 32), SCREEN_SIZE - Size2D(0, 32) ); g.drawCursor( Vector2D(4, 42) + Vector2D( cursor() % 2 * 160, cursor() / 2 * CURSOR_H ), Size2D(152, CURSOR_H) ); int index = 0; for(std::map< uint16_t, model::SaveData::Item >::const_iterator it = itemList.begin(); it != itemList.end(); ++it) { Vector2D base = Vector2D(8, 42) + Vector2D( index % 2 * 160, index / 2 * CURSOR_H ); if( cursor() == index ) { g.drawString( item[it->first][2], Vector2D(8, 10) ); } g.drawString(item[it->first][1], base); ss.str(""); ss << ":" << std::setw(2) << it->second.num; g.drawString( ss.str(), base + Vector2D( font::HALF_FONT_W*21, 0 ) ); index++; } } break; case 2: // select char break; } }
virtual void HandleMessage(const Var& var_message) { if (busy) return; busy = true; static int thread_pool_size = 8; static int halide_last_t = 0; static int halide_time_weight = 0; static int last_demo = -1; int demo = 0; if (var_message.is_string()) { std::string msg = var_message.AsString(); int threads = atoi(msg.c_str()+2); if (threads < 1) threads = 1; if (threads > 32) threads = 32; if (threads > 0 && threads <= 32 && thread_pool_size != threads) { halide_shutdown_thread_pool(); thread_pool_size = threads; char buf[256]; snprintf(buf, 256, "%d", threads); setenv("HL_NUMTHREADS", buf, 1); halide_last_t = 0; halide_time_weight = 0; } demo = msg[0] - '0'; } static bool first_run = true; if (first_run) { first_run = false; setenv("HL_NUMTHREADS", "8", 1); } // Initialize the input if (demo != last_demo) { last_demo = demo; // Delete any existing state free_buffer(&state_1); free_buffer(&state_2); halide_last_t = 0; halide_time_weight = 0; switch (demo) { case 0: // Query how large the state arrays need to be in // order to hit our render target using Halide's // bounds query mode. game_of_life_render(&state_1, &render_target); state_2 = state_1; alloc_buffer(&state_1); alloc_buffer(&state_2); // Initialize into the first one game_of_life_init(&state_1); break; case 1: julia_render(&state_1, &render_target); state_2 = state_1; alloc_buffer(&state_1); alloc_buffer(&state_2); julia_init(&state_1); break; case 2: reaction_diffusion_render(&state_1, &render_target); state_2 = state_1; alloc_buffer(&state_1); alloc_buffer(&state_2); print_buffer(&state_1); reaction_diffusion_init(&state_1); break; case 3: reaction_diffusion_2_render(&state_1, &render_target); state_2 = state_1; alloc_buffer(&state_1); alloc_buffer(&state_2); print_buffer(&state_1); reaction_diffusion_2_init(&state_1); break; default: PostMessage("Bad demo index"); return; } } if (pipeline_barfed) { return; } timeval t1, t2; gettimeofday(&t1, NULL); switch (demo) { case 0: game_of_life_update(&state_1, mouse_x, mouse_y, &state_2); game_of_life_render(&state_2, &render_target); break; case 1: julia_update(&state_1, mouse_x, mouse_y, &state_2); julia_render(&state_2, &render_target); break; case 2: reaction_diffusion_update(&state_1, mouse_x, mouse_y, &state_2); reaction_diffusion_render(&state_2, &render_target); break; case 3: reaction_diffusion_2_update(&state_1, mouse_x, mouse_y, &state_2); reaction_diffusion_2_render(&state_2, &render_target); break; } gettimeofday(&t2, NULL); std::swap(state_1, state_2); mouse_x = mouse_y = -100; if (pipeline_barfed) { return; } int t = t2.tv_usec - t1.tv_usec; t += (t2.tv_sec - t1.tv_sec)*1000000; // Smooth it out so we can see a rolling average t = (halide_last_t * halide_time_weight + t) / (halide_time_weight + 1); halide_last_t = t; if (halide_time_weight < 100) { halide_time_weight++; } std::ostringstream oss; oss << "<table cellspacing=8><tr><td width=200 height=30>Halide routine takes:</td><td>"; if (halide_time_weight < 10) { oss << "?"; } else { oss << halide_last_t; } oss << " us</td></tr></table>"; PostMessage(oss.str()); graphics.PaintImageData(framebuffer, Point(0, 0)); graphics.Flush(callback); }
void Menu::drawMainMenu(Graphics2D& g, bool charSelect) { model::Project& proj = getOwner().getProject(); model::SaveData& lsd = proj.getLSD(); model::DataBase& ldb = proj.getLDB(); std::ostringstream ss; // main menu g.drawWindow( Vector2D(0, 0), Size2D(88, 96) ); // cursor if(charSelect) g.drawCursorPassive( Vector2D(4, cursor(0)*16 + 8), Size2D(80, CURSOR_H) ); else g.drawCursor( Vector2D(4, cursor(0)*16 + 8) + cursorMove(), Size2D(80, CURSOR_H) ); // command font::FontColor c = lsd.memberNum() != 0 ? font::FNT_ENABLE : font::FNT_DISABLE; g.drawString(command_[0], Vector2D(8, 10 + CURSOR_H*0), font::FNT_ENABLE); g.drawString(command_[1], Vector2D(8, 10 + CURSOR_H*1), c); g.drawString(command_[2], Vector2D(8, 10 + CURSOR_H*2), c); g.drawString(command_[3], Vector2D(8, 10 + CURSOR_H*3), proj.canSave() ? font::FNT_ENABLE : font::FNT_DISABLE); g.drawString(command_[4], Vector2D(8, 10 + CURSOR_H*4), font::FNT_ENABLE); // money g.drawMoneyWindow( Vector2D( 0, 208) ); // char info g.drawWindow( Vector2D(88, 0), Size2D(232, 240) ); // char cursor if(charSelect) g.drawCursor( Vector2D(92, cursor(1)*58 + 4) + cursorMove(), Size2D(224, 56) ); std::vector< uint16_t >& mem = lsd.member(); for(uint i = 0; i < mem.size(); i++) { uint charID = mem[i]; Vector2D base(88 + 8, 8 + (FACE_SIZE[1] + 10)*i); g.drawFaceSet( proj.faceSet(charID), proj.faceSetPos(mem[i]), base ); base += Vector2D(FACE_SIZE[0] + 8, 3); g.drawString( proj.name(charID), base); g.drawString( proj.title(charID), base + Vector2D(font::HALF_FONT_W*15, 0) ); base += Vector2D(0, font::FONT_H + 3); // level g.drawString(ldb.vocabulary(128), base, font::FNT_STATUS); ss.str(""); ss << std::setw(2) << proj.level(charID); g.drawString( ss.str(), base + Vector2D(font::FULL_FONT_W, 0) ); // condition g.drawString( proj.condition(charID), base + Vector2D(font::HALF_FONT_W*7, 0), proj.conditionColor(charID) ); // HP g.drawString( ldb.vocabulary(129), base + Vector2D(font::HALF_FONT_W*18, 0), font::FNT_STATUS ); ss.str(""); ss << std::setw(3) << proj.hp(charID) << "/" << std::setw(3) << proj.param(charID, Param::HP); g.drawString( ss.str(), base + Vector2D(font::HALF_FONT_W*20, 0) ); base += Vector2D(0, font::FONT_H + 3); // experience g.drawString(ldb.vocabulary(127), base, font::FNT_STATUS); ss.str(""); if( proj.level(charID) >= LV_MAX ) ss << RPG2kString(6, '-') << "/" << RPG2kString(6, '-'); else ss << std::setw(6) << proj.exp(charID) << "/" << std::setw(6) << proj.nextLevelExp(charID); g.drawString( ss.str(), base + Vector2D(font::FULL_FONT_W, 0) ); // MP g.drawString( ldb.vocabulary(130), base + Vector2D(font::HALF_FONT_W*18, 0), font::FNT_STATUS ); ss.str(""); ss << std::setw(3) << proj.mp(charID) << "/" << std::setw(3) << proj.param(charID, Param::MP); g.drawString( ss.str(), base + Vector2D(font::HALF_FONT_W*20, 0) ); } }
void Skill::draw(Graphics2D& g) { model::Project& proj = getOwner().getProject(); // model::SaveData& lsd = proj.getLSD(); model::DataBase& ldb = proj.getLDB(); std::ostringstream ss; switch( cursorNum() ) { case 2: { // select skill structure::Array2D const& skill = ldb[12]; g.drawWindow( Vector2D(0, 32*0), Size2D(SCREEN_SIZE[0], 32) ); if( cursor() != (int)idList_.size() ) { g.drawString( skill[ idList_[ cursor() ] ][2], Vector2D(8, 10) ); } g.drawWindow( Vector2D(0, 32*1), Size2D(SCREEN_SIZE[0], 32) ); // name Vector2D base(8, 32 + 10); g.drawString( proj.name(curCharID_), base ); // level base += Vector2D( font::HALF_FONT_W*14, 0 ); g.drawString( ldb.vocabulary(128), base, font::FNT_STATUS ); base += Vector2D( font::FULL_FONT_W*1, 0 ); ss.str(""); ss << proj.level(curCharID_); g.drawString( ss.str(), base ); // condition base += Vector2D( font::HALF_FONT_W*5, 0 ); g.drawString( proj.condition(curCharID_), base, proj.conditionColor(curCharID_) ); // HP base += Vector2D( font::HALF_FONT_W*10, 0 ); g.drawString( ldb.vocabulary(129), base, font::FNT_STATUS ); base += Vector2D( font::FULL_FONT_W*1, 0 ); ss.str(""); ss << std::setw(3) << proj.hp(curCharID_) << "/" << std::setw(3) << proj.param(curCharID_, Param::HP); g.drawString( ss.str(), base ); // MP base += Vector2D( font::HALF_FONT_W*9, 0 ); g.drawString( ldb.vocabulary(130), base, font::FNT_STATUS ); base += Vector2D( font::FULL_FONT_W*1, 0 ); ss.str(""); ss << std::setw(3) << proj.mp(curCharID_) << "/" << std::setw(3) << proj.param(curCharID_, Param::MP); g.drawString( ss.str(), base ); g.drawWindow( Vector2D(0, 32*2), SCREEN_SIZE - Size2D(0, 32*2) ); g.drawCursor( Vector2D(4, 72) + Vector2D( cursor() % 2 * 160, cursor() / 2 * CURSOR_H ), Size2D(152, CURSOR_H) ); int index = 0; for(std::vector< uint16_t >::const_iterator it = idList_.begin(); it != idList_.end(); ++it) { if( *it == 0 ) break; base = Vector2D(8, 74) + Vector2D( index % 2 * 160, index / 2 * CURSOR_H ); g.drawString(skill[*it][1], base); ss.str(""); ss << "-" << std::setw(3) << skill[*it][11].get<int>(); g.drawString( ss.str(), base + Vector2D( font::HALF_FONT_W*20, 0 ) ); index++; } } break; case 3: // select char break; } }
void RenderUtility::setBrush( Graphics2D& g , int color , int type ) { g.setBrush( getColorBrush( color , type ) ); }
void RenderUtility::setPen( Graphics2D& g , int color , int type ) { g.setPen( hCPen[ color ] ); }
void RenderUtility::setFont( Graphics2D& g , int fontID ) { g.setFont( hFont[fontID] ); }