2009-08-03 19:12:47 +03:00
|
|
|
/*
|
|
|
|
* gui_canvas.c - GUI, canvas
|
|
|
|
*
|
2010-01-02 14:55:34 +02:00
|
|
|
* Written 2009, 2010 by Werner Almesberger
|
|
|
|
* Copyright 2009, 2010 by Werner Almesberger
|
2009-08-03 19:12:47 +03:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
#include <gtk/gtk.h>
|
2009-08-05 03:32:38 +03:00
|
|
|
#include <gdk/gdkkeysyms.h>
|
2009-08-03 19:12:47 +03:00
|
|
|
|
|
|
|
#include "obj.h"
|
2009-08-05 03:32:38 +03:00
|
|
|
#include "delete.h"
|
2009-08-03 19:12:47 +03:00
|
|
|
#include "inst.h"
|
2009-08-08 17:11:26 +03:00
|
|
|
#include "gui_util.h"
|
2009-08-03 19:12:47 +03:00
|
|
|
#include "gui_inst.h"
|
|
|
|
#include "gui_style.h"
|
|
|
|
#include "gui_status.h"
|
2009-08-08 22:44:17 +03:00
|
|
|
#include "gui_tool.h"
|
2009-08-03 19:12:47 +03:00
|
|
|
#include "gui.h"
|
Working towards the dragging of frames. Changed the press/drag/release logic of
tables such that items are selected on release and we can thus drag without
selecting. (From a user point of view, selecting would be fine. But selecting
may sometimes cause a change_world or similar, destroying the widget, which
upsets drag and drop.)
- gui_frame_drag.c (setup_var_drag, setup_value_drag): moved targets to file
scope
- gui_frame_drag.c (has_target, drag_var_motion, drag_value_motion): Gtk
doesn't check target compatibility for us, so we have to do this explicitly
- gui_frame_drag.c (drag_begin): don't leak the pixbuf
- gui_frame_drag.c (is_dragging, drag_end), gui_frame_drag.h: for drag vs.
activations on button release, we now can test what is being dragged. For
this, we have to explicitly clear the variable "dragging" when done.
- gui_frame_drag.c (setup_var_drag, setup_value_drag): moved common setup to
setup_drag_common
- gui_frame_drag.c (setup_frame_drag, drag_frame_motion), gui_frame_drag.h,
gui_frame.c (frame_select_event, build_frame_label): added infrastructure for
dragging frames
- gui_frame_drag.c (setup_canvas_drag, drag_canvas_motion), gui_frame_drag.h,
gui_canvas.c (motion_notify_event, make_canvas): added infrastructure for
dragging to the canvas
- gui_frame.c (table_var_select_event, table_value_select_event, build_table):
split logic into press and release action, so that we can drag without
implicitly selecting
git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5930 99fdad57-331a-0410-800a-d7fa5415bdb3
2010-04-24 01:01:56 +03:00
|
|
|
#include "gui_frame_drag.h"
|
2009-08-03 19:12:47 +03:00
|
|
|
#include "gui_canvas.h"
|
|
|
|
|
|
|
|
|
2009-08-10 16:51:51 +03:00
|
|
|
#if 0
|
|
|
|
#define DPRINTF(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)
|
|
|
|
#else
|
|
|
|
#define DPRINTF(fmt, ...)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2009-08-08 17:11:26 +03:00
|
|
|
void (*highlight)(void) = NULL;
|
2009-08-08 00:47:51 +03:00
|
|
|
|
2009-12-15 21:33:15 +02:00
|
|
|
static struct coord curr_pos; /* canvas coordinates ! */
|
2009-08-03 19:12:47 +03:00
|
|
|
static struct coord user_origin = { 0, 0 };
|
|
|
|
|
2009-08-04 15:06:04 +03:00
|
|
|
static int dragging = 0;
|
2010-01-03 00:04:25 +02:00
|
|
|
static int drag_escaped = 0; /* 1 once we've made it out of the drag radius */
|
2009-08-04 15:06:04 +03:00
|
|
|
static struct coord drag_start;
|
2010-01-03 00:04:25 +02:00
|
|
|
static struct inst *selected_before_drag;
|
|
|
|
/* instance selected before dragging. we use it to do the click-to-select
|
|
|
|
routine in case we later find out the drag was really just a click. */
|
2009-08-04 15:06:04 +03:00
|
|
|
|
2009-08-03 19:12:47 +03:00
|
|
|
|
|
|
|
/* ----- status display ---------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
static void update_zoom(void)
|
|
|
|
{
|
2010-01-03 01:27:36 +02:00
|
|
|
status_set_zoom("Zoom factor", "x%d", draw_ctx.scale);
|
2009-08-03 19:12:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void update_pos(struct coord pos)
|
|
|
|
{
|
2009-12-15 21:33:15 +02:00
|
|
|
struct coord user;
|
|
|
|
unit_type diag;
|
|
|
|
|
2010-01-03 01:27:36 +02:00
|
|
|
set_with_units(status_set_sys_x, "X ", pos.x, "Absolute X position");
|
|
|
|
set_with_units(status_set_sys_y, "Y ", pos.y, "Absolute Y position");
|
2009-12-15 21:33:15 +02:00
|
|
|
|
|
|
|
user.x = pos.x-user_origin.x;
|
|
|
|
user.y = pos.y-user_origin.y;
|
2010-01-03 01:27:36 +02:00
|
|
|
set_with_units(status_set_user_x, "x ", user.x,
|
|
|
|
"User X position. Press SPACE to zero.");
|
|
|
|
set_with_units(status_set_user_y, "y ", user.y,
|
|
|
|
"User Y position. Press SPACE to zero.");
|
2009-12-15 21:33:15 +02:00
|
|
|
|
|
|
|
if (!selected_inst) {
|
|
|
|
diag = hypot(user.x, user.y);
|
2010-01-03 01:27:36 +02:00
|
|
|
set_with_units(status_set_r, "r = ", diag,
|
|
|
|
"Distance from user origin");
|
|
|
|
status_set_angle_xy("Angle from user origin", user);
|
2009-12-15 21:33:15 +02:00
|
|
|
}
|
2009-08-03 19:12:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-16 14:21:48 +03:00
|
|
|
void refresh_pos(void)
|
|
|
|
{
|
2009-12-15 21:33:15 +02:00
|
|
|
update_pos(canvas_to_coord(curr_pos.x, curr_pos.y));
|
2009-08-16 14:21:48 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-03 19:12:47 +03:00
|
|
|
/* ----- coordinate system ------------------------------------------------- */
|
|
|
|
|
|
|
|
|
2009-08-04 00:52:21 +03:00
|
|
|
static void center(const struct bbox *this_bbox)
|
2009-08-03 19:12:47 +03:00
|
|
|
{
|
|
|
|
struct bbox bbox;
|
|
|
|
|
2009-08-04 00:52:21 +03:00
|
|
|
bbox = this_bbox ? *this_bbox : inst_get_bbox();
|
2009-08-08 17:11:26 +03:00
|
|
|
draw_ctx.center.x = (bbox.min.x+bbox.max.x)/2;
|
|
|
|
draw_ctx.center.y = (bbox.min.y+bbox.max.y)/2;
|
2009-08-03 19:12:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-04 00:52:21 +03:00
|
|
|
static void auto_scale(const struct bbox *this_bbox)
|
2009-08-03 19:12:47 +03:00
|
|
|
{
|
|
|
|
struct bbox bbox;
|
|
|
|
unit_type h, w;
|
|
|
|
int sx, sy;
|
|
|
|
float aw, ah;
|
|
|
|
|
2009-08-04 00:52:21 +03:00
|
|
|
bbox = this_bbox ? *this_bbox : inst_get_bbox();
|
2009-08-08 17:11:26 +03:00
|
|
|
aw = draw_ctx.widget->allocation.width;
|
|
|
|
ah = draw_ctx.widget->allocation.height;
|
2009-08-03 19:12:47 +03:00
|
|
|
h = bbox.max.x-bbox.min.x;
|
|
|
|
w = bbox.max.y-bbox.min.y;
|
|
|
|
aw -= 2*CANVAS_CLEARANCE;
|
|
|
|
ah -= 2*CANVAS_CLEARANCE;
|
|
|
|
if (aw < 1)
|
|
|
|
aw = 1;
|
|
|
|
if (ah < 1)
|
|
|
|
ah = 1;
|
|
|
|
sx = ceil(h/aw);
|
|
|
|
sy = ceil(w/ah);
|
2009-08-08 17:11:26 +03:00
|
|
|
draw_ctx.scale = sx > sy ? sx : sy > 0 ? sy : 1;
|
2009-08-03 19:12:47 +03:00
|
|
|
|
|
|
|
update_zoom();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ----- drawing ----------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
void redraw(void)
|
|
|
|
{
|
|
|
|
float aw, ah;
|
|
|
|
|
2009-08-08 17:11:26 +03:00
|
|
|
aw = draw_ctx.widget->allocation.width;
|
|
|
|
ah = draw_ctx.widget->allocation.height;
|
|
|
|
gdk_draw_rectangle(draw_ctx.widget->window,
|
2009-08-13 12:30:16 +03:00
|
|
|
instantiation_error ? gc_bg_error : gc_bg, TRUE, 0, 0, aw, ah);
|
2009-08-03 19:12:47 +03:00
|
|
|
|
2010-01-02 14:55:34 +02:00
|
|
|
DPRINTF("--- redraw: inst_draw ---");
|
2009-08-08 17:11:26 +03:00
|
|
|
inst_draw();
|
2009-08-08 00:47:51 +03:00
|
|
|
if (highlight)
|
2009-08-08 17:11:26 +03:00
|
|
|
highlight();
|
2010-01-02 14:55:34 +02:00
|
|
|
DPRINTF("--- redraw: tool_redraw ---");
|
2009-08-08 17:11:26 +03:00
|
|
|
tool_redraw();
|
2010-01-02 14:55:34 +02:00
|
|
|
DPRINTF("--- redraw: done ---");
|
2009-08-03 19:12:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ----- drag -------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
static void drag_left(struct coord pos)
|
|
|
|
{
|
2009-08-04 15:06:04 +03:00
|
|
|
if (!dragging)
|
|
|
|
return;
|
2009-08-05 03:32:38 +03:00
|
|
|
if (!drag_escaped &&
|
2009-08-08 17:11:26 +03:00
|
|
|
hypot(pos.x-drag_start.x, pos.y-drag_start.y)/draw_ctx.scale <
|
2009-08-04 15:06:04 +03:00
|
|
|
DRAG_MIN_R)
|
|
|
|
return;
|
2009-08-05 03:32:38 +03:00
|
|
|
drag_escaped = 1;
|
2009-08-08 17:11:26 +03:00
|
|
|
tool_drag(pos);
|
2009-08-03 19:12:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void drag_middle(struct coord pos)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean motion_notify_event(GtkWidget *widget, GdkEventMotion *event,
|
2009-08-04 15:06:04 +03:00
|
|
|
gpointer data)
|
2009-08-03 19:12:47 +03:00
|
|
|
{
|
2009-08-08 17:11:26 +03:00
|
|
|
struct coord pos = canvas_to_coord(event->x, event->y);
|
2009-08-03 19:12:47 +03:00
|
|
|
|
2009-08-10 16:51:51 +03:00
|
|
|
DPRINTF("--- motion ---");
|
2009-08-03 19:12:47 +03:00
|
|
|
curr_pos.x = event->x;
|
|
|
|
curr_pos.y = event->y;
|
2009-08-08 17:11:26 +03:00
|
|
|
tool_hover(pos);
|
2009-08-03 19:12:47 +03:00
|
|
|
if (event->state & GDK_BUTTON1_MASK)
|
|
|
|
drag_left(pos);
|
|
|
|
if (event->state & GDK_BUTTON2_MASK)
|
|
|
|
drag_middle(pos);
|
|
|
|
update_pos(pos);
|
Working towards the dragging of frames. Changed the press/drag/release logic of
tables such that items are selected on release and we can thus drag without
selecting. (From a user point of view, selecting would be fine. But selecting
may sometimes cause a change_world or similar, destroying the widget, which
upsets drag and drop.)
- gui_frame_drag.c (setup_var_drag, setup_value_drag): moved targets to file
scope
- gui_frame_drag.c (has_target, drag_var_motion, drag_value_motion): Gtk
doesn't check target compatibility for us, so we have to do this explicitly
- gui_frame_drag.c (drag_begin): don't leak the pixbuf
- gui_frame_drag.c (is_dragging, drag_end), gui_frame_drag.h: for drag vs.
activations on button release, we now can test what is being dragged. For
this, we have to explicitly clear the variable "dragging" when done.
- gui_frame_drag.c (setup_var_drag, setup_value_drag): moved common setup to
setup_drag_common
- gui_frame_drag.c (setup_frame_drag, drag_frame_motion), gui_frame_drag.h,
gui_frame.c (frame_select_event, build_frame_label): added infrastructure for
dragging frames
- gui_frame_drag.c (setup_canvas_drag, drag_canvas_motion), gui_frame_drag.h,
gui_canvas.c (motion_notify_event, make_canvas): added infrastructure for
dragging to the canvas
- gui_frame.c (table_var_select_event, table_value_select_event, build_table):
split logic into press and release action, so that we can drag without
implicitly selecting
git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5930 99fdad57-331a-0410-800a-d7fa5415bdb3
2010-04-24 01:01:56 +03:00
|
|
|
return FALSE;
|
2009-08-03 19:12:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
Dragging a frame into the canvas now works. It's built on top of the frame
tool, with all the old code still around, so the code paths are a bit obscure.
- gui_frame_drag.c: use GTK_DEST_DEFAULT_MOTION instead of
GTK_DEST_DEFAULT_HIGHLIGHT
- gui_frame_drag.c: put meat on the frame and canvas drag and drop skeleton
- gui_frame_drag.c (setup_frame_drag, setup_canvas_drag): use GDK_ACTION_COPY
instead of GDK_ACTION_PRIVATE
- gui_frame_drag.h, gui_frame_drag.c (is_dragging_anything): new helper
function to check if we're dragging anything, without specifying what
- gui_canvas.h, gui_canvas.c: added thin interface layer between gui_frame.c
and gui_tool.c
- gui_canvas.c (enter_notify_event, leave_notify_event): return FALSE so that
other widgets can get the events, too
- gui_tool.h, gui_tool.c (tool_hover): return whether we found anything to
hover on
- gui_tool.h, gui_tool.c: added interface for dropping a frame on the canvas
git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5932 99fdad57-331a-0410-800a-d7fa5415bdb3
2010-04-25 00:46:43 +03:00
|
|
|
/* ----- drag and drop (frame to canvas) ----------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
void canvas_frame_begin(struct frame *frame)
|
|
|
|
{
|
|
|
|
tool_push_frame(frame);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int canvas_frame_motion(struct frame *frame, int x, int y)
|
|
|
|
{
|
|
|
|
struct coord pos = canvas_to_coord(x, y);
|
|
|
|
|
|
|
|
return tool_hover(pos);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void canvas_frame_end(void)
|
|
|
|
{
|
|
|
|
tool_dehover();
|
|
|
|
tool_pop_frame();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int canvas_frame_drop(struct frame *frame, int x, int y)
|
|
|
|
{
|
|
|
|
struct coord pos = canvas_to_coord(x, y);
|
|
|
|
|
|
|
|
if (!tool_place_frame(frame, pos))
|
|
|
|
return FALSE;
|
|
|
|
change_world();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-03 19:12:47 +03:00
|
|
|
/* ----- button press and release ------------------------------------------ */
|
|
|
|
|
|
|
|
|
2010-01-03 00:04:25 +02:00
|
|
|
static void click_to_select(struct coord pos)
|
|
|
|
{
|
|
|
|
const struct inst *prev;
|
|
|
|
|
|
|
|
tool_reset();
|
|
|
|
prev = selected_inst;
|
|
|
|
inst_select(pos);
|
|
|
|
if (prev != selected_inst)
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-03 19:12:47 +03:00
|
|
|
static gboolean button_press_event(GtkWidget *widget, GdkEventButton *event,
|
2009-08-04 15:06:04 +03:00
|
|
|
gpointer data)
|
2009-08-03 19:12:47 +03:00
|
|
|
{
|
2009-08-08 17:11:26 +03:00
|
|
|
struct coord pos = canvas_to_coord(event->x, event->y);
|
2009-08-05 17:44:36 +03:00
|
|
|
int res;
|
2009-08-03 19:12:47 +03:00
|
|
|
|
2009-08-10 16:51:51 +03:00
|
|
|
DPRINTF("--- button press ---");
|
2009-08-09 04:51:20 +03:00
|
|
|
gtk_widget_grab_focus(widget);
|
2009-08-03 19:12:47 +03:00
|
|
|
switch (event->button) {
|
|
|
|
case 1:
|
2009-08-04 15:06:04 +03:00
|
|
|
if (dragging) {
|
|
|
|
fprintf(stderr, "HUH ?!?\n");
|
2009-08-08 17:11:26 +03:00
|
|
|
tool_cancel_drag();
|
2009-08-04 15:06:04 +03:00
|
|
|
dragging = 0;
|
|
|
|
}
|
2009-08-08 17:11:26 +03:00
|
|
|
res = tool_consider_drag(pos);
|
2009-08-05 17:44:36 +03:00
|
|
|
/* tool doesn't do drag */
|
|
|
|
if (res < 0) {
|
|
|
|
change_world();
|
|
|
|
inst_deselect();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (res) {
|
2010-01-03 00:04:25 +02:00
|
|
|
selected_before_drag = selected_inst;
|
2009-08-05 17:44:36 +03:00
|
|
|
inst_deselect();
|
2009-08-06 15:07:24 +03:00
|
|
|
redraw();
|
2009-08-04 15:06:04 +03:00
|
|
|
dragging = 1;
|
2009-08-05 03:32:38 +03:00
|
|
|
drag_escaped = 0;
|
2009-08-04 15:06:04 +03:00
|
|
|
drag_start = pos;
|
|
|
|
break;
|
|
|
|
}
|
2010-01-03 00:04:25 +02:00
|
|
|
click_to_select(pos);
|
2009-08-03 19:12:47 +03:00
|
|
|
break;
|
|
|
|
case 2:
|
2009-08-08 22:01:45 +03:00
|
|
|
tool_dehover();
|
2009-08-08 17:11:26 +03:00
|
|
|
draw_ctx.center = pos;
|
2009-08-03 19:12:47 +03:00
|
|
|
redraw();
|
2009-08-08 22:01:45 +03:00
|
|
|
tool_hover(canvas_to_coord(event->x, event->y));
|
2009-08-03 19:12:47 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean button_release_event(GtkWidget *widget, GdkEventButton *event,
|
2009-08-04 15:06:04 +03:00
|
|
|
gpointer data)
|
2009-08-03 19:12:47 +03:00
|
|
|
{
|
2009-08-08 17:11:26 +03:00
|
|
|
struct coord pos = canvas_to_coord(event->x, event->y);
|
2009-08-04 15:06:04 +03:00
|
|
|
|
2009-08-10 16:51:51 +03:00
|
|
|
DPRINTF("--- button release ---");
|
2009-08-07 19:19:23 +03:00
|
|
|
switch (event->button) {
|
|
|
|
case 1:
|
Dragging a frame into the canvas now works. It's built on top of the frame
tool, with all the old code still around, so the code paths are a bit obscure.
- gui_frame_drag.c: use GTK_DEST_DEFAULT_MOTION instead of
GTK_DEST_DEFAULT_HIGHLIGHT
- gui_frame_drag.c: put meat on the frame and canvas drag and drop skeleton
- gui_frame_drag.c (setup_frame_drag, setup_canvas_drag): use GDK_ACTION_COPY
instead of GDK_ACTION_PRIVATE
- gui_frame_drag.h, gui_frame_drag.c (is_dragging_anything): new helper
function to check if we're dragging anything, without specifying what
- gui_canvas.h, gui_canvas.c: added thin interface layer between gui_frame.c
and gui_tool.c
- gui_canvas.c (enter_notify_event, leave_notify_event): return FALSE so that
other widgets can get the events, too
- gui_tool.h, gui_tool.c (tool_hover): return whether we found anything to
hover on
- gui_tool.h, gui_tool.c: added interface for dropping a frame on the canvas
git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5932 99fdad57-331a-0410-800a-d7fa5415bdb3
2010-04-25 00:46:43 +03:00
|
|
|
if (is_dragging_anything())
|
|
|
|
return FALSE;
|
2009-08-07 19:19:23 +03:00
|
|
|
if (!dragging)
|
|
|
|
break;
|
2010-01-03 00:04:25 +02:00
|
|
|
drag_left(pos);
|
2009-08-04 15:06:04 +03:00
|
|
|
dragging = 0;
|
2010-01-03 00:04:25 +02:00
|
|
|
if (!drag_escaped) {
|
2009-08-08 17:11:26 +03:00
|
|
|
tool_cancel_drag();
|
2010-01-03 00:04:25 +02:00
|
|
|
selected_inst = selected_before_drag;
|
|
|
|
click_to_select(pos);
|
|
|
|
break;
|
2009-08-04 15:06:04 +03:00
|
|
|
}
|
2010-01-03 00:04:25 +02:00
|
|
|
if (tool_end_drag(pos))
|
|
|
|
change_world();
|
2009-08-07 19:19:23 +03:00
|
|
|
break;
|
2009-08-04 15:06:04 +03:00
|
|
|
}
|
2009-08-03 19:12:47 +03:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ----- zoom control ------------------------------------------------------ */
|
|
|
|
|
|
|
|
|
|
|
|
static void zoom_in(struct coord pos)
|
|
|
|
{
|
2009-08-08 17:11:26 +03:00
|
|
|
if (draw_ctx.scale < 2)
|
2009-08-03 19:12:47 +03:00
|
|
|
return;
|
2009-08-08 22:01:45 +03:00
|
|
|
tool_dehover();
|
2009-08-08 17:11:26 +03:00
|
|
|
draw_ctx.scale /= 2;
|
|
|
|
draw_ctx.center.x = (draw_ctx.center.x+pos.x)/2;
|
|
|
|
draw_ctx.center.y = (draw_ctx.center.y+pos.y)/2;
|
2009-08-03 19:12:47 +03:00
|
|
|
update_zoom();
|
|
|
|
redraw();
|
2009-08-08 22:01:45 +03:00
|
|
|
tool_hover(pos);
|
2009-08-03 19:12:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void zoom_out(struct coord pos)
|
|
|
|
{
|
|
|
|
struct bbox bbox;
|
|
|
|
|
|
|
|
bbox = inst_get_bbox();
|
2009-08-08 17:11:26 +03:00
|
|
|
bbox.min = translate(bbox.min);
|
|
|
|
bbox.max = translate(bbox.max);
|
2009-08-07 19:19:23 +03:00
|
|
|
if (bbox.min.x >= ZOOM_STOP_BORDER &&
|
|
|
|
bbox.max.y >= ZOOM_STOP_BORDER &&
|
2009-08-08 17:11:26 +03:00
|
|
|
bbox.max.x < draw_ctx.widget->allocation.width-ZOOM_STOP_BORDER &&
|
|
|
|
bbox.min.y < draw_ctx.widget->allocation.height-ZOOM_STOP_BORDER)
|
2009-08-03 19:12:47 +03:00
|
|
|
return;
|
2009-08-08 22:01:45 +03:00
|
|
|
tool_dehover();
|
2009-08-08 17:11:26 +03:00
|
|
|
draw_ctx.scale *= 2;
|
|
|
|
draw_ctx.center.x = 2*draw_ctx.center.x-pos.x;
|
|
|
|
draw_ctx.center.y = 2*draw_ctx.center.y-pos.y;
|
2009-08-03 19:12:47 +03:00
|
|
|
update_zoom();
|
|
|
|
redraw();
|
2009-08-08 22:01:45 +03:00
|
|
|
tool_hover(pos);
|
2009-08-03 19:12:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-16 15:04:01 +03:00
|
|
|
void zoom_in_center(void)
|
|
|
|
{
|
|
|
|
zoom_in(draw_ctx.center);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void zoom_out_center(void)
|
|
|
|
{
|
|
|
|
zoom_out(draw_ctx.center);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void zoom_to_frame(void)
|
|
|
|
{
|
|
|
|
tool_dehover();
|
|
|
|
center(&active_frame_bbox);
|
|
|
|
auto_scale(&active_frame_bbox);
|
|
|
|
redraw();
|
|
|
|
tool_hover(canvas_to_coord(curr_pos.x, curr_pos.y));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void zoom_to_extents(void)
|
|
|
|
{
|
|
|
|
tool_dehover();
|
|
|
|
center(NULL);
|
|
|
|
auto_scale(NULL);
|
|
|
|
redraw();
|
|
|
|
tool_hover(canvas_to_coord(curr_pos.x, curr_pos.y));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-03 19:12:47 +03:00
|
|
|
static gboolean scroll_event(GtkWidget *widget, GdkEventScroll *event,
|
2009-08-04 15:06:04 +03:00
|
|
|
gpointer data)
|
2009-08-03 19:12:47 +03:00
|
|
|
{
|
2009-08-08 17:11:26 +03:00
|
|
|
struct coord pos = canvas_to_coord(event->x, event->y);
|
2009-08-03 19:12:47 +03:00
|
|
|
|
2009-08-09 04:51:20 +03:00
|
|
|
gtk_widget_grab_focus(widget);
|
2009-08-03 19:12:47 +03:00
|
|
|
switch (event->direction) {
|
|
|
|
case GDK_SCROLL_UP:
|
|
|
|
zoom_in(pos);
|
|
|
|
break;
|
|
|
|
case GDK_SCROLL_DOWN:
|
|
|
|
zoom_out(pos);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
/* ignore */;
|
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ----- keys -------------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean key_press_event(GtkWidget *widget, GdkEventKey *event,
|
2009-08-04 15:06:04 +03:00
|
|
|
gpointer data)
|
2009-08-03 19:12:47 +03:00
|
|
|
{
|
2009-08-08 17:11:26 +03:00
|
|
|
struct coord pos = canvas_to_coord(curr_pos.x, curr_pos.y);
|
2009-08-03 19:12:47 +03:00
|
|
|
|
2009-08-10 16:51:51 +03:00
|
|
|
DPRINTF("--- key press ---");
|
2009-08-03 19:12:47 +03:00
|
|
|
switch (event->keyval) {
|
|
|
|
case ' ':
|
|
|
|
user_origin = pos;
|
|
|
|
update_pos(pos);
|
|
|
|
break;
|
2009-08-03 20:58:32 +03:00
|
|
|
case '+':
|
|
|
|
case '=':
|
|
|
|
zoom_in(pos);
|
|
|
|
break;
|
|
|
|
case '-':
|
|
|
|
zoom_out(pos);
|
|
|
|
break;
|
|
|
|
case '*':
|
2009-08-16 15:04:01 +03:00
|
|
|
zoom_to_extents();
|
2009-08-04 00:52:21 +03:00
|
|
|
break;
|
|
|
|
case '#':
|
2009-08-16 15:04:01 +03:00
|
|
|
zoom_to_frame();
|
2009-08-04 00:52:21 +03:00
|
|
|
break;
|
2009-08-03 20:58:32 +03:00
|
|
|
case '.':
|
2009-08-08 22:01:45 +03:00
|
|
|
tool_dehover();
|
2009-08-08 17:11:26 +03:00
|
|
|
draw_ctx.center = pos;
|
2009-08-03 20:58:32 +03:00
|
|
|
redraw();
|
2009-08-08 22:01:45 +03:00
|
|
|
tool_hover(canvas_to_coord(curr_pos.x, curr_pos.y));
|
2009-08-03 20:58:32 +03:00
|
|
|
break;
|
2009-08-05 03:32:38 +03:00
|
|
|
case GDK_BackSpace:
|
|
|
|
case GDK_Delete:
|
2009-08-07 22:42:57 +03:00
|
|
|
#if 0
|
2009-08-05 03:32:38 +03:00
|
|
|
case GDK_KP_Delete:
|
2009-08-05 21:43:00 +03:00
|
|
|
if (selected_inst) {
|
|
|
|
inst_delete(selected_inst);
|
2009-08-05 17:44:36 +03:00
|
|
|
tool_frame_update();
|
2009-08-05 03:32:38 +03:00
|
|
|
change_world();
|
2009-08-05 17:44:36 +03:00
|
|
|
}
|
2009-08-05 03:32:38 +03:00
|
|
|
break;
|
2009-08-07 22:42:57 +03:00
|
|
|
#endif
|
2009-08-05 03:32:38 +03:00
|
|
|
case 'u':
|
|
|
|
if (undelete())
|
|
|
|
change_world();
|
|
|
|
break;
|
2009-08-12 17:44:17 +03:00
|
|
|
case '/':
|
|
|
|
{
|
|
|
|
/* @@@ find a better place for this */
|
|
|
|
extern int show_vars;
|
|
|
|
show_vars = !show_vars;
|
|
|
|
change_world();
|
|
|
|
}
|
2009-08-03 19:12:47 +03:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ----- expose event ------------------------------------------------------ */
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean expose_event(GtkWidget *widget, GdkEventExpose *event,
|
2009-08-04 15:06:04 +03:00
|
|
|
gpointer data)
|
2009-08-03 19:12:47 +03:00
|
|
|
{
|
|
|
|
static int first = 1;
|
2009-08-10 16:51:51 +03:00
|
|
|
|
|
|
|
DPRINTF("--- expose ---");
|
2009-08-03 19:12:47 +03:00
|
|
|
if (first) {
|
|
|
|
init_canvas();
|
|
|
|
first = 0;
|
|
|
|
}
|
2009-08-10 16:51:51 +03:00
|
|
|
tool_dehover();
|
2009-08-03 19:12:47 +03:00
|
|
|
redraw();
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ----- enter/leave ------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean enter_notify_event(GtkWidget *widget, GdkEventCrossing *event,
|
2009-08-04 15:06:04 +03:00
|
|
|
gpointer data)
|
2009-08-03 19:12:47 +03:00
|
|
|
{
|
Dragging a frame into the canvas now works. It's built on top of the frame
tool, with all the old code still around, so the code paths are a bit obscure.
- gui_frame_drag.c: use GTK_DEST_DEFAULT_MOTION instead of
GTK_DEST_DEFAULT_HIGHLIGHT
- gui_frame_drag.c: put meat on the frame and canvas drag and drop skeleton
- gui_frame_drag.c (setup_frame_drag, setup_canvas_drag): use GDK_ACTION_COPY
instead of GDK_ACTION_PRIVATE
- gui_frame_drag.h, gui_frame_drag.c (is_dragging_anything): new helper
function to check if we're dragging anything, without specifying what
- gui_canvas.h, gui_canvas.c: added thin interface layer between gui_frame.c
and gui_tool.c
- gui_canvas.c (enter_notify_event, leave_notify_event): return FALSE so that
other widgets can get the events, too
- gui_tool.h, gui_tool.c (tool_hover): return whether we found anything to
hover on
- gui_tool.h, gui_tool.c: added interface for dropping a frame on the canvas
git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5932 99fdad57-331a-0410-800a-d7fa5415bdb3
2010-04-25 00:46:43 +03:00
|
|
|
DPRINTF("--- enter ---");
|
2009-08-03 19:12:47 +03:00
|
|
|
gtk_widget_grab_focus(widget);
|
Dragging a frame into the canvas now works. It's built on top of the frame
tool, with all the old code still around, so the code paths are a bit obscure.
- gui_frame_drag.c: use GTK_DEST_DEFAULT_MOTION instead of
GTK_DEST_DEFAULT_HIGHLIGHT
- gui_frame_drag.c: put meat on the frame and canvas drag and drop skeleton
- gui_frame_drag.c (setup_frame_drag, setup_canvas_drag): use GDK_ACTION_COPY
instead of GDK_ACTION_PRIVATE
- gui_frame_drag.h, gui_frame_drag.c (is_dragging_anything): new helper
function to check if we're dragging anything, without specifying what
- gui_canvas.h, gui_canvas.c: added thin interface layer between gui_frame.c
and gui_tool.c
- gui_canvas.c (enter_notify_event, leave_notify_event): return FALSE so that
other widgets can get the events, too
- gui_tool.h, gui_tool.c (tool_hover): return whether we found anything to
hover on
- gui_tool.h, gui_tool.c: added interface for dropping a frame on the canvas
git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5932 99fdad57-331a-0410-800a-d7fa5415bdb3
2010-04-25 00:46:43 +03:00
|
|
|
return FALSE;
|
2009-08-03 19:12:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean leave_notify_event(GtkWidget *widget, GdkEventCrossing *event,
|
2009-08-04 15:06:04 +03:00
|
|
|
gpointer data)
|
2009-08-03 19:12:47 +03:00
|
|
|
{
|
2009-08-10 16:51:51 +03:00
|
|
|
DPRINTF("--- leave ---");
|
2009-08-04 15:06:04 +03:00
|
|
|
if (dragging)
|
2009-08-08 17:11:26 +03:00
|
|
|
tool_cancel_drag();
|
|
|
|
tool_dehover();
|
2009-08-04 15:06:04 +03:00
|
|
|
dragging = 0;
|
Dragging a frame into the canvas now works. It's built on top of the frame
tool, with all the old code still around, so the code paths are a bit obscure.
- gui_frame_drag.c: use GTK_DEST_DEFAULT_MOTION instead of
GTK_DEST_DEFAULT_HIGHLIGHT
- gui_frame_drag.c: put meat on the frame and canvas drag and drop skeleton
- gui_frame_drag.c (setup_frame_drag, setup_canvas_drag): use GDK_ACTION_COPY
instead of GDK_ACTION_PRIVATE
- gui_frame_drag.h, gui_frame_drag.c (is_dragging_anything): new helper
function to check if we're dragging anything, without specifying what
- gui_canvas.h, gui_canvas.c: added thin interface layer between gui_frame.c
and gui_tool.c
- gui_canvas.c (enter_notify_event, leave_notify_event): return FALSE so that
other widgets can get the events, too
- gui_tool.h, gui_tool.c (tool_hover): return whether we found anything to
hover on
- gui_tool.h, gui_tool.c: added interface for dropping a frame on the canvas
git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5932 99fdad57-331a-0410-800a-d7fa5415bdb3
2010-04-25 00:46:43 +03:00
|
|
|
return FALSE;
|
2009-08-03 19:12:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-01-02 14:55:34 +02:00
|
|
|
/* ----- tooltip ----------------------------------------------------------- */
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean canvas_tooltip(GtkWidget *widget, gint x, gint y,
|
|
|
|
gboolean keyboard_mode, GtkTooltip *tooltip, gpointer user_data)
|
|
|
|
{
|
|
|
|
struct coord pos = canvas_to_coord(x, y);
|
|
|
|
const char *res;
|
|
|
|
|
|
|
|
res = tool_tip(pos);
|
|
|
|
if (!res)
|
|
|
|
return FALSE;
|
|
|
|
gtk_tooltip_set_markup(tooltip, res);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-08-03 19:12:47 +03:00
|
|
|
/* ----- canvas setup ------------------------------------------------------ */
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note that we call init_canvas twice: first to make sure we'll make it safely
|
|
|
|
* through select_frame, and the second time to set the geometry for the actual
|
|
|
|
* screen.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void init_canvas(void)
|
|
|
|
{
|
2009-08-04 00:52:21 +03:00
|
|
|
center(NULL);
|
|
|
|
auto_scale(NULL);
|
2009-08-03 19:12:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
GtkWidget *make_canvas(void)
|
|
|
|
{
|
|
|
|
GtkWidget *canvas;
|
|
|
|
GdkColor black = { 0, 0, 0, 0 };
|
|
|
|
|
|
|
|
/* Canvas */
|
|
|
|
|
|
|
|
canvas = gtk_drawing_area_new();
|
|
|
|
gtk_widget_modify_bg(canvas, GTK_STATE_NORMAL, &black);
|
|
|
|
|
|
|
|
g_signal_connect(G_OBJECT(canvas), "motion_notify_event",
|
|
|
|
G_CALLBACK(motion_notify_event), NULL);
|
|
|
|
g_signal_connect(G_OBJECT(canvas), "button_press_event",
|
|
|
|
G_CALLBACK(button_press_event), NULL);
|
|
|
|
g_signal_connect(G_OBJECT(canvas), "button_release_event",
|
|
|
|
G_CALLBACK(button_release_event), NULL);
|
|
|
|
g_signal_connect(G_OBJECT(canvas), "scroll_event",
|
|
|
|
G_CALLBACK(scroll_event), NULL);
|
|
|
|
|
|
|
|
GTK_WIDGET_SET_FLAGS(canvas, GTK_CAN_FOCUS);
|
|
|
|
|
|
|
|
g_signal_connect(G_OBJECT(canvas), "key_press_event",
|
|
|
|
G_CALLBACK(key_press_event), NULL);
|
|
|
|
|
|
|
|
g_signal_connect(G_OBJECT(canvas), "expose_event",
|
|
|
|
G_CALLBACK(expose_event), NULL);
|
|
|
|
g_signal_connect(G_OBJECT(canvas), "enter_notify_event",
|
|
|
|
G_CALLBACK(enter_notify_event), NULL);
|
|
|
|
g_signal_connect(G_OBJECT(canvas), "leave_notify_event",
|
|
|
|
G_CALLBACK(leave_notify_event), NULL);
|
|
|
|
|
2010-01-02 14:55:34 +02:00
|
|
|
gtk_widget_set(canvas, "has-tooltip", TRUE, NULL);
|
|
|
|
g_signal_connect(G_OBJECT(canvas), "query_tooltip",
|
|
|
|
G_CALLBACK(canvas_tooltip), NULL);
|
|
|
|
|
2009-08-03 19:12:47 +03:00
|
|
|
gtk_widget_set_events(canvas,
|
|
|
|
GDK_EXPOSE | GDK_ENTER_NOTIFY_MASK | GDK_LEAVE_NOTIFY_MASK |
|
|
|
|
GDK_KEY_PRESS_MASK |
|
|
|
|
GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK |
|
|
|
|
GDK_SCROLL |
|
|
|
|
GDK_POINTER_MOTION_MASK);
|
|
|
|
|
2010-01-02 17:47:46 +02:00
|
|
|
gtk_widget_set_double_buffered(canvas, FALSE);
|
|
|
|
|
Working towards the dragging of frames. Changed the press/drag/release logic of
tables such that items are selected on release and we can thus drag without
selecting. (From a user point of view, selecting would be fine. But selecting
may sometimes cause a change_world or similar, destroying the widget, which
upsets drag and drop.)
- gui_frame_drag.c (setup_var_drag, setup_value_drag): moved targets to file
scope
- gui_frame_drag.c (has_target, drag_var_motion, drag_value_motion): Gtk
doesn't check target compatibility for us, so we have to do this explicitly
- gui_frame_drag.c (drag_begin): don't leak the pixbuf
- gui_frame_drag.c (is_dragging, drag_end), gui_frame_drag.h: for drag vs.
activations on button release, we now can test what is being dragged. For
this, we have to explicitly clear the variable "dragging" when done.
- gui_frame_drag.c (setup_var_drag, setup_value_drag): moved common setup to
setup_drag_common
- gui_frame_drag.c (setup_frame_drag, drag_frame_motion), gui_frame_drag.h,
gui_frame.c (frame_select_event, build_frame_label): added infrastructure for
dragging frames
- gui_frame_drag.c (setup_canvas_drag, drag_canvas_motion), gui_frame_drag.h,
gui_canvas.c (motion_notify_event, make_canvas): added infrastructure for
dragging to the canvas
- gui_frame.c (table_var_select_event, table_value_select_event, build_table):
split logic into press and release action, so that we can drag without
implicitly selecting
git-svn-id: http://svn.openmoko.org/trunk/eda/fped@5930 99fdad57-331a-0410-800a-d7fa5415bdb3
2010-04-24 01:01:56 +03:00
|
|
|
setup_canvas_drag(canvas);
|
|
|
|
|
2009-08-08 17:11:26 +03:00
|
|
|
draw_ctx.widget = canvas;
|
2009-08-03 19:12:47 +03:00
|
|
|
|
|
|
|
return canvas;
|
|
|
|
}
|