Commit 37dcded7 by Anselme

added application icon

parent f1492c56
......@@ -14,6 +14,7 @@
#include <thread>
#include "graphics.h"
#include "spriteatlas.h"
#include "menu.h"
Client::Client(Graphics* graphics, Menu* menu, const std::string &address, unsigned short port):
......@@ -280,6 +281,8 @@ void Client::update(sf::RenderWindow& window)
msg.append(" . . .");
m_graphics->setMessage(msg);
new std::thread(connectToServer, this, m_address, m_port, m_name, color);
SpriteAtlas::setIconColor(sf::Color(color));
window.setIcon(32, 32, SpriteAtlas::getIcon());
}
// Clear screen
......
......@@ -48,6 +48,9 @@ int main(int argc, char** argv)
sf::RenderWindow window(sf::VideoMode(WINDOW_WIDTH, WINDOW_HEIGHT), "MMOkoban");
Graphics* graphics = new Graphics(WINDOW_WIDTH, WINDOW_HEIGHT);
Menu* menu = new Menu(WINDOW_WIDTH, WINDOW_HEIGHT);
window.setKeyRepeatEnabled(false);
SpriteAtlas::setIconColor(sf::Color(0xe8a71bFF));
window.setIcon(32, 32, SpriteAtlas::getIcon());
Client client(graphics, menu, address, port);
while(client.isRunning())
......
......@@ -340,12 +340,8 @@ void Menu::updateBlobSprite()
if(m_blobSprite != nullptr)
delete m_blobSprite;
sf::Color color = sf::Color(getColor());
sf::Color dark = color;
sf::Color light = color;
dark *= sf::Color(160, 160, 160);
light += sf::Color(80, 80, 80, 50);
m_blobSprite = SpriteAtlas::createSprite(dark, color, light);
sf::Color color(getColor());
m_blobSprite = SpriteAtlas::createSprite(color);
m_blobSprite->setScale(4, 4);
m_blobSprite->setPosition((m_width - m_blobSprite->getGlobalBounds().width)/2.f, (m_height - 600)/2.f + 200);
}
......
......@@ -12,11 +12,7 @@ PlayerEntity::PlayerEntity(const std::string &name, sf::Color color) :
{
m_animationOffset = static_cast<float>(std::rand()) / static_cast<float>(RAND_MAX);
sf::Color dark = color;
sf::Color light = color;
dark *= sf::Color(160, 160, 160);
light += sf::Color(80, 80, 80, 50);
m_sprite = SpriteAtlas::createSprite(dark, color, light);
m_sprite = SpriteAtlas::createSprite(color);
m_nameTag = new sf::Text(sf::String::fromUtf8(m_name.begin(), m_name.end()), Fonts::getArialFont(), NAME_TAG_SIZE*2);
m_nameTag->scale(0.5f, 0.5f);
......
......@@ -31,8 +31,52 @@ sf::Sprite* SpriteAtlas::createSprite()
return sprite;
}
sf::Sprite* SpriteAtlas::createSprite(sf::Color dark, sf::Color main, sf::Color light)
void SpriteAtlas::setIconColor(sf::Color color)
{
sf::Color dark = color;
sf::Color light = color;
dark *= sf::Color(160, 160, 160);
light += sf::Color(80, 80, 80, 50);
sf::Color referenceDark = getPixel(224, 0);
sf::Color referenceMain = getPixel(225, 0);
sf::Color referenceLight = getPixel(226, 0);
for(unsigned int x = 0; x < 32; ++x)
{
for(unsigned int y = 32; y < 64; ++y)
{
sf::Color c = getPixel(x, y);
if(c == referenceDark)
c = dark;
else if(c == referenceMain)
c = color;
else if(c == referenceLight)
c = light;
sf::Uint8 temp = c.a;
c.a = c.r;
c.r = temp;
temp = c.b;
c.b = c.g;
c.g = temp;
iconPixels[x + (y-32)*32] = c.toInteger();
}
}
}
const sf::Uint8* SpriteAtlas::getIcon()
{
return (sf::Uint8*)iconPixels;
}
sf::Sprite* SpriteAtlas::createSprite(sf::Color color)
{
sf::Color dark = color;
sf::Color light = color;
dark *= sf::Color(160, 160, 160);
light += sf::Color(80, 80, 80, 50);
sf::Image img;
img.create(atlasWidth, atlasHeight);
sf::Color referenceDark = getPixel(224, 0);
......@@ -46,7 +90,7 @@ sf::Sprite* SpriteAtlas::createSprite(sf::Color dark, sf::Color main, sf::Color
if(c == referenceDark)
c = dark;
else if(c == referenceMain)
c = main;
c = color;
else if(c == referenceLight)
c = light;
img.setPixel(x, y, c);
......@@ -117,6 +161,8 @@ sf::Color SpriteAtlas::getPixel(unsigned int x, unsigned int y)
return sf::Color(atlasImg[x + y*atlasWidth]);
}
unsigned int SpriteAtlas::iconPixels[32*32] = {0xFFFFFFFF};
const unsigned int SpriteAtlas::atlasWidth = 256;
const unsigned int SpriteAtlas::atlasHeight = 256;
const unsigned int SpriteAtlas::atlasImg[atlasWidth*atlasHeight] = {
......
......@@ -2,6 +2,7 @@
#define SPRITEATLAS_H
#include <string>
#include <SFML/Config.hpp>
namespace sf
{
......@@ -15,12 +16,17 @@ class SpriteAtlas
static const unsigned int atlasHeight;
static const unsigned int atlasImg[];
static unsigned int iconPixels[];
static sf::Color getPixel(unsigned int x, unsigned int y);
public:
static sf::Sprite* createSprite(sf::Color dark, sf::Color main, sf::Color light);
static sf::Sprite* createSprite(sf::Color color);
static sf::Sprite* createSprite();
static void setIconColor(sf::Color color);
static const sf::Uint8* getIcon();
static void fileToC(const std::string& filename);
static void imageToC(const std::string& filename);
};
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment