Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP #2

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
18 changes: 18 additions & 0 deletions kernel/EventHandler.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#pragma once

using MouseEventHandler = void (*)(MouseEvent&);

struct MouseEvent {
public:
Sheet *sheet;
Task *task;

MouseEvent(Sheet *sht, Task *t);
};

struct TaskEvent {
public:
Task *task;

TaskEvent(Task *t);
};
26 changes: 26 additions & 0 deletions kernel/GUI/GUITask.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once

class Screen {
private:
static union VRAM {
unsigned short *p16;
unsigned char (*p24)[3];
unsigned int *p32;
} vram;
Container container;

Screen() : container() {
// BootInfo から

// 描画
}
void refresh() {
// container の buf を vram に書き写し
}

public:
Screen &getInstance() {
static Screen instance = Screen();
return instance;
}
};
14 changes: 14 additions & 0 deletions kernel/GUI/LLGraphics.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#pragma once

namespace LLG {
drawLine
drawRect
drawCircle
fillRect
fillCircle
gradLine
gradRect
gradCircle
drawString
drawCharacter
};
23 changes: 23 additions & 0 deletions kernel/GUI/ModalWindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "../headers.h"

ModalWindow::ModalWindow(const string &msg) : sheet(new Sheet(Size(480, 300))), message(msg) {
// background and message
sheet->fillRect(sheet->frame, 0xffffff);
sheet->drawString(msg, Point((480 - msg.length() * 8) / 2, ((300 - 48 - 10) - 16) / 2), 0);

// button
Sheet *button = new Sheet(Size(64, 48), true);
button->fillRect(button->frame, 0xaaaaaa);
button->drawString("OK", Point((button->frame.size.width - 16) / 2, (button->frame.size.height - 16) / 2), 0);
button->borderRadius(true, true, true, true);
button->moveTo(Point((sheet->frame.size.width - button->frame.size.width) / 2, sheet->frame.size.height - button->frame.size.height - 10));
sheet->appendChild(button, true);
button->onClick = [](const Point &pos, Sheet &sheet) {
delete sheet.parent;
};

// show this window
sheet->moveTo(Point((SheetCtl::resolution.width - 480) / 2, (SheetCtl::resolution.height - 300) / 2));
SheetCtl::back->appendChild(sheet);
sheet->upDown(1);
}
11 changes: 11 additions & 0 deletions kernel/GUI/ModalWindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#pragma once
#include <SmartPointer.h>

class ModalWindow {
private:
unique_ptr<Sheet> sheet;
string message;

public:
ModalWindow(const string &msg);
};
105 changes: 105 additions & 0 deletions kernel/GUI/Tab.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#include "../headers.h"

Tab::Tab(const string &tabName) : index(SheetCtl::numOfTab++), tabBar(new Sheet(Size(150 - 2, 22), true)), sheet(new Sheet(Size(SheetCtl::resolution.width - 150, SheetCtl::resolution.height), false)), name(tabName) {
// タブ一覧に登録
SheetCtl::tabs[index] = this;

// 基本デザイン
sheet->fillRect(sheet->frame, 0xffffff);
sheet->drawRect(sheet->frame, 0);
sheet->moveTo(Point(150, 0));
SheetCtl::back->appendChild(sheet);

// タブバー初期化の続き
tabBar->tab = this;
tabBar->onClick = [](const Point &pos, Sheet &sht) {
if (2 <= pos.x && pos.x <= 2 + 22) {
// 閉じる
delete sht.tab;
} else if (sht.tab->index != SheetCtl::activeTab && 2 <= pos.x) {
// アクティブ化
sht.tab->active();
}
};
Rectangle newTabRange(2, 35 + 23 * index, 150 - 2, 22);
tabBar->fillRect(tabBar->frame, kActiveTabColor);
tabBar->borderRadius(true, false, true, false);
tabBar->drawLine(Line(7, 7, 15, 15), kActiveTextColor);
tabBar->drawLine(Line(7, 15, 15, 7), kActiveTextColor);
tabBar->drawString(string(tabName, 0, 15), Point(4 + 22, 4), kActiveTextColor);
tabBar->moveTo(Point(2, 35 + 23 * index));
SheetCtl::back->appendChild(tabBar);
tabBar->upDown(1);

// タブ切り替え
active();
}

