Beispiel #1
0
        private void updateMenuImage()
        {
            menu = fbgfx.ImageCreate(menuWidth, menuHeight, menuColor);

            int btnScale = 3;

            int buttonSize = menuHeight / shopItems.Length;

            for (int i = 0; i < shopItems.Length; i++)
            {
                if (shopItems[i].item != null && shopItems[i].item.imgPath != "")
                {
                    shopItems[i].button.x      = 0;
                    shopItems[i].button.y      = i * buttonSize;
                    shopItems[i].button.height = buttonSize;
                    shopItems[i].button.width  = buttonSize * btnScale;

                    String imgName = shopItems[i].item.imgPath.Substring(4, shopItems[i].item.imgPath.Length - 8);
                    shopItems[i].button.caption = imgName + " - $" + shopItems[i].item.cost;
                }
            }

            int optBtnSize = shopItems[0].button.width / 2;          //(shopItems.Length-2)*buttonSize

            shopItems[MB_EXIT].button         = new GameButton(0, (shopItems.Length - 2) * buttonSize, optBtnSize, menuHeight - (shopItems.Length - 2) * buttonSize);
            shopItems[MB_EXIT].button.caption = "EXIT";
            shopItems[MB_BUY].button          = new GameButton(optBtnSize, (shopItems.Length - 2) * buttonSize, optBtnSize, menuHeight - (shopItems.Length - 2) * buttonSize);
            shopItems[MB_BUY].button.caption  = "BUY";
        }
Beispiel #2
0
        protected void renderButton()
        {
            // Check if we need to re-size the image
            if (imgRendered != null)
            {
                if (imgRendered->width != width || imgRendered->height != height)
                {
                    // to avoid memory leaks
                    fbgfx.ImageDestroy(imgRendered);
                    imgRendered = fbgfx.ImageCreate(width, height, _style.bgColor);
                    imgFade     = fbgfx.ImageCreate(width, height, _highlightColor);
                    updateImage(imgPath);
                }
            }
            else             // Image doesn't exist, create it
            {
                imgRendered = fbgfx.ImageCreate(width, height, _style.bgColor);
                imgFade     = fbgfx.ImageCreate(width, height, _highlightColor);
                updateImage(imgPath);
            }

            // Fill background color
            fbgfx.Rectangle(imgRendered, 0, 0, width, height, _style.bgColor, true);


            drawImage();
            if (caption != "")
            {
                drawFont();
            }
            drawBorder();
        }
Beispiel #3
0
        private void updateImage(String sBitmap)
        {
            bool isPng;

            // check if we need to delete old image
            if (imgBgn != null)
            {
                isPng = imgPath[imgPath.Length - 1] == 'g' || imgPath[imgPath.Length - 1] == 'G';
                if (isPng)
                {
                    fbgfx.DestroyPNG(imgBgn);
                }
                else
                {
                    fbgfx.ImageDestroy(imgBgn);
                }
            }

            isPng = sBitmap[sBitmap.Length - 1] == 'g' || imgPath[sBitmap.Length - 1] == 'G';

            if (isPng)
            {
                imgBgn = fbgfx.LoadPNG(sBitmap);
            }
            else
            {
                imgBgn = fbgfx.ImageCreate(width, height, fbgfx.RGB(0xFF, 0, 0xFF));
                fbgfx.LoadBitmap(sBitmap, imgBgn);
            }
        }
Beispiel #4
0
        public GameButton(int x_, int y_, int width_, int height_, string text, ButtonStyle bs, Action <GameButton> btnClicked)
        {
            this.x        = x_; this.y = y_;
            _width        = width_;
            _height       = height_;
            _caption      = text;
            _style        = bs;
            clickedAction = btnClicked;

            _highlightColor = 0xA07F7F7F;     //default
            _highlightAlpha = 128;            //default

            imgBgn = fbgfx.ImageCreate(_width, _height, fbgfx.RGB(0xFF, 0, 0xFF));

            renderButton();
        }