CAndroidFont::CAndroidFont(int size, const char * fontName) { // fontName = NULL; // ハングするので一旦 // // フォント管理クラスを取得(static class) jclass cls_fntManage = CJNI::getJNIEnv()->FindClass(JNI_FONTMANAGER_LOAD_PATH); // Paint作成函数ID取得 jmethodID mtd_createPaint = getEnv()->GetStaticMethodID(cls_fntManage, "CreatePaint", "(Ljava/lang/String;)Landroid/graphics/Paint;"); // エイリアスからフォント名を取得 const char* fntName = NULL; for( int i=0; fontName && ms_fontlist[i].alias; i++ ) { if( !strcmp(ms_fontlist[i].alias, fontName) ) { fntName = ms_fontlist[i].fontname; } } jstring strj = NULL; if( fntName ) { strj = getEnv()->NewStringUTF(fntName); } // 指定フォント名でPaintを作成 jobject local_font = CJNI::getJNIEnv()->CallStaticObjectMethod( cls_fntManage, mtd_createPaint, strj ); // グローバル的な変数として設定 m_paint = getEnv()->NewGlobalRef(local_font); m_getfontmetrics = getEnv()->GetStaticMethodID(cls_fntManage, "getFontMetrics", "(Landroid/graphics/Paint;)Landroid/graphics/Paint$FontMetrics;"); m_settextsize = getEnv()->GetStaticMethodID(cls_fntManage, "setTextSize", "(Landroid/graphics/Paint;F)V"); m_setantialias = getEnv()->GetStaticMethodID(cls_fntManage, "setAntiAlias", "(Landroid/graphics/Paint;Z)V"); m_measuretext = getEnv()->GetStaticMethodID(cls_fntManage, "measureText", "(Landroid/graphics/Paint;Ljava/lang/String;)F"); /* { char buf[256]; sprintf(buf, "m_getfontmetrics = %d, m_settextsize = %d, m_setantialias = %d", m_getfontmetrics, m_settextsize, m_setantialias); __android_log_write(ANDROID_LOG_DEBUG, "Cpp", buf); } */ // アンチエイリアス設定(PFInterface.javaのdrawTextでの描画時と、ただ文章幅を取得したい場合の幅値が異なるため) 2013/04/11 setAntiAlias(true); // テキストサイズを設定 setTextSize(size); CJNI::getJNIEnv()->DeleteLocalRef(cls_fntManage); CJNI::getJNIEnv()->DeleteLocalRef(strj); CJNI::getJNIEnv()->DeleteLocalRef(local_font); }
void onOnceBeforeDraw() override { const SkRect fieldBounds = kBounds.makeOutset(kBallSize / 2, kBallSize / 2); const SkRRect ball = SkRRect::MakeOval(SkRect::MakeWH(kBallSize, kBallSize)); const SkRRect paddle = SkRRect::MakeRectXY(SkRect::MakeWH(kPaddleSize.width(), kPaddleSize.height()), kPaddleSize.width() / 2, kPaddleSize.width() / 2); fBall.initialize(ball, SkPoint::Make(kBounds.centerX(), kBounds.centerY()), SkVector::Make(fRand.nextRangeScalar(kBallSpeedMin, kBallSpeedMax), fRand.nextRangeScalar(kBallSpeedMin, kBallSpeedMax))); fPaddle0.initialize(paddle, SkPoint::Make(fieldBounds.left() - kPaddleSize.width() / 2, fieldBounds.centerY()), SkVector::Make(0, 0)); fPaddle1.initialize(paddle, SkPoint::Make(fieldBounds.right() + kPaddleSize.width() / 2, fieldBounds.centerY()), SkVector::Make(0, 0)); // Background decoration. SkPath bgPath; bgPath.moveTo(kBounds.left() , fieldBounds.top()); bgPath.lineTo(kBounds.right(), fieldBounds.top()); bgPath.moveTo(kBounds.left() , fieldBounds.bottom()); bgPath.lineTo(kBounds.right(), fieldBounds.bottom()); // TODO: stroke-dash support would come in handy right about now. for (uint32_t i = 0; i < kBackgroundDashCount; ++i) { bgPath.moveTo(kBounds.centerX(), kBounds.top() + (i + 0.25f) * kBounds.height() / kBackgroundDashCount); bgPath.lineTo(kBounds.centerX(), kBounds.top() + (i + 0.75f) * kBounds.height() / kBackgroundDashCount); } auto bg_path = sksg::Path::Make(bgPath); auto bg_paint = sksg::Color::Make(SK_ColorBLACK); bg_paint->setStyle(SkPaint::kStroke_Style); bg_paint->setStrokeWidth(kBackgroundStroke); auto ball_paint = sksg::Color::Make(SK_ColorGREEN), paddle0_paint = sksg::Color::Make(SK_ColorBLUE), paddle1_paint = sksg::Color::Make(SK_ColorRED), shadow_paint = sksg::Color::Make(SK_ColorBLACK); ball_paint->setAntiAlias(true); paddle0_paint->setAntiAlias(true); paddle1_paint->setAntiAlias(true); shadow_paint->setAntiAlias(true); shadow_paint->setOpacity(kShadowOpacity); // Build the scene graph. auto group = sksg::Group::Make(); group->addChild(sksg::Draw::Make(std::move(bg_path), std::move(bg_paint))); group->addChild(sksg::Draw::Make(fPaddle0.shadowNode, shadow_paint)); group->addChild(sksg::Draw::Make(fPaddle1.shadowNode, shadow_paint)); group->addChild(sksg::Draw::Make(fBall.shadowNode, shadow_paint)); group->addChild(sksg::Draw::Make(fPaddle0.objectNode, paddle0_paint)); group->addChild(sksg::Draw::Make(fPaddle1.objectNode, paddle1_paint)); group->addChild(sksg::Draw::Make(fBall.objectNode, ball_paint)); // Handle everything in a normalized 1x1 space. fContentMatrix = sksg::Matrix<SkMatrix>::Make( SkMatrix::MakeRectToRect(SkRect::MakeWH(1, 1), SkRect::MakeIWH(this->width(), this->height()), SkMatrix::kFill_ScaleToFit)); auto root = sksg::TransformEffect::Make(std::move(group), fContentMatrix); fScene = sksg::Scene::Make(std::move(root), sksg::AnimatorList()); // Off we go. this->updatePaddleStrategy(); }