-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTerminalBrowser.h
109 lines (81 loc) · 2.17 KB
/
TerminalBrowser.h
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#ifndef TERMINALBROWSER_H
#define TERMINALBROWSER_H
#include <iostream>
#include "AwesomiumPanel.h"
#include "Misc.h"
class TerminalBrowser
{
public:
TerminalBrowser(int windowWith, int windowHeight, int terminalWidth, int terminalHeight)
{
m_terminalWidth = terminalWidth;
m_terminalHeight = terminalHeight;
m_panel = new AwesomiumPanel(windowWith, windowHeight);
isDirty = true;
m_pageX = 0;
m_pageY = 0;
}
~TerminalBrowser()
{
delete m_panel;
}
void LoadURL(const std::string &URL)
{
m_panel->LoadURL(URL);
}
bool IsDirty() //if the page needs to be rendered again..
{
return m_panel->IsDirty() || isDirty;
}
void Update()
{
m_panel->Update();
}
void Render()
{
isDirty = false;
int panelWidth = m_panel->GetWidth();
//int panelHeight = m_panel->GetHeight();
const unsigned char *buff = m_panel->GetBuffer();
if(buff == NULL) { return; }
//int offset = 0;
for(int y = 0; y < m_terminalHeight; y++)
{
for(int x = 0; x < m_terminalWidth; x++)
{
int i = (y * m_terminalWidth + x + m_pageX + y * (panelWidth - m_terminalWidth)) * 4; // TOTO: take into account pageY, can only scroll from left to right
gotoXY(x*2, y);
int c = 32 + (buff[i] + buff[i+1] + buff[i+2]) / (float)(255*3) * 10;
std::cout << "\033[" << c << ";30m";
std::cout << " ";
std::cout << "\033[0m";
}
}
}
void SetPageX(int x)
{
if(x != m_pageX) isDirty = true;
m_pageX = x;
}
void SetPageY(int y)
{
if(y != m_pageY) isDirty = true;
m_pageY = y;
}
int GetPageX()
{
return m_pageX;
}
int GetPageY()
{
return m_pageY;
}
private:
int m_terminalWidth; //Width & Height of the rendering window in the terminal
int m_terminalHeight;
int m_pageX; //The location of the window on the webpage
int m_pageY;
bool isDirty;
AwesomiumPanel *m_panel;
};
#endif