Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
fe03decb
Commit
fe03decb
authored
Feb 11, 2014
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Now you can ctrl+left click on a rectangle in the image_display to change its
label.
parent
1f35b44d
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
89 additions
and
2 deletions
+89
-2
widgets.cpp
dlib/gui_widgets/widgets.cpp
+63
-2
widgets.h
dlib/gui_widgets/widgets.h
+24
-0
widgets_abstract.h
dlib/gui_widgets/widgets_abstract.h
+2
-0
No files found.
dlib/gui_widgets/widgets.cpp
View file @
fe03decb
...
@@ -5690,10 +5690,13 @@ namespace dlib
...
@@ -5690,10 +5690,13 @@ namespace dlib
default_rect_color
(
255
,
0
,
0
,
255
),
default_rect_color
(
255
,
0
,
0
,
255
),
parts_menu
(
w
),
parts_menu
(
w
),
part_width
(
15
),
// width part circles are drawn on the screen
part_width
(
15
),
// width part circles are drawn on the screen
overlay_editing_enabled
(
true
)
overlay_editing_enabled
(
true
),
highlight_timer
(
*
this
,
&
image_display
::
timer_event_unhighlight_rect
),
highlighted_rect
(
std
::
numeric_limits
<
unsigned
long
>::
max
())
{
{
enable_mouse_drag
();
enable_mouse_drag
();
highlight_timer
.
set_delay_time
(
250
);
set_horizontal_scroll_increment
(
1
);
set_horizontal_scroll_increment
(
1
);
set_vertical_scroll_increment
(
1
);
set_vertical_scroll_increment
(
1
);
set_horizontal_mouse_wheel_scroll_increment
(
30
);
set_horizontal_mouse_wheel_scroll_increment
(
30
);
...
@@ -5744,6 +5747,7 @@ namespace dlib
...
@@ -5744,6 +5747,7 @@ namespace dlib
~
image_display
(
~
image_display
(
)
)
{
{
highlight_timer
.
stop_and_wait
();
disable_events
();
disable_events
();
parent
.
invalidate_rectangle
(
rect
);
parent
.
invalidate_rectangle
(
rect
);
}
}
...
@@ -5943,9 +5947,37 @@ namespace dlib
...
@@ -5943,9 +5947,37 @@ namespace dlib
const
rectangle
orect
=
get_rect_on_screen
(
i
);
const
rectangle
orect
=
get_rect_on_screen
(
i
);
if
(
rect_is_selected
&&
selected_rect
==
i
)
if
(
rect_is_selected
&&
selected_rect
==
i
)
{
draw_rectangle
(
c
,
orect
,
invert_pixel
(
overlay_rects
[
i
].
color
),
area
);
draw_rectangle
(
c
,
orect
,
invert_pixel
(
overlay_rects
[
i
].
color
),
area
);
}
else
if
(
highlighted_rect
<
overlay_rects
.
size
()
&&
highlighted_rect
==
i
)
{
// Draw the rectangle wider and with a slightly different color that tapers
// out at the edges of the line.
hsi_pixel
temp
;
assign_pixel
(
temp
,
0
);
assign_pixel
(
temp
,
overlay_rects
[
i
].
color
);
temp
.
s
=
255
;
temp
.
h
=
temp
.
h
+
20
;
if
(
temp
.
i
<
245
)
temp
.
i
+=
10
;
rgb_pixel
p
;
assign_pixel
(
p
,
temp
);
rgb_alpha_pixel
po
,
po2
;
assign_pixel
(
po
,
p
);
po
.
alpha
=
160
;
po2
=
po
;
po2
.
alpha
=
90
;
draw_rectangle
(
c
,
grow_rect
(
orect
,
2
),
po2
,
area
);
draw_rectangle
(
c
,
grow_rect
(
orect
,
1
),
po
,
area
);
draw_rectangle
(
c
,
orect
,
p
,
area
);
draw_rectangle
(
c
,
shrink_rect
(
orect
,
1
),
po
,
area
);
draw_rectangle
(
c
,
shrink_rect
(
orect
,
2
),
po2
,
area
);
}
else
else
{
draw_rectangle
(
c
,
orect
,
overlay_rects
[
i
].
color
,
area
);
draw_rectangle
(
c
,
orect
,
overlay_rects
[
i
].
color
,
area
);
}
if
(
overlay_rects
[
i
].
label
.
size
()
!=
0
)
if
(
overlay_rects
[
i
].
label
.
size
()
!=
0
)
{
{
...
@@ -6131,6 +6163,36 @@ namespace dlib
...
@@ -6131,6 +6163,36 @@ namespace dlib
return
;
return
;
}
}
if
(
btn
==
base_window
::
LEFT
&&
(
state
&
base_window
::
CONTROL
)
&&
!
drawing_rect
)
{
long
best_dist
=
std
::
numeric_limits
<
long
>::
max
();
long
best_idx
=
0
;
// check if this click landed on any of the overlay rectangles
for
(
unsigned
long
i
=
0
;
i
<
overlay_rects
.
size
();
++
i
)
{
const
rectangle
orect
=
get_rect_on_screen
(
i
);
const
long
dist
=
distance_to_rect_edge
(
orect
,
point
(
x
,
y
));
if
(
dist
<
best_dist
)
{
best_dist
=
dist
;
best_idx
=
i
;
}
}
if
(
best_dist
<
13
)
{
overlay_rects
[
best_idx
].
label
=
default_rect_label
;
highlighted_rect
=
best_idx
;
highlight_timer
.
stop
();
highlight_timer
.
start
();
if
(
event_handler
.
is_set
())
event_handler
();
parent
.
invalidate_rectangle
(
rect
);
}
return
;
}
if
(
!
is_double_click
&&
btn
==
base_window
::
LEFT
&&
(
state
&
base_window
::
SHIFT
))
if
(
!
is_double_click
&&
btn
==
base_window
::
LEFT
&&
(
state
&
base_window
::
SHIFT
))
{
{
drawing_rect
=
true
;
drawing_rect
=
true
;
...
@@ -6156,7 +6218,6 @@ namespace dlib
...
@@ -6156,7 +6218,6 @@ namespace dlib
}
}
else
if
(
is_double_click
)
else
if
(
is_double_click
)
{
{
const
point
origin
(
total_rect
().
tl_corner
());
const
bool
rect_was_selected
=
rect_is_selected
;
const
bool
rect_was_selected
=
rect_is_selected
;
rect_is_selected
=
false
;
rect_is_selected
=
false
;
parts_menu
.
disable
();
parts_menu
.
disable
();
...
...
dlib/gui_widgets/widgets.h
View file @
fe03decb
...
@@ -3530,6 +3530,28 @@ namespace dlib
...
@@ -3530,6 +3530,28 @@ namespace dlib
rgb_alpha_pixel
invert_pixel
(
const
rgb_alpha_pixel
&
p
)
const
rgb_alpha_pixel
invert_pixel
(
const
rgb_alpha_pixel
&
p
)
const
{
return
rgb_alpha_pixel
(
255
-
p
.
red
,
255
-
p
.
green
,
255
-
p
.
blue
,
p
.
alpha
);
}
{
return
rgb_alpha_pixel
(
255
-
p
.
red
,
255
-
p
.
green
,
255
-
p
.
blue
,
p
.
alpha
);
}
virtual
int
next_free_user_event_number
(
)
const
{
return
scrollable_region
::
next_free_user_event_number
()
+
1
;
}
// The reason for using user actions here rather than just having the timer just call
// what it needs directly is to avoid a potential deadlock during destruction of this widget.
void
timer_event_unhighlight_rect
()
{
highlight_timer
.
stop
();
parent
.
trigger_user_event
(
this
,
scrollable_region
::
next_free_user_event_number
());
}
void
on_user_event
(
int
num
)
{
// ignore this user event if it isn't for us
if
(
num
!=
scrollable_region
::
next_free_user_event_number
())
return
;
if
(
highlighted_rect
<
overlay_rects
.
size
())
{
highlighted_rect
=
std
::
numeric_limits
<
unsigned
long
>::
max
();
parent
.
invalidate_rectangle
(
rect
);
}
}
array2d
<
rgb_alpha_pixel
>
img
;
array2d
<
rgb_alpha_pixel
>
img
;
...
@@ -3555,6 +3577,8 @@ namespace dlib
...
@@ -3555,6 +3577,8 @@ namespace dlib
const
int
part_width
;
const
int
part_width
;
std
::
set
<
std
::
string
>
part_names
;
std
::
set
<
std
::
string
>
part_names
;
bool
overlay_editing_enabled
;
bool
overlay_editing_enabled
;
timer
<
image_display
>
highlight_timer
;
unsigned
long
highlighted_rect
;
// restricted functions
// restricted functions
image_display
(
image_display
&
);
// copy constructor
image_display
(
image_display
&
);
// copy constructor
...
...
dlib/gui_widgets/widgets_abstract.h
View file @
fe03decb
...
@@ -2340,6 +2340,8 @@ namespace dlib
...
@@ -2340,6 +2340,8 @@ namespace dlib
by selecting an overlay rectangle with the mouse and then right clicking
by selecting an overlay rectangle with the mouse and then right clicking
on the part.
on the part.
Finally, if you hold Ctrl and left click an overlay rectangle it will
change its label to get_default_overlay_rect_label().
The image is drawn such that:
The image is drawn such that:
- the pixel img[0][0] is the upper left corner of the image.
- the pixel img[0][0] is the upper left corner of the image.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment