draw_core.c 2.75 KB
Newer Older
Elliot Lee's avatar
Elliot Lee committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
/* 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
16
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
Elliot Lee's avatar
Elliot Lee committed
17 18 19 20 21 22
 */
#include "appenv.h"
#include "draw_core.h"


DrawCore *
23
draw_core_new (DrawCoreDraw draw_func)
Elliot Lee's avatar
Elliot Lee committed
24 25 26 27 28 29 30 31 32 33
{
  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;
34
  core->line_width   = 0;
Elliot Lee's avatar
Elliot Lee committed
35
  core->line_style   = GDK_LINE_SOLID;
36
  core->cap_style    = GDK_CAP_NOT_LAST;
Elliot Lee's avatar
Elliot Lee committed
37 38 39 40 41 42 43
  core->join_style   = GDK_JOIN_MITER;

  return core;
}


void
44 45 46
draw_core_start (DrawCore  *core,
		 GdkWindow *win,
		 Tool      *tool)
Elliot Lee's avatar
Elliot Lee committed
47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
{
  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
76 77
draw_core_stop (DrawCore *core,
		Tool     *tool)
Elliot Lee's avatar
Elliot Lee committed
78 79 80 81 82 83 84 85 86 87 88
{
  if (core->draw_state == INVISIBLE)
    return;

  (* core->draw_func) (tool);

  core->draw_state = INVISIBLE;
}


void
89 90
draw_core_resume (DrawCore *core,
		  Tool     *tool)
Elliot Lee's avatar
Elliot Lee committed
91 92 93 94 95 96 97 98 99 100 101
{
  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
102 103
draw_core_pause (DrawCore *core,
		 Tool     *tool)
Elliot Lee's avatar
Elliot Lee committed
104 105 106 107 108 109 110 111 112 113 114
{
  if (core->paused_count == 0)
    {
      core->draw_state = INVISIBLE;
      (* core->draw_func) (tool);
    }
  core->paused_count++;
}


void
115
draw_core_free (DrawCore *core)
Elliot Lee's avatar
Elliot Lee committed
116 117 118 119 120 121 122 123 124 125
{
  if (core)
    {
      if (core->gc)
	gdk_gc_destroy (core->gc);
      g_free (core);
    }
}