-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
239 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
#include <nekosys.h> | ||
#include <libgui/application.h> | ||
#include <libgui/packets.h> | ||
|
||
using namespace Gui; | ||
|
||
Application::Application() | ||
{ | ||
} | ||
|
||
void Application::Run() | ||
{ | ||
while (!exitRequested) | ||
{ | ||
connection.Receive(); | ||
} | ||
} | ||
|
||
void Application::Exit() | ||
{ | ||
exitRequested = true; | ||
} | ||
|
||
void Application::OpenWindow(Window &win) | ||
{ | ||
PCreateWindow packet{}; | ||
packet.width = win.width; | ||
packet.height = win.height; | ||
memcpy(packet.title, win.title.CStr(), win.title.Length()); | ||
connection.Send(ID_PCreateWindow, sizeof(packet), &packet); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#include <nekosys.h> | ||
#include <string.h> | ||
#include <libgui/guiconnection.h> | ||
|
||
using namespace Gui; | ||
|
||
GuiConnection::GuiConnection() | ||
{ | ||
recvBuffer = new uint8_t[16384]; | ||
pipe = pipe_open("sakura"); | ||
} | ||
|
||
GuiConnection::~GuiConnection() | ||
{ | ||
delete[] recvBuffer; | ||
pipe_close(pipe); | ||
} | ||
|
||
void GuiConnection::Send(uint8_t packetId, size_t size, void *data) | ||
{ | ||
uint8_t *packet = new uint8_t[size + 1]; | ||
packet[0] = packetId; | ||
memcpy(packet + 1, data, size); | ||
pipe_send(pipe, 0, size + 1, packet); | ||
delete[] packet; | ||
} | ||
|
||
PacketData GuiConnection::Receive() | ||
{ | ||
PacketData data{}; | ||
int size = pipe_recv(pipe, &data.source, 16384, recvBuffer) - 1; | ||
data.packetId = recvBuffer[0]; | ||
data.size = size; | ||
data.data = recvBuffer + 1; | ||
return data; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef _APPLICATION_H | ||
#define _APPLICATION_H | ||
|
||
#include <libgui/window.h> | ||
#include <libgui/guiconnection.h> | ||
|
||
namespace Gui | ||
{ | ||
|
||
class Application | ||
{ | ||
private: | ||
GuiConnection connection; | ||
|
||
bool exitRequested; | ||
|
||
public: | ||
Application(); | ||
|
||
void Run(); | ||
|
||
void Exit(); | ||
|
||
void OpenWindow(Window &window); | ||
}; | ||
|
||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#ifndef _GUI_CONNECTION_H | ||
#define _GUI_CONNECTION_H | ||
|
||
#include <stdint.h> | ||
#include <sys/types.h> | ||
|
||
namespace Gui | ||
{ | ||
struct PacketData | ||
{ | ||
uint8_t packetId; | ||
pid_t source; | ||
size_t size; | ||
void *data; | ||
}; | ||
|
||
class GuiConnection | ||
{ | ||
private: | ||
int pipe; | ||
|
||
uint8_t *recvBuffer; | ||
|
||
public: | ||
GuiConnection(); | ||
|
||
~GuiConnection(); | ||
|
||
void Send(uint8_t packetId, size_t size, void *data); | ||
|
||
PacketData Receive(); | ||
}; | ||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef _PACKETS_H | ||
#define _PACKETS_H | ||
|
||
#include <stdint.h> | ||
|
||
#define ID_PCreateWindow 1 | ||
|
||
namespace Gui | ||
{ | ||
|
||
struct PCreateWindow | ||
{ | ||
int width; | ||
int height; | ||
char title[128]; | ||
}; | ||
|
||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef _WINDOW_H | ||
#define _WINDOW_H | ||
|
||
#include <nk/string.h> | ||
|
||
namespace Gui | ||
{ | ||
|
||
class Window | ||
{ | ||
public: | ||
nk::String title; | ||
int width; | ||
int height; | ||
|
||
Window(const nk::String &title, int width, int height); | ||
}; | ||
|
||
}; | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#include <libgui/window.h> | ||
|
||
using namespace Gui; | ||
|
||
Window::Window(const nk::String &title, int width, int height) | ||
: title(title), width(width), height(height) | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
#!/bin/bash | ||
neko-gcc -std=gnu++11 -fno-exceptions main.cpp -lgui -o ../../sysroot/bin/hellogui |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <libgui/application.h> | ||
|
||
int main() | ||
{ | ||
Gui::Application application; | ||
|
||
Gui::Window window("Test", 128, 128); | ||
application.OpenWindow(window); | ||
|
||
application.Run(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
#!/bin/bash | ||
neko-gcc -std=gnu++11 -fno-exceptions main.cpp -o ../../sysroot/bin/sakura | ||
neko-gcc -std=gnu++11 -fno-exceptions main.cpp -lgui -o ../../sysroot/bin/sakura |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters