pcb 4.1.1
An interactive printed circuit board layout editor.

gtkhid-gl.c File Reference

#include <stdio.h>
#include "crosshair.h"
#include "clip.h"
#include "../hidint.h"
#include "gui.h"
#include "gui-pinout-preview.h"
#include <gtk/gtkgl.h>
#include "hid/common/hidgl.h"
#include "hid/common/draw_helpers.h"
#include "hid/common/trackball.h"
Include dependency graph for gtkhid-gl.c:

Go to the source code of this file.

Data Structures

struct  render_priv
struct  hid_gc_struct
struct  ColorCache

Defines

#define GL_GLEXT_PROTOTYPES   1
#define USE_GC(gc)   if (!use_gc(gc)) return
#define MAX_ELAPSED   (50. / 1000.)
#define Z_NEAR   3.0
#define LEAD_USER_WIDTH   0.2
#define LEAD_USER_PERIOD   (1000 / 20)
#define LEAD_USER_VELOCITY   3.
#define LEAD_USER_ARC_COUNT   3
#define LEAD_USER_ARC_SEPARATION   3.
#define LEAD_USER_INITIAL_RADIUS   10.
#define LEAD_USER_COLOR_R   1.
#define LEAD_USER_COLOR_G   1.
#define LEAD_USER_COLOR_B   0.

Typedefs

typedef struct render_priv render_priv
typedef struct hid_gc_struct hid_gc_struct

Functions

static void draw_lead_user (render_priv *priv)
static void ghid_unproject_to_z_plane (int ex, int ey, Coord pcb_z, Coord *pcb_x, Coord *pcb_y)
static void start_subcomposite (void)
static void end_subcomposite (void)
int ghid_set_layer (const char *name, int group, int empty)
static void ghid_end_layer (void)
void ghid_destroy_gc (hidGC gc)
hidGC ghid_make_gc (void)
void ghid_draw_grid (BoxType *drawn_area)
 Draw the grid on the 2D canvas.
