Skip to content

Commit b9133ba

Browse files
committed
Update fenster & use new namespaces
1 parent 64a95bd commit b9133ba

File tree

17 files changed

+208
-185
lines changed

17 files changed

+208
-185
lines changed

applications/calculator/src/calculator.cpp

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -24,56 +24,59 @@
2424
#include <libwindow/textfield.hpp>
2525
#include <libwindow/ui.hpp>
2626
#include <libwindow/window.hpp>
27+
#include <libwindow/metrics/rectangle.hpp>
2728

2829
#include <algorithm>
2930
#include <sstream>
3031

31-
g_window* window;
32-
g_textfield* display;
33-
g_button* but1;
34-
g_button* but2;
35-
g_button* but3;
36-
g_button* but4;
37-
g_button* but5;
38-
g_button* but6;
39-
g_button* but7;
40-
g_button* but8;
41-
g_button* but9;
42-
g_button* but0;
43-
g_button* butPlus;
44-
g_button* butMinus;
45-
g_button* butMult;
46-
g_button* butDiv;
47-
g_button* butEq;
48-
g_button* butClear;
32+
using namespace fenster;
33+
34+
Window* window;
35+
TextField* display;
36+
Button* but1;
37+
Button* but2;
38+
Button* but3;
39+
Button* but4;
40+
Button* but5;
41+
Button* but6;
42+
Button* but7;
43+
Button* but8;
44+
Button* but9;
45+
Button* but0;
46+
Button* butPlus;
47+
Button* butMinus;
48+
Button* butMult;
49+
Button* butDiv;
50+
Button* butEq;
51+
Button* butClear;
4952

5053
double totalValue = 0;
5154
double currentValue = 0;
5255
int previousCommand = COM_NONE;
5356

