⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 moveicon.cc

📁 模糊聚类分析的源程序!
💻 CC
📖 第 1 页 / 共 4 页
字号:
//**************************************************************//*   filename: moveicon.cc                                    *//*                                                            *//**************************************************************//* programmed by: Thomas Wagner                               *//* last change: 25-05-95                                      *//**************************************************************#include <stdio.h>#include <stdlib.h>#include <string.h>#include "moveicon.h"extern unsigned long blackpix, buttonpix, shadowpix, lightpix, yellowbuttonpix,  yellowshadowpix, yellowlightpix, bluebuttonpix, blueshadowpix, bluelightpix,  redbuttonpix, redshadowpix, redlightpix, greenbuttonpix, greenshadowpix,  greenlightpix;extern Cursor movecursor, delconnectcursor, createendcursor, maincursor,  waitcursor;MoveableIconlist::MoveableIconlist (){  moveableicon = NULL;  next = NULL;}MoveableIconlist::~MoveableIconlist (){}void MoveableIconlist::operator+= (MoveableIcon * NewIcon){  if (moveableicon == NULL) {    moveableicon = NewIcon;    first = this;  } else {    MoveableIconlist *temp = this;    while (temp->next != NULL)      temp = temp->next;    temp->next = new MoveableIconlist ();    temp = temp->next;    temp->first = this;    temp->moveableicon = NewIcon;  }}void MoveableIconlist::operator-= (MoveableIcon * DeleteIcon){  if (moveableicon == NULL)    printf ("OhOh - icon not in this list\n");  else {    MoveableIconlist *temp = this, *last;    if (temp->moveableicon == DeleteIcon)	// at first position     {      if (temp->next != NULL) {	temp->moveableicon = temp->next->moveableicon;	temp->next = temp->next->next;      } else	temp->moveableicon = NULL;    } else {      last = temp;      temp = temp->next;      while ((temp->next != NULL) &&	     (temp->moveableicon != DeleteIcon)) {	last = temp;	temp = temp->next;      }      if (temp->moveableicon == NULL)	printf ("OhOh - icon not in this list\n");      else {	last->next = temp->next;      }    }				// if(temp->moveableicon==DeleteIcon)  }}MoveableIcon::MoveableIcon (Display * initdisplay,	      GC initgc,	      XFontStruct * fontstruct,	      MainWindow * initMainwindow,	      int initx, int inity,	      int initwidth, int initheight,	      char *inittext):Icon (initdisplay,      initgc,      initMainwindow->GetWindow (),      fontstruct,      initx, inity, initwidth, initheight,      inittext,      NULL, 0, 0, DEFAULT_BDWIDTH, 0){  short length = strlen (text), counter, textstart = 0;  for (counter = length - 1; counter >= 0; counter--)    if (text[counter] == '/')	// found last "/"     {      textstart = counter + 1;      break;    }  text += textstart;  Mainwindow = initMainwindow;  In = NULL;  Outputs = new Connectlist ();  if (width < XTextWidth (fontstruct, text, strlen (text)))    width = XTextWidth (fontstruct, text, strlen (text)) + 4;  SetSelectedInput (ExposureMask |		    ButtonPressMask |		    ButtonReleaseMask |		    LeaveWindowMask |		    EnterWindowMask |		    ButtonMotionMask);};MoveableIcon::~MoveableIcon (){  Mainwindow->DelMoveableIcon (this);}void MoveableIcon::HandleEvent (XEvent * Event){  static int oldx, oldy;  static Time lastpresstime = 0;  static MoveableIcon *lastpressicon = NULL;  switch (Event->type) {  case Expose:    if (status & ICON_SELECTED)      XCopyArea (display, pixmap_down, window, gc,		 Event->xgraphicsexpose.x, Event->xgraphicsexpose.y,		 Event->xgraphicsexpose.width, Event->xgraphicsexpose.height,		 Event->xgraphicsexpose.x, Event->xgraphicsexpose.y);    else      XCopyArea (display, pixmap_up, window, gc,		 Event->xgraphicsexpose.x, Event->xgraphicsexpose.y,		 Event->xgraphicsexpose.width, Event->xgraphicsexpose.height,		 Event->xgraphicsexpose.x, Event->xgraphicsexpose.y);    break;  case ButtonPress:    if (Event->xbutton.button == Button1) {      RaiseMe ();      Mainwindow->RaiseMe ();      int iconoldx, iconoldy;      char DeleteIcon = FALSE;      switch (Mainwindow->GetStatus ()) {      case MAINNORMALSTATUS:	XGrabPointer (display,		      window,		      TRUE,		      0,		      GrabModeAsync,		      GrabModeAsync,		      window,		      movecursor,		      CurrentTime);	oldx = Event->xbutton.x_root;	oldy = Event->xbutton.y_root;	iconoldx = x;	iconoldy = y;	x -= (int) (width / 2) - Event->xmotion.x;	y -= (int) (height / 2) - Event->xmotion.y;	XMoveWindow (display, window, x, y);	if ((x != iconoldx) || (y != iconoldy)) {	  if (In != NULL) {	    In->EraseArrow ();	    In->MoveEnd (x - iconoldx, y - iconoldy);	  }	  Connectlist *temp = Outputs;	  Connection *connection = temp->GetConnection ();	  while (connection != NULL) {	    connection->EraseArrow ();	    connection->MoveStart (x - iconoldx, y - iconoldy);	    temp = temp->GetNext ();	    if (temp != NULL)	      connection = temp->GetConnection ();	    else	      connection = NULL;	  }	}	DrawIcon (ICON_SELECTED);	status |= ICON_SELECTED;	break;			// // case MAINNORMALSTATUS      case MAINDELETEINPUTSTATUS:	if (GetTyp () == MOVEABLEICONTYP_INPUT)	  DeleteIcon = TRUE;	else	  Mainwindow->printError ("Not an Input-Object!");	break;      case MAINDELETECLASSIFYSTATUS:	if (GetTyp () == MOVEABLEICONTYP_CLASSIFY)	  DeleteIcon = TRUE;	else	  Mainwindow->printError ("Not a Classify-Object!");	break;      case MAINDELETECLUSTERINGSTATUS:	if (GetTyp () == MOVEABLEICONTYP_CLUSTER)	  DeleteIcon = TRUE;	else	  Mainwindow->printError ("Not a Cluster-Object!");	break;      case MAINDELETERULESTATUS:	if (GetTyp () == MOVEABLEICONTYP_RULE)	  DeleteIcon = TRUE;	else	  Mainwindow->printError ("Not a Rule-Object!");	break;      case MAINSAVEINPUTSTATUS:	if (GetTyp () == MOVEABLEICONTYP_INPUT) {	  Mainwindow->Getsaveloadwindow ()	    ->ChangeFunction (WORK_AS_SAVE_SELECTOR,			      ((InputIcon *) this)->GetOutput (),			      OUTPUT_SAVEOBJECT,			      "SAVE INPUT-OBJECT");	  Mainwindow->Getsaveloadwindow ()->MapMe ();	  Mainwindow->SetStatus (MAIN_SAVELOADDISPLAYING_STATUS);	} else	  Mainwindow->printError ("Not a Rule-Object!");	break;      case MAINSAVERULESTATUS:	if (GetTyp () == MOVEABLEICONTYP_RULE) {	  Mainwindow->Getsaveloadwindow ()	    ->ChangeFunction (WORK_AS_SAVE_SELECTOR,			      ((RuleIcon *) this)->GetOutput (),			      OUTPUT_SAVEOBJECT,			      "SAVE RULE-OBJECT");	  Mainwindow->Getsaveloadwindow ()->MapMe ();	  Mainwindow->SetStatus (MAIN_SAVELOADDISPLAYING_STATUS);	} else	  Mainwindow->printError ("Not a Rule-Object!");	break;      case MAINSAVECLASSIFYSTATUS:	if (GetTyp () == MOVEABLEICONTYP_CLASSIFY) {	  Mainwindow->Getsaveloadwindow ()	    ->ChangeFunction (WORK_AS_SAVE_SELECTOR,			      ((ClassifyIcon *) this)->GetOutput (),			      OUTPUT_SAVEOBJECT,			      "SAVE CLASSIFY-OBJECT");	  Mainwindow->Getsaveloadwindow ()->MapMe ();	  Mainwindow->SetStatus (MAIN_SAVELOADDISPLAYING_STATUS);	} else	  Mainwindow->printError ("Not a Classify-Object!");	break;      default:	break;      }      if (DeleteIcon == TRUE) {	// first delete connections	if (In != NULL) {	  In->SendActiontoStart (ICON_REMOVECONNECTOUT, (int) In);	  delete In;	}	Outputs->SendActiontoallEnds (ICON_REMOVECONNECTIN, 0);	delete Outputs;	UnmapMe ();#if 0	/* XXX: would you believe this ??? */	delete this;#endif	Mainwindow->SetStatus (MAINNORMALSTATUS);      }    }    break;			// case ButtonPress  case ButtonRelease:    switch (Event->xbutton.button) {    case Button1:      {	XUngrabPointer (display, CurrentTime);	status &= ~ICON_SELECTED;	DrawIcon (~ICON_SELECTED);	if (((Event->xbutton.time - lastpresstime) < DOUBLECLICKTIME) &&	    (this == lastpressicon) &&	    (Mainwindow->GetStatus () == MAINNORMALSTATUS))	  Doubleclicked ();	lastpresstime = Event->xbutton.time;	lastpressicon = this;      }      if (Event->xbutton.button == Button1 &&	  Event->xbutton.x <= width &&	  Event->xbutton.y <= height &&	  Event->xbutton.y >= -DEFAULT_BDWIDTH &&	  Event->xbutton.x >= -DEFAULT_BDWIDTH) {	Connection *acuteconnection = Mainwindow->GetAcuteconnection ();	switch (Mainwindow->GetStatus ()) {	case MAINSTARTCONNECTSTATUS:	  Mainwindow->SetAcuteconnection (					   new Connection (display,							   gc,							   Mainwindow,			    (int) (x + width * .5), (int) (y + height * .5),			  (int) (x + width * .5), (int) (y + height * .5)));	  Connectout (Mainwindow->GetAcuteconnection ());	  break;	case MAINENDCONNECTSTATUS:	  Connectin (Mainwindow->GetAcuteconnection ());	  break;	case MAINMOVECONNECTSTARTSTATUS:	  if (this == Mainwindow->GetAcuteconnection ()->GetStartIcon ()) {	    acuteconnection->ErasetempArrow ();	    acuteconnection->SetStart (acuteconnection->GetStartIcon ()->x + (int) (acuteconnection->GetStartIcon ()->width / 2),				       acuteconnection->GetStartIcon ()->y + (int) (acuteconnection->GetStartIcon ()->height / 2));	    acuteconnection->SetStatus (CONNECTSTATUS_VISIBLE);	    acuteconnection->DrawArrow ();	    Mainwindow->SetStatus (MAINNORMALSTATUS);	    XDefineCursor (display, Mainwindow->GetWindow (), maincursor);	  } else	    ChangeConnectout (Mainwindow->GetAcuteconnection ());	  break;	case MAINMOVECONNECTENDSTATUS:	  if (this == Mainwindow->GetAcuteconnection ()->GetEndIcon ()) {	    acuteconnection->ErasetempArrow ();	    acuteconnection->SetEnd (acuteconnection->GetEndIcon ()->x + (int) (acuteconnection->GetEndIcon ()->width / 2),				     acuteconnection->GetEndIcon ()->y + (int) (acuteconnection->GetEndIcon ()->height / 2));	    acuteconnection->SetStatus (CONNECTSTATUS_VISIBLE);	    acuteconnection->DrawArrow ();	    Mainwindow->SetStatus (MAINNORMALSTATUS);	    XDefineCursor (display, Mainwindow->GetWindow (), maincursor);	    In = Mainwindow->GetAcuteconnection ();	  } else	    Connectin (Mainwindow->GetAcuteconnection ());	  break;	default:	  break;	}      } {	int oldx = x, oldy = y;	if (x < 0)	  x = 0;	if (x > Mainwindow->width - width)	  x = Mainwindow->width - width - 2 * DEFAULT_BDWIDTH;	if (y < MAIN_TOP_SPACE)	  y = MAIN_TOP_SPACE;	if (y > Mainwindow->height - height)	  y = Mainwindow->height - height - 2 * DEFAULT_BDWIDTH;	if ((oldx != x) || (oldy != y)) {	  XMoveWindow (display, window, x, y);	  CenterConnections ();	}      }      break;			//case Button1:    case Button3:      if (Mainwindow->GetStatus () == MAINNORMALSTATUS)	Pressedbutton3 ();      break;    }    break;			// case ButtonRelease:  case EnterNotify:    if (!(Event->xmotion.state & Button1MotionMask) &&	(status & ICON_SELECTED)) {      status &= ~ICON_SELECTED;      DrawIcon (~ICON_SELECTED);      XUngrabPointer (display, CurrentTime);    }    break;  case MotionNotify:    if ((status & ICON_SELECTED) &&	(Mainwindow->GetStatus () == MAINNORMALSTATUS)) {      /* Next calculate difference and move */      int newx, newy;      newx = Event->xmotion.x_root;      newy = Event->xmotion.y_root;      x += newx - oldx;      y += newy - oldy;      if (In != 0) {	In->EraseArrow ();	In->MoveEnd (newx - oldx, newy - oldy);      }      Connectlist *temp = Outputs;      Connection *acuteconnection = temp->GetConnection ();      while (acuteconnection != NULL) {	acuteconnection->EraseArrow ();	acuteconnection->MoveStart (newx - oldx, newy - oldy);	temp = temp->GetNext ();	if (temp != NULL)	  acuteconnection = temp->GetConnection ();	else	  acuteconnection = NULL;      }      XMoveWindow (display, window, x, y);      oldx = newx;      oldy = newy;    }    break;  }}void MoveableIcon::CenterConnections (){  Connection *connection;  if (In != 0) {    connection = In;    In->EraseArrow ();    In->SetEnd (x + width / 2, y + height / 2);    In->DrawArrow ();  }  Connectlist *temp = Outputs;  connection = temp->GetConnection ();  while (connection != NULL) {    connection->EraseArrow ();    connection->SetStart (x + width / 2, y + height / 2);    temp = temp->GetNext ();    if (temp != NULL)      connection = temp->GetConnection ();    else      connection = NULL;  }  Outputs->DrawAllArrow ();}InputIcon::InputIcon (Display * initdisplay,	   GC initgc,	   XFontStruct * fontstruct,	   MainWindow * initMainwindow,

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -