• <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>

            麒麟子

            ~~

            導航

            <2025年6月>
            25262728293031
            1234567
            891011121314
            15161718192021
            22232425262728
            293012345

            統計

            常用鏈接

            留言簿(12)

            隨筆分類

            隨筆檔案

            Friends

            WebSites

            積分與排名

            最新隨筆

            最新評論

            閱讀排行榜

            評論排行榜

            FlasCC例子研究之bitmapdata

            bitmapdata是FlasCC官方例子02_Interop中的例子。這例子比起c++interop來說,多了一個鼠標事件監聽。

            我們逐行分析一下吧。

            #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;

            這個函數主要是根據一個給出的offset值,返回一個計算后的值

            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;
            }

             

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

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

             

            //監聽鼠標點擊事件,然后混淆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()
            {
                //取得舞臺
                flash::display::Stage stage = internal::get_Stage();

                //創建一個Shape
                flash::display::Shape myShape = flash::display::Shape::_new();
                flash::display::Graphics graphics = myShape->graphics;

                //繪制簡單的圖形 這是一個像把子一樣的圓

                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();

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

                myBitmapData->draw(myShape);

                // 創建一個Bitmap

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

                // 加到一個Sprite中,以便顯示

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

                mySprite->addChild(myBitmap);
                // 增加一個鼠標監聽器
                mySprite->addEventListener("mouseDown", Function::_new(&mouseDownHandler, NULL));
                // 添加到舞臺
                stage->addChild(mySprite);

                // 這個函數將會使C++與AS3進行同步,以使可以處理鼠標事件。
                AS3_GoAsync();

                // 因為運行機制的原因,這行代碼是無法到達的。
                return 0;
            }

            還是上個圖吧。

            image

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

            久久国产高清一区二区三区| 欧美精品国产综合久久| AV狠狠色丁香婷婷综合久久| 国产精品久久久久9999高清| 国产成人精品久久| 久久久久亚洲精品日久生情 | 国产成人久久AV免费| 91精品国产91久久久久久青草 | 久久国产精品一国产精品金尊| 91精品国产91久久久久福利| 久久精品人妻一区二区三区| 色8久久人人97超碰香蕉987| 免费国产99久久久香蕉| 亚洲色欲久久久综合网 | 97精品伊人久久久大香线蕉| 久久美女网站免费| 欧美噜噜久久久XXX| 欧美亚洲日本久久精品| 久久免费精品一区二区| 偷偷做久久久久网站| 久久久黄片| 国产福利电影一区二区三区久久老子无码午夜伦不 | 久久久老熟女一区二区三区| 伊人久久大香线蕉成人| 99久久伊人精品综合观看| 久久亚洲私人国产精品| 奇米影视7777久久精品人人爽| 国产午夜精品久久久久九九电影 | 国产91久久精品一区二区| 久久成人国产精品免费软件| 色欲综合久久躁天天躁| 久久久久久国产精品无码下载| 色综合久久久久| 国产精品无码久久综合网| 99久久精品免费看国产| 国产成人综合久久精品尤物| 久久91这里精品国产2020| 久久av免费天堂小草播放| 美女久久久久久| 久久亚洲精品无码VA大香大香| 狠狠色综合网站久久久久久久高清|