mirror of
https://github.com/wichtounet/thor-os.git
synced 2025-09-10 21:14:38 -04:00
Review odin mouse support
This commit is contained in:
parent
bc460e91c5
commit
e0dc61693e
@ -12,6 +12,9 @@
|
|||||||
#include <tlib/print.hpp>
|
#include <tlib/print.hpp>
|
||||||
#include <tlib/malloc.hpp>
|
#include <tlib/malloc.hpp>
|
||||||
|
|
||||||
|
// TODO The order of the windows should be maintained by an
|
||||||
|
// intrusive list
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
uint32_t* z_buffer = nullptr;
|
uint32_t* z_buffer = nullptr;
|
||||||
@ -214,6 +217,10 @@ public:
|
|||||||
return mouse_x >= x && mouse_x <= x + width && mouse_y >= y + 2 && mouse_y <= mouse_y + 18;
|
return mouse_x >= x && mouse_x <= x + width && mouse_y >= y + 2 && mouse_y <= mouse_y + 18;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool inside(size_t look_x, size_t look_y){
|
||||||
|
return look_x >= x && look_x <= x + width && look_y >= y && look_y <= y + height;
|
||||||
|
}
|
||||||
|
|
||||||
void start_drag(){
|
void start_drag(){
|
||||||
if(!drag){
|
if(!drag){
|
||||||
drag = true;
|
drag = true;
|
||||||
@ -229,6 +236,26 @@ public:
|
|||||||
|
|
||||||
std::vector<window> windows;
|
std::vector<window> windows;
|
||||||
|
|
||||||
|
void raise(){
|
||||||
|
auto mouse_x = tlib::graphics::mouse_x();
|
||||||
|
auto mouse_y = tlib::graphics::mouse_y();
|
||||||
|
|
||||||
|
for(auto it = windows.begin(); it != windows.end(); ++it){
|
||||||
|
auto& window = *it;
|
||||||
|
|
||||||
|
if(window.inside(mouse_x, mouse_y)){
|
||||||
|
//If the window is not the first, we raise it
|
||||||
|
if(it != windows.begin()){
|
||||||
|
auto copy = window;
|
||||||
|
windows.erase(it);
|
||||||
|
windows.push_front(copy);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // end of anonnymous namespace
|
} // end of anonnymous namespace
|
||||||
|
|
||||||
int main(int /*argc*/, char* /*argv*/[]){
|
int main(int /*argc*/, char* /*argv*/[]){
|
||||||
@ -268,9 +295,10 @@ int main(int /*argc*/, char* /*argv*/[]){
|
|||||||
window.update();
|
window.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
for(auto& window : windows){
|
// Draw the window from back to front
|
||||||
|
std::for_each(windows.rbegin(), windows.rend(), [](window& window) {
|
||||||
window.draw();
|
window.draw();
|
||||||
}
|
});
|
||||||
|
|
||||||
paint_cursor();
|
paint_cursor();
|
||||||
|
|
||||||
@ -281,8 +309,6 @@ int main(int /*argc*/, char* /*argv*/[]){
|
|||||||
auto after = tlib::ms_time();
|
auto after = tlib::ms_time();
|
||||||
|
|
||||||
if(code != std::keycode::TIMEOUT){
|
if(code != std::keycode::TIMEOUT){
|
||||||
// TODO Handle event at this point
|
|
||||||
|
|
||||||
switch(code){
|
switch(code){
|
||||||
case std::keycode::RELEASED_ENTER: {
|
case std::keycode::RELEASED_ENTER: {
|
||||||
size_t width = width_dist(eng);
|
size_t width = width_dist(eng);
|
||||||
@ -298,10 +324,10 @@ int main(int /*argc*/, char* /*argv*/[]){
|
|||||||
case std::keycode::MOUSE_LEFT_PRESS:
|
case std::keycode::MOUSE_LEFT_PRESS:
|
||||||
tlib::user_logf("odin: left press");
|
tlib::user_logf("odin: left press");
|
||||||
|
|
||||||
for(auto& window: windows){
|
raise();
|
||||||
if(window.mouse_in_title()){
|
|
||||||
window.start_drag();
|
if(windows.front().mouse_in_title()){
|
||||||
}
|
windows.front().start_drag();
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@ -309,17 +335,21 @@ int main(int /*argc*/, char* /*argv*/[]){
|
|||||||
case std::keycode::MOUSE_LEFT_RELEASE:
|
case std::keycode::MOUSE_LEFT_RELEASE:
|
||||||
tlib::user_logf("odin: left release");
|
tlib::user_logf("odin: left release");
|
||||||
|
|
||||||
for(auto& window: windows){
|
raise();
|
||||||
window.stop_drag();
|
|
||||||
}
|
windows.front().stop_drag();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case std::keycode::MOUSE_RIGHT_PRESS:
|
case std::keycode::MOUSE_RIGHT_PRESS:
|
||||||
|
raise();
|
||||||
|
|
||||||
tlib::user_logf("odin: right press");
|
tlib::user_logf("odin: right press");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case std::keycode::MOUSE_RIGHT_RELEASE:
|
case std::keycode::MOUSE_RIGHT_RELEASE:
|
||||||
|
raise();
|
||||||
|
|
||||||
tlib::user_logf("odin: right release");
|
tlib::user_logf("odin: right release");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user