Exemple #1
0
RectangleShape::RectangleShape(void)
	: OutlinedShape()
{
	setOutlineColor(Color::Transparent);

#ifndef _3DS
	glGenVertexArrays(1, &_vao);
	glGenBuffers(1, &_vbo);

	glBindVertexArray(_vao);
	glBindBuffer(GL_ARRAY_BUFFER, _vbo);
	glBufferData(GL_ARRAY_BUFFER, sizeof(float) * 36, nullptr, GL_DYNAMIC_DRAW);
	glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(float) * 9, 0);
	glEnableVertexAttribArray(0);
	glVertexAttribPointer(1, 4, GL_FLOAT, GL_FALSE, sizeof(float) * 9, (GLvoid*)(sizeof(float) * 3));
	glEnableVertexAttribArray(1);
	glVertexAttribPointer(2, 2, GL_FLOAT, GL_FALSE, sizeof(float) * 9, (GLvoid*)(sizeof(float) * 7));
	glEnableVertexAttribArray(2);
	glBindVertexArray(0);
	glBindBuffer(GL_ARRAY_BUFFER, 0);

#endif // _3DS
}
Exemple #2
0
GlRegularPolygon::GlRegularPolygon(const Coord &position,
                                   const Size &size,
                                   unsigned int numberOfSides,
                                   const Color &fillColor,
                                   const Color &outlineColor,
                                   bool filled,
                                   bool outlined,
                                   const string &textureName,
                                   float outlineSize):
  position(position),
  size(size),
  numberOfSides(numberOfSides),
  startAngle(float(M_PI)/2.0f) {
  computePolygon();

  invertYTexture=false;

  setFillColor(fillColor);
  setOutlineColor(outlineColor);
  setFillMode(filled);
  setOutlineMode(outlined);
  setTextureName(textureName);
  setOutlineSize(outlineSize);
}
Exemple #3
0
ScrollBar::ScrollBar()
	: currentValue_(0),
	  maxValue_(1),
	  stepSize_(0.1)
{
	setOutlineColor(DEFAULT_OUTLINE_COLOR);
	setOutlineThickness(DEFAULT_OUTLINE_THICKNESS);

	scrollIndicator_ = new RectangularWidget();
	scrollIndicator_->setSize({this->getSize().x, 4});
	scrollIndicator_->setAnchor({0.5, 0.5});
	scrollIndicator_->setParentAnchor({0.5, 0});
	scrollIndicator_->setFillColor(sf::Color::Red);
	updateScrollIndicator();
	addWidget(scrollIndicator_);

	scrollUpButton_ = new Button();
	scrollUpButton_->signalLeftMouseButtonPressed.connect([this] { stepScroll(UP); });
	scrollUpButton_->signalLeftMouseButtonHeld.connect([this] (float frameTimeInSeconds) { smoothScroll(UP, frameTimeInSeconds); });
//	scrollUpButton_->setText("^");
	scrollUpButton_->setSize(this->getSize());
	scrollUpButton_->setOutlineThickness(1);
	scrollUpButton_->setOutlineColor(DEFAULT_OUTLINE_COLOR);
	addWidget(scrollUpButton_);

	scrollDownButton_ = new Button();
	scrollDownButton_->signalLeftMouseButtonPressed.connect([this] { stepScroll(DOWN); });
	scrollDownButton_->signalLeftMouseButtonHeld.connect([this] (float frameTimeInSeconds) { smoothScroll(DOWN, frameTimeInSeconds); });
//	scrollDownButton_->setText("v");
	scrollDownButton_->setSize(this->getSize());
	scrollDownButton_->setOutlineThickness(1);
	scrollDownButton_->setOutlineColor(DEFAULT_OUTLINE_COLOR);
	scrollDownButton_->setAnchor({0, 1});
	scrollDownButton_->setParentAnchor({0, 1});
	addWidget(scrollDownButton_);
}
void Opcode810AHandler::_run()
{
    Logger::debug("SCRIPT") << "[810A] [=] void float_msg(object who, string msg, int type) " << std::endl;
    int type = _vm->dataStack()->popInteger();
    unsigned int color = 0x000000ff;
    switch (type)
    {
        case -2:
            // CAPITAL RED LETTERS  FF 00 00
            color = 0xff0000ff;
            break;
        case -1:
            // Self-rotating colors @todo
            color = 0xff0000ff; // temporary taken from -2
            break;
        case 0:
        case 8:
        case 13:
            color = 0xffff7fff;
            break;
        case 1:
        case 5:
        case 10:
            color = 0x555555ff;
            break;
        case 2:
            color = 0xff0000ff;
            break;
        case 3:
            color = 0x3cfb00ff;
            break;
        case 4:
            color = 0x30598eff;
            break;
        case 6:
            color = 0xa2a2a2ff;
            break;
        case 7:
            color = 0xff4949ff;
            break;
        case 9:
            color = 0xffffffff;
            break;
        case 11:
            color = 0x3c3c3cff;
            break;
        case 12:
            color = 0x757575ff;
            break;
        default:
            _error("float_msg - wrong type: " + std::to_string(type));
    }

    auto string = _vm->dataStack()->popString();
    auto object = _vm->dataStack()->popObject();

    auto floatMessage = new UI::TextArea(string);
    floatMessage->setWidth(200);
    floatMessage->setWordWrap(true);
    floatMessage->setHorizontalAlign(UI::TextArea::HorizontalAlign::CENTER);
    floatMessage->setOutline(true);
    floatMessage->setOutlineColor(0x000000ff);
    floatMessage->setFont(ResourceManager::getInstance()->font("font1.aaf", color));
    object->setFloatMessage(floatMessage);

}
Exemple #5
0
void visualizer::setOutlineColor(GLfloat r, GLfloat g, GLfloat b){
  setOutlineColor(r,g,b,1);
}
Exemple #6
0
void sfShape_setOutlineColor(sfShape* shape, sfColor color)
{
    CSFML_CALL(shape, setOutlineColor(sf::Color(color.r, color.g, color.b, color.a)));
}
Exemple #7
0
int main(int argc, char*argv[]) {
    // ████████ INITS 1 ████████
#ifndef COMMON_INITS1
    cfg.init("bedlab.cfg");
    ui2::init_ui();
    Vec2i windowsize;
    Vec2i screen_resolution = { int(VideoMode::getDesktopMode().width), int(VideoMode::getDesktopMode().height) };
    if (cfg.getvar<int>("auto_winsize")) {
        auto window_scale = cfg.getvar<Vec2>("window_scale");
        windowsize = Vec2i(scal(Vec2(screen_resolution), window_scale));
    }
    else {
        windowsize = cfg.getvar<Vec2i>("windowsize");
    }
    winsize = Vec2(windowsize);
    //UI.init_console(); // ALWAYS AFTER SO IT CAN GET WINDOW SIZE
    ui2::init_console(); // ALWAYS AFTER SO IT CAN GET WINDOW SIZE

    wincenter = 0.5f*Vec2(windowsize);
    Vec2i windowpos;
    VideoMode::getDesktopMode().height;
    if (cfg.getvar<int>("stick_left")) {
        windowpos = Vec2i(
            screen_resolution.x - windowsize.x - 10,
            screen_resolution.y - windowsize.y - 40
        );
    }
    else
        windowpos = (Vec2i(5, 25));

    sf::RenderWindow window(sf::VideoMode(windowsize.x, windowsize.y),
        "bedlab!", 7
        //,sf::ContextSettings(0, 0, 1)
    );
    window.setFramerateLimit(cfg.getvar<int>("fps_max"));
    frame_duration = 1.0f / cfg.getvar<int>("fps_max");

    window.setPosition(windowpos);

    vector<string> keys;
    auto choice = cfg.getstr("app");
    // show_keys(cfg.getstr("app"), keys);
#endif
// ████████ INITS2 ████████
#ifndef COMMON_INITS2

// we don't have a class/interface/struct with data, everything is local to this function, like a classic stack that all programs are anyway.
// Texture cursor_tx;
// if (!cursor_tx.loadFromFile(cfg.getstr("cursor")))
//     cout << "did not load cursor" << endl;
// Sprite cursor;
// cursor.setTexture(cursor_tx);
// cursor.setOrigin(3, 3);

    CircleShape cursor = mkcircle({ 0,0 }, Color::Transparent, 3, 1);
    Color background = cfg.getvar<Color>("background");
    window.setMouseCursorVisible(false);
    Vec2 mpos;
    bool leftclicked = false, rightclicked = false;

    // view and zoom
    View view, ui_view;
    ui_view = view = window.getDefaultView();
    float zoomlevel = 1;
    Vec2 mpos_abs;
    float frame_duration = 1.0f / cfg.getvar<int>("fps_max");
#endif // COMMON_INITS2
    // ████████ APP ACTUAL ████████
    {
        auto testarea = Vec2(winsize.y, winsize.y);
        auto offset = Vec2(-.5f*testarea);
        offset = { 0,0 };
        int many = 4;
        float cellsize = 0.5*testarea.x / many;
        map<Vec2i, RectangleShape> zone_rects;
    for (int i = 0; i < many + 1; ++i) {
        for (int j = 0; j < many + 1; ++j)
        {
            auto c = rgb_from_hue((float((i + j) % many)) / many);
            c.a = 128;
            auto r = mkrect2(
                Vec2(i*cellsize, j*cellsize)
                //+ offset
                ,
                Vec2(1, 1)*(cellsize - 10),
                Color::Transparent,
                5,
                false
            );
            r.setOutlineColor(c);
            //auto r_p = new RectangleShape();
            //*r_p = r;
            //grid[Vec2i(i, j)].insert(r_p);
            zone_rects[Vec2i(i, j)] = r;
            lf.logw(strfy(
                (float((i + j) % many)) / many) + " " + strfy(c)
            );
        }
    }
    }

    set<Vec2i> surround = {
        Vec2i(-1, -1) ,
        Vec2i(0, -1)  ,
        Vec2i(1, -1)  ,
        Vec2i(1, 0)   ,
        Vec2i(1, 1)   ,
        Vec2i(0, 1)   ,
        Vec2i(-1, 1)  ,
        Vec2i(-1, 0),
        Vec2i(0, 0)
    },
    active_chunks;
    float cell_size = 30;
    RectangleShape view_center = mkrect2({ 0,0 }, { 10,10 }, Color::Transparent, 1);
    RectangleShape world_center = mkrect2({ 0,0 }, { 6,6 }, Color::Red);
    //Vec2i reference_chunk = { 2,2 };
    Vec2i reference_chunk = {0,0};
    map<Vec2i, RectangleShape> chunks;
    
    for (int i = -5; i <= 5; ++i) {
        for (int j = -5; j <= 5; ++j) {
            chunks[Vec2i(i, j)] = mkrect2(cell_size*Vec2(i, j), { cell_size,cell_size }, Color::Transparent, 1);
        }
    }
    auto recenter_world = [&](Vec2i shift) {
        msgm("shifting", shift);
        world_center.move(Vec2(shift)*cell_size);
        for (auto&a : chunks) {
            a.second.move(Vec2(shift)*cell_size);
        }
        view.move(Vec2(shift)*cell_size);
        //world_center.setPosition(view.getCenter());
        world_center.move(-Vec2(shift)*cell_size);
        //for (auto&a : chunks) {
        //    a.second.setPosition(cell_size*Vec2(shift));
        //}

        for (auto&a : active_chunks) {
            chunks[a].setFillColor(Color::Transparent);
        }
        
        active_chunks.clear();
        // activate chunk surrounding the reference
        for (auto&a : surround) { 
            auto index = reference_chunk + a;
            active_chunks.insert(index);
            //chunks[index].setPosition(cell_size*Vec2(index));
            chunks[index].setFillColor(Color(255,0,0,128));
        }
    };
    recenter_world({ 0,0 });
    auto recenter_check = [&]() {
        view_center.setPosition(view.getCenter());
        //auto shift = Vec2i(2.f*view.getCenter() / (1.2f*cellsize));
        auto shift = -Vec2i(0.8f * view.getCenter() / cell_size);
        show(view.getCenter());
        //if (view.getCenter().x > cell_size*1.2f) reference_chunk.x -= 1;
        //if (view.getCenter().y > cell_size*1.2f) reference_chunk.y -= 1;
        //if (view.getCenter().x < -cell_size*1.2f) reference_chunk.x += 1;
        //if (view.getCenter().y < -cell_size*1.2f) reference_chunk.y += 1;

        //msg("recenter triggered!");
        //reposition_chunks();
        //reference_chunk = Vec2i();
        if (shift != Vec2i{0, 0}) recenter_world(shift);
        reference_chunk -= shift;
    };
    // ████████ callbacks ████████
    bool panning = false;
    Vec2 previous_mouse_pos;
    view.setCenter({ 0,0 });
    //view.sets
#ifndef LOOP_LAMBDAS
    draw = [&]() {
        window.setView(view);
        //////////////// OBJECTS THAT CAN ZOOMED ////////////////
        window.draw(glob_vert_single);
        for (auto&a : glob_pts)window.draw(a);
        for (auto&a : glob_rects)window.draw(a);
        for (auto&a : glob_vert)window.draw(a);
        for (auto&a : glob_texts)window.draw(a);
        //////////////// OBJECTS THAT CAN ZOOMED ////////////////
        //for (auto&a : zone_rects) window.draw(a.second);
        for (auto&a : chunks) window.draw(a.second);

        window.draw(view_center);
        window.draw(world_center);

        // UI draw, AFTER ui view and BEFORE other draw
        window.setView(ui_view);
        //////////////// OBJECTS THAT CANNOT ZOOMED, MEANING UI ////////////////
        //br.drawwithtext(window);
        ui2::draw(window);
        //UI.draw(window);
        window.draw(cursor);
    };
    update = [&]() {
        recenter_check();
    };
    treatkeyevent = [&](Keyboard::Key k) {
        switch (k)
        {
        case Keyboard::E:
            break;
        case Keyboard::I:

            break;
        case Keyboard::Q:
            break;
        case Keyboard::BackSpace:
            glob_pts.clear();
            glob_texts.clear();
            glob_rects.clear();
            glob_vert.clear();
            break;

        case Keyboard::Space:
            break;

        case Keyboard::S:
            screenshot(window);
            break;
        case Keyboard::Num1:
        case Keyboard::Num2:
        case Keyboard::Num3:
        case Keyboard::Num4:
        case Keyboard::Num5:
            break;
        }
    };
    mousemoved = [&](Vec2 pos) {
        cursor.setPosition(pos);
        if (leftclicked);
        if (panning) {
            view.move((previous_mouse_pos - pos));
        }
        previous_mouse_pos = pos;
    };
    mouseclick = [&](sf::Mouse::Button button) {
        if (button == Mouse::Button::Left) leftclicked = true;
        if (button == Mouse::Button::Right) rightclicked = true;
        if (button == Mouse::Button::Left) {
        };
        panning = leftclicked;

    };
    mouserelease = [&](sf::Mouse::Button button) {
        if (button == Mouse::Button::Left) leftclicked = false;
        if (button == Mouse::Button::Right) rightclicked = false;
        if (button == Mouse::Button::Left) {
        }
        panning = leftclicked;

    };
    loop = [&]() {
        while (window.isOpen())
        {
            sf::Event event;
            while (window.pollEvent(event))
            {
                switch (event.type)
                {
                case sf::Event::KeyPressed:
                    if (event.key.code == sf::Keyboard::Escape)
                        window.close();
                    treatkeyevent(event.key.code);
                    break;
                case sf::Event::Closed:
                    window.close();
                    break;
                case sf::Event::MouseButtonPressed:
                    mouseclick(event.mouseButton.button);
                    break;
                case sf::Event::MouseButtonReleased:
                    mouserelease(event.mouseButton.button);
                    break;
                case sf::Event::MouseMoved:
                    mpos = Vec2(event.mouseMove.x, event.mouseMove.y);
                    mpos_abs = window.mapPixelToCoords(Vec2i(mpos), view);
                    mousemoved(mpos);
                    break;
                default:
                    treatotherevent(event);
                    break;
                }
            }

            window.clear(background);
            update();
            draw();
            window.display();
        }
    };
    treatotherevent = [&](Event&e) {
        if (e.type == Event::MouseWheelMoved && e.mouseWheel.delta)
        {
            mpos_abs = window.mapPixelToCoords(Vec2i(mpos), view);

            //view = window.getView();
            if (e.mouseWheel.delta < 0)
            {
                zoomlevel *= 2.f;
                view.setSize(view.getSize()*2.f);
                view.setCenter(interp(mpos_abs, view.getCenter(), 2.f));
                //view.setCenter(interp(mpos_abs, view.getCenter(), 2.f));
            }
            if (e.mouseWheel.delta > 0)
            {
                zoomlevel *= 0.5;
                view.setSize(view.getSize()*.5f);
                view.setCenter(.5f*(view.getCenter() + mpos_abs));
                //view.setCenter(.5f*(view.getCenter() + mpos_abs));
            }
            window.setView(view);
        }
    };
#endif // LOOP_LAMBDAS

    loop();
}
Exemple #8
0
 TextButton::TextButton(const std::string& text,Widget* parent) : Button(parent), _label(text,this)
 {
     setFillColor(sf::Color(86,20,19));
     setOutlineThickness(5);
     setOutlineColor(sf::Color(146,20,19));
 }
void RenderSystem::update(entityx::EntityManager &es, entityx::EventManager &events, entityx::TimeDelta dt)
{
    m_renderingQueue.clear();

    if(m_debugHitboxDraw)
    {
        es.each<PositionComponent, PlatformerHitboxComponent>([&](
            entityx::Entity entity,
            PositionComponent& position,
            PlatformerHitboxComponent& hitbox) {
            auto shape = std::make_shared<sf::ConvexShape>(hitbox.getHitbox().getPointsCount());
            shape->setOutlineThickness(1.f);
            shape->setFillColor(sf::Color::Transparent);
            shape->setOutlineColor(sf::Color::Black);
            for(std::size_t i = 0; i < shape->getPointCount(); ++i)
            {
                shape->setPoint(i, sf::Vector2f(
                    hitbox.getHitbox().getPoint(i).x,
                    hitbox.getHitbox().getPoint(i).y
                ));
            }

            addToRenderingQueue(shape, sf::RenderStates(position.getPositionTransform()), 100000.f);
        });
    }

    auto drawFunc = [&](entityx::Entity entity, PositionComponent& position, RenderComponent& render) {
        //Update the animated sprite and put it in the render queue
        auto animatedSprite = getAnimatedSprite(entity);

        animatedSprite->update(dt);
        animatedSprite->setOrigin(sf::Vector2f(0.5f, 0.5f));
        animatedSprite->setPosition(position.x + position.width/2.f, position.y + position.height/2.f);
        animatedSprite->setScale((render.flipped ? (-1) : (1)) * position.width, position.height);

        //Call the lua callback if the animation has just been restarted
        if(animatedSprite->hadRestartedAnimation() && render.onAnimationEndFunc.valid())
            render.onAnimationEndFunc.call(EntityHandle(entity), render.currentAnimation);

        addToRenderingQueue(animatedSprite, sf::RenderStates::Default, position.z); //TODO: Get z position from RenderComponent
    };

    sf::FloatRect viewAABB(
        m_renderingView.getCenter().x - 1024.f/2.f,
        m_renderingView.getCenter().y - 768.f/2.f,
        1024.f,
        768.f
    );

    std::set<entityx::Entity> entitiesToDraw = m_grid.getEntitiesIntersectingAABB(viewAABB);
    for(entityx::Entity entity : entitiesToDraw)
    {
        if(entity.has_component<PositionComponent>() && entity.has_component<RenderComponent>())
        {
            drawFunc(entity, *(entity.component<PositionComponent>().get()), *(entity.component<RenderComponent>().get()));
        }
    }

    if(m_cameraFollowPlayers)
    {
        //Update the camera
        es.each<PlayerComponent, PlatformerComponent, PositionComponent>([&](entityx::Entity entity, PlayerComponent& player, PlatformerComponent& platformer, PositionComponent& position) {
            if(player.playerNumber != m_centerOnPlayer)
                return; //Only center on the selected player

            float newX = position.x + position.width / 2.f;
            float newY = m_renderingView.getCenter().y;

            if(platformer.groundEntity && platformer.groundEntity.has_component<PositionComponent>())
            {
                m_lastGroundEntity = platformer.groundEntity;
            }

            if(m_lastGroundEntity)
            {
                auto groundPosition = m_lastGroundEntity.component<PositionComponent>();

                //If the player is on the ground, update to Y position.
                if(std::abs(newY - groundPosition->y) > 10.f)
                {
                    newY += (newY > groundPosition->y ? -1 : 1) * 150.f * dt;
                }

                //If the player goes beyond some limits, remove the last ground entity and try to center on player
                if(position.y + position.height > newY + 200.f || position.y + position.height < newY - 200.f)
                {
                    m_lastGroundEntity = entityx::Entity();
                }
            }
            else
            {
                newY += (newY > position.y ? -1 : 1) * std::abs(newY - position.y) * 2 * dt + (platformer.fallingSpeed - platformer.jumpingSpeed) * dt;
            }

            m_renderingView.setCenter(sf::Vector2f(newX, newY));
        });
    }
}
void Opcode810AHandler::_run()
{
    Logger::debug("SCRIPT") << "[810A] [=] void float_msg(void* who, string* msg, int type) " << std::endl;
    int type = _vm->popDataInteger();
    unsigned int color;
    switch (type)
    {
        case -2:
            //БОЛЬШИЕ КРАСНЫЕ БУКВЫ	FF 00 00
            color = 0xff0000ff;
            break;
        case -1:
            //Самоперебирающиеся цвета @todo
            color = 0xff0000ff; // временно взят из -2
            break;
        case 0:
        case 8:
        case 13:
            color = 0xffff7fff;
            break;
        case 1:
        case 5:
        case 10:
            color = 0x555555ff;
            break;
        case 2:
            color = 0xff0000ff;
            break;
        case 3:
            color = 0x3cfb00ff;
            break;
        case 4:
            color = 0x30598eff;
            break;
        case 6:
            color = 0xa2a2a2ff;
            break;
        case 7:
            color = 0xff4949ff;
            break;
        case 9:
            color = 0xffffffff;
            break;
        case 11:
            color = 0x3c3c3cff;
            break;
        case 12:
            color = 0x757575ff;
            break;
        default:
            throw Exception("Opcode810AHandler - wrong type: " + std::to_string(type));
    }

    auto string = static_cast<std::string*>(_vm->popDataPointer());
    auto object = static_cast<GameObject*>(_vm->popDataPointer());

    auto floatMessage = new TextArea(*string);
    floatMessage->setWidth(200);
    floatMessage->setWordWrap(true);
    floatMessage->setHorizontalAlign(TextArea::HORIZONTAL_ALIGN_CENTER);
    floatMessage->setFont(ResourceManager::font("font1.aaf", color));
    floatMessage->setOutlineColor(0x000000ff);
    object->setFloatMessage(floatMessage);

}