Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // C++ Implementation: j_window
- //
- // Description:
- //
- //
- // Author: Charles Grunwald (Juntalis) <cgrunwald@gmail.com>, (C) 2009
- //
- // Copyright: See COPYING file that comes with this distribution
- //
- //
- #include "j_window.h"
- #include "j_parentcontainer.h"
- #include <guichan/graphics.hpp>
- #include <guichan/image.hpp>
- #include <cmath>
- #include <guichan/font.hpp>
- using namespace std;
- /*
- // Callback for the Minimize (shade) Button.
- void minCall(gcn::ActionEvent actionEvent, void * inf)
- {
- // First things first; we want to get all info associated with the callback.
- // We are able to get the ParentContainer and the jWindow used.
- // We don't really need the parent container, but if we wanted it, we would do :
- // ParentContainer * pSource = ((ParentContainer *)(((gcn::ImageButton * )(actionEvent.getSource()))->getParent()));
- jWindow * pWindow = (jWindow *)inf;
- // As usual, simple debugging.
- #ifdef DEBUG
- std::cout << " " << pWindow->getId() << "-> " << actionEvent.getSource()->getId() << " pressed.\n";
- #endif
- // Check if window is minimized.
- if (!pWindow->isMinimized())
- {
- // If the window is not minimized, we must store the current height for later use.
- pWindow->setDHeight (pWindow->getHeight());
- // We will then shrink the widget into its titlebar.
- pWindow->setHeight (pWindow->getTitleBarHeight());
- //Finally, we let the window know it is now minimized.
- pWindow->setMinimized(true);
- }
- else
- {
- // Simply set the window back to its default state.
- pWindow->setHeight (pWindow->getDHeight());
- // Let the window know that it is no longer minimized.
- pWindow->setMinimized(false);
- }
- #ifdef DEBUG
- std::cout << " " << pWindow->getId() << "->setMinimized(" << pWindow->isMinimized() << ")\n";
- #endif
- }
- // Callback for the X (Close) Button
- void xCall(gcn::ActionEvent actionEvent, void * inf)
- {
- // First things first; we want to get all info associated with the callback.
- // We are able to get the ParentContainer and the jWindow used.
- ParentContainer * pSource = ((ParentContainer *)(((gcn::Button * )(actionEvent.getSource()))->getParent()));
- jWindow * pWindow = (jWindow *)inf;
- #ifdef DEBUG
- std::cout << " " << pWindow->getId() << "-> " << actionEvent.getSource()->getId() << " pressed.\n";
- #endif
- // We have to remove the control box.
- pSource->remove(pWindow->getBMin());
- pSource->remove(pWindow->getBX());
- // And now we call the deconstructor for the class.
- delete pWindow;
- }
- */
- void jWindow::Setup(std::string Id, CONTROLBOX cb)
- {
- // We start off by setting the Id.
- jWindow::setId(Id);
- #ifdef DEBUG
- std::cout << " " << getId() << "-> Constructor called.\n";
- #endif
- /* * * Control box shit * * */
- //Next, we're going to set the control box up.
- jWindow::setControlBox(cb);
- setMinimized(false);
- /* * * /Control box shit * * */
- // I also need to make sure that the window knows that it's not minimized.
- /* Set Defaults */
- jWindow::bFormImage = false;
- jWindow::bTitleImage = false;
- jWindow::setAlignment(gcn::Graphics::LEFT);
- jWindow::setWindowAlpha(255);
- jWindow::setAlwaysOnTop(false);
- jWindow::setSnapToEdges(false);
- jWindow::setTitleBarHeight(20);
- jWindow::setTitleBarAppearance(RAISED);
- jWindow::setFormAppearance(RAISED);
- jWindow::setTitlebarColor(gcn::Color(175,175,175));
- jWindow::setFormBackground(gcn::Color(125,125,125));
- jWindow::setTitleBarTextColor(gcn::Color(0,0,0));
- jWindow::setFormBorder(gcn::Color(200,200,200,255));
- jWindow::setSize(300,300);
- xMouseDown = false;
- minMouseDown = false;
- bResizable = false;
- /* /Defaults */
- }
- // Deconstructor
- jWindow::~jWindow()
- {
- #ifdef DEBUG
- std::cout << " " << getId() << "-> Deconstructor called.\n";
- #endif
- ((ParentContainer*)getParent())->remove(this);
- }
- /***********************
- ******* WRAPPERS *******
- ***********************/
- void jWindow::add(gcn::Widget *widget)
- {
- gcn::Window::add(widget);
- #ifdef DEBUG
- if (strlen(widget->getId().c_str()))
- std::cout << " " << getId() << "-> " << widget->getId() << " added.\n";
- else
- std::cout << " " << getId() << "-> Widget added.\n";
- #endif
- }
- void jWindow::add(gcn::Widget *widget, int x, int y)
- {
- gcn::Window::add(widget,x,y);
- #ifdef DEBUG
- if (strlen(widget->getId().c_str()))
- std::cout << " " << getId() << "-> " << widget->getId() << " added.\n";
- else
- std::cout << " mImages[1]" << getId() << "-> Widget added.\n";
- #endif
- }
- void jWindow::draw(gcn::Graphics *graphics)
- {
- jWindow::drawForm(graphics);
- jWindow::drawTitleBar(graphics);
- }
- void jWindow::logic()
- {
- // I want to make sure it stays inside the window.
- if (getY() < 0) setY(0);
- if (getY() + getHeight() > getParent()->getHeight()) setY(getParent()->getHeight() - getHeight());
- if (getX() < 0) setX(0);
- if (getX() + getWidth() > getParent()->getWidth()) setX(getParent()->getWidth() - getWidth());
- // Autosnap.
- if (bSnapToEdges)
- {
- if(getY() <= iSnaptoEdges)
- setY(0);
- else if ((getY()+getHeight()) >= (getParent()->getHeight() - iSnaptoEdges))
- setY(getParent()->getHeight() - getHeight());
- if(getX() <= iSnaptoEdges)
- setX(0);
- else if ((getX()+getWidth()) >= (getParent()->getWidth() - iSnaptoEdges))
- setX(getParent()->getWidth() - getWidth());
- }
- // Of course we want to call the window logic, as usual.
- gcn::Window::logic();
- // For starters, I'd like the controlbox to match the jWindow..
- rectMinButton.height = ((int)floor(getTitleBarHeight() * 0.8));
- rectMinButton.width = rectMinButton.height;
- rectXButton.height = rectMinButton.height;
- rectXButton.width = rectMinButton.height;
- rectMinButton.y = ((int)floor((getTitleBarHeight() - rectMinButton.height)/ 2));
- rectXButton.y = rectMinButton.y;
- switch(mControlBox)
- {
- case NONE:
- break;
- case MINBOX:
- rectMinButton.x = (getWidth() - 1 - (int)floor((getTitleBarHeight() - rectMinButton.height)/ 2)) - rectMinButton.width;
- ControlBoxWidth = rectXButton.width;
- break;
- case XBOX:
- rectXButton.x = (getWidth() - 1 - (int)floor((getTitleBarHeight() - rectMinButton.height)/ 2)) - rectMinButton.width;
- ControlBoxWidth = rectXButton.width;
- break;
- case BOTH:
- rectXButton.x = (getWidth() - 1 - (int)floor((getTitleBarHeight() - rectMinButton.height)/ 2)) - rectMinButton.width;
- rectMinButton.x = rectXButton.x - rectMinButton.width - 1;
- ControlBoxWidth = rectXButton.width * 2;
- break;
- }
- }
- void jWindow::mousePressed(gcn::MouseEvent& mouseEvent)
- {
- gcn::Window::mousePressed(mouseEvent);
- switch(mControlBox)
- {
- case NONE:
- break;
- case MINBOX:
- if (rectMinButton.isPointInRect(mouseEvent.getX(),mouseEvent.getY()))
- {
- mMoved = false;
- minMouseDown = true;
- }
- break;
- case XBOX:
- if (rectXButton.isPointInRect(mouseEvent.getX(),mouseEvent.getY()))
- {
- mMoved = false;
- xMouseDown = true;
- }
- break;
- case BOTH:
- if (rectXButton.isPointInRect(mouseEvent.getX(),mouseEvent.getY()))
- {
- mMoved = false;
- xMouseDown = true;
- }
- else if (rectMinButton.isPointInRect(mouseEvent.getX(),mouseEvent.getY()))
- {
- mMoved = false;
- minMouseDown = true;
- }
- break;
- }
- }
- void jWindow::mouseReleased(gcn::MouseEvent& mouseEvent)
- {
- gcn::Window::mouseReleased(mouseEvent);
- switch(mControlBox)
- {
- case NONE:
- break;
- case MINBOX:
- if ( (rectMinButton.isPointInRect(mouseEvent.getX(),mouseEvent.getY())) && (minMouseDown) )
- MinButton();
- break;
- case XBOX:
- if ((rectXButton.isPointInRect(mouseEvent.getX(),mouseEvent.getY())) && (xMouseDown) )
- XButton();
- break;
- case BOTH:
- if ( (rectMinButton.isPointInRect(mouseEvent.getX(),mouseEvent.getY())) && (minMouseDown) )
- MinButton();
- else if ((rectXButton.isPointInRect(mouseEvent.getX(),mouseEvent.getY())) && (xMouseDown) )
- XButton();
- break;
- }
- minMouseDown = false;
- xMouseDown = false;
- }
- void jWindow::XButton()
- {
- delete this;
- }
- void jWindow::MinButton()
- {
- if (!isMinimized())
- {
- // If the window is not minimized, we must store the current height for later use.
- setDHeight (getHeight());
- // We will then shrink the widget into its titlebar.
- setHeight (getTitleBarHeight());
- //Finally, we let the window know it is now minimized.
- setMinimized(true);
- }
- else
- {
- // Simply set the window back to its default state.
- setHeight (getDHeight());
- // Let the window know that it is no longer minimized.
- setMinimized(false);
- }
- }
- /************************
- ******** DRAWING ********
- ************************/
- /*FLATNOBORDER,
- FLATBORDER,
- RAISED,
- SUNKEN*/
- /*IMAGE,
- HGRADIENT,
- VGRADIENT,
- SOLID}*/
- void jWindow::drawTitleBar(gcn::Graphics *graphics)
- {
- int stB = 0;
- int width = getWidth();
- int height = getTitleBarHeight();
- int destX, destY;
- gcn::Color selColor;
- int imgWidth, imgHeight;
- int iColorDiff[4];
- float fColorDiff[4];
- float fColorCurr[4];
- switch(jWindow::tStyle)
- {
- case IMAGE:
- // Tile the image.
- imgWidth = jWindow::tBG->getWidth();
- imgHeight = jWindow::tBG->getHeight();
- destX = imgWidth;
- destY = imgHeight;
- for (int x=stB;x<=width;x+=imgWidth)
- {
- for(int y=stB;y<height;y+=imgHeight)
- {
- if ((x + destX) > width)
- destX = (x + destX) - width;
- if ((y + destY) > height)
- destY = (y + destY) - height;
- graphics->drawImage(jWindow::tBG, 0, 0, x, y, destX, destY);
- }
- }
- break;
- case HGRADIENT:
- destX = width - ControlBoxWidth - 1;
- selColor = jWindow::tBaseColor;
- iColorDiff[0] = jWindow::tEndColor.r - jWindow::tBaseColor.r;
- iColorDiff[1] = jWindow::tEndColor.g - jWindow::tBaseColor.g;
- iColorDiff[2] = jWindow::tEndColor.b - jWindow::tBaseColor.b;
- iColorDiff[3] = jWindow::tEndColor.a - jWindow::tBaseColor.a;
- fColorDiff[0] = (float)iColorDiff[0] / (float)destX;
- fColorDiff[1] = (float)iColorDiff[1] / (float)destX;
- fColorDiff[2] = (float)iColorDiff[2] / (float)destX;
- fColorDiff[3] = (float)iColorDiff[3] / (float)destX;
- fColorCurr[0] = (float)selColor.r;
- fColorCurr[1] = (float)selColor.b;
- fColorCurr[2] = (float)selColor.g;
- fColorCurr[3] = (float)selColor.a;
- for(int x=stB;x<destX;x++)
- {
- graphics->setColor(selColor);
- graphics->drawLine(x,stB,x,height);
- fColorCurr[0] += fColorDiff[0];
- fColorCurr[1] += fColorDiff[1];
- fColorCurr[2] += fColorDiff[2];
- fColorCurr[3] += fColorDiff[3];
- iColorDiff[0] = (int)(ceil(fColorCurr[0]));
- iColorDiff[1] = (int)(ceil(fColorCurr[1]));
- iColorDiff[2] = (int)(ceil(fColorCurr[2]));
- iColorDiff[3] = (int)(ceil(fColorCurr[3]));
- selColor.r = iColorDiff[0] > 255 ? 255 : (iColorDiff[0] < 0 ? 0 : iColorDiff[0]);
- selColor.g = iColorDiff[1] > 255 ? 255 : (iColorDiff[1] < 0 ? 0 : iColorDiff[1]);
- selColor.b = iColorDiff[2] > 255 ? 255 : (iColorDiff[2] < 0 ? 0 : iColorDiff[2]);
- selColor.a = iColorDiff[3] > 255 ? 255 : (iColorDiff[3] < 0 ? 0 : iColorDiff[3]);
- }
- graphics->setColor(jWindow::tEndColor);
- graphics->fillRectangle(gcn::Rectangle(destX,stB,width,height));
- break;
- case VGRADIENT:
- selColor = jWindow::tBaseColor;
- iColorDiff[0] = jWindow::tEndColor.r - jWindow::tBaseColor.r;
- iColorDiff[1] = jWindow::tEndColor.g - jWindow::tBaseColor.g;
- iColorDiff[2] = jWindow::tEndColor.b - jWindow::tBaseColor.b;
- iColorDiff[3] = jWindow::tEndColor.a - jWindow::tBaseColor.a;
- fColorDiff[0] = (float)iColorDiff[0] / (float)height;
- fColorDiff[1] = (float)iColorDiff[1] / (float)height;
- fColorDiff[2] = (float)iColorDiff[2] / (float)height;
- fColorDiff[3] = (float)iColorDiff[3] / (float)height;
- fColorCurr[0] = (float)selColor.r;
- fColorCurr[1] = (float)selColor.b;
- fColorCurr[2] = (float)selColor.g;
- fColorCurr[3] = (float)selColor.a;
- for(int y=stB;y<=height;y++)
- {
- graphics->setColor(selColor);
- graphics->drawLine(stB,y,width,y);
- fColorCurr[0] += fColorDiff[0];
- fColorCurr[1] += fColorDiff[1];
- fColorCurr[2] += fColorDiff[2];
- fColorCurr[3] += fColorDiff[3];
- iColorDiff[0] = (int)(ceil(fColorCurr[0]));
- iColorDiff[1] = (int)(ceil(fColorCurr[1]));
- iColorDiff[2] = (int)(ceil(fColorCurr[2]));
- iColorDiff[3] = (int)(ceil(fColorCurr[3]));
- selColor.r = iColorDiff[0] > 255 ? 255 : (iColorDiff[0] < 0 ? 0 : iColorDiff[0]);
- selColor.g = iColorDiff[1] > 255 ? 255 : (iColorDiff[1] < 0 ? 0 : iColorDiff[1]);
- selColor.b = iColorDiff[2] > 255 ? 255 : (iColorDiff[2] < 0 ? 0 : iColorDiff[2]);
- selColor.a = iColorDiff[3] > 255 ? 255 : (iColorDiff[3] < 0 ? 0 : iColorDiff[3]);
- }
- break;
- case SOLID:
- graphics->setColor(jWindow::tBaseColor);
- graphics->fillRectangle(gcn::Rectangle(stB,stB,width,height));
- break;
- }
- gcn::Color minBackcolor, xBackcolor;
- if(!minMouseDown)
- minBackcolor = tBaseColor + 0x303030;
- else
- minBackcolor = tBaseColor - 0x303030;
- if(!xMouseDown)
- xBackcolor = tBaseColor + 0x303030;
- else
- xBackcolor = tBaseColor - 0x303030;
- switch(mControlBox)
- {
- case NONE:
- break;
- case MINBOX:
- graphics->setColor(minBackcolor);
- graphics->fillRectangle(rectMinButton);
- break;
- case XBOX:
- graphics->setColor(xBackcolor);
- graphics->fillRectangle(rectXButton);
- break;
- case BOTH:
- graphics->setColor(minBackcolor);
- graphics->fillRectangle(rectMinButton);
- graphics->setColor(xBackcolor);
- graphics->fillRectangle(rectXButton);
- break;
- }
- if((tAppearance!=FLATNOBORDER)&&(fAppearance!=FLATNOBORDER))
- {
- graphics->setColor(jWindow::tBorderColor);
- graphics->drawLine(0,height, jWindow::getWidth(),height);
- }
- else if ((tAppearance==FLATNOBORDER)&&(fAppearance!=FLATNOBORDER))
- {
- graphics->setColor(jWindow::fBorderColor);
- graphics->drawLine(0,height, jWindow::getWidth(),height);
- }
- else if ((tAppearance!=FLATNOBORDER)&&(fAppearance==FLATNOBORDER))
- {
- graphics->setColor(jWindow::tBorderColor);
- graphics->drawLine(0,height, jWindow::getWidth(),height);
- }
- else if ((tAppearance==FLATNOBORDER)&&(fAppearance==FLATNOBORDER))
- {
- graphics->setColor(getForegroundColor());
- }
- gcn::Color minForecolor, xForecolor;
- if(!minMouseDown)
- minForecolor = getForegroundColor();
- else
- minForecolor = getForegroundColor() - 0x303030;
- if(!xMouseDown)
- xForecolor = getForegroundColor();
- else
- xForecolor = getForegroundColor() - 0x303030;
- switch(mControlBox)
- {
- case NONE:
- break;
- case MINBOX:
- graphics->drawRectangle(rectMinButton);
- graphics->setColor(minForecolor);
- graphics->drawLine(rectMinButton.x + 2, rectMinButton.y + 3, rectMinButton.x + rectMinButton.width - 3, rectMinButton.y + 3);
- graphics->drawLine(rectMinButton.x + 2, rectMinButton.y + 4, rectMinButton.x + rectMinButton.width - 3, rectMinButton.y + 4);
- break;
- case XBOX:
- graphics->drawRectangle(rectXButton);
- graphics->setColor(xForecolor);
- graphics->drawLine(rectXButton.x + 3, rectXButton.y + 3, rectXButton.x + rectXButton.width - 4, rectXButton.y + rectXButton.height - 4);
- graphics->drawLine(rectXButton.x + 4, rectXButton.y + 3, rectXButton.x + rectXButton.width - 5, rectXButton.y + rectXButton.height - 4);
- graphics->drawLine(rectXButton.x + 3, rectXButton.y + rectXButton.height - 4, rectXButton.x + rectXButton.width - 4, rectXButton.y + 3);
- graphics->drawLine(rectXButton.x + 4, rectXButton.y + rectXButton.height - 4, rectXButton.x + rectXButton.width - 5, rectXButton.y + 3);
- graphics->drawPoint(rectXButton.x + 6,rectXButton.y + rectXButton.height - 5);
- graphics->drawPoint(rectXButton.x + rectXButton.width - 7, rectXButton.y + 6);
- break;
- case BOTH:
- graphics->drawRectangle(rectXButton);
- graphics->drawRectangle(rectMinButton);
- graphics->setColor(minForecolor);
- graphics->drawLine(rectMinButton.x + 2, rectMinButton.y + 3, rectMinButton.x + rectMinButton.width - 3, rectMinButton.y + 3);
- graphics->drawLine(rectMinButton.x + 2, rectMinButton.y + 4, rectMinButton.x + rectMinButton.width - 3, rectMinButton.y + 4);
- graphics->setColor(xForecolor);
- graphics->drawLine(rectXButton.x + 3, rectXButton.y + 3, rectXButton.x + rectXButton.width - 4, rectXButton.y + rectXButton.height - 4);
- graphics->drawLine(rectXButton.x + 4, rectXButton.y + 3, rectXButton.x + rectXButton.width - 5, rectXButton.y + rectXButton.height - 4);
- graphics->drawLine(rectXButton.x + 3, rectXButton.y + rectXButton.height - 4, rectXButton.x + rectXButton.width - 4, rectXButton.y + 3);
- graphics->drawLine(rectXButton.x + 4, rectXButton.y + rectXButton.height - 4, rectXButton.x + rectXButton.width - 5, rectXButton.y + 3);
- graphics->drawPoint(rectXButton.x + 6,rectXButton.y + rectXButton.height - 5);
- graphics->drawPoint(rectXButton.x + rectXButton.width - 7, rectXButton.y + 6);
- break;
- }
- int textX;
- int textY = (int)((getTitleBarHeight() - getFont()->getHeight()) / 2);
- switch (getAlignment())
- {
- case gcn::Graphics::LEFT:
- textX = 4;
- break;
- case gcn::Graphics::CENTER:
- textX = getWidth() / 2;
- break;
- case gcn::Graphics::RIGHT:
- textX = getWidth() - 4;
- break;
- default:
- throw GCN_EXCEPTION("Unknown alignment.");
- }
- graphics->setColor(getForegroundColor());
- graphics->setFont(getFont());
- graphics->pushClipArea(gcn::Rectangle(0, 0, getWidth(), getTitleBarHeight() - 1));
- graphics->drawText(getCaption(), textX, textY, getAlignment());
- graphics->popClipArea();
- }
- void jWindow::drawForm(gcn::Graphics *graphics)
- {
- int stB = 0;
- int width = getWidth() - (stB * 2);
- int height = getHeight() - (stB * 2);
- int destX, destY;
- gcn::Color selColor;
- int iColorDiff[4];
- float fColorDiff[4];
- float fColorCurr[4];
- int imgWidth, imgHeight;
- switch(jWindow::fStyle)
- {
- case IMAGE:
- // Tile the image.
- imgWidth = jWindow::fBG->getWidth();
- imgHeight = jWindow::fBG->getHeight();
- destX = imgWidth;
- destY = imgHeight;
- for (int x=stB;x<=width;x+=imgWidth)
- {
- for(int y=stB;y<height;y+=imgHeight)
- {
- if ((x + destX) > width)
- destX = (x + destX) - width;
- if ((y + destY) > height)
- destY = (y + destY) - height;
- graphics->drawImage(jWindow::fBG, 0, 0, x, y, destX, destY);
- }
- }
- break;
- case HGRADIENT:
- destX = width;
- selColor = jWindow::fBaseColor;
- selColor.a = fAlpha;
- iColorDiff[0] = jWindow::fEndColor.r - jWindow::fBaseColor.r;
- iColorDiff[1] = jWindow::fEndColor.g - jWindow::fBaseColor.g;
- iColorDiff[2] = jWindow::fEndColor.b - jWindow::fBaseColor.b;
- iColorDiff[3] = jWindow::fEndColor.a - jWindow::fBaseColor.a;
- fColorDiff[0] = (float)iColorDiff[0] / (float)destX;
- fColorDiff[1] = (float)iColorDiff[1] / (float)destX;
- fColorDiff[2] = (float)iColorDiff[2] / (float)destX;
- fColorDiff[3] = (float)iColorDiff[3] / (float)destX;
- fColorCurr[0] = (float)selColor.r;
- fColorCurr[1] = (float)selColor.b;
- fColorCurr[2] = (float)selColor.g;
- fColorCurr[3] = (float)selColor.a;
- for(int x=stB;x<destX;x++)
- {
- graphics->setColor(selColor);
- graphics->drawLine(x,stB,x,height);
- fColorCurr[0] += fColorDiff[0];
- fColorCurr[1] += fColorDiff[1];
- fColorCurr[2] += fColorDiff[2];
- fColorCurr[3] += fColorDiff[3];
- iColorDiff[0] = (int)(ceil(fColorCurr[0]));
- iColorDiff[1] = (int)(ceil(fColorCurr[1]));
- iColorDiff[2] = (int)(ceil(fColorCurr[2]));
- iColorDiff[3] = (int)(ceil(fColorCurr[3]));
- selColor.r = iColorDiff[0] > 255 ? 255 : (iColorDiff[0] < 0 ? 0 : iColorDiff[0]);
- selColor.g = iColorDiff[1] > 255 ? 255 : (iColorDiff[1] < 0 ? 0 : iColorDiff[1]);
- selColor.b = iColorDiff[2] > 255 ? 255 : (iColorDiff[2] < 0 ? 0 : iColorDiff[2]);
- selColor.a = iColorDiff[3] > 255 ? 255 : (iColorDiff[3] < 0 ? 0 : iColorDiff[3]);
- }
- break;
- case VGRADIENT:
- selColor = jWindow::fBaseColor;
- iColorDiff[0] = jWindow::fEndColor.r - jWindow::fBaseColor.r;
- iColorDiff[1] = jWindow::fEndColor.g - jWindow::fBaseColor.g;
- iColorDiff[2] = jWindow::fEndColor.b - jWindow::fBaseColor.b;
- iColorDiff[3] = jWindow::fEndColor.a - jWindow::fBaseColor.a;
- fColorDiff[0] = (float)iColorDiff[0] / (float)height;
- fColorDiff[1] = (float)iColorDiff[1] / (float)height;
- fColorDiff[2] = (float)iColorDiff[2] / (float)height;
- fColorDiff[3] = (float)iColorDiff[3] / (float)height;
- fColorCurr[0] = (float)selColor.r;
- fColorCurr[1] = (float)selColor.b;
- fColorCurr[2] = (float)selColor.g;
- fColorCurr[3] = (float)selColor.a;
- for(int y=stB;y<=height;y++)
- {
- graphics->setColor(selColor);
- graphics->drawLine(stB,y,width,y);
- fColorCurr[0] += fColorDiff[0];
- fColorCurr[1] += fColorDiff[1];
- fColorCurr[2] += fColorDiff[2];
- fColorCurr[3] += fColorDiff[3];
- iColorDiff[0] = (int)(ceil(fColorCurr[0]));
- iColorDiff[1] = (int)(ceil(fColorCurr[1]));
- iColorDiff[2] = (int)(ceil(fColorCurr[2]));
- iColorDiff[3] = (int)(ceil(fColorCurr[3]));
- selColor.r = iColorDiff[0] > 255 ? 255 : (iColorDiff[0] < 0 ? 0 : iColorDiff[0]);
- selColor.g = iColorDiff[1] > 255 ? 255 : (iColorDiff[1] < 0 ? 0 : iColorDiff[1]);
- selColor.b = iColorDiff[2] > 255 ? 255 : (iColorDiff[2] < 0 ? 0 : iColorDiff[2]);
- selColor.a = iColorDiff[3] > 255 ? 255 : (iColorDiff[3] < 0 ? 0 : iColorDiff[3]);
- }
- break;
- case SOLID:
- graphics->setColor(jWindow::fBaseColor);
- graphics->fillRectangle(gcn::Rectangle(stB,stB,width,height));
- break;
- }
- drawChildren(graphics);
- }
- void jWindow::drawFrame(gcn::Graphics * graphics)
- {
- gcn::Color highlightColor, shadowColor;
- int width, height;
- if(fAppearance != FLATNOBORDER)
- {
- switch(jWindow::fAppearance)
- {
- case FLATBORDER:
- highlightColor = jWindow::fBorderColor;
- shadowColor = jWindow::fBorderColor;
- break;
- case RAISED:
- highlightColor = jWindow::fBorderColor + 0x303030;
- shadowColor = jWindow::fBorderColor - 0x303030;
- break;
- case SUNKEN:
- highlightColor = jWindow::fBorderColor - 0x303030;
- shadowColor = jWindow::fBorderColor + 0x303030;
- break;
- }
- // Make sure transparency remains.
- highlightColor.a = jWindow::fAlpha;
- shadowColor.a = jWindow::fAlpha;
- width = getWidth() + getFrameSize() * 2 - 1;
- height = getHeight() + getFrameSize() * 2 - 1;
- for (unsigned int i = 0,y = getTitleBarHeight()+2; i < getFrameSize(); ++i,++y)
- {
- // Top - left
- graphics->setColor(shadowColor);
- graphics->drawLine(i,y, i, height - i - 1);
- // Right, bottom
- graphics->setColor(highlightColor);
- graphics->drawLine(width - i,y, width - i, height - i);
- graphics->drawLine(i,height - i, width - i - 1, height - i);
- }
- }
- if(tAppearance!=FLATNOBORDER)
- {
- switch(jWindow::tAppearance)
- {
- case FLATBORDER:
- highlightColor = jWindow::tBorderColor;
- shadowColor = jWindow::tBorderColor;
- break;
- case RAISED:
- highlightColor = jWindow::tBorderColor + 0x303030;
- shadowColor = jWindow::tBorderColor - 0x303030;
- break;
- case SUNKEN:
- highlightColor = jWindow::tBorderColor - 0x303030;
- shadowColor = jWindow::tBorderColor + 0x303030;
- break;
- }
- // Make sure transparency remains.
- highlightColor.a = jWindow::tAlpha;
- shadowColor.a = jWindow::tAlpha;
- width = getWidth() + getFrameSize() * 2 - 1;
- height = getTitleBarHeight() + getFrameSize() * 2 - 1 + 2;
- for (unsigned int i = 0; i < getFrameSize(); ++i)
- {
- graphics->setColor(shadowColor);
- graphics->drawLine(i,i, width - i, i);
- graphics->drawLine(i,i + 1, i, height);
- graphics->setColor(highlightColor);
- graphics->drawLine(width - i,i + 1, width - i, height);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement