/
application.cpp
57 lines (44 loc) · 1.81 KB
/
application.cpp
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
#include "application.hpp"
#include <iostream>
#include <X11/Xlib.h>
Application::Application(int argc, char** argv) : QApplication(argc, argv) {
gdk_init (&argc, &argv);
}
Application::~Application() {}
void Application::init() {
b2Vec2 gravity(0.0f, 10.0f);
mWorld = QSharedPointer<b2World>(new b2World(gravity));
mWorld->SetAllowSleeping(false);
// Get windowing system
WnckScreen *screen;
WnckWindow *active_window;
WnckWorkspace *active_workspace;
GList *window_l;
screen = wnck_screen_get_default ();
wnck_screen_force_update (screen);
active_window = wnck_screen_get_active_window (screen);
active_workspace = wnck_screen_get_active_workspace (screen);
for(window_l = wnck_screen_get_windows (screen); window_l != NULL; window_l = window_l->next) {
WnckWindow *window = WNCK_WINDOW (window_l->data);
if(wnck_window_is_on_workspace(window, active_workspace) &&
!wnck_window_is_minimized(window) &&
wnck_window_get_window_type(window) == WNCK_WINDOW_NORMAL) {
mPhysicalWindows.append(QSharedPointer<PhysicalWindow>(new PhysicalWindow(window, mWorld)));
}
}
mPhysicalWindows.append(QSharedPointer<PhysicalWindow>(new PhysicalWindow(100, 100, 100, 100, mWorld)));
}
void Application::update() {
float32 timeStep = 1.0/60.f;
int32 velocityIterations = 6;
int32 positionIterations = 2;
mWorld->Step(timeStep, velocityIterations, positionIterations);
foreach(QSharedPointer<PhysicalWindow> physwin, mPhysicalWindows) {
physwin->update();
}
}
void Application::spawnStuff() {
int random = (qrand() % 50) + 10;
mPhysicalWindows.append(QSharedPointer<PhysicalWindow>(new PhysicalWindow(QCursor::pos().x(), QCursor::pos().y(),
random, random, mWorld)));
}