Ejemplo n.º 1
0
    void Text::insertRow(const std::string& row, unsigned int position)
    {
        unsigned int totalRows = mRows.size();
        
        if(position >= totalRows)
        {
            if(position == totalRows)
            {
                addRow(row);
                return;
            }
            else
            {
                throw FCN_EXCEPTION("Position out of bounds!");
            }
        }
        
        unsigned int i;
        for(i = 0; i < row.size(); i++)
        {
            if(row[i] == '\n')
                throw FCN_EXCEPTION("Line feed not allowed in the row to be inserted!");
        }

        mRows.insert(mRows.begin() + position, row);
    }
Ejemplo n.º 2
0
        void AllegroGlyphKeeperFont::load(const std::string& filename, int w, int h)
        {
            mKeeper = gk_create_keeper(0,0);

            if (mKeeper == NULL)
            {
                throw FCN_EXCEPTION("Can't create keeper.");
            }

            mFace = gk_load_face_from_file(filename.c_str(), 0);

            if (mFace == NULL)
            {
                throw FCN_EXCEPTION("Can't load font from file.");
            }

            mRend = gk_create_renderer(mFace,mKeeper);
        
            if (mRend == NULL)
            {
                throw FCN_EXCEPTION("Can't create renderer.");
            }

            gk_rend_set_hinting_off(mRend);
            gk_rend_set_size_pixels(mRend, w, h);
            gk_rend_set_text_color_rgb(mRend, 0, 0, 0);
        }
Ejemplo n.º 3
0
    void DirectX3DGraphics::drawImage(const Image* image,
                                      int srcX,
                                      int srcY,
                                      int dstX,
                                      int dstY,
                                      int width,
                                      int height)
    {
		const DirectX3DImage* srcImage = dynamic_cast<const DirectX3DImage*>(image);

        if (srcImage == NULL)
        {
            throw FCN_EXCEPTION("Trying to draw an image of unknown format, must be a DirectXImage.");
        }

        if (mClipStack.empty())
        {
            throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?");
        }

        const ClipRectangle& top = mClipStack.top();
        
       
        dstX += top.xOffset;
        dstY += top.yOffset;

         
        // Find DirectX texture coordinates
        float texX1 = srcX / (float)srcImage->getTextureWidth();
        float texY1 = srcY / (float)srcImage->getTextureHeight();
        float texX2 = (srcX+width) / (float)srcImage->getTextureWidth();
        float texY2 = (srcY+height) / (float)srcImage->getTextureHeight();
          
  
        // Check if blending already is enabled
        if (!mAlpha)
        {
            mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, TRUE);
        }

        DWORD color = 0xFFFFFFFF;
     
        VertexWithTexture vertices[]=
        {
            {(float)dstX, (float)dstY + height, 0.0f, 1.0f, color, texX1, texY2},
            {(float)dstX, (float)dstY, 0.0f, 1.0f, color, texX1, texY1},
            {(float)dstX + width, (float)dstY + height, 0.0f, 1.0f, color, texX2, texY2},
            {(float)dstX + width, (float)dstY, 0.0f, 1.0f, color, texX2, texY1},
        };

        mDevice->SetFVF(D3DFVF_XYZRHW|D3DFVF_DIFFUSE|D3DFVF_TEX1);
        mDevice->SetTexture(0, srcImage->getTexture());
        mDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, vertices, sizeof(VertexWithTexture));
        mDevice->SetTexture(0, 0);

        if (!mAlpha)
        {
            mDevice->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE); 
        }
    }
Ejemplo n.º 4
0
    void OpenGLImage::convertToDisplayFormat()
    {
        if (mPixels == NULL)
        {
            throw FCN_EXCEPTION("Image has already been converted to display format");
        }

        glGenTextures(1, &mTextureHandle);
        glBindTexture(GL_TEXTURE_2D, mTextureHandle);

        glTexImage2D(GL_TEXTURE_2D,
                     0,
                     4,
                     mTextureWidth,
                     mTextureHeight,
                     0,
                     GL_RGBA,
                     GL_UNSIGNED_BYTE,
                     mPixels);

        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
        glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

        delete[] mPixels;
        mPixels = NULL;

        GLenum error = glGetError();
        if (error)
        {
            std::string errmsg;
            switch (error)
            {
              case GL_INVALID_ENUM:
                  errmsg = "GL_INVALID_ENUM";
                  break;

              case GL_INVALID_VALUE:
                  errmsg = "GL_INVALID_VALUE";
                  break;

              case GL_INVALID_OPERATION:
                  errmsg = "GL_INVALID_OPERATION";
                  break;

              case GL_STACK_OVERFLOW:
                  errmsg = "GL_STACK_OVERFLOW";
                  break;

              case GL_STACK_UNDERFLOW:
                  errmsg = "GL_STACK_UNDERFLOW";
                  break;

              case GL_OUT_OF_MEMORY:
                  errmsg = "GL_OUT_OF_MEMORY";
                  break;
            }

            throw FCN_EXCEPTION(std::string("Unable to convert to OpenGL display format, glGetError said: ") + errmsg);
        }
    }
Ejemplo n.º 5
0
    void IrrlichtGraphics::drawImage(const Image* image,
                                int srcX,
                                int srcY,
                                int dstX,
                                int dstY,
                                int width,
                                int height)
    {
        if (mClipStack.empty())
        {
            throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?");
        }

        const ClipRectangle& top = mClipStack.top();

        const IrrlichtImage* srcImage = dynamic_cast<const IrrlichtImage*>(image);

        if (srcImage == NULL)
        {
            throw FCN_EXCEPTION("Trying to draw an image of unknown format, must be an IrrlichtImage.");
        }

        irr::core::position2d<irr::s32> destPos(dstX + top.xOffset, dstY + top.yOffset);
        irr::core::rect<irr::s32> sourceRect(srcX, srcY, srcX + width, srcY + height);
        irr::core::rect<irr::s32> clipRect(top.x, top.y, top.x + top.width, top.y + top.height);
        irr::video::SColor color(255, 255, 255, 255);

        mDriver->draw2DImage(srcImage->getTexture(), destPos, sourceRect, &clipRect, color, true);
    }
Ejemplo n.º 6
0
	Image* SDLImageLoader::load(const std::string& filename,
								bool convertToDisplayFormat)
	{
		SDL_Surface *loadedSurface = loadSDLSurface(filename);

		if (loadedSurface == NULL)
		{
			throw FCN_EXCEPTION(
					std::string("Unable to load image file: ") + filename);
		}

		SDL_Surface *surface = convertToStandardFormat(loadedSurface);
		SDL_FreeSurface(loadedSurface);

		if (surface == NULL)
		{
			throw FCN_EXCEPTION(
					std::string("Not enough memory to load: ") + filename);
		}

		Image *image = new SDLImage(surface, true);

		if (convertToDisplayFormat)
		{
			image->convertToDisplayFormat();
		}

		return image;
	}
Ejemplo n.º 7
0
    Color OpenGLImage::getPixel(int x, int y)
    {
        if (mPixels == NULL)
        {
            throw FCN_EXCEPTION("Image has been converted to display format");
        }

        if (x < 0 || x >= mWidth || y < 0 || y >= mHeight)
        {
            throw FCN_EXCEPTION("Coordinates outside of the image");
        }

        unsigned int c = mPixels[x + y * mTextureWidth];

#ifdef __BIG_ENDIAN__
        unsigned char r = (unsigned char) ((c >> 24) & 0xff);
        unsigned char g = (unsigned char) ((c >> 16) & 0xff);
        unsigned char b = (unsigned char) ((c >> 8) & 0xff);
        unsigned char a = (unsigned char) (c & 0xff);
#else
        unsigned char a = (unsigned char) ((c >> 24) & 0xff);
        unsigned char b = (unsigned char) ((c >> 16) & 0xff);
        unsigned char g = (unsigned char) ((c >> 8) & 0xff);
        unsigned char r = (unsigned char) (c & 0xff);
#endif

        return Color(r, g, b, a);
    }
Ejemplo n.º 8
0
    Rectangle ImageFont::scanForGlyph(unsigned char glyph,
                                      int x,
                                      int y,
                                      const Color& separator)
    {
        Color color;
        do
        {
            ++x;

            if (x >= mImage->getWidth())
            {
                y += mHeight + 1;
                x = 0;

                if (y >= mImage->getHeight())
                {
                    std::string str;
                    std::ostringstream os(str);
                    os << "Image ";
                    os << mFilename;
                    os << " with font is corrupt near character '";
                    os << glyph;
                    os << "'";
                    throw FCN_EXCEPTION(os.str());
                }
            }

            color = mImage->getPixel(x, y);

        } while (color == separator);

        int width = 0;

        do
        {
            ++width;

            if (x + width >= mImage->getWidth())
            {
                std::string str;
                std::ostringstream os(str);
                os << "Image ";
                os << mFilename;
                os << " with font is corrupt near character '";
                os << glyph;
                os << "'";
                throw FCN_EXCEPTION(os.str());
            }

            color = mImage->getPixel(x + width, y);

        } while (color != separator);

        return Rectangle(x, y, width, mHeight);
    }
