static typename std::enable_if<std::is_integral<Src>::value, void>::type run_constexpr_clamp_cast_test(Src, Dst) { constexpr auto kSrcMax = std::numeric_limits<Src>::max(); constexpr auto kSrcMin = std::numeric_limits<Src>::min(); constexpr auto kDstMax = std::numeric_limits<Dst>::max(); constexpr auto kDstMin = std::numeric_limits<Dst>::min(); // value in range -> same value EXPECT_EQ(Dst(0), folly::constexpr_clamp_cast<Dst>(Src(0))); EXPECT_EQ(Dst(123), folly::constexpr_clamp_cast<Dst>(Src(123))); // int -> uint if (std::is_signed<Src>::value && std::is_unsigned<Dst>::value) { EXPECT_EQ(Dst(0), folly::constexpr_clamp_cast<Dst>(Src(-123))); } if (sizeof(Src) > sizeof(Dst)) { // range clamping EXPECT_EQ(kDstMax, folly::constexpr_clamp_cast<Dst>(kSrcMax)); // int -> int if (std::is_signed<Src>::value && std::is_signed<Dst>::value) { EXPECT_EQ(kDstMin, folly::constexpr_clamp_cast<Dst>(kSrcMin)); } } else if ( std::is_unsigned<Src>::value && std::is_signed<Dst>::value && sizeof(Src) == sizeof(Dst)) { // uint -> int, same size EXPECT_EQ(kDstMax, folly::constexpr_clamp_cast<Dst>(kSrcMax)); } }
static typename std::enable_if<std::is_floating_point<Src>::value, void>::type run_constexpr_clamp_cast_test(Src, Dst) { constexpr auto kQuietNaN = std::numeric_limits<Src>::quiet_NaN(); constexpr auto kSignalingNaN = std::numeric_limits<Src>::signaling_NaN(); constexpr auto kPositiveInf = std::numeric_limits<Src>::infinity(); constexpr auto kNegativeInf = -kPositiveInf; constexpr auto kDstMax = std::numeric_limits<Dst>::max(); constexpr auto kDstMin = std::numeric_limits<Dst>::min(); // Check f != f trick for identifying NaN. EXPECT_TRUE(kQuietNaN != kQuietNaN); EXPECT_TRUE(kSignalingNaN != kSignalingNaN); EXPECT_FALSE(kPositiveInf != kPositiveInf); EXPECT_FALSE(kNegativeInf != kNegativeInf); // NaN -> 0 EXPECT_EQ(0, folly::constexpr_clamp_cast<Dst>(kQuietNaN)); EXPECT_EQ(0, folly::constexpr_clamp_cast<Dst>(kSignalingNaN)); // Inf -> Max/Min EXPECT_EQ(kDstMax, folly::constexpr_clamp_cast<Dst>(kPositiveInf)); EXPECT_EQ(kDstMin, folly::constexpr_clamp_cast<Dst>(kNegativeInf)); // barely out of range -> Max/Min EXPECT_EQ(kDstMax, folly::constexpr_clamp_cast<Dst>(Src(kDstMax) * 1.001)); EXPECT_EQ(kDstMin, folly::constexpr_clamp_cast<Dst>(Src(kDstMin) * 1.001)); // value in range -> same value EXPECT_EQ(Dst(0), folly::constexpr_clamp_cast<Dst>(Src(0))); EXPECT_EQ(Dst(123), folly::constexpr_clamp_cast<Dst>(Src(123))); }
//============================================================================ //グレースケール描画 //============================================================================ //[input] // pRender:レンダラー用デバイス //=========================================================================== void CSprite::DrawGrayScale( Renderer::IRender *pRender ) { if( m_pTex != NULL ) { Math::Rect2DF Dst( m_vPos.x, m_vPos.y, m_fSize.x, m_fSize.y ); Math::Rect2DF Src( 0, 0, m_fSize.x, m_fSize.y ); pRender->DrawGrayscale( Dst, CColor( 255, 254, 255 ), Src, m_pTex ); } }
// -------------------------------------------------------------- // Set up the dynamic elastic sail deformation code // -------------------------------------------------------------- void SolarSail::SetupElasticity (MESHHANDLE hMesh) { MESHGROUP *sail = oapiMeshGroup (hMesh, GRP_sail1); // all sail segments have the same mesh structure, so segment 1 represents all 4 DWORD nvtx = sail->nVtx/2; // scan front side only DWORD nidx = sail->nIdx/2; // scan front side only DWORD ntri = nidx/3; WORD *idx = sail->Idx; NTVERTEX *vtx = sail->Vtx; DWORD i, j, k, m, nj, nk; // generate node neighbour graph sail_vbuf = new VECTOR3[nvtx]; nbhr = new NBHR[nvtx]; for (i = 0; i < nvtx; i++) { nbhr[i].nnd = 0; nbhr[i].fix = (vtx[i].x == 0 || vtx[i].y == 0); } for (i = 0; i < ntri; i++) { WORD *tri = idx+(i*3); for (j = 0; j < 3; j++) { nj = tri[j]; for (k = 0; k < 3; k++) { if (j == k) continue; nk = tri[k]; for (m = 0; m < nbhr[nj].nnd; m++) if (nbhr[nj].nd[m] == nk) break; // already in neighbour list if (m == nbhr[nj].nnd) { if (nbhr[nj].nnd == MAXNBHR) strcpy (oapiDebugString(), "Problems!"); else { nbhr[nj].nd[m] = nk; nbhr[nj].dst0[m] = Dst (vtx+nj, vtx+nk); nbhr[nj].nnd++; } } } } } sail_nvtx = nvtx; sail_ntri = ntri; }
int main(int argc, char **argv) { /* Plant signal catcher. */ { static int getsigs[] = { /* signals to catch */ #ifdef SIGHUP SIGHUP, /* hangup */ #endif #ifdef SIGINT SIGINT, /* interrupt */ #endif #ifdef SIGQUIT SIGQUIT, /* quit */ #endif #ifdef SIGPIPE SIGPIPE, /* write on a broken pipe */ #endif #ifdef SIGTERM SIGTERM, /* software termination signal */ #endif 0 }; int i; for (i = 0; getsigs[i] != 0; ++i) if (signal(getsigs[i], SIG_IGN) != SIG_IGN) (void)signal(getsigs[i], Sig_Catcher); } /* Process arguments. */ { int c; bool_t errors = 0; while ((c = bu_getopt(argc, argv, OPTSTR)) != -1) switch (c) { default: /* '?': invalid option */ errors = 1; break; case 'a': /* -a */ sample = 1; break; case 'f': /* -f in_fb */ src_file = bu_optarg; break; case 'F': /* -F out_fb */ dst_file = bu_optarg; break; case 'n': /* -n height */ if ((src_height = atoi(bu_optarg)) <= 0) errors = 1; break; case 'N': /* -N height */ if ((dst_height = atoi(bu_optarg)) <= 0) errors = 1; break; case 's': /* -s size */ if ((src_height = src_width = atoi(bu_optarg)) <= 0 ) errors = 1; break; case 'S': /* -S size */ if ((dst_height = dst_width = atoi(bu_optarg)) <= 0 ) errors = 1; break; case 'v': verbose = 1; break; case 'w': /* -w width */ if ((src_width = atoi(bu_optarg)) <= 0) errors = 1; break; case 'W': /* -W width */ if ((dst_width = atoi(bu_optarg)) <= 0) errors = 1; break; case 'x': /* -x x_scale */ if ((x_scale = atof(bu_optarg)) <= 0) { Message("Nonpositive x scale factor"); errors = 1; } break; case 'y': /* -y y_scale */ if ((y_scale = atof(bu_optarg)) <= 0) { Message("Nonpositive y scale factor"); errors = 1; } break; } if (argc == 1 && isatty(fileno(stdin)) && isatty(fileno(stdout))) errors = 1; if (errors) bu_exit(1, "Usage: %s\n%s\n%s\n", USAGE1, USAGE2, USAGE3); } if (bu_optind < argc) { /* dst_file */ if (bu_optind < argc - 1 || dst_file != NULL) { bu_log("Usage: %s\n%s\n%s", USAGE1, USAGE2, USAGE3); Stretch_Fatal("Can't handle multiple output frame buffers!"); } dst_file = argv[bu_optind]; } if (dst_file == NULL) dst_file = getenv("FB_FILE"); /* Figure out what scale factors to use before messing up size info. */ if (x_scale < 0.0) { if (src_width == 0 || dst_width == 0) x_scale = 1.0; else x_scale = (double)dst_width / (double)src_width; } if (y_scale < 0.0) { if (src_height == 0 || dst_height == 0) y_scale = 1.0; else y_scale = (double)dst_height / (double)src_height; } if (verbose) Message("Scale factors %gx%g", x_scale, y_scale); /* Open frame buffer(s) for unbuffered input/output. */ if ((src_fbp = fb_open(src_file == NULL ? dst_file : src_file, src_width, src_height ) ) == FB_NULL ) Stretch_Fatal("Couldn't open input image"); else { int wt, ht; /* actual frame buffer size */ /* Use smaller input size in preference to requested size. */ if ((wt = fb_getwidth(src_fbp)) < src_width) src_width = wt; if ((ht = fb_getheight(src_fbp)) < src_height) src_height = ht; if (verbose) Message("Source image %dx%d", src_width, src_height); if (dst_width == 0) dst_width = src_width * x_scale + EPSILON; if (dst_height == 0) dst_height = src_height * y_scale + EPSILON; if (verbose) Message("Requested output size %dx%d", dst_width, dst_height ); if (src_file == NULL || (dst_file != NULL && BU_STR_EQUAL(src_file, dst_file)) ) dst_fbp = src_fbp; /* No No No Not a Second Time */ else if ((dst_fbp = fb_open(dst_file, dst_width, dst_height)) == FB_NULL ) Stretch_Fatal("Couldn't open output frame buffer"); /* Use smaller output size in preference to requested size. */ if ((wt = fb_getwidth(dst_fbp)) < dst_width) dst_width = wt; if ((ht = fb_getheight(dst_fbp)) < dst_height) dst_height = ht; if (verbose) Message("Destination image %dx%d", dst_width, dst_height ); } /* Determine compression/expansion directions. */ x_compress = x_scale < 1 - EPSILON; y_compress = y_scale < 1 - EPSILON; /* Allocate input/output scan line buffers. These could overlap, but I decided to keep them separate for simplicity. The algorithms are arranged so that source and destination can access the same image; if at some future time offsets are supported, that would no longer hold. calloc is used instead of malloc just to avoid integer overflow. */ if ((src_buf = (unsigned char *)calloc( y_compress ? (int)(1 / y_scale + 1 - EPSILON) * src_width : src_width, sizeof(RGBpixel) ) ) == NULL || (dst_buf = (unsigned char *)calloc( y_compress ? dst_width : (int)(y_scale + 1 - EPSILON) * dst_width, sizeof(RGBpixel) ) ) == NULL ) Stretch_Fatal("Insufficient memory for scan line buffers."); #define Src(x, y) (&src_buf[(x) + src_width * (y) * sizeof(RGBpixel)]) #define Dst(x, y) (&dst_buf[(x) + dst_width * (y) * sizeof(RGBpixel)]) /* Do the horizontal/vertical expansion/compression. I wanted to merge these but didn't like the extra bookkeeping overhead in the loops. */ if (x_compress && y_compress) { int src_x, src_y; /* source rect. pixel coords. */ int dst_x, dst_y; /* destination pixel coords. */ int top_x, top_y; /* source rect. upper bounds */ int bot_x, bot_y; /* source rect. lower bounds */ /* Compute coords. of source rectangle and destination pixel. */ dst_y = 0; ccyloop: if (dst_y >= dst_height) goto done; /* that's all folks */ bot_y = dst_y / y_scale + EPSILON; if ((top_y = (dst_y + 1) / y_scale + EPSILON) > src_height) top_y = src_height; if (top_y <= bot_y) { /* End of image. */ /* Clear beginning of output scan line buffer. */ dst_x = src_width * y_scale + EPSILON; if (dst_x < dst_width) ++dst_x; /* sometimes needed */ while (--dst_x >= 0) { assert(dst_x < dst_width); Dst(dst_x, 0)[RED] = 0; Dst(dst_x, 0)[GRN] = 0; Dst(dst_x, 0)[BLU] = 0; } /* Clear out top margin. */ for (; dst_y < dst_height; ++dst_y) if (fb_write(dst_fbp, 0, dst_y, (unsigned char *)Dst(0, 0), dst_width ) == -1 ) Stretch_Fatal("Error writing top margin"); goto done; /* that's all folks */ } assert(0 <= bot_y && bot_y < top_y && top_y <= src_height); assert(0 <= dst_y && dst_y <= bot_y); assert(top_y - bot_y <= (int)(1 / y_scale + 1 - EPSILON)); /* Fill input scan line buffer. */ for (src_y = bot_y; src_y < top_y; ++src_y) if (fb_read(src_fbp, 0, src_y, (unsigned char *)Src(0, src_y - bot_y), src_width ) == -1 ) Stretch_Fatal("Error reading scan line"); dst_x = 0; ccxloop: if (dst_x >= dst_width) goto ccflush; bot_x = dst_x / x_scale + EPSILON; if ((top_x = (dst_x + 1) / x_scale + EPSILON) > src_width) top_x = src_width; if (top_x <= bot_x) { ccflush: /* End of band; flush buffer. */ if (fb_write(dst_fbp, 0, dst_y, (unsigned char *)Dst(0, 0), dst_width ) == -1 ) Stretch_Fatal("Error writing scan line"); ++dst_y; goto ccyloop; } assert(0 <= bot_x && bot_x < top_x && top_x <= src_width); assert(0 <= dst_x && dst_x <= bot_x); assert(top_x - bot_x <= (int)(1 / x_scale + 1 - EPSILON)); /* Copy sample or averaged source pixel(s) to destination. */ if (sample) { Dst(dst_x, 0)[RED] = Src(bot_x, 0)[RED]; Dst(dst_x, 0)[GRN] = Src(bot_x, 0)[GRN]; Dst(dst_x, 0)[BLU] = Src(bot_x, 0)[BLU]; } else { int sum[3]; /* pixel value accumulator */ float tally; /* # of pixels accumulated */ /* "Read in" source rectangle and average pixels. */ sum[RED] = sum[GRN] = sum[BLU] = 0; for (src_y = top_y - bot_y; --src_y >= 0;) for (src_x = bot_x; src_x < top_x; ++src_x) { sum[RED] += Src(src_x, src_y)[RED]; sum[GRN] += Src(src_x, src_y)[GRN]; sum[BLU] += Src(src_x, src_y)[BLU]; } tally = (top_x - bot_x) * (top_y - bot_y); assert(tally > 0.0); Dst(dst_x, 0)[RED] = sum[RED] / tally + 0.5; Dst(dst_x, 0)[GRN] = sum[GRN] / tally + 0.5; Dst(dst_x, 0)[BLU] = sum[BLU] / tally + 0.5; } ++dst_x; goto ccxloop; } else if (x_compress && !y_compress) { int src_x, src_y; /* source rect. pixel coords. */ int dst_x, dst_y; /* dest. rect. pixel coords. */ int bot_x, top_x; /* source rectangle bounds */ int bot_y, top_y; /* destination rect. bounds */ /* Compute coords. of source and destination rectangles. */ src_y = (dst_height - 1) / y_scale + EPSILON; ceyloop: if (src_y < 0) goto done; /* that's all folks */ bot_y = src_y * y_scale + EPSILON; if ((top_y = (src_y + 1) * y_scale + EPSILON) > dst_height) top_y = dst_height; assert(0 <= src_y && src_y <= bot_y && src_y < src_height); assert(bot_y < top_y && top_y <= dst_height); assert(top_y - bot_y <= (int)(y_scale + 1 - EPSILON)); /* Fill input scan line buffer. */ if (fb_read(src_fbp, 0, src_y, (unsigned char *)Src(0, 0), src_width ) == -1 ) Stretch_Fatal("Error reading scan line"); dst_x = 0; cexloop: if (dst_x >= dst_width) goto ceflush; bot_x = dst_x / x_scale + EPSILON; if ((top_x = (dst_x + 1) / x_scale + EPSILON) > src_width) top_x = src_width; if (top_x <= bot_x) { ceflush: /* End of band; flush buffer. */ for (dst_y = top_y; --dst_y >= bot_y;) if (fb_write(dst_fbp, 0, dst_y, (unsigned char *)Dst(0, dst_y - bot_y ), dst_width ) == -1 ) Stretch_Fatal("Error writing scan line"); --src_y; goto ceyloop; } assert(0 <= bot_x && bot_x < top_x && top_x <= src_width); assert(0 <= dst_x && dst_x <= bot_x); assert(top_x - bot_x <= (int)(1 / x_scale + 1 - EPSILON)); /* Replicate sample or averaged source pixel(s) to dest. */ if (sample) { for (dst_y = top_y - bot_y; --dst_y >= 0;) { Dst(dst_x, dst_y)[RED] = Src(bot_x, 0)[RED]; Dst(dst_x, dst_y)[GRN] = Src(bot_x, 0)[GRN]; Dst(dst_x, dst_y)[BLU] = Src(bot_x, 0)[BLU]; } } else { int sum[3]; /* pixel value accumulator */ float tally; /* # of pixels accumulated */ /* "Read in" source rectangle and average pixels. */ sum[RED] = sum[GRN] = sum[BLU] = 0; for (src_x = bot_x; src_x < top_x; ++src_x) { sum[RED] += Src(src_x, 0)[RED]; sum[GRN] += Src(src_x, 0)[GRN]; sum[BLU] += Src(src_x, 0)[BLU]; } tally = top_x - bot_x; assert(tally > 0.0); sum[RED] = sum[RED] / tally + 0.5; sum[GRN] = sum[GRN] / tally + 0.5; sum[BLU] = sum[BLU] / tally + 0.5; for (dst_y = top_y - bot_y; --dst_y >= 0;) { Dst(dst_x, dst_y)[RED] = sum[RED]; Dst(dst_x, dst_y)[GRN] = sum[GRN]; Dst(dst_x, dst_y)[BLU] = sum[BLU]; } } ++dst_x; goto cexloop; } else if (!x_compress && y_compress) { int src_x, src_y; /* source rect. pixel coords. */ int dst_x, dst_y; /* dest. rect. pixel coords. */ int bot_x, top_x; /* destination rect. bounds */ int bot_y, top_y; /* source rectangle bounds */ assert(dst_width >= src_width); /* (thus no right margin) */ /* Compute coords. of source and destination rectangles. */ dst_y = 0; ecyloop: if (dst_y >= dst_height) goto done; /* that's all folks */ bot_y = dst_y / y_scale + EPSILON; if ((top_y = (dst_y + 1) / y_scale + EPSILON) > src_height) top_y = src_height; if (top_y <= bot_y) { /* End of image. */ /* Clear output scan line buffer. */ for (dst_x = dst_width; --dst_x >= 0;) { Dst(dst_x, 0)[RED] = 0; Dst(dst_x, 0)[GRN] = 0; Dst(dst_x, 0)[BLU] = 0; } /* Clear out top margin. */ for (; dst_y < dst_height; ++dst_y) if (fb_write(dst_fbp, 0, dst_y, (unsigned char *)Dst(0, 0), dst_width ) == -1 ) Stretch_Fatal("Error writing top margin"); goto done; /* that's all folks */ } assert(0 <= bot_y && bot_y < top_y && top_y <= src_height); assert(0 <= dst_y && dst_y <= bot_y); assert(top_y - bot_y <= (int)(1 / y_scale + 1 - EPSILON)); /* Fill input scan line buffer. */ for (src_y = bot_y; src_y < top_y; ++src_y) if (fb_read(src_fbp, 0, src_y, (unsigned char *)Src(0, src_y - bot_y), src_width ) == -1 ) Stretch_Fatal("Error reading scan line"); src_x = (dst_width - 1) / x_scale + EPSILON; ecxloop: if (src_x < 0) { /* End of band; flush buffer. */ if (fb_write(dst_fbp, 0, dst_y, (unsigned char *)Dst(0, 0), dst_width ) == -1 ) Stretch_Fatal("Error writing scan line"); ++dst_y; goto ecyloop; } bot_x = src_x * x_scale + EPSILON; if ((top_x = (src_x + 1) * x_scale + EPSILON) > dst_width) top_x = dst_width; assert(0 <= src_x && src_x <= bot_x && src_x <= src_width); assert(bot_x < top_x && top_x <= dst_width); assert(top_x - bot_x <= (int)(x_scale + 1 - EPSILON)); /* Replicate sample or averaged source pixel(s) to dest. */ if (sample) { for (dst_x = top_x; --dst_x >= bot_x;) { Dst(dst_x, 0)[RED] = Src(src_x, 0)[RED]; Dst(dst_x, 0)[GRN] = Src(src_x, 0)[GRN]; Dst(dst_x, 0)[BLU] = Src(src_x, 0)[BLU]; } } else { int sum[3]; /* pixel value accumulator */ float tally; /* # of pixels accumulated */ /* "Read in" source rectangle and average pixels. */ sum[RED] = sum[GRN] = sum[BLU] = 0; for (src_y = top_y - bot_y; --src_y >= 0;) { sum[RED] += Src(src_x, src_y)[RED]; sum[GRN] += Src(src_x, src_y)[GRN]; sum[BLU] += Src(src_x, src_y)[BLU]; } tally = top_y - bot_y; assert(tally > 0.0); sum[RED] = sum[RED] / tally + 0.5; sum[GRN] = sum[GRN] / tally + 0.5; sum[BLU] = sum[BLU] / tally + 0.5; for (dst_x = top_x; --dst_x >= bot_x;) { Dst(dst_x, 0)[RED] = sum[RED]; Dst(dst_x, 0)[GRN] = sum[GRN]; Dst(dst_x, 0)[BLU] = sum[BLU]; } } --src_x; goto ecxloop; } else if (!x_compress && !y_compress) { int src_x, src_y; /* source pixel coords. */ int dst_x, dst_y; /* dest. rect. pixel coords. */ int bot_x, bot_y; /* dest. rect. lower bounds */ int top_x, top_y; /* dest. rect. upper bounds */ assert(dst_width >= src_width); /* (thus no right margin) */ /* Compute coords. of source and destination rectangles. */ src_y = (dst_height - 1) / y_scale + EPSILON; eeyloop: if (src_y < 0) goto done; /* that's all folks */ bot_y = src_y * y_scale + EPSILON; if ((top_y = (src_y + 1) * y_scale + EPSILON) > dst_height) top_y = dst_height; assert(0 <= src_y && src_y <= bot_y && src_y < src_height); assert(bot_y < top_y && top_y <= dst_height); assert(top_y - bot_y <= (int)(y_scale + 1 - EPSILON)); /* Fill input scan line buffer. */ if (fb_read(src_fbp, 0, src_y, (unsigned char *)Src(0, 0), src_width ) == -1 ) Stretch_Fatal("Error reading scan line"); src_x = (dst_width - 1) / x_scale + EPSILON; eexloop: if (src_x < 0) { /* End of band; flush buffer. */ for (dst_y = top_y; --dst_y >= bot_y;) if (fb_write(dst_fbp, 0, dst_y, (unsigned char *)Dst(0, dst_y - bot_y ), dst_width ) == -1 ) Stretch_Fatal("Error writing scan line"); --src_y; goto eeyloop; } bot_x = src_x * x_scale + EPSILON; if ((top_x = (src_x + 1) * x_scale + EPSILON) > dst_width) top_x = dst_width; assert(0 <= src_x && src_x <= bot_x && src_x <= src_width); assert(bot_x < top_x && top_x <= dst_width); assert(top_x - bot_x <= (int)(x_scale + 1 - EPSILON)); /* Replicate sample source pixel to destination. */ for (dst_y = top_y - bot_y; --dst_y >= 0;) for (dst_x = top_x; --dst_x >= bot_x;) { Dst(dst_x, dst_y)[RED] = Src(src_x, 0)[RED]; Dst(dst_x, dst_y)[GRN] = Src(src_x, 0)[GRN]; Dst(dst_x, dst_y)[BLU] = Src(src_x, 0)[BLU]; } --src_x; goto eexloop; } done: /* Close the frame buffers. */ assert(src_fbp != FB_NULL && dst_fbp != FB_NULL); if (fb_close(src_fbp) == -1) Message("Error closing input frame buffer"); if (dst_fbp != src_fbp && fb_close(dst_fbp) == -1) Message("Error closing output frame buffer"); return 0; }
//============================================================================ //ノベル風に描画 //============================================================================ bool CFontSprite::DrawNovelStyle( ICore *pCore, Peripheral::IInputController *pCtrl ) { if( (pCore->GetSyncCount() % 5) == 0 ) { m_StrCount ++; } //if( pCtrl->GetState( BUTTON_STATE_HOLD, BUTTON_R1 ) ) //{ // if( pCore->GetSyncCount() % 3 == 0 ) // { // m_StrCount += 1; // } //} if( m_pFontSpr != NULL ) { Uint32 Cnt = m_StrCount; const char *pStr = m_vecText.at( m_RefCount ).c_str();//(char *)( m_Str.c_str() ); Math::Rect2DF Dst( m_vPos.x, m_vPos.y, 0, 0 ); /*描画開始*/ m_pFontSpr->Begin(); while( (*pStr != '\0') && (Cnt > 0) ) { /*2Byte文字かどうか*/ Bool Is2Byte = Is2ByteChara( (unsigned char)(*pStr) ); //Math::Point2DF Size = m_pFontSpr->GetStringSize( pStr ); Sint32 FontSize = m_pFontSpr->GetSize();//21;//m_pFontSpr->gt;//フォントサイズ if( !Is2Byte ) { /*改行かどうか*/ if( *pStr == '\n' ) { //Dst.y += toF( Size.y ); //Dst.y += FontSize; //Dst.x = m_vPos.x; pStr += 1; continue; } /*改行*/ else if( *pStr == 'B' ) { Dst.x = m_vInitPos.x; Dst.y += FontSize; pStr += 1; //m_pFontSpr->Begin(); continue; } else if( *pStr == '@') { //IsStop = true; pStr += 1; continue; } /*終了フラグ*/ else if( *pStr == 'E') { m_IsTextEnd = true; return true; } } Dst.x += FontSize; //Dst.x += Size; // Math::Point2DF Size = m_pFontSpr->GetStringSize( Str2.c_str() ); Dst.w = toF( FontSize ); Dst.h = toF( FontSize ); /*一文字描画*/ m_pFontSpr->DrawChara( pStr, Dst, CColor(0, 0, 0 )); Dst.x -= FontSize; if( Is2Byte ) { //Dst.x += Size.y; Dst.x += FontSize; } else { Dst.x += FontSize; } if( Dst.x >= 700 - FontSize * 2 ) { Dst.x = m_vInitPos.x; Dst.y += FontSize; } pStr += Is2Byte ? 2 : 1; Cnt--; } /*描画終了*/ m_pFontSpr->End(); if( Cnt > 0 && !m_IsTextEnd ) { //if( pCtrl->GetState( BUTTON_STATE_PUSH, BUTTON_R2 ) ) //{ // m_StrCount = 1; // m_RefCount++; // //} } if( m_RefCount >= m_vecText.size() -1) { m_RefCount = m_vecText.size() -1; } } return false; }
int CModelListHelper::BuildList(LPCTSTR SectName, char* pGroup, CComboBox* pCB, CTreeCtrl *pTree, CProfINIFile *pPF) { LPCTSTR InitialSelect = pPF?pPF->RdStr(SectName, "$LastInsert", (char*)DefaultLastUnit):"?"; if (!InitialSelect) InitialSelect =""; DWORD LicCat = gs_License.LicCatagories(); Strng Desc; RequestModelInfoRec MInfo; HTREEITEM hSelected=NULL, hFirst=NULL; CString Sect(SectName); Sect+=".Tree"; int nValidModels = 0; int nModels = 0; while (gs_pPrj->RequestModelInfoByGroupIndex(pGroup, nModels, MInfo)) { const bool ModelGroupOK = ((LicCat & TOC_MDL_MASK & MInfo.Category)!=0); const bool SolveModeOK = ((LicCat & TOC_SOLVE_MASK & MInfo.Category)!=0); if (MInfo.IsSelectable && ModelGroupOK && SolveModeOK) { char* pSlctText = MInfo.ShortDesc() ? MInfo.ShortDesc() : MInfo.Class(); if (pCB) pCB->AddString(pSlctText); Desc.Set("%s:%s", pSlctText, (MInfo.Desc() ? MInfo.Desc() : "No Description Available")); m_ModelDescLst.Append(Desc()); m_ModelBaseTagLst.Append(MInfo.TagInitialID()); m_ModelClassLst.Append(MInfo.Class()); m_ModelDrwGroupLst.Append(MInfo.DrwGroup()); if (0) { // temporary code to Restructure FlwSymbols for (int Pass=0; Pass<4; Pass++) { Strng Path; Path.Set("%s%s.*.%s", Pass<2?BaseGrfSymbolFiles():GrfSymbolFiles(), MInfo.TagInitialID(), Pass%2==0?"DXF":"BMP"); WIN32_FIND_DATA fd; HANDLE H = FindFirstFile(Path(), &fd); bool AllDone = (H==INVALID_HANDLE_VALUE); while (!AllDone) { Strng Folder, Src, Dst; Folder.Set("%s%s", BaseGrfSymbolFiles(), MInfo.DrwGroup()); Src.Set("%s%s", BaseGrfSymbolFiles(), fd.cFileName); Dst.Set("%s%s\\%s", BaseGrfSymbolFiles(), MInfo.DrwGroup(), &fd.cFileName[MInfo.TagInitialID.Length()+1]); dbgpln("MOVE %-60s >> %s", Src(), Dst()); Strng E; if (FnCreatePath(Folder(), E)) { Move_FileEx(Src(), Dst(), MOVEFILE_REPLACE_EXISTING|MOVEFILE_WRITE_THROUGH); } AllDone = !FindNextFile(H, &fd); } FindClose(H); } } if (pTree) { HTREEITEM hParent = TVI_ROOT, hItem; char Buff[2048]; char *pS=Buff, *pE; strcpy(Buff, pSlctText); while ((pE=strchr(pS, ':'))!=NULL) { *pE=0; XStrTrim(pS, " "); for (hItem=pTree->GetNextItem(hParent, TVGN_CHILD); hItem!=NULL; hItem=pTree->GetNextItem(hItem, TVGN_NEXT)) { CString S=pTree->GetItemText(hItem); if (S.CompareNoCase(pS)==0) break; } if (hItem==NULL) { XStrTrim(pS, " "); hItem=pTree->InsertItem(pS, 0, 0, hParent); pTree->SortChildren(hParent); pTree->SetItemData(hItem, 0xFFFF); pTree->SetItemImage(hItem, 0, 1); } hParent=hItem; pS=pE+1; } XStrTrim(pS, " "); hItem=pTree->InsertItem(pS, 0, 0, hParent); if (_stricmp(MInfo.Class(), InitialSelect)==0) hSelected=hItem; if (hFirst==NULL) hFirst=hItem; pTree->SetItemData(hItem, nValidModels); pTree->SortChildren(hParent); pTree->SetItemImage(hItem, 2, 3); if (pPF) { // Restore State of Tree HTREEITEM hParent = TVI_ROOT, hItem; CString Txt[10]; long iDepth=0; hItem=pTree->GetNextItem(TVI_ROOT, TVGN_CHILD); while (hItem && iDepth>=0) { UINT State=pTree->GetItemState(hItem, TVIS_EXPANDED ); if (1) { CString S; for (int i=0; i<iDepth; i++) S+=Txt[i]; S+=pTree->GetItemText(hItem); UINT State=(UINT)pPF->RdInt(Sect, S, 0); if (State&TVIS_EXPANDED) { pTree->Expand(hItem, TVE_EXPAND); //?????????? } } HTREEITEM h=pTree->GetNextItem(hItem, TVGN_CHILD); if (h) { Txt[iDepth]=pTree->GetItemText(hItem); Txt[iDepth]+=":"; iDepth++; hItem=h; } else { h=pTree->GetNextItem(hItem, TVGN_NEXT); if (h) { hItem=h; } else { // Go One up & One along hItem=pTree->GetNextItem(hItem, TVGN_PARENT); if (hItem) hItem=pTree->GetNextItem(hItem, TVGN_NEXT); iDepth--; } } } } } nValidModels++; } nModels++; } if (pTree) { if (!hSelected) hSelected=hFirst; pTree->Select(hSelected, TVGN_CARET); //pTree->SelectSetFirstVisible(hSelected); } return nValidModels; }