1 /*
2 * Copyright (c) 2008 Hypertriton, Inc. <http://hypertriton.com/>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
15 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
18 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
20 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
21 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
22 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
23 * USE OF THIS SOFTWARE EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 */
25
26 /*
27 * Point tool.
28 */
29
30 #include <agar/core/core.h>
31 #include <agar/gui/widget.h>
32 #include <agar/gui/primitive.h>
33 #include <agar/gui/iconmgr.h>
34 #include <agar/vg/vg.h>
35 #include <agar/vg/vg_view.h>
36 #include <agar/vg/icons.h>
37
38 static int
MouseButtonDown(void * p,VG_Vector v,int b)39 MouseButtonDown(void *p, VG_Vector v, int b)
40 {
41 VG_Tool *t = p;
42 VG_View *vv = VGTOOL(t)->vgv;
43 VG *vg = vv->vg;
44
45 switch (b) {
46 case AG_MOUSE_LEFT:
47 VG_Status(vv, _("New point at %.2f,%.2f"), v.x, v.y);
48 VG_PointNew(vg->root, v);
49 return (1);
50 default:
51 return (0);
52 }
53 }
54
55 static void
PostDraw(void * p,VG_View * vv)56 PostDraw(void *p, VG_View *vv)
57 {
58 VG_Tool *t = p;
59 int x, y;
60
61 VG_GetViewCoords(vv, t->vCursor, &x,&y);
62 AG_DrawCircle(vv, x,y, 3, VG_MapColorRGB(vv->vg->selectionColor));
63 }
64
65 VG_ToolOps vgPointTool = {
66 N_("Point"),
67 N_("Insert point in drawing."),
68 &vgIconPoints,
69 sizeof(VG_Tool),
70 0,
71 NULL, /* init */
72 NULL, /* destroy */
73 NULL, /* edit */
74 NULL, /* predraw */
75 PostDraw,
76 NULL, /* selected */
77 NULL, /* deselected */
78 NULL, /* mousemotion */
79 MouseButtonDown,
80 NULL, /* mousebuttonup */
81 NULL, /* keydown */
82 NULL /* keyup */
83 };
84