mirror of
https://github.com/edeproject/ede.git
synced 2023-08-10 21:13:03 +03:00
Made correctly working selection box
This commit is contained in:
parent
0c8e41bd37
commit
9c4fb55bc7
@ -22,6 +22,11 @@ Atom NET_NUMBER_OF_DESKTOPS = 0;
|
|||||||
Atom NET_CURRENT_DESKTOP = 0;
|
Atom NET_CURRENT_DESKTOP = 0;
|
||||||
Atom NET_DESKTOP_NAMES = 0;
|
Atom NET_DESKTOP_NAMES = 0;
|
||||||
|
|
||||||
|
int overlay_x = 0;
|
||||||
|
int overlay_y = 0;
|
||||||
|
int overlay_w = 0;
|
||||||
|
int overlay_h = 0;
|
||||||
|
|
||||||
bool net_get_workarea(int& x, int& y, int& w, int &h) {
|
bool net_get_workarea(int& x, int& y, int& w, int &h) {
|
||||||
Atom real;
|
Atom real;
|
||||||
|
|
||||||
@ -173,3 +178,51 @@ int net_get_workspace_names(char** names) {
|
|||||||
return alloc;
|
return alloc;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void draw_overlay_rect(void) {
|
||||||
|
if(overlay_w <= 0 || overlay_h <= 0)
|
||||||
|
return;
|
||||||
|
XSetFunction(fltk::xdisplay, fltk::gc, GXxor);
|
||||||
|
XSetForeground(fltk::xdisplay, fltk::gc, 0xffffffff);
|
||||||
|
XDrawRectangle(fltk::xdisplay, fltk::xwindow, fltk::gc, overlay_x, overlay_y, overlay_w-1, overlay_h-1);
|
||||||
|
XSetFunction(fltk::xdisplay, fltk::gc, GXcopy);
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_xoverlay(int x, int y, int w, int h) {
|
||||||
|
if(w < 0) {
|
||||||
|
x += w;
|
||||||
|
w = -w;
|
||||||
|
} else if(!w)
|
||||||
|
w = 1;
|
||||||
|
|
||||||
|
if(h < 0) {
|
||||||
|
y += h;
|
||||||
|
h = -h;
|
||||||
|
} else if(!h)
|
||||||
|
h = 1;
|
||||||
|
|
||||||
|
//if(overlay_w <= 0 || overlay_h <= 0) {
|
||||||
|
if(overlay_w > 0) {
|
||||||
|
if(x == overlay_x && y == overlay_y && w == overlay_w && h == overlay_h)
|
||||||
|
return;
|
||||||
|
draw_overlay_rect();
|
||||||
|
}
|
||||||
|
|
||||||
|
overlay_x = x;
|
||||||
|
overlay_y = y;
|
||||||
|
overlay_w = w;
|
||||||
|
overlay_h = h;
|
||||||
|
|
||||||
|
draw_overlay_rect();
|
||||||
|
}
|
||||||
|
|
||||||
|
void clear_xoverlay(void) {
|
||||||
|
if(overlay_w > 0) {
|
||||||
|
draw_overlay_rect();
|
||||||
|
overlay_w = 0;
|
||||||
|
}
|
||||||
|
/*
|
||||||
|
overlay_x = overlay_y = overlay_w = overlay_h = 0;
|
||||||
|
draw_overlay_rect();
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
@ -21,4 +21,7 @@ bool net_get_workarea(int& x, int& y, int& w, int &h);
|
|||||||
void net_make_me_desktop(fltk::Window* w);
|
void net_make_me_desktop(fltk::Window* w);
|
||||||
int net_get_workspace_names(char**& names);
|
int net_get_workspace_names(char**& names);
|
||||||
|
|
||||||
|
void draw_xoverlay(int x, int y, int w, int h);
|
||||||
|
void clear_xoverlay(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -99,9 +99,9 @@ Desktop::Desktop() : fltk::Window(0, 0, 100, 100, "")
|
|||||||
{
|
{
|
||||||
moving = false;
|
moving = false;
|
||||||
|
|
||||||
selection_box_x_start = selection_box_y_start = 0;
|
selbox = new SelectionOverlay;
|
||||||
selection_box_x = selection_box_y = 0;
|
selbox->x = selbox->y = selbox->w = selbox->h = 0;
|
||||||
selection_box_show = false;
|
selbox->show = false;
|
||||||
|
|
||||||
// fallback if update_workarea() fails
|
// fallback if update_workarea() fails
|
||||||
int dw, dh;
|
int dw, dh;
|
||||||
@ -143,6 +143,9 @@ Desktop::~Desktop()
|
|||||||
{
|
{
|
||||||
EDEBUG(ESTRLOC ": Desktop::~Desktop()\n");
|
EDEBUG(ESTRLOC ": Desktop::~Desktop()\n");
|
||||||
|
|
||||||
|
if(selbox)
|
||||||
|
delete selbox;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* icons member deleting is not needed, since add_icon will
|
* icons member deleting is not needed, since add_icon will
|
||||||
* append to icons and to fltk::Group array. Desktop at the end
|
* append to icons and to fltk::Group array. Desktop at the end
|
||||||
@ -159,6 +162,7 @@ void Desktop::update_workarea(void) {
|
|||||||
int X,Y,W,H;
|
int X,Y,W,H;
|
||||||
if(net_get_workarea(X, Y, W, H))
|
if(net_get_workarea(X, Y, W, H))
|
||||||
resize(X,Y,W,H);
|
resize(X,Y,W,H);
|
||||||
|
EDEBUG(ESTRLOC ": area: %i %i %i %i\n", X,Y,W,H);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Desktop::read_config(void) {
|
void Desktop::read_config(void) {
|
||||||
@ -453,36 +457,14 @@ void Desktop::select_only(DesktopIcon* ic) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Desktop::draw(void) {
|
void Desktop::draw(void) {
|
||||||
if(damage() & fltk::DAMAGE_ALL) {
|
if(damage() & fltk::DAMAGE_ALL)
|
||||||
fltk::Window::draw();
|
fltk::Window::draw();
|
||||||
fltk::overlay_clear();
|
|
||||||
}
|
|
||||||
|
|
||||||
if(damage() & (fltk::DAMAGE_ALL|fltk::DAMAGE_VALUE)) {
|
if(damage() & (fltk::DAMAGE_ALL|fltk::DAMAGE_VALUE)) {
|
||||||
if(selection_box_show) {
|
clear_xoverlay();
|
||||||
fltk::Rectangle selrect(selection_box_x_start, selection_box_y_start, selection_box_x, selection_box_y);
|
|
||||||
fltk::overlay_rect(selrect.x(), selrect.y(), selrect.w(), selrect.h());
|
|
||||||
|
|
||||||
/*dd
|
if(selbox->show)
|
||||||
fltk::line_style(fltk::DOT);
|
draw_xoverlay(selbox->x, selbox->y, selbox->w, selbox->h);
|
||||||
|
|
||||||
fltk::push_matrix();
|
|
||||||
fltk::setcolor(gisett.label_foreground);
|
|
||||||
fltk::addvertex(selrect.x(),selrect.y());
|
|
||||||
fltk::addvertex(selrect.x() + selrect.w(), selrect.y());
|
|
||||||
//fltk::addvertex(X+lwidth,Y+lheight);
|
|
||||||
fltk::addvertex(selrect.x() + selrect.w(), selrect.y() + selrect.h());
|
|
||||||
fltk::addvertex(selrect.x(), selrect.y() + selrect.h());
|
|
||||||
fltk::addvertex(selection_box_x_start,selection_box_y_start);
|
|
||||||
fltk::addvertex(selrect.x(),selrect.y());
|
|
||||||
fltk::strokepath();
|
|
||||||
|
|
||||||
fltk::pop_matrix();
|
|
||||||
|
|
||||||
// revert to default line style
|
|
||||||
fltk::line_style(0);
|
|
||||||
*/
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -509,9 +491,10 @@ int Desktop::handle(int event) {
|
|||||||
|
|
||||||
// track position so moving can be deduced
|
// track position so moving can be deduced
|
||||||
if(fltk::event_button() == 1) {
|
if(fltk::event_button() == 1) {
|
||||||
selection_box_x_start = fltk::event_x_root();
|
selbox->x = fltk::event_x();
|
||||||
selection_box_y_start = fltk::event_y_root();
|
selbox->y = fltk::event_y();
|
||||||
}
|
}
|
||||||
|
EDEBUG("overlay: %i %i %i %i\n", selbox->x, selbox->y, selbox->w, selbox->h);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@ -560,12 +543,13 @@ int Desktop::handle(int event) {
|
|||||||
} else {
|
} else {
|
||||||
EDEBUG(ESTRLOC ": DRAG from desktop\n");
|
EDEBUG(ESTRLOC ": DRAG from desktop\n");
|
||||||
|
|
||||||
selection_box_x = fltk::event_x_root() - selection_box_x_start;
|
|
||||||
selection_box_y = fltk::event_y_root() - selection_box_y_start;
|
|
||||||
|
|
||||||
// moving is started
|
// moving is started
|
||||||
if(selection_box_x != 0 || selection_box_y != 0) {
|
if(selbox->x != 0 || selbox->y != 0) {
|
||||||
selection_box_show = true;
|
selbox->w = fltk::event_x() - selbox->x;
|
||||||
|
selbox->h = fltk::event_y() - selbox->y;
|
||||||
|
|
||||||
|
selbox->show = true;
|
||||||
redraw(fltk::DAMAGE_VALUE);
|
redraw(fltk::DAMAGE_VALUE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -576,10 +560,11 @@ int Desktop::handle(int event) {
|
|||||||
EDEBUG(ESTRLOC ": RELEASE from desktop\n");
|
EDEBUG(ESTRLOC ": RELEASE from desktop\n");
|
||||||
EDEBUG(ESTRLOC ": clicks: %i\n", fltk::event_is_click());
|
EDEBUG(ESTRLOC ": clicks: %i\n", fltk::event_is_click());
|
||||||
|
|
||||||
if(selection_box_show) {
|
if(selbox->show) {
|
||||||
selection_box_show = false;
|
EDEBUG("overlay: %i %i %i %i\n", selbox->x, selbox->y, selbox->w, selbox->h);
|
||||||
selection_box_x = selection_box_y = selection_box_x_start = selection_box_y_start = 0;
|
selbox->w = selbox->h = 0;
|
||||||
redraw(fltk::DAMAGE_ALL);
|
selbox->show = false;
|
||||||
|
redraw(fltk::DAMAGE_VALUE);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,6 +52,11 @@ struct IconSettings {
|
|||||||
edelib::String desktop_name; // name used as key when storing positions
|
edelib::String desktop_name; // name used as key when storing positions
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// selection overlay
|
||||||
|
struct SelectionOverlay {
|
||||||
|
int x, y, w, h;
|
||||||
|
bool show;
|
||||||
|
};
|
||||||
|
|
||||||
class DesktopIcon;
|
class DesktopIcon;
|
||||||
|
|
||||||
@ -65,11 +70,7 @@ class Desktop : public fltk::Window {
|
|||||||
int selection_x;
|
int selection_x;
|
||||||
int selection_y;
|
int selection_y;
|
||||||
|
|
||||||
int selection_box_x_start;
|
SelectionOverlay* selbox;
|
||||||
int selection_box_y_start;
|
|
||||||
int selection_box_x;
|
|
||||||
int selection_box_y;
|
|
||||||
bool selection_box_show;
|
|
||||||
|
|
||||||
//DesktopSettings* dsett;
|
//DesktopSettings* dsett;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user