aboutsummaryrefslogtreecommitdiff
path: root/src/main.cpp
blob: 3cebfe703516abbca1e75a34e9654d7c05189e98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#include "../include/Channel.hpp"
#include "../include/ChannelSidePanel.hpp"
#include "../include/Cache.hpp"
#include "../include/ResourceCache.hpp"
#include "../include/Video.hpp"
#include <string>
#include <SFML/Graphics.hpp>
#include <cstring>
#include <X11/Xlib.h>
#include <boost/filesystem/path.hpp>

using namespace std;
using namespace dchat;
using namespace TinyProcessLib;

int main(int argc, char **argv)
{
    /*
    boost::filesystem::path programPath(argv[0]);
    auto parentPath = programPath.parent_path();
    printf("parent path: %s\n", parentPath.string().c_str());
    boost::filesystem::current_path(parentPath); // Ensures loading of resources works no matter which path we run this executable from
    */
    
    XInitThreads();
    sf::RenderWindow window(sf::VideoMode(1920, 1080), "dchat");
    window.setVerticalSyncEnabled(false);
    window.setFramerateLimit(60);
    
    //odhtdb::Database database("bootstrap.ring.cx", 4222, Cache::getDchatDir());
    //Video video(500, 500, "https://www.youtube.com/watch?v=bs0-EX9mJmg");
    
    Cache cache;
    
    Channel channel("latenightshiendjs");
    ChannelSidePanel channelSidePanel(300.0f);
    channelSidePanel.addChannel(&channel);
    
    sf::Event event;
    while (window.isOpen())
    {
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
                window.close();
            else if(event.type == sf::Event::Resized)
            {
                sf::FloatRect viewRect(0.0f, 0.0f, event.size.width, event.size.height);
                const int minWidth = 800;
                if(event.size.width < minWidth)
                {
                    viewRect.width = minWidth;
                    window.setSize(sf::Vector2u(minWidth, event.size.height));
                }
                
                sf::View view(viewRect);
                window.setView(view);
            }
            channel.processEvent(event);
        }

        window.clear(sf::Color(40, 40, 40));
        channel.draw(window, sf::Vector2f(channelSidePanel.width, 0.0f), cache);
        channelSidePanel.draw(window);
        //video.draw(window);
        window.display();
    }

    return 0;
}