Ejemplo n.º 9
0
    /**
     * Initialises the Allegro application. This function creates the global
     * Gui object that can be populated by various examples.
     */
    void init()
    {
        // We simply initialise Allegro as we would do with any Allegro application.
        allegro_init();

        int bpp = desktop_color_depth();
        if (bpp == 0)
        {
            bpp = 16;
        }

        set_color_depth(bpp);

        if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0))
        {
            if (set_gfx_mode(GFX_AUTODETECT, 640, 480, 0, 0))
            {
                throw FCN_EXCEPTION("Unable to set graphics mode");
            }
        }

        screenBuffer = create_bitmap(SCREEN_W, SCREEN_H);

        if (screenBuffer == NULL)
        {
            throw FCN_EXCEPTION("Unable to create a screen buffer");
        }

        install_keyboard();
        install_mouse();
        install_timer();

        // Now it's time to initialise the Guichan Allegro back end.

        imageLoader = new fcn::AllegroImageLoader();
        // The ImageLoader Guichan should use needs to be passed to the Image object
        // using a static function.
        fcn::Image::setImageLoader(imageLoader);
        graphics = new fcn::AllegroGraphics();
        // Set the target for the graphics object to be the doublebuffer
        // for the screen. Drawing to the screen directly is not a good
        // idea, as it will produce flicker, unless you use page flipping.
        graphics->setTarget(screenBuffer);
        input = new fcn::AllegroInput();

        // Now we create the Gui object to be used with this Allegro application.
        globals::gui = new fcn::Gui();
        // The Gui object needs a Graphics to be able to draw itself and an Input
        // object to be able to check for user input. In this case we provide the
        // Gui object with Allegro implementations of these objects hence making Guichan
        // able to utilise Allegro.
        globals::gui->setGraphics(graphics);
        globals::gui->setInput(input);
    }
Ejemplo n.º 10
0
    ImageFont::ImageFont(Image* image,
                         const std::string& glyphs)
    {
        mFilename = "Image*";
        if (image == NULL)
        {
                FCN_EXCEPTION("Font image is NULL");
        }
        mImage = image;

        Color separator = mImage->getPixel(0, 0);

        int i = 0;
        for (i = 0;
             i < mImage->getWidth() && separator == mImage->getPixel(i, 0);
             ++i)
        {
        }

        if (i >= mImage->getWidth())
        {
            throw FCN_EXCEPTION("Corrupt image.");
        }

        int j = 0;
        for (j = 0; j < mImage->getHeight(); ++j)
        {
            if (separator == mImage->getPixel(i, j))
            {
                break;
            }
        }

        mHeight = j;
        int x = 0, y = 0;
        unsigned char k;

        for (i = 0; i < (int)glyphs.size(); ++i)
        {
            k = glyphs.at(i);
            mGlyph[k] = scanForGlyph(k, x, y, separator);
            // Update x och y with new coordinates.
            x = mGlyph[k].x + mGlyph[k].width;
            y =  mGlyph[k].y;
        }

        mImage->convertToDisplayFormat();

        mRowSpacing = 0;
        mGlyphSpacing = 0;
    }
Ejemplo n.º 11
0
    void DirectX3DGraphics::fillRectangle(const Rectangle& rectangle)
    {
        if (mClipStack.empty())
        {
            throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?");
        }

        const ClipRectangle& top = mClipStack.top();
       
        DWORD color = D3DCOLOR_RGBA(mColor.r, mColor.g, mColor.b, mColor.a);
        Vertex vertices[]=
        {
           {(float)rectangle.x + top.xOffset, 
            (float)rectangle.y + rectangle.height + top.yOffset, 0.0f, 1.0f, color},
           {(float)rectangle.x + top.xOffset, 
            (float)rectangle.y + top.yOffset, 0.0f, 1.0f, color},
           {(float)rectangle.x + rectangle.width + top.xOffset, 
            (float)rectangle.y + rectangle.height + top.yOffset, 0.0f, 1.0f, color},
           {(float)rectangle.x + rectangle.width + top.xOffset, 
            (float)rectangle.y + top.yOffset, 0.0f, 1.0f, color}
        };

        mDevice->SetFVF(D3DFVF_XYZRHW|D3DFVF_DIFFUSE);
        mDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2, vertices, sizeof(Vertex));
    }
Ejemplo n.º 12
0
        void OGLFTFont::drawString(fcn::Graphics* graphics, const std::string& text, int x, int y)
        {
            if (text == "")
            {
                return;
            }

            fcn::OpenGLGraphics* glGraphics = dynamic_cast<fcn::OpenGLGraphics *>(graphics);

            if(glGraphics == NULL)
            {
                throw FCN_EXCEPTION("Graphics object not an OpenGL graphics object!");
            }

            const fcn::ClipRectangle& top = glGraphics->getCurrentClipArea();

            mFont->setForegroundColor(mFontColor.r/255, mFontColor.g/255, mFontColor.b/255);

            glPushMatrix();
            glEnable(GL_TEXTURE_2D);
            glEnable(GL_BLEND);
            glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

            glTranslated(x + top.xOffset, y + top.yOffset + (mSize/2)+5, 0.);
            glRotatef(180., 1., 0., 0.);

            mFont->draw(text.c_str());

            glDisable(GL_BLEND);
            glDisable(GL_TEXTURE_2D);
            glPopMatrix();
        }
Ejemplo n.º 13
0
    void HGEGraphics::drawImage(const Image *image, 
                                int srcX, 
                                int srcY, 
                                int dstX, 
                                int dstY, 
                                int width, 
                                int height)
    {
        if (mClipNull)
        {
            return;
        }

        const HGEImage *hgeImage = static_cast<const HGEImage*>(image);

        if (hgeImage == NULL)
        {
            throw FCN_EXCEPTION("Trying to draw an image of unknown format, must be an HGEImage.");
        }

        ClipRectangle const top = mClipStack.top();

        dstX += top.xOffset;
        dstY += top.yOffset;

        hgeImage->getSprite()->SetTextureRect(srcX, srcY, width, height);
        hgeImage->getSprite()->Render(dstX, dstY);
    }
Ejemplo n.º 14
0
    void HGEImage::convertToDisplayFormat()
    {
        DWORD *pLockPtr = mHGE->Texture_Lock(mTexture);

        if (pLockPtr == NULL)
        {
            throw FCN_EXCEPTION("Locking of the texture failed. HGE only support locking of 32bit textures.");
        }

        int i;
        int end = mHGE->Texture_GetWidth(mTexture, true) *
            mHGE->Texture_GetHeight(mTexture, true);

        for (i = 0; i < end; i++)
        {
            DWORD color = pLockPtr[i];
            if (GETR(color) == 0xFF
                && GETG(color) == 0x00
                && GETB(color) == 0xFF)
            {
                pLockPtr[i] = ARGB(0x00, 0x00, 0x00, 0x00);
            }
        }

        mHGE->Texture_Unlock(mTexture);

        mHGESprite = new hgeSprite(mTexture,  
                                   0, 
                                   0, 
                                   mHGE->Texture_GetWidth(mTexture, true),
                                   mHGE->Texture_GetHeight(mTexture, true));
    }
Ejemplo n.º 15
0
    std::string& Text::getRow(unsigned int row)
    {
        if (row >= mRows.size())
            throw FCN_EXCEPTION("Row out of bounds!");

        return mRows[row];
    }
Ejemplo n.º 16
0
 void Text::eraseRow(unsigned int row)
 {
     if(row >= mRows.size())
         throw FCN_EXCEPTION("Row to be erased out of bounds!");
     
     mRows.erase(mRows.begin() + row);
 }
Ejemplo n.º 17
0
    void Text::setRow(unsigned int row, const std::string& content)
    {
        if (row >= mRows.size())
            throw FCN_EXCEPTION("Row out of bounds!");

        mRows[row] = content;
    }
Ejemplo n.º 18
0
 Spacer::Spacer(SizeConstraint* sizeConstraint)
 {
     if(sizeConstraint == NULL)
         throw FCN_EXCEPTION("Spacer cannot have a NULL size constraint!");
     
     setSizeConstraint(sizeConstraint);
 }
Ejemplo n.º 19
0
    void IrrlichtGraphics::drawLine(int x1, int y1, int x2, int y2)
    {
        if (mClipStack.empty())
        {
            throw FCN_EXCEPTION("Clip stack is empty, perhaps you called a draw funtion outside of _beginDraw() and _endDraw()?");
        }

        const ClipRectangle& top = mClipStack.top();

        x1 += top.xOffset;
        y1 += top.yOffset;
        x2 += top.xOffset;
        y2 += top.yOffset;

        if(x2 > top.x + top.width)
            x2 = top.x + top.width;

        if(y2 > top.y + top.height)
            y2 = top.y + top.height;

        irr::core::position2d<irr::s32> start(x1, y1);
        irr::core::position2d<irr::s32> end(x2, y2);
        irr::video::SColor color(mColor.a, mColor.r, mColor.g, mColor.b);

        mDriver->draw2DLine(start, end, color);
    }
Ejemplo n.º 20
0
    void OpenLayerImage::convertToDisplayFormat()
    {
        if (mAllegroBitmap == NULL)
        {
            throw FCN_EXCEPTION("Trying to convert a non loaded image to display format.");
        }

        if (mOpenLayerBitmap != NULL)
        {
            throw FCN_EXCEPTION("Trying to convert an image to display format which has already been converted.");
        }

        mOpenLayerBitmap = new ol::Bitmap(mAllegroBitmap, false, true);
        mOpenLayerBitmap->SendToGPU();
        
        destroy_bitmap(mAllegroBitmap);
        mAllegroBitmap = NULL;
    }
Ejemplo n.º 21
0
    void TabbedArea::removeTabWithIndex(unsigned int index)
    {
        if (index >= mTabs.size())
        {
            throw FCN_EXCEPTION("No such tab index.");
        }

        removeTab(mTabs[index].first);
    }
Ejemplo n.º 22
0
    const ClipRectangle& Graphics::getCurrentClipArea()
    {
        if (mClipStack.empty())
        {
            throw FCN_EXCEPTION("The clip area stack is empty.");
        }

        return mClipStack.top();
    }
Ejemplo n.º 23
0
    bool TabbedArea::isTabSelected(unsigned int index) const
    {
        if (index >= mTabs.size())
        {
            throw FCN_EXCEPTION("No such tab index.");
        }

        return mSelectedTab == mTabs[index].first;
    }
Ejemplo n.º 24
0
    void TabbedArea::setSelectedTab(unsigned int index)
    {
        if (index >= mTabs.size())
        {
            throw FCN_EXCEPTION("No such tab index.");
        }

        setSelectedTab(mTabs[index].first);
    }
Ejemplo n.º 25
0
    int SDLImage::getHeight() const
    {
        if (mSurface == NULL)
        {
            throw FCN_EXCEPTION("Trying to get the height of a non loaded image.");
        }

        return mSurface->h;
    }
Ejemplo n.º 26
0
    int SDLImage::getWidth() const
    {
        if (mSurface == NULL)
        {
            throw FCN_EXCEPTION("Trying to get the width of a non loaded image.");
        }

        return mSurface->w;
    }
Ejemplo n.º 27
0
    void SDLImage::putPixel(int x, int y, const Color& color)
    {
        if (mSurface == NULL)
        {
            throw FCN_EXCEPTION("Trying to put a pixel in a non loaded image.");
        }

        SDLputPixel(mSurface, x, y, color);
    }
Ejemplo n.º 28
0
    Color SDLImage::getPixel(int x, int y)
    {
        if (mSurface == NULL)
        {
            throw FCN_EXCEPTION("Trying to get a pixel from a non loaded image.");
        }

        return SDLgetPixel(mSurface, x, y);
    }
Ejemplo n.º 29
0
    void FocusHandler::requestModalMouseInputFocus(Widget* widget)
    {
        if (mModalMouseInputFocusedWidget != NULL
            && mModalMouseInputFocusedWidget != widget)
        {
            throw FCN_EXCEPTION("Another widget already has modal input focus.");
        }

        mModalMouseInputFocusedWidget = widget;
    }
Ejemplo n.º 30
0
    void Graphics::popClipArea()
    {

        if (mClipStack.empty())
        {
            throw FCN_EXCEPTION("Tried to pop clip area from empty stack.");
        }

        mClipStack.pop();
    }