1997-11-25 06:05:25 +08:00
|
|
|
/* The GIMP -- an image manipulation program
|
|
|
|
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
1998-04-13 13:44:11 +08:00
|
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
1997-11-25 06:05:25 +08:00
|
|
|
*/
|
|
|
|
#include "appenv.h"
|
|
|
|
#include "draw_core.h"
|
|
|
|
|
|
|
|
|
|
|
|
DrawCore *
|
1999-06-26 19:16:47 +08:00
|
|
|
draw_core_new (DrawCoreDraw draw_func)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
DrawCore * core;
|
|
|
|
|
|
|
|
core = (DrawCore *) g_malloc (sizeof (DrawCore));
|
|
|
|
|
|
|
|
core->draw_func = draw_func;
|
|
|
|
core->draw_state = INVISIBLE;
|
|
|
|
core->gc = NULL;
|
|
|
|
core->paused_count = 0;
|
|
|
|
core->data = NULL;
|
1999-05-30 11:08:24 +08:00
|
|
|
core->line_width = 0;
|
1997-11-25 06:05:25 +08:00
|
|
|
core->line_style = GDK_LINE_SOLID;
|
1999-05-02 05:37:34 +08:00
|
|
|
core->cap_style = GDK_CAP_NOT_LAST;
|
1997-11-25 06:05:25 +08:00
|
|
|
core->join_style = GDK_JOIN_MITER;
|
|
|
|
|
|
|
|
return core;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
1999-06-26 19:16:47 +08:00
|
|
|
draw_core_start (DrawCore *core,
|
|
|
|
GdkWindow *win,
|
|
|
|
Tool *tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
GdkColor fg, bg;
|
|
|
|
|
|
|
|
if (core->draw_state != INVISIBLE)
|
|
|
|
draw_core_stop (core, tool);
|
|
|
|
|
|
|
|
core->win = win;
|
|
|
|
core->data = (void *) tool;
|
|
|
|
core->paused_count = 0; /* reset pause counter to 0 */
|
|
|
|
|
|
|
|
/* create a new graphics context */
|
|
|
|
if (! core->gc)
|
|
|
|
core->gc = gdk_gc_new (win);
|
|
|
|
|
|
|
|
gdk_gc_set_function (core->gc, GDK_INVERT);
|
|
|
|
fg.pixel = 0xFFFFFFFF;
|
|
|
|
bg.pixel = 0x00000000;
|
|
|
|
gdk_gc_set_foreground (core->gc, &fg);
|
|
|
|
gdk_gc_set_background (core->gc, &bg);
|
|
|
|
gdk_gc_set_line_attributes (core->gc, core->line_width, core->line_style,
|
|
|
|
core->cap_style, core->join_style);
|
|
|
|
|
|
|
|
(* core->draw_func) (tool);
|
|
|
|
|
|
|
|
core->draw_state = VISIBLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
1999-06-26 19:16:47 +08:00
|
|
|
draw_core_stop (DrawCore *core,
|
|
|
|
Tool *tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
if (core->draw_state == INVISIBLE)
|
|
|
|
return;
|
|
|
|
|
|
|
|
(* core->draw_func) (tool);
|
|
|
|
|
|
|
|
core->draw_state = INVISIBLE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
1999-06-26 19:16:47 +08:00
|
|
|
draw_core_resume (DrawCore *core,
|
|
|
|
Tool *tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
core->paused_count = (core->paused_count > 0) ? core->paused_count - 1 : 0;
|
|
|
|
if (core->paused_count == 0)
|
|
|
|
{
|
|
|
|
core->draw_state = VISIBLE;
|
|
|
|
(* core->draw_func) (tool);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
1999-06-26 19:16:47 +08:00
|
|
|
draw_core_pause (DrawCore *core,
|
|
|
|
Tool *tool)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
if (core->paused_count == 0)
|
|
|
|
{
|
|
|
|
core->draw_state = INVISIBLE;
|
|
|
|
(* core->draw_func) (tool);
|
|
|
|
}
|
|
|
|
core->paused_count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
1999-06-26 19:16:47 +08:00
|
|
|
draw_core_free (DrawCore *core)
|
1997-11-25 06:05:25 +08:00
|
|
|
{
|
|
|
|
if (core)
|
|
|
|
{
|
|
|
|
if (core->gc)
|
|
|
|
gdk_gc_destroy (core->gc);
|
|
|
|
g_free (core);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|