• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            麒麟子

            ~~

            導(dǎo)航

            <2009年4月>
            2930311234
            567891011
            12131415161718
            19202122232425
            262728293012
            3456789

            統(tǒng)計(jì)

            常用鏈接

            留言簿(12)

            隨筆分類

            隨筆檔案

            Friends

            WebSites

            積分與排名

            最新隨筆

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            FlasCC例子研究之bitmapdata

            bitmapdata是FlasCC官方例子02_Interop中的例子。這例子比起c++interop來說,多了一個(gè)鼠標(biāo)事件監(jiān)聽。

            我們逐行分析一下吧。

            #include <AS3/AS3.h>
            #include <Flash++.h>

            using namespace AS3::ui;

            static const int COORDBITS = 7; // 7 bits => dim of 128
            static const int DIM = 1 << COORDBITS;

            這個(gè)函數(shù)主要是根據(jù)一個(gè)給出的offset值,返回一個(gè)計(jì)算后的值

            static int swizzleOffset(int offs)
            {
              int result = 0;
              int coordBits = COORDBITS;
              int offsHi = offs >> COORDBITS; // take the higher order bits
              int coordBits2 = COORDBITS * 2;
              while(coordBits--)
              {
                // put the lowest bit in the "lo" offset bits
                // into the highest bit of the result...
                // it'll get shifted into a lower position
                // as the loop executes
                result |= ((offs & 1) << coordBits2);
                offs >>= 1;
                result >>= 1;
                // same for the "hi" offset bits
                result |= ((offsHi & 1) << coordBits2);
                offsHi >>= 1;
                result >>= 1;
              }
              return result;
            }

             

            // 將一個(gè)圖像的像素進(jìn)行混淆
            static void swizzlePixels(unsigned *dst, unsigned *src)
            {
                int offs = DIM * DIM;

                while(offs--)
                {
                    int swiz = swizzleOffset(offs);
                    dst[swiz] = src[offs];
                }
            }

             

            //監(jiān)聽鼠標(biāo)點(diǎn)擊事件,然后混淆BitmapData的像素值
            static var mouseDownHandler(void *arg, var args)
            {
                flash::events::MouseEvent event = flash::events::MouseEvent(args[0]);
                flash::display::Sprite sprite = flash::display::Sprite(event->target); // the container Sprite
                flash::display::Bitmap bitmap = flash::display::Bitmap(sprite->getChildAt(0)); // Bitmap is the only child
                flash::display::BitmapData bitmapData = bitmap->bitmapData;
                // ByteArray corresponding to our ram!
                // C ptrs are equivalent to offsets into this ByteArray
                flash::utils::ByteArray ram = internal::get_ram();

                // allocate space for the pixels
                unsigned *src = new unsigned[DIM * DIM];
                unsigned *dst = new unsigned[DIM * DIM];
                // copy current pixels directly to ram
                bitmapData->copyPixelsToByteArray(bitmapData->rect, ram, src);
                // swizzle them!
                swizzlePixels(dst, src);
                // write new pixels directly from ram
                bitmapData->setPixels(bitmapData->rect, ram, dst);
                // clean up
                delete dst;
                delete src;
                return internal::_undefined;
            }

             

            int main()
            {
                //取得舞臺(tái)
                flash::display::Stage stage = internal::get_Stage();

                //創(chuàng)建一個(gè)Shape
                flash::display::Shape myShape = flash::display::Shape::_new();
                flash::display::Graphics graphics = myShape->graphics;

                //繪制簡(jiǎn)單的圖形 這是一個(gè)像把子一樣的圓

                graphics->beginFill(0xff00ff, 0.5);
                graphics->drawCircle(64.0, 64.0, 64.0);
                graphics->endFill();
                graphics->beginFill(0xffff00, 0.5);
                graphics->drawCircle(64.0, 64.0, 40.0);
                graphics->endFill();
                graphics->beginFill(0x00ffff, 0.5);
                graphics->drawCircle(64.0, 64.0, 16.0);
                graphics->endFill();

                //創(chuàng)建一個(gè)BitmapData
                flash::display::BitmapData myBitmapData = flash::display::BitmapData::_new(DIM, DIM);
                //把圖形繪制到這個(gè)bitmapdata上

                myBitmapData->draw(myShape);

                // 創(chuàng)建一個(gè)Bitmap

                flash::display::Bitmap myBitmap = flash::display::Bitmap::_new(myBitmapData);

                // 加到一個(gè)Sprite中,以便顯示

                flash::display::Sprite mySprite = flash::display::Sprite::_new();

                mySprite->addChild(myBitmap);
                // 增加一個(gè)鼠標(biāo)監(jiān)聽器
                mySprite->addEventListener("mouseDown", Function::_new(&mouseDownHandler, NULL));
                // 添加到舞臺(tái)
                stage->addChild(mySprite);

                // 這個(gè)函數(shù)將會(huì)使C++與AS3進(jìn)行同步,以使可以處理鼠標(biāo)事件。
                AS3_GoAsync();

                // 因?yàn)檫\(yùn)行機(jī)制的原因,這行代碼是無法到達(dá)的。
                return 0;
            }

            還是上個(gè)圖吧。

            image

            posted on 2013-05-15 23:48 麒麟子 閱讀(846) 評(píng)論(0)  編輯 收藏 引用


            只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            久久91精品国产91久久小草| 久久成人18免费网站| 亚洲欧美日韩久久精品第一区| 久久99久久99精品免视看动漫| 精品人妻久久久久久888| 伊人久久综合热线大杳蕉下载| 久久久黄片| 久久夜色精品国产亚洲| 久久只有这精品99| 99久久亚洲综合精品网站| 国产精品99久久久精品无码| 99久久免费国产精品热| 一本一本久久a久久精品综合麻豆| 久久香蕉超碰97国产精品| 久久精品国产精品亚洲艾草网美妙| 亚洲国产精品高清久久久| 精品视频久久久久| 婷婷综合久久狠狠色99h| 狠狠综合久久AV一区二区三区| 狠狠久久综合| 亚洲午夜久久久精品影院| 久久综合给合久久狠狠狠97色69| 久久av高潮av无码av喷吹| 久久久青草青青亚洲国产免观| 无码人妻久久久一区二区三区| 四虎影视久久久免费| 久久综合狠狠综合久久激情 | 91精品国产综合久久婷婷| 久久精品国产亚洲AV无码娇色| 人妻少妇久久中文字幕一区二区| 亚洲国产天堂久久综合| 久久这里只有精品视频99| 日本精品久久久久久久久免费| 久久综合综合久久97色| 久久精品一区二区国产| 精品国产一区二区三区久久| 久久国产精品无码一区二区三区| 久久大香香蕉国产| 99久久99久久精品国产| 久久精品国产一区二区三区不卡 | A级毛片无码久久精品免费|