5457
int main()
5558
{
56-
g_ui_open_status open_stat = g_ui::open();
59+
ApplicationOpenStatus open_stat = Application::open();
5760

58-
if(open_stat == G_UI_OPEN_STATUS_SUCCESSFUL)
61+
if(open_stat == FENSTER_APPLICATION_STATUS_SUCCESSFUL)
5962
{
60-
window = g_window::create();
63+
window = Window::create();
6164
window->setTitle("Calculator");
6265
window->setResizable(false);
6366
window->onClose([]()
6467
{
6568
g_exit(0);
6669
});
6770

68-
display = g_textfield::create();
71+
display = TextField::create();
6972
display->setTitle("0");
70-
display->setBounds(g_rectangle(10, 10, 150, 30));
73+
display->setBounds(Rectangle(10, 10, 150, 30));
7174
window->addChild(display);
7275

7376
#define PLACE_BUTTON_T(num, text, x, y) \
74-
but##num = g_button::create(); \
77+
but##num = Button::create(); \
7578
but##num->setTitle(text); \
76-
but##num->setBounds(g_rectangle(x, y, 30, 30)); \
79+
but##num->setBounds(Rectangle(x, y, 30, 30)); \
7780
window->addChild(but##num);
7881

7982
#define PLACE_BUTTON(num, x, y) PLACE_BUTTON_T(num, #num, x, y);
@@ -123,7 +126,7 @@ int main()
123126
PLACE_BUTTON_T(Eq, "=", grid4, grid5 + dispOff);
124127
butEq->setActionListener([]() { command_pressed(COM_EQ); });
125128

126-
window->setBounds(g_rectangle(70, 70, 190, 320));
129+
window->setBounds(Rectangle(70, 70, 190, 320));
127130
window->setVisible(true);
128131

129132
g_user_mutex lock = g_mutex_initialize();

applications/desktop/src/background.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include <cairo/cairo.h>
2323
#include <stdlib.h>
2424

25+
using namespace fenster;
26+
2527
background_t* background_t::create()
2628
{
2729
auto instance = createCanvasComponent<background_t>();
@@ -38,40 +40,40 @@ void background_t::init()
3840
paint();
3941
});
4042

41-
this->addMouseListener([this](g_ui_component_mouse_event* e)
43+
this->addMouseListener([this](ComponentMouseEvent* e)
4244
{
4345
auto position = e->position;
44-
if(e->type == G_MOUSE_EVENT_MOVE)
46+
if(e->type == FENSTER_MOUSE_EVENT_MOVE)
4547
{
4648
onMouseMove(position);
4749
}
48-
else if(e->type == G_MOUSE_EVENT_PRESS && e->buttons & G_MOUSE_BUTTON_1)
50+
else if(e->type == FENSTER_MOUSE_EVENT_PRESS && e->buttons & FENSTER_MOUSE_BUTTON_1)
4951
{
5052
onMouseLeftPress(position, e->clickCount);
5153
}
52-
else if(e->type == G_MOUSE_EVENT_DRAG && e->buttons & G_MOUSE_BUTTON_1)
54+
else if(e->type == FENSTER_MOUSE_EVENT_DRAG && e->buttons & FENSTER_MOUSE_BUTTON_1)
5355
{
5456
onMouseDrag(position);
5557
}
56-
else if(e->type == G_MOUSE_EVENT_RELEASE)
58+
else if(e->type == FENSTER_MOUSE_EVENT_RELEASE)
5759
{
5860
onMouseRelease(position);
5961
}
60-
else if(e->type == G_MOUSE_EVENT_LEAVE)
62+
else if(e->type == FENSTER_MOUSE_EVENT_LEAVE)
6163
{
6264
onMouseRelease(position);
6365
}
6466
});
6567

66-
selection = g_selection::create();
68+
selection = Selection::create();
6769
selection->setBounds(this->getBounds());
6870
selection->setVisible(false);
6971
this->addChild(selection);
7072

7173
this->organize();
7274
}
7375

74-
void background_t::onMouseMove(const g_point& position)
76+
void background_t::onMouseMove(const Point& position)
7577
{
7678
for(auto item: items)
7779
{
@@ -84,10 +86,10 @@ void background_t::onMouseMove(const g_point& position)
8486
}
8587
}
8688

87-
void background_t::onMouseLeftPress(const g_point& position, int clickCount)
89+
void background_t::onMouseLeftPress(const Point& position, int clickCount)
8890
{
8991
item_t* pressedItem = nullptr;
90-
std::vector<g_rectangle> itemsBounds;
92+
std::vector<Rectangle> itemsBounds;
9193
for(auto& item: items)
9294
{
9395
auto itemBounds = item->getBounds();
@@ -148,7 +150,7 @@ void background_t::onMouseLeftPress(const g_point& position, int clickCount)
148150
}
149151
}
150152

151-
void background_t::onMouseDrag(const g_point& position)
153+
void background_t::onMouseDrag(const Point& position)
152154
{
153155
if(dragItems)
154156
{
@@ -157,21 +159,21 @@ void background_t::onMouseDrag(const g_point& position)
157159
if(item->selected)
158160
{
159161
auto point = position - item->dragOffset;
160-
item->setBounds(g_rectangle(point.x, point.y, 100, 100));
162+
item->setBounds(Rectangle(point.x, point.y, 100, 100));
161163
}
162164
}
163165
}
164166
else
165167
{
166-
g_rectangle bounds(selectionStart.x, selectionStart.y, position.x - selectionStart.x,
168+
Rectangle bounds(selectionStart.x, selectionStart.y, position.x - selectionStart.x,
167169
position.y - selectionStart.y);
168170
auto boundsNorm = bounds.asNormalized();
169171
selection->setBounds(boundsNorm);
170172
selection->setVisible(true);
171173

172174
for(auto item: items)
173175
{
174-
g_rectangle rect = item->getBounds();
176+
Rectangle rect = item->getBounds();
175177
if(boundsNorm.intersects(rect))
176178
{
177179
auto wasSelected = item->selected;
@@ -190,7 +192,7 @@ void background_t::onMouseDrag(const g_point& position)
190192
}
191193
}
192194

193-
void background_t::onMouseRelease(const g_point& position)
195+
void background_t::onMouseRelease(const Point& position)
194196
{
195197
if(dragItems)
196198
dragItems = false;
@@ -240,7 +242,7 @@ void background_t::paint()
240242
cairo_rectangle(cr, bgX, bgY, bounds.width, bounds.height);
241243
cairo_fill(cr);
242244

243-
this->blit(g_rectangle(0, 0, bounds.width, bounds.height));
245+
this->blit(Rectangle(0, 0, bounds.width, bounds.height));
244246

245247
this->releaseGraphics();
246248
}

applications/desktop/src/background.hpp

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,28 +30,30 @@
3030
#include <libwindow/selection.hpp>
3131
#include <vector>
3232

33-
class background_t : virtual public g_canvas
33+
using namespace fenster;
34+
35+
class background_t : virtual public Canvas
3436
{
3537
protected:
3638
void init();
3739

3840
taskbar_t* taskbar;
3941
std::vector<item_t*> items;
40-
void onMouseMove(const g_point& position);
42+
void onMouseMove(const Point& position);
4143
bool dragItems;
42-
g_point selectionStart;
43-
g_selection* selection = nullptr;
44+
Point selectionStart;
45+
Selection* selection = nullptr;
4446
item_organizer_t* organizer = nullptr;
4547

46-
void onMouseLeftPress(const g_point& position, int clickCount);
47-
void onMouseDrag(const g_point& position);
48-
void onMouseRelease(const g_point& position);
48+
void onMouseLeftPress(const Point& position, int clickCount);
49+
void onMouseDrag(const Point& position);
50+
void onMouseRelease(const Point& position);
4951

5052
public:
51-
explicit background_t(g_ui_component_id id):
52-
g_component(id),
53-
g_canvas(id), dragItems(false),
54-
g_focusable_component(id)
53+
explicit background_t(ComponentId id):
54+
Component(id),
55+
Canvas(id), dragItems(false),
56+
FocusableComponent(id)
5557
{
5658
}
5759

applications/desktop/src/desktop.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,30 +23,31 @@
2323
#include "taskbar.hpp"
2424

2525
#include <fstream>
26-
#include <libproperties/parser.hpp>
26+
#include <libproperties/properties.hpp>
2727

2828
#define USER_DESKTOP_DIR "/user/desktop/"
2929

30+
using namespace fenster;
3031
background_t* background = nullptr;
3132
taskbar_t* taskbar = nullptr;
3233

3334
int main()
3435
{
35-
if(g_ui::open() != G_UI_OPEN_STATUS_SUCCESSFUL)
36+
if(Application::open() != FENSTER_APPLICATION_STATUS_SUCCESSFUL)
3637
{
3738
klog("failed to create UI");
3839
return -1;
3940
}
4041

4142
background = background_t::create();
42-
g_ui::registerDesktopCanvas(background);
43+
Application::registerDesktopCanvas(background);
4344

44-
g_dimension screenDimension;
45-
g_ui::getScreenDimension(screenDimension);
45+
Dimension screenDimension;
46+
Application::getScreenDimension(screenDimension);
4647
taskbar = taskbar_t::create();
47-
taskbar->setBounds(g_rectangle(0, screenDimension.height - 40, screenDimension.width, 40));
48+
taskbar->setBounds(Rectangle(0, screenDimension.height - 40, screenDimension.width, 40));
4849
background->addTaskbar(taskbar);
49-
background->setDesktopListener([](g_ui_windows_event* event)
50+
background->setDesktopListener([](WindowsEvent* event)
5051
{
5152
taskbar->handleDesktopEvent(event);
5253
});
@@ -70,12 +71,12 @@ void desktopLoadItems()
7071
std::string path = std::string(USER_DESKTOP_DIR) + entry->name;
7172

7273
std::ifstream cfg(path);
73-
g_properties_parser parser(cfg);
74+
properties::Properties parser(cfg);
7475
auto properties = parser.getProperties();
7576

7677
auto item = item_t::create(properties["name"], properties["icon"], properties["application"]);
7778
background->addItem(item);
78-
item->setBounds(g_rectangle(0, next++ * 100, 100, 100));
79+
item->setBounds(Rectangle(0, next++ * 100, 100, 100));
7980
}
8081
background->organize();
8182
}

applications/desktop/src/item.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,12 @@
2525
#include <libwindow/color_argb.hpp>
2626
#include <helper.hpp>
2727

28+
using namespace fenster;
29+
2830
item_t::item_t(uint32_t id):
29-
g_component(id),
30-
g_canvas(id),
31-
g_focusable_component(id)
31+
Component(id),
32+
Canvas(id),
33+
FocusableComponent(id)
3234
{
3335
this->setBufferListener([this]()
3436
{
@@ -53,11 +55,11 @@ void item_t::init(std::string name, std::string icon, std::string application)
5355
iconSurface = nullptr;
5456
}
5557

56-
label = g_label::create();
58+
label = Label::create();
5759
label->setTitle(name.c_str());
58-
label->setBounds(g_rectangle(0, 75, 100, 20));
60+
label->setBounds(Rectangle(0, 75, 100, 20));
5961
label->setColor(ARGB(255, 255, 255, 255));
60-
label->setAlignment(g_text_alignment::CENTER);
62+
label->setAlignment(TextAlignment::CENTER);
6163
this->addChild(label);
6264
}
6365

@@ -97,7 +99,7 @@ void item_t::paint()
9799
}
98100

99101
this->releaseGraphics();
100-
this->blit(g_rectangle(0, 0, bounds.width, bounds.height));
102+
this->blit(Rectangle(0, 0, bounds.width, bounds.height));
101103
}
102104

103105
void item_t::onDoubleClick()

applications/desktop/src/item.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,13 @@
2525
#include <libwindow/label.hpp>
2626
#include <cairo/cairo.h>
2727

28-
class item_t : virtual public g_canvas
28+
using namespace fenster;
29+
30+
class item_t : virtual public Canvas
2931
{
3032
protected:
3133
cairo_surface_t* iconSurface = nullptr;
32-
g_label* label = nullptr;
34+
Label* label = nullptr;
3335
std::string application;
3436

3537
void init(std::string name, std::string icon, std::string application);
@@ -39,7 +41,7 @@ class item_t : virtual public g_canvas
3941

4042
bool hover = false;
4143
bool selected = false;
42-
g_point dragOffset;
44+
Point dragOffset;
4345

4446
static item_t* create(std::string name, std::string icon, std::string application);
4547

applications/desktop/src/item_organizer.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@
2121

2222
#include "item_organizer.hpp"
2323

24-
void item_organizer_t::organize(const std::vector<item_t*>& items, const g_rectangle& backgroundBounds) const
24+
using namespace fenster;
25+
26+
void item_organizer_t::organize(const std::vector<item_t*>& items, const Rectangle& backgroundBounds) const
2527
{
26-
std::vector<g_rectangle> allBounds;
28+
std::vector<Rectangle> allBounds;
2729
for(auto& item: items)
2830
{
2931
auto bounds = item->getBounds();

0 commit comments

Comments
 (0)