Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals

drawTv_pick.c

Go to the documentation of this file.
00001 /*********
00002  * Copyright (c) 2003, Division of Imaging Science and Biomedical Engineering,
00003  * University of Manchester, UK.  All rights reserved.
00004  * 
00005  * Redistribution and use in source and binary forms, with or without modification, 
00006  * are permitted provided that the following conditions are met:
00007  * 
00008  *   . Redistributions of source code must retain the above copyright notice, 
00009  *     this list of conditions and the following disclaimer.
00010  *    
00011  *   . Redistributions in binary form must reproduce the above copyright notice,
00012  *     this list of conditions and the following disclaimer in the documentation 
00013  *     and/or other materials provided with the distribution.
00014  * 
00015  *   . Neither the name of the University of Manchester nor the names of its
00016  *     contributors may be used to endorse or promote products derived from this 
00017  *     software without specific prior written permission.
00018  * 
00019  * 
00020  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
00021  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
00022  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
00023  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
00024  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
00025  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
00026  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00027  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
00028  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
00029  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
00030  * POSSIBILITY OF SUCH DAMAGE.
00031  *
00032  **********
00033  *
00034  * Program :    TINA
00035  * File    :  $Source: /home/tina/cvs/tina-tools/tinatool/draw/drawTv_pick.c,v $
00036  * Date    :  $Date: 2003/10/01 16:02:47 $
00037  * Version :  $Revision: 1.2 $
00038  * CVS Id  :  $Id: drawTv_pick.c,v 1.2 2003/10/01 16:02:47 tony Exp $
00039  *
00040  * Author  : Legacy TINA
00041  *
00042  * Notes :
00043  *
00044  *********
00045 */
00046 
00047 #include "drawTv_pick.h"
00048 
00049 #if HAVE_CONFIG_H
00050   #include <config.h>
00051 #endif
00052 
00053 #include <stdio.h>
00054 #include <string.h>
00055 #include <math.h>
00056 
00057 #if HAVE_STDARG_H
00058 #  include <stdarg.h>
00059 #  define VA_START(a, f)                va_start(a, f)
00060 #else
00061 #  if HAVE_VARARGS_H
00062 #    include <varargs.h>
00063 #    define VA_START(a, f)  va_start(a)
00064 #  endif
00065 #endif /* HAVE_STDARG_H */
00066 #ifndef VA_START
00067   error no variadic api available
00068 #endif
00069 
00070 #include <tina/sys/sysDef.h>
00071 #include <tina/sys/sysPro.h>
00072 #include <tina/math/mathDef.h>
00073 #include <tina/math/mathPro.h>
00074 #include <tinatool/draw/draw_TvDef.h>
00075 #include <tinatool/draw/draw_TvPro.h>
00076 
00077 void    tv_set_pick(Tv * tv, Tv_pick pick)
00078 {
00079     if (tv == NULL)
00080         return;
00081 
00082     list_rm(tv->pick.picklist, tv->pick.free);
00083     /* tv_repaint(tv);  */
00084 
00085     tv->pick = pick;
00086     if (tv->tv_screen != NULL && tv->activity == PICK)
00087         (void) tv_set_activity_message(tv);
00088 }
00089 
00090 void    tv_set_pick_reset(Tv * tv, void (*reset) ( /* ??? */ ))
00091 {
00092     if (tv->pick_reset != reset)
00093     {
00094         (*tv->pick_reset) ();
00095         tv->pick_reset = reset;
00096     }
00097 }
00098 
00099 void    tv_pick_proc(Tv * tv, int state, Ipos pos)
00100 {
00101     static void *picked;
00102     static int type;
00103     Tv_pick *pick = &tv->pick;
00104     List   *ref_addtostart();
00105 
00106     switch (state)
00107     {
00108     case LEFT_DOWN:
00109         tv_set_overlay(tv);     /* also calls tv_save_draw */
00110         picked = (*pick->closest) (tv, pos, &type);
00111         (*pick->draw) (tv, picked, type);
00112         break;
00113     case LEFT_DRAG:
00114         (*pick->draw) (tv, picked, type);
00115         picked = (*pick->closest) (tv, pos, &type);
00116         (*pick->draw) (tv, picked, type);
00117         break;
00118     case LEFT_UP:
00119         (*pick->draw) (tv, picked, type);
00120         if (picked != NULL)
00121             pick->picklist = ref_addtostart(pick->picklist, picked, type);
00122         tv_reset_draw(tv);
00123         tv_save_draw(tv);
00124         tv_color_set(tv, green);
00125         (*pick->draw) (tv, picked, type);
00126         tv_reset_draw(tv);
00127         break;
00128     case MIDDLE_DOWN:
00129         (*pick->func) (tv, pick->picklist);
00130         list_rm(pick->picklist, pick->free);
00131         pick->picklist = NULL;
00132         if (pick->do_repaint)
00133             tv_repaint(tv);
00134         break;
00135     case RIGHT_DOWN:
00136         list_rm(pick->picklist, pick->free);
00137         pick->picklist = NULL;
00138         if (pick->do_repaint)
00139             tv_repaint(tv);
00140         break;
00141     }
00142 }
00143 
00144 static void *null_closest(void)
00145 {
00146     return (NULL);
00147 }
00148 
00149 Tv_pick null_pick(void)
00150 {
00151     Tv_pick pick = {Tv_pick_id};
00152 
00153     (void) strcpy(pick.name, "null");
00154     pick.picklist = NULL;
00155     pick.closest = null_closest;
00156     pick.highlight = null_function;
00157     pick.draw = null_function;
00158     pick.func = null_function;
00159     pick.free = null_function;
00160     pick.do_repaint = true;
00161     return (pick);
00162 }
00163 
00164 
00165 Tv_pick 
00166 #if HAVE_STDARG_H
00167 pick_define(int case_flag, ...)
00168 #else
00169 pick_define(case_flag, va_alist)
00170         int case_flag;
00171   va_dcl
00172 #endif /* HAVE_STDARG_H */
00173 {
00174     Tv_pick pick = {Tv_pick_id};
00175     va_list ap;
00176 
00177     VA_START(ap, case_flag);
00178 
00179     pick = null_pick();
00180     pick.picklist = NULL;
00181     while (case_flag)
00182     {
00183         switch (case_flag)
00184         {
00185         case PICK_NAME:
00186             (void) strcpy(pick.name, (char *) va_arg(ap, char *));
00187             break;
00188         case PICK_CLOSEST:
00189             pick.closest = (void *((*) ())) va_arg(ap, void *);
00190             break;
00191         case PICK_HIGHLIGHT:
00192             pick.highlight = (void (*) ()) va_arg(ap, void *);
00193             break;
00194         case PICK_DRAW:
00195             pick.draw = (void (*) ()) va_arg(ap, void *);
00196             break;
00197         case PICK_FUNC:
00198             pick.func = (void (*) ()) va_arg(ap, void *);
00199             break;
00200         case PICK_FREE:
00201             pick.free = (void (*) ()) va_arg(ap, void *);
00202             break;
00203         case PICK_REPAINT:
00204             pick.do_repaint = (Bool) va_arg(ap, int);
00205             break;
00206         }
00207         case_flag = (int) va_arg(ap, int);
00208     }
00209     va_end(ap);
00210     return (pick);
00211 }

Generated on Thu Nov 12 02:20:44 2009 for Tools by doxygen 1.3.6