Exemplo n.º 1
0
void CMiscPrefPage::HandleOK()
{
	HWND hActiveWnd;
	LPIMAGE lpImage = NULL;
	if (hActiveWnd = GetActiveDoc())
		lpImage = GetImagePtr(hActiveWnd);
	if (lpImage && m_MaskTint != Control.MaskTint &&
		ImgGetViewMode(lpImage) == VM_SLIME)
	{
		RECT rRect;

		rRect = GetDisplayPtr(hActiveWnd)->DispRect;
		AstralToWindowsRect(&rRect);
		::InvalidateRect( hActiveWnd, &rRect, FALSE );
	}
	if (!Control.IndependentSettings &&
		Control.IndependentSettings != m_IndependentSettings)
		SetCommonSettings();
	if (Control.UseTablet)
    {
		Control.UseTablet = TabletStart();
        if (!Control.UseTablet)
        {
            LPSTR    lp;

            AstralStr(IDS_NOTABLET, &lp);
            ::MessageBox(PictPubApp.Get_hWndAstral(), lp, szAppName, 
               MB_ICONHAND | MB_OK | MB_TASKMODAL);
        }
    }
	CPPPropertyPage::HandleOK();
}
Exemplo n.º 2
0
void MAPaintTabletInit(
  ThreeDViewStruct	*view_struct)
{
  TabletEvent	event;
  int		quitFlag;
  Widget	dialog;
  XmString	text, title;
  WlzDVertex2	tabVtxs[2], wlzVtxs[2];
  Widget	slider;
  WlzAffineTransform	*trans;

  /* ignore if already open */
  if( tablet ){
    return;
  }

  /* open the tablet */
  if( (tablet = TabletOpen(WACOM_IV_TABLET_TYPE,
			   "/dev/term/b", NULL)) == NULL ){
    HGU_XmUserError(globals.topl,
		    "Open Wacom Tablet:\n"
		    "    Failed to open the tablet, please check\n"
		    "    the tablet is connected to serial line b\n"
		    "    and switched on, then try again.",
		    XmDIALOG_FULL_APPLICATION_MODAL);
    return;
  }

  /* set tilt mode and start the tablet */
  TabletSetMode(tablet, TABLET_TILTMODE_MASK);
  tablet->cntrlMode2 |= TABLET_CORRECT_TILT_MASK;
  tablet->cntrlMode2 |= TABLET_TRANSFORM_MASK;
  TabletStart(tablet);

  /* if the tablet needs the coordinates set then do so here */
  if( !view_struct->tablet_initialised ){
    /* get first coordinate */
    /* put up an application modal dialog to request first
       coordinate */
    dialog = XmCreateMessageDialog(view_struct->canvas,
				   "MAPaint Message", NULL, 0);
    XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_CANCEL_BUTTON));
    XtUnmanageChild(XmMessageBoxGetChild(dialog, XmDIALOG_OK_BUTTON));
    XtSetSensitive(XmMessageBoxGetChild(dialog, XmDIALOG_HELP_BUTTON),
		   False);
    text  = XmStringCreateLtoR("Input tablet reference point 1 please",
			       XmSTRING_DEFAULT_CHARSET);
    title = XmStringCreateSimple("MAPaint Tablet Message");

    XtVaSetValues(dialog,
		  XmNmessageString,	text,
		  XmNdialogTitle,	title,
		  XmNdialogStyle,	XmDIALOG_FULL_APPLICATION_MODAL,
		  NULL);

    XmStringFree( text );
    XmStringFree( title );

    /* popup widget and process events */
    XtManageChild( dialog );
    XSync(XtDisplay(view_struct->canvas), False);
    quitFlag = 0;
    while( quitFlag < 100 ){
      if((XtAppPending(globals.app_con) > 0) ){
	XtAppProcessEvent(globals.app_con, XtIMAll);
      }
      else {
	XSync(XtDisplay(view_struct->canvas), False);
	usleep(1000);
	quitFlag++;
      }
    }
    
    quitFlag = 0;
    while( !quitFlag ){
      if( TabletNextEvent(tablet, &event) == TABLET_ERR_NONE ){
	if(event.buttonPressed && 
	   ((event.buttons == 1) || (event.buttons == 3))){
	  tabVtxs[0].vtX = event.x;
	  tabVtxs[0].vtY = event.y;
	  quitFlag = 1;
	  XBell(XtDisplay(view_struct->canvas), 100);
	  XFlush(XtDisplay(view_struct->canvas));
	}
      }
      else {
	TabletClose(tablet);
	tablet = NULL;
	XtDestroyWidget(dialog);
	return;
      }
    }

    /* get second coordinate */
    text  = XmStringCreateLtoR("Input tablet reference point 2 please",
			       XmSTRING_DEFAULT_CHARSET);

    XtVaSetValues(dialog,
		  XmNmessageString,	text,
		  NULL);

    XmStringFree( text );

    /* popup widget and process events */
    XtManageChild( dialog );
    XSync(XtDisplay(view_struct->canvas), False);
    while( (XtAppPending(globals.app_con) > 0) ){
      XtAppProcessEvent(globals.app_con, XtIMAll);
      XSync(XtDisplay(view_struct->canvas), False);
    }
    
    quitFlag = 0;
    sleep(1);
    TabletClearEvents(tablet);
    while( !quitFlag ){
      if( TabletNextEvent(tablet, &event) == TABLET_ERR_NONE ){
	if(event.buttonPressed && 
	   ((event.buttons == 1) || (event.buttons == 3))){
	  tabVtxs[1].vtX = event.x;
	  tabVtxs[1].vtY = event.y;
	  quitFlag = 1;
	  XBell(XtDisplay(view_struct->canvas), 100);
	  XFlush(XtDisplay(view_struct->canvas));
	}
      }
      else {
	TabletClose(tablet);
	XtDestroyWidget(dialog);
	tablet = NULL;
	return;
      }
    }
    TabletStop(tablet);
    XtDestroyWidget(dialog);
    usleep(10000);
    TabletClearEvents(tablet);

    /* set the reference coordinates */
    view_struct->ref1.vtX = tabVtxs[0].vtX;
    view_struct->ref1.vtY = tabVtxs[0].vtY;
    view_struct->ref2.vtX = tabVtxs[1].vtX;
    view_struct->ref2.vtY = tabVtxs[1].vtY;
  }
  else {
    tabVtxs[0].vtX = view_struct->ref1.vtX;
    tabVtxs[0].vtY = view_struct->ref1.vtY;
    tabVtxs[1].vtX = view_struct->ref2.vtX;
    tabVtxs[1].vtY = view_struct->ref2.vtY;
  }

  /* set tablet transform parameters */
  if((slider = XtNameToWidget(tablet_controls, "*.x1")) )
  {
    wlzVtxs[0].vtX = HGU_XmGetSliderValue(slider);
  }
  if((slider = XtNameToWidget(tablet_controls, "*.y1")) )
  {
    wlzVtxs[0].vtY = HGU_XmGetSliderValue(slider);
  }
  if((slider = XtNameToWidget(tablet_controls, "*.x2")) )
  {
    wlzVtxs[1].vtX = HGU_XmGetSliderValue(slider);
  }
  if( (slider = XtNameToWidget(tablet_controls, "*.y2")))
  {
    wlzVtxs[1].vtY = HGU_XmGetSliderValue(slider);
  }
  trans = WlzAffineTransformLSq2D(2, tabVtxs, 2, wlzVtxs, 0, NULL,
				  WLZ_TRANSFORM_2D_NOSHEAR, NULL);
  tablet->xTrans[0] = trans->mat[0][0];
  tablet->xTrans[1] = trans->mat[0][1];
  tablet->xTrans[2] = trans->mat[0][2];
  tablet->yTrans[0] = trans->mat[1][0];
  tablet->yTrans[1] = trans->mat[1][1];
  tablet->yTrans[2] = trans->mat[1][2];
  WlzFreeAffineTransform(trans);
  view_struct->tablet_initialised = 1;

  /* initialise the globals */
  modifiers = 0;
  tabletDrawingFlag = 0;
  quitDrawingTrigger = 0;
  if( tabletPoly ){
    WlzFreePolyDmn(tabletPoly);
    tabletPoly = NULL;
  }

  /* now add the tablet stream as an event input source */
  TabletStart(tablet);
  TabletClearEvents(tablet);
  tabletInputId = XtAppAddInput(globals.app_con, tablet->fd,
				(XtPointer) XtInputReadMask,
				tabletInputProc, (XtPointer) view_struct);

  return;
}