Tab::Tab(const string &tabName, void (*mainLoop)(Tab *)) : Tab(tabName) {
int args[] = { (int)this };
_task = new Task(name, 3, 2, mainLoop, args);
}
Tab::Tab(const string &tabName, int queueSize, void (*mainLoop)(Tab *)) : Tab(tabName) {
int args[] = { (int)this };
_task = new Task(name, 3, 2, queueSize, mainLoop, args);
}

Tab::~Tab() {
// アクティブタブの調整
if (SheetCtl::activeTab == index) {
if (SheetCtl::numOfTab > 1) {
// アクティブタブでかつ他のタブがあれば,他のタブへ切り替える
if (SheetCtl::numOfTab - 1 == index) {
SheetCtl::tabs[index - 1]->active();
} else {
// 次のタブを選ばせる
SheetCtl::tabs[(SheetCtl::activeTab + 1) % SheetCtl::numOfTab]->active();
}
} else {
// 最後の1つのタブなら,SheetCtl::activeTab を -1 へ
SheetCtl::activeTab = -1;
}
}
if (SheetCtl::activeTab > index) {
--SheetCtl::activeTab;
}

// タブを閉じる
delete tabBar;

// タブをずらす
for (int i = index; i < SheetCtl::numOfTab - 1; ++i) {
SheetCtl::tabs[i] = SheetCtl::tabs[i + 1];
--SheetCtl::tabs[i]->index;
SheetCtl::tabs[i]->tabBar->moveTo(Point(SheetCtl::tabs[i]->tabBar->frame.offset.x, SheetCtl::tabs[i]->tabBar->frame.offset.y - 23));
}

// タブの個数を減らす
--SheetCtl::numOfTab;

// その他の解放
delete sheet;
if (_task) delete _task;
}

void Tab::active() {
if (SheetCtl::activeTab == index) return;

Rectangle tabRect(0, 0, tabBar->frame.size.width, tabBar->frame.size.height);

// 新しくアクティブになるタブ
tabBar->changeColor(tabRect, kPassiveTabColor, kActiveTabColor);
tabBar->changeColor(tabRect, kPassiveTextColor, kActiveTextColor);
tabBar->refresh(tabRect);
sheet->upDown(1);

// アクティブだったタブ
if (SheetCtl::activeTab >= 0) {
SheetCtl::tabs[SheetCtl::activeTab]->tabBar->changeColor(tabRect, kActiveTabColor, kPassiveTabColor);
SheetCtl::tabs[SheetCtl::activeTab]->tabBar->changeColor(tabRect, kActiveTextColor, kPassiveTextColor);
SheetCtl::tabs[SheetCtl::activeTab]->tabBar->refresh(tabRect);
SheetCtl::tabs[SheetCtl::activeTab]->sheet->upDown(-1);
}

SheetCtl::activeTab = index;
}
22 changes: 22 additions & 0 deletions kernel/GUI/Tab.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#pragma once

#include <pistring.h>

class Tab {
private:
Task *_task = nullptr;
int index;
Sheet *tabBar;

Tab(const string &tabName);

public:
Sheet *sheet;
string name;
Task *const &task = _task;

Tab(const string &tabName, void (*mainLoop)(Tab *));
Tab(const string &tabName, int queueSize, void (*mainLoop)(Tab *));
~Tab();
void active();
};
9 changes: 9 additions & 0 deletions kernel/GUI/Widget.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

class Widget {

};

class Container : public Widget {

};
Loading