Skip to content

Commit 777713e

Browse files
committed
annotation: add counter bubble + refactor switch case in GetFinalImage
the switch case has been moved to an if/else if long branch for keeping away duplicated code because of the counter bubble being just a combination of a circle and text inside it
1 parent bfd5d50 commit 777713e

4 files changed

Lines changed: 434 additions & 172 deletions

File tree

include/screenshot_tool.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
#include <algorithm>
55
#include <bitset>
6+
#include <cstdint>
67
#include <cstdlib>
78
#include <deque>
89
#include <functional>
@@ -25,6 +26,7 @@ enum class ToolType : size_t
2526
RectangleFilled,
2627
Circle,
2728
CircleFilled,
29+
CounterBubble,
2830
Line,
2931
Text,
3032
Pencil,
@@ -109,6 +111,7 @@ struct annotation_t
109111
point_t start;
110112
point_t end;
111113
std::string text; // For text tool
114+
std::uint8_t count = 1; // For CounterBubble tool
112115
std::vector<point_t> points; // For pencil tool
113116
rgba_t color = rgba_t::from_rgba(0xFF0000FF); // RGBA
114117
float thickness = 3.0f;
@@ -229,6 +232,7 @@ class ScreenshotTool
229232
std::vector<annotation_t> m_annotations;
230233
annotation_t m_current_annotation;
231234
rgba_t m_current_color;
235+
std::uint8_t m_current_count = 1;
232236
std::array<float, idx(ToolType::Count)> m_tool_thickness;
233237
ImVec4 m_picker_color{ 1, 0, 0, 1 };
234238
bool m_is_drawing = false;

include/tool_icons.h

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,3 +1499,153 @@ inline constexpr unsigned char OSHOT_LOGO_RGBA[2304] = {
14991499
0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255,
15001500
0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255, 0, 0, 255, 255
15011501
};
1502+
1503+
/* counter_bubble */
1504+
inline constexpr int ICON_COUNTER_BUBBLE_W = 24;
1505+
inline constexpr int ICON_COUNTER_BUBBLE_H = 24;
1506+
inline constexpr unsigned char ICON_COUNTER_BUB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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1527+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1528+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1529+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1530+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1531+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1532+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1533+
0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 153, 255, 255, 255, 187,
1534+
255, 255, 255, 187, 255, 255, 255, 153, 0, 0, 0, 0, 0, 0, 0, 0,
1535+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1536+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1537+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1538+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1539+
255, 255, 255, 221, 255, 255, 255, 255, 255, 255, 255, 234, 255, 255, 255, 196,
1540+
255, 255, 255, 196, 255, 255, 255, 234, 255, 255, 255, 255, 255, 255, 255, 221,
1541+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1542+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1543+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1544+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255,
1545+
255, 255, 255, 196, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1546+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 196,
1547+
255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1548+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1549+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1550+
0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 156,
1551+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1552+
255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1553+
255, 255, 255, 156, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0,
1554+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1555+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1556+
0, 0, 0, 0, 255, 255, 255, 221, 255, 255, 255, 196, 0, 0, 0, 0,
1557+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255,
1558+
255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1559+
0, 0, 0, 0, 255, 255, 255, 196, 255, 255, 255, 221, 0, 0, 0, 0,
1560+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1561+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1562+
0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0,
1563+
0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0,
1564+
255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1565+
0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0,
1566+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1567+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1568+
255, 255, 255, 153, 255, 255, 255, 234, 0, 0, 0, 0, 0, 0, 0, 0,
1569+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1570+
255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1571+
0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 234, 255, 255, 255, 153,
1572+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1573+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1574+
255, 255, 255, 187, 255, 255, 255, 196, 0, 0, 0, 0, 0, 0, 0, 0,
1575+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1576+
255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1577+
0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 196, 255, 255, 255, 187,
1578+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1579+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1580+
255, 255, 255, 187, 255, 255, 255, 196, 0, 0, 0, 0, 0, 0, 0, 0,
1581+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1582+
255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1583+
0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 196, 255, 255, 255, 187,
1584+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1585+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1586+
255, 255, 255, 153, 255, 255, 255, 234, 0, 0, 0, 0, 0, 0, 0, 0,
1587+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1588+
255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1589+
0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 234, 255, 255, 255, 153,
1590+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1591+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1592+
0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0,
1593+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1594+
255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1595+
0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0,
1596+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1597+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1598+
0, 0, 0, 0, 255, 255, 255, 221, 255, 255, 255, 196, 0, 0, 0, 0,
1599+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1600+
255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1601+
0, 0, 0, 0, 255, 255, 255, 196, 255, 255, 255, 221, 0, 0, 0, 0,
1602+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1603+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1604+
0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 156,
1605+
0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255,
1606+
255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 178, 0, 0, 0, 0,
1607+
255, 255, 255, 156, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0,
1608+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1609+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1610+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 255,
1611+
255, 255, 255, 196, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1612+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 196,
1613+
255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1614+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1615+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1616+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1617+
255, 255, 255, 221, 255, 255, 255, 255, 255, 255, 255, 234, 255, 255, 255, 196,
1618+
255, 255, 255, 196, 255, 255, 255, 234, 255, 255, 255, 255, 255, 255, 255, 221,
1619+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1620+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1621+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1622+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1623+
0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 255, 153, 255, 255, 255, 187,
1624+
255, 255, 255, 187, 255, 255, 255, 153, 0, 0, 0, 0, 0, 0,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, 0, 0, 0, 0, 0, 0, 0,
1645+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1646+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1647+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1648+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1649+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1650+
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
1651+
};

scripts/icon_generator.py

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,38 @@ def create_filled_rectangle_pixels(margin=5):
133133

134134
return pixels
135135

136+
def create_counter_bubble_pixels(circle_thickness=1.5):
137+
size = 24
138+
pixels = create_circle_pixels(circle_thickness)
139+
140+
def dist_to_segment(px, py, ax, ay, bx, by):
141+
dx, dy = bx - ax, by - ay
142+
len_sq = dx * dx + dy * dy
143+
if len_sq == 0:
144+
return ((px - ax) ** 2 + (py - ay) ** 2) ** 0.5
145+
t = max(0.0, min(1.0, ((px - ax) * dx + (py - ay) * dy) / len_sq))
146+
return ((px - ax - t * dx) ** 2 + (py - ay - t * dy) ** 2) ** 0.5
147+
148+
def blend_pixel(idx, alpha):
149+
if alpha > pixels[idx + 3]:
150+
pixels[idx:idx + 4] = [255, 255, 255, alpha]
151+
152+
def draw_segment(ax, ay, bx, by, seg_thickness=1.4):
153+
ht = seg_thickness / 2.0
154+
for y in range(size):
155+
for x in range(size):
156+
d = dist_to_segment(x, y, ax, ay, bx, by)
157+
if d <= ht:
158+
alpha = 255 if d <= ht - 0.5 else int(255 * (ht + 0.5 - d))
159+
blend_pixel((y * size + x) * 4, alpha)
160+
161+
# "1" glyph, centered in the circle
162+
draw_segment(12, 7, 12, 15) # Main vertical stroke
163+
draw_segment(10, 9, 12, 7) # Top-left diagonal flag
164+
draw_segment(10, 16, 13.5, 16) # Bottom serif
165+
166+
return pixels
167+
136168
def create_icon_from_image(image_path, use_rgba=False, threshold=128):
137169
try:
138170
from PIL import Image
@@ -187,22 +219,23 @@ def format_c_array(name, pixels):
187219

188220
def main():
189221
icons = [
190-
("ICON_CIRCLE", create_circle_pixels()),
191-
("ICON_CIRCLE_FILLED", create_filled_circle_pixels()),
192-
("ICON_SQUARE", create_square_pixels()),
193-
("ICON_RECT_FILLED", create_filled_rectangle_pixels()),
194-
("ICON_LINE", create_line_pixels()),
222+
# ("ICON_CIRCLE", create_circle_pixels()),
223+
# ("ICON_CIRCLE_FILLED", create_filled_circle_pixels()),
224+
# ("ICON_SQUARE", create_square_pixels()),
225+
# ("ICON_RECT_FILLED", create_filled_rectangle_pixels()),
226+
# ("ICON_LINE", create_line_pixels()),
227+
("ICON_COUNTER_BUBBLE", create_counter_bubble_pixels())
195228
]
196229

197230
header = """#pragma once
198231
199232
"""
200233
# Optional: Add external images
201234
external_images = [
202-
("ICON_PENCIL", "/tmp/image.png"),
203-
("ICON_ARROW", "/tmp/image2.png"),
204-
("ICON_TEXT", "/tmp/text.png")
205-
("OSHOT_LOGO", "./oshot.png", True)
235+
# ("ICON_PENCIL", "/tmp/image.png"),
236+
# ("ICON_ARROW", "/tmp/image2.png"),
237+
# ("ICON_TEXT", "/tmp/text.png")
238+
# ("OSHOT_LOGO", "./oshot.png", True)
206239
]
207240

208241
for name, image_path, use_rgba in external_images:

0 commit comments

Comments
 (0)