static void ghid_draw_bg_image (void)
void ghid_use_mask (enum mask_mode mode)
static void set_special_grid_color (void)
void ghid_set_special_colors (HID_Attribute *ha)
static void set_gl_color_for_gc (hidGC gc)
void ghid_set_color (hidGC gc, const char *name)
void ghid_set_alpha_mult (hidGC gc, double alpha_mult)
void ghid_set_line_cap (hidGC gc, EndCapStyle style)
void ghid_set_line_width (hidGC gc, Coord width)
void ghid_set_draw_xor (hidGC gc, int xor)
void ghid_set_draw_faded (hidGC gc, int faded)
void ghid_set_line_cap_angle (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
static void ghid_invalidate_current_gc (void)
static int use_gc (hidGC gc)
void ghid_draw_line (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
void ghid_draw_arc (hidGC gc, Coord cx, Coord cy, Coord xradius, Coord yradius, Angle start_angle, Angle delta_angle)
void ghid_draw_rect (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
void ghid_fill_circle (hidGC gc, Coord cx, Coord cy, Coord radius)
void ghid_fill_polygon (hidGC gc, int n_coords, Coord *x, Coord *y)
void ghid_fill_pcb_polygon (hidGC gc, PolygonType *poly, const BoxType *clip_box)
void ghid_thindraw_pcb_polygon (hidGC gc, PolygonType *poly, const BoxType *clip_box)
void ghid_fill_rect (hidGC gc, Coord x1, Coord y1, Coord x2, Coord y2)
void ghid_invalidate_lr (Coord left, Coord right, Coord top, Coord bottom)
void ghid_invalidate_all ()
void ghid_notify_crosshair_change (bool changes_complete)
void ghid_notify_mark_change (bool changes_complete)
static void draw_right_cross (gint x, gint y, gint z)
static void draw_slanted_cross (gint x, gint y, gint z)
static void draw_dozen_cross (gint x, gint y, gint z)
static void draw_crosshair (render_priv *priv)
void ghid_init_renderer (int *argc, char ***argv, GHidPort *port)
void ghid_shutdown_renderer (GHidPort *port)
void ghid_init_drawing_widget (GtkWidget *widget, GHidPort *port)
void ghid_drawing_area_configure_hook (GHidPort *port)
gboolean ghid_start_drawing (GHidPort *port, GtkWidget *widget)
void ghid_end_drawing (GHidPort *port, GtkWidget *widget)
void ghid_screen_update (void)
gboolean ghid_drawing_area_expose_cb (GtkWidget *widget, GdkEventExpose *ev, GHidPort *port)
void ghid_port_drawing_realize_cb (GtkWidget *widget, gpointer data)
gboolean ghid_pinout_preview_expose (GtkWidget *widget, GdkEventExpose *ev)
GdkPixmap * ghid_render_pixmap (int cx, int cy, double zoom, int width, int height, int depth)
HID_DRAWghid_request_debug_draw (void)
void ghid_flush_debug_draw (void)
void ghid_finish_debug_draw (void)
static float determinant_2x2 (float m[2][2])
static void invert_2x2 (float m[2][2], float out[2][2])
bool ghid_event_to_pcb_coords (int event_x, int event_y, Coord *pcb_x, Coord *pcb_y)
bool ghid_pcb_to_event_coords (Coord pcb_x, Coord pcb_y, int *event_x, int *event_y)
void ghid_view_2d (void *ball, gboolean view_2d, gpointer userdata)
void ghid_port_rotate (void *ball, float *quarternion, gpointer userdata)
gboolean lead_user_cb (gpointer data)
void ghid_lead_user_to_location (Coord x, Coord y)
void ghid_cancel_lead_user (void)

Variables

HID ghid_hid
HID_DRAW ghid_graphics
static hidGC current_gc = NULL
static enum mask_mode cur_mask = HID_MASK_OFF
static GLfloat view_matrix [4][4]
static GLfloat last_modelview_matrix [4][4]
static int global_view_2d = 1

Define Documentation

#define GL_GLEXT_PROTOTYPES   1

Definition at line 18 of file gtkhid-gl.c.

#define LEAD_USER_ARC_COUNT   3

Definition at line 1597 of file gtkhid-gl.c.

Referenced by draw_lead_user().

#define LEAD_USER_ARC_SEPARATION   3.

Definition at line 1598 of file gtkhid-gl.c.

Referenced by draw_lead_user().

#define LEAD_USER_COLOR_B   0.

Definition at line 1602 of file gtkhid-gl.c.

Referenced by draw_lead_user().

#define LEAD_USER_COLOR_G   1.

Definition at line 1601 of file gtkhid-gl.c.

Referenced by draw_lead_user().

#define LEAD_USER_COLOR_R   1.

Definition at line 1600 of file gtkhid-gl.c.

Referenced by draw_lead_user().

#define LEAD_USER_INITIAL_RADIUS   10.

Definition at line 1599 of file gtkhid-gl.c.

Referenced by draw_lead_user(), ghid_lead_user_to_location(), and lead_user_cb().

#define LEAD_USER_PERIOD   (1000 / 20)

Definition at line 1595 of file gtkhid-gl.c.

Referenced by ghid_lead_user_to_location().

#define LEAD_USER_VELOCITY   3.

Definition at line 1596 of file gtkhid-gl.c.

Referenced by lead_user_cb().

#define LEAD_USER_WIDTH   0.2

Definition at line 1594 of file gtkhid-gl.c.

Referenced by draw_lead_user().

#define MAX_ELAPSED   (50. / 1000.)

Definition at line 617 of file gtkhid-gl.c.

Referenced by ghid_invalidate_all().

#define USE_GC (   gc)    if (!use_gc(gc)) return
#define Z_NEAR   3.0

Typedef Documentation

typedef struct hid_gc_struct hid_gc_struct
typedef struct render_priv render_priv

Function Documentation

static float determinant_2x2 ( float  m[2][2]) [static]

Definition at line 1372 of file gtkhid-gl.c.

References det().

Referenced by invert_2x2().

Here is the call graph for this function:

static void draw_dozen_cross ( gint  x,
gint  y,
gint  z 
) [static]

Definition at line 690 of file gtkhid-gl.c.

References MAX, PCBType::MaxHeight, PCBType::MaxWidth, MIN, PCB, x, and y.

Referenced by draw_crosshair().

static void draw_right_cross ( gint  x,
gint  y,
gint  z 
) [static]

Definition at line 653 of file gtkhid-gl.c.

References PCBType::MaxHeight, PCBType::MaxWidth, and PCB.

Referenced by draw_crosshair().

static void draw_slanted_cross ( gint  x,
gint  y,
gint  z 
) [static]

Definition at line 662 of file gtkhid-gl.c.

References MAX, PCBType::MaxHeight, PCBType::MaxWidth, MIN, PCB, x, and y.

Referenced by draw_crosshair().

static void end_subcomposite ( void  ) [static]

Definition at line 120 of file gtkhid-gl.c.

References buffer, gport, hidgl_flush_triangles(), hidgl_return_stencil_bit(), GHidPort::render_priv, and render_priv::subcomposite_stencil_bit.

Referenced by ghid_end_layer(), and ghid_set_layer().

Here is the call graph for this function:

void ghid_cancel_lead_user ( void  )

Definition at line 1676 of file gtkhid-gl.c.

References ghid_invalidate_all(), gport, render_priv::lead_user, render_priv::lead_user_timeout, render_priv::lead_user_timer, and GHidPort::render_priv.

Here is the call graph for this function:

void ghid_destroy_gc ( hidGC  gc)

Definition at line 199 of file gtkhid-gl.c.

References hid_gc_struct::gc.

void ghid_draw_arc ( hidGC  gc,
Coord  cx,
Coord  cy,
Coord  xradius,
Coord  yradius,
Angle  start_angle,
Angle  delta_angle 
)
static void ghid_draw_bg_image ( void  ) [static]

Definition at line 242 of file gtkhid-gl.c.

References GhidGui::bg_pixbuf, ghidgui, PCBType::MaxHeight, PCBType::MaxWidth, and PCB.

Referenced by ghid_drawing_area_expose_cb().

void ghid_draw_line ( hidGC  gc,
Coord  x1,
Coord  y1,
Coord  x2,
Coord  y2 
)
void ghid_draw_rect ( hidGC  gc,
Coord  x1,
Coord  y1,
Coord  x2,
Coord  y2 
)
void ghid_end_drawing ( GHidPort port,
GtkWidget *  widget 
)
static void ghid_end_layer ( void  ) [static]

Definition at line 193 of file gtkhid-gl.c.

References end_subcomposite().

Referenced by ghid_init_renderer().

Here is the call graph for this function:

bool ghid_event_to_pcb_coords ( int  event_x,
int  event_y,
Coord pcb_x,
Coord pcb_y 
)

Definition at line 1535 of file gtkhid-gl.c.

References EVENT_TO_PCB_X, EVENT_TO_PCB_Y, and ghid_unproject_to_z_plane().

Here is the call graph for this function:

void ghid_fill_circle ( hidGC  gc,
Coord  cx,
Coord  cy,
Coord  radius 
)
void ghid_fill_pcb_polygon ( hidGC  gc,
PolygonType poly,
const BoxType clip_box 
)

Definition at line 587 of file gtkhid-gl.c.

References view_data::coord_per_px, gport, hidgl_fill_pcb_polygon(), USE_GC, and GHidPort::view.

Referenced by ghid_init_renderer().

Here is the call graph for this function:

void ghid_fill_polygon ( hidGC  gc,
int  n_coords,
Coord x,
Coord y 
)

Definition at line 579 of file gtkhid-gl.c.

References GHidPort::drawable, gport, hidgl_fill_polygon(), realloc(), GHidPort::render_priv, render_priv::u_gc, USE_GC, Vx(), and Vy().

Here is the call graph for this function:

void ghid_fill_rect ( hidGC  gc,
Coord  x1,
Coord  y1,
Coord  x2,
Coord  y2 
)
void ghid_finish_debug_draw ( void  )

Definition at line 1362 of file gtkhid-gl.c.

References buffer, GHidPort::drawing_area, ghid_end_drawing(), ghid_flush_debug_draw(), gport, hidgl_finish_render(), and hidgl_flush_triangles().

Here is the call graph for this function:

void ghid_flush_debug_draw ( void  )

Definition at line 1348 of file gtkhid-gl.c.

References buffer, GHidPort::drawing_area, ghid_screen_update(), gport, and hidgl_flush_triangles().

Here is the call graph for this function:

void ghid_init_drawing_widget ( GtkWidget *  widget,
GHidPort port 
)

Definition at line 818 of file gtkhid-gl.c.

References render_priv::glconfig, GHidPort::render_priv, and TRUE.

void ghid_invalidate_all ( )

Definition at line 619 of file gtkhid-gl.c.

References ghid_draw_area_update(), ghid_screen_update(), gport, MAX_ELAPSED, redraw_region(), GHidPort::render_priv, and render_priv::time_since_expose.

Here is the call graph for this function:

static void ghid_invalidate_current_gc ( void  ) [static]
void ghid_invalidate_lr ( Coord  left,
Coord  right,
Coord  top,
Coord  bottom 
)

Definition at line 612 of file gtkhid-gl.c.

References ghid_invalidate_all(), ghid_screen_update(), MAX, maxx, maxy, MIN, minx, miny, redraw_region(), Vx(), and Vy().

Here is the call graph for this function:

void ghid_notify_crosshair_change ( bool  changes_complete)
void ghid_notify_mark_change ( bool  changes_complete)
bool ghid_pcb_to_event_coords ( Coord  pcb_x,
Coord  pcb_y,
int *  event_x,
int *  event_y 
)

Definition at line 1543 of file gtkhid-gl.c.

References DRAW_X, DRAW_Y, and last_modelview_matrix.

void ghid_port_drawing_realize_cb ( GtkWidget *  widget,
gpointer  data 
)

Definition at line 1046 of file gtkhid-gl.c.

void ghid_port_rotate ( void *  ball,
float *  quarternion,
gpointer  userdata 
)

Definition at line 1571 of file gtkhid-gl.c.

References build_rotmatrix(), ghid_invalidate_all(), and view_matrix.

Referenced by ghid_build_pcb_top_window().

Here is the call graph for this function:

void ghid_screen_update ( void  )

Definition at line 866 of file gtkhid-gl.c.

References render_priv::bg_gc, draw_crosshair(), GHidPort::drawing_area, gport, GHidPort::height, GHidPort::pixmap, GHidPort::render_priv, GHidPort::width, and window.

Here is the call graph for this function:

void ghid_set_alpha_mult ( hidGC  gc,
double  alpha_mult 
)

Definition at line 478 of file gtkhid-gl.c.

References hid_gc_struct::alpha_mult, and set_gl_color_for_gc().

Referenced by ghid_thindraw_pcb_polygon().

Here is the call graph for this function:

void ghid_set_color ( hidGC  gc,
const char *  name 
)
void ghid_set_draw_faded ( hidGC  gc,
int  faded 
)

Definition at line 507 of file gtkhid-gl.c.

void ghid_set_draw_xor ( hidGC  gc,
int  xor 
)

Definition at line 498 of file gtkhid-gl.c.

References hid_gc_struct::colorname, hid_gc_struct::gc, ghid_set_color(), and hid_gc_struct::xor_mask.

Here is the call graph for this function:

void ghid_set_line_cap ( hidGC  gc,
EndCapStyle  style 
)

Definition at line 485 of file gtkhid-gl.c.

References Beveled_Cap, hid_gc_struct::cap, hid_gc_struct::gc, gport, hid_gc_struct::join, GHidPort::render_priv, Round_Cap, Square_Cap, style, Trace_Cap, Vz(), WHICH_GC, and hid_gc_struct::width.

Here is the call graph for this function:

void ghid_set_line_cap_angle ( hidGC  gc,
Coord  x1,
Coord  y1,
Coord  x2,
Coord  y2 
)

Definition at line 513 of file gtkhid-gl.c.

void ghid_set_line_width ( hidGC  gc,
Coord  width 
)

Definition at line 491 of file gtkhid-gl.c.

References hid_gc_struct::cap, hid_gc_struct::gc, gport, hid_gc_struct::join, GHidPort::render_priv, Vz(), WHICH_GC, and hid_gc_struct::width.

Here is the call graph for this function:

void ghid_shutdown_renderer ( GHidPort port)

Definition at line 807 of file gtkhid-gl.c.

References render_priv::crosshair_gc, hid_draw_st::destroy_gc, ghid_cancel_lead_user(), hid_st::graphics, gui, and GHidPort::render_priv.

Here is the call graph for this function:

gboolean ghid_start_drawing ( GHidPort port,
GtkWidget *  widget 
)
void ghid_thindraw_pcb_polygon ( hidGC  gc,
PolygonType poly,
const BoxType clip_box 
)

Definition at line 595 of file gtkhid-gl.c.

References common_thindraw_pcb_polygon(), hid_draw_st::fill_pcb_polygon, ghid_set_alpha_mult(), hid_st::graphics, and gui.

Referenced by ghid_init_renderer().

Here is the call graph for this function:

static void ghid_unproject_to_z_plane ( int  ex,
int  ey,
Coord  pcb_z,
Coord pcb_x,
Coord pcb_y 
) [static]

Definition at line 1470 of file gtkhid-gl.c.

References invert_2x2(), last_modelview_matrix, x, and y.

Referenced by ghid_drawing_area_expose_cb(), and ghid_event_to_pcb_coords().

Here is the call graph for this function:

void ghid_view_2d ( void *  ball,
gboolean  view_2d,
gpointer  userdata 
)

Definition at line 1564 of file gtkhid-gl.c.

References ghid_invalidate_all(), and global_view_2d.

Referenced by ghid_build_pcb_top_window().

Here is the call graph for this function:

static void invert_2x2 ( float  m[2][2],
float  out[2][2] 
) [static]

Definition at line 1402 of file gtkhid-gl.c.

References determinant_2x2(), and scale.

Referenced by ghid_unproject_to_z_plane().

Here is the call graph for this function:

gboolean lead_user_cb ( gpointer  data)

Definition at line 1638 of file gtkhid-gl.c.

References ghid_invalidate_all(), LEAD_USER_INITIAL_RADIUS, render_priv::lead_user_radius, render_priv::lead_user_timer, LEAD_USER_VELOCITY, MM_TO_COORD, and TRUE.

Here is the call graph for this function:

static void set_special_grid_color ( void  ) [static]

Definition at line 346 of file gtkhid-gl.c.

References GHidPort::bg_color, GHidPort::colormap, gport, and GHidPort::grid_color.

Referenced by ghid_set_special_colors().

static void start_subcomposite ( void  ) [static]

Definition at line 101 of file gtkhid-gl.c.

References buffer, gport, hidgl_assign_clear_stencil_bit(), hidgl_flush_triangles(), GHidPort::render_priv, and render_priv::subcomposite_stencil_bit.

Referenced by ghid_set_layer().

Here is the call graph for this function:

static int use_gc ( hidGC  gc) [static]

Definition at line 525 of file gtkhid-gl.c.

References hid_gc_struct::me_pointer, and set_gl_color_for_gc().

Here is the call graph for this function:


Variable Documentation

enum mask_mode cur_mask = HID_MASK_OFF [static]

Definition at line 52 of file gtkhid-gl.c.

Referenced by ghid_use_mask().

hidGC current_gc = NULL [static]

Definition at line 46 of file gtkhid-gl.c.

int global_view_2d = 1 [static]

Definition at line 61 of file gtkhid-gl.c.

Referenced by ghid_view_2d().

GLfloat last_modelview_matrix[4][4] [static]
Initial value:
 {{1.0, 0.0, 0.0, 0.0},
                                              {0.0, 1.0, 0.0, 0.0},
                                              {0.0, 0.0, 1.0, 0.0},
                                              {0.0, 0.0, 0.0, 1.0}}

Definition at line 57 of file gtkhid-gl.c.

Referenced by ghid_drawing_area_expose_cb(), ghid_pcb_to_event_coords(), and ghid_unproject_to_z_plane().

GLfloat view_matrix[4][4] [static]
Initial value:
 {{1.0, 0.0, 0.0, 0.0},
                                    {0.0, 1.0, 0.0, 0.0},
                                    {0.0, 0.0, 1.0, 0.0},
                                    {0.0, 0.0, 0.0, 1.0}}

Definition at line 53 of file gtkhid-gl.c.

Referenced by ghid_drawing_area_expose_cb(), and ghid_port_rotate().