Example #1
0
// stream-based function for the fileIn primitive
static Value* file_in(CharStream* source, int quiet)
{
	init_thread_locals();
	push_alloc_frame();
	three_typed_value_locals(Parser* parser, Value* code, Value* result);
	save_current_frames();
	set_error_trace_back_active( FALSE );

	CharStream* out = thread_local(current_stdout);
	if (!quiet)
		source->log_to(out);

	// loop through stream compiling & evaluating all expressions
	try
	{
		// make a new compiler instance
		vl.parser = new Parser (out);
		source->flush_whitespace();
		while (!source->at_eos() || vl.parser->back_tracked)
		{
			vl.code = vl.parser->compile(source);
			vl.result = vl.code->eval();
			if (!quiet)
				vl.result->print();
			source->flush_whitespace();
		}
		if (vl.parser->expr_level != 0 || vl.parser->back_tracked && vl.parser->token != t_end)
			throw RuntimeError (MaxSDK::GetResourceStringAsMSTR(IDS_UNEXPECTED_END_OF_FILE_DURING_FILEIN));
		source->close();
	}
	catch (...)
	{
		// catch any errors and tell what file we are in if any
		out->puts(_T("Error occurred during fileIn: "));
		source->sprin1(out);
		out->puts(_T("\n"));
		source->close();
		pop_alloc_frame();
		throw;
	}

	// if there was one, return last expression in stream as result
	if (vl.result == NULL)
		vl.result = &ok;
	else
		vl.result = vl.result->get_heap_ptr();
	pop_alloc_frame();
	return_value(vl.result);
}
Example #2
0
// ============================================================================
void AngleControl::CallChangedHandler()
{
   init_thread_locals();
   push_alloc_frame();
   one_value_local(arg);
   vl.arg = Float::intern(m_degrees);
   run_event_handler(parent_rollout, n_changed, &vl.arg, 1);
   pop_value_locals();
   pop_alloc_frame();
}
Example #3
0
// called by TrackMouseCallBack to apply the scripted callback function 
static BOOL
do_track_callback(TrackMouseCallBack* ppcb, Value* message, int flags)
{
	init_thread_locals();
	push_alloc_frame();
	save_current_frames();
	try 
	{
		// build arg list and apply callback fn
		// called as:  callBackFn message intersectRay obj faceNum shiftKey ctrlKey altKey [callback_arg]
		//    message = #mousePoint | #mouseMove | #freeMove | #mouseAbort
		// should return #continue to contine, any other value to stop which is passed back as result of mouseTrack fn
		Value* shiftKey = (flags & MOUSE_SHIFT) ? &true_value : &false_value;
		Value* ctrlKey = (flags & MOUSE_CTRL) ? &true_value : &false_value;
		Value* altKey = (flags & MOUSE_ALT) ? &true_value : &false_value;
		Value* args[8] = { message, ppcb->vl->ray_val, MAXNode::intern(ppcb->hit_node),
						   ppcb->vl->face_num_val, shiftKey, ctrlKey, altKey, 
						   ppcb->track_callback_arg 
						};
		ppcb->vl->result = ppcb->track_callback->apply(args, (ppcb->track_callback_arg ? 8 : 7));
	}
	catch (MAXScriptException)// & e)
	{
		clear_error_source_data();
		restore_current_frames();
		// any error disables the callback
		ppcb->track_callback = NULL;
		MAXScript_signals = 0;
		ppcb->vl->result = &undefined;
	}
	catch (...)
	{
		clear_error_source_data();
		restore_current_frames();
		// any error disables the callback
		ppcb->track_callback = NULL;
		ppcb->vl->result = &undefined;
	}

	if (thread_local(redraw_mode) && thread_local(needs_redraw))
	{
		MAXScript_interface->RedrawViews(MAXScript_interface->GetTime());
		needs_redraw_clear();
	}
	BOOL res = ppcb->vl->result == n_continue;
	pop_alloc_frame(ppcb->vl->result); // make sure stack-based values are handled correctly
	// callback fn returns #continue -> keep going, false -> stop pickpoint
	return res;
}
Example #4
0
LRESULT CALLBACK ish3_ProgressBar::WndProc( HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam )
{
   // Get back at our stored class pointer
   ish3_ProgressBar *UGC = DLGetWindowLongPtr<ish3_ProgressBar*>(hWnd);
   if(UGC == NULL && message != WM_CREATE)
      return DefWindowProc(hWnd, message, wParam, lParam);

   switch ( message ) {
   
      case WM_CREATE:
         {
            LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
            UGC = (ish3_ProgressBar*)lpcs->lpCreateParams;
            DLSetWindowLongPtr(hWnd, UGC);
            break;
         }

      case WM_MOUSEMOVE:
         {
         if(wParam && MK_LBUTTON)
         {
            init_thread_locals();
            push_alloc_frame();
            one_value_local(arg);
            // work out a positional click value and fire a 'clicked' event
            int xPos = LOWORD(lParam);
            int yPos = HIWORD(lParam);
            Rect rect;
            GetClientRect(hWnd,&rect);
            float fDelta = 0.0f;

            if(UGC->type==TYPE_HORIZ)
            {
               int rWide = (rect.right-1)-(rect.left+2);

               float Delta = 100.0f/rWide;
               fDelta = Delta*xPos;
            }
            if(UGC->type==TYPE_VERT)
            {
               int rHigh = (rect.bottom)-(rect.top);

               float Delta = 100.0f/rHigh;
               fDelta = Delta*(rHigh-yPos);
            }
            
            vl.arg = Integer::intern((int)fDelta);
            UGC->run_event_handler(UGC->parent_rollout, n_clicked, &vl.arg, 1);
            pop_value_locals();
            pop_alloc_frame();
         }

         if(UGC->enabled)
            SetCursor(LoadCursor(NULL, IDC_ARROW));
         }
      break;

      case WM_LBUTTONDOWN:
         {
            init_thread_locals();
            push_alloc_frame();
            one_value_local(arg);
            // ditto - just wanted to handle first time clicks
            int xPos = LOWORD(lParam);
            int yPos = HIWORD(lParam);
            Rect rect;
            GetClientRect(hWnd,&rect);
            float fDelta = 0.0f;

            if(UGC->type==TYPE_HORIZ)
            {
               int rWide = (rect.right-1)-(rect.left+2);

               float Delta = 100.0f/rWide;
               fDelta = Delta*xPos;
            }
            if(UGC->type==TYPE_VERT)
            {
               int rHigh = (rect.bottom)-(rect.top);

               float Delta = 100.0f/rHigh;
               fDelta = Delta*(rHigh-yPos);
            }
            
            vl.arg = Integer::intern((int)fDelta);
            UGC->run_event_handler(UGC->parent_rollout, n_clicked, &vl.arg, 1);
            pop_value_locals();
            pop_alloc_frame();
         }
         break;

	  case WM_RBUTTONUP:
		  UGC->call_event_handler(UGC->parent_rollout, n_rightClick, NULL, 0);
		  break;

      case WM_PAINT:
         {
            // begin paint cycle
            PAINTSTRUCT ps;
            HDC hdc;
            hdc = BeginPaint( hWnd, &ps );

            Rect rect;
            GetClientRect(hWnd,&rect);


            // Setup pens, brushes and colours
            SetBkColor( hdc, GetCustSysColor( COLOR_BTNFACE ) );
            SetBkMode( hdc, TRANSPARENT );   
            HPEN hLight = CreatePen( PS_SOLID, 0, GetCustSysColor( COLOR_BTNHIGHLIGHT ) );
            HPEN hBlack = (HPEN)GetStockObject(BLACK_PEN);
            HPEN hDark  = CreatePen( PS_SOLID, 0, GetCustSysColor( COLOR_BTNSHADOW ) );   

            // setup the progress bar colour, taking enabled flag into account
            HBRUSH hProgress;
            if(UGC->enabled)
             hProgress = CreateSolidBrush( UGC->colorPro );
            else hProgress = CreatePatternBrush( LoadBitmap(g_hInst,MAKEINTRESOURCE(IDB_DISABLED)) );

            HPEN hPP;
            if(UGC->enabled)
               hPP = CreatePen( PS_SOLID, 0, UGC->colorPro );
            else hPP = CreatePen( PS_SOLID, 0, GetCustSysColor( COLOR_BTNFACE ) );

            // the 'blanker' definition
            HBRUSH hProgressTerm = CreateSolidBrush( GetCustSysColor( COLOR_BTNFACE ) );
            HPEN hPT = CreatePen( PS_SOLID, 0, GetCustSysColor( COLOR_BTNFACE ) );


            // Do some 3D control drawing (frame)
            SelectObject(hdc, hDark);

            MoveToEx(hdc, rect.right-1, 0, NULL);
            LineTo  (hdc, 0, 0);
            LineTo  (hdc, 0, rect.bottom-1);

            SelectObject(hdc, hBlack);

            MoveToEx(hdc, rect.right-2, 1, NULL);
            LineTo  (hdc, 1, 1);
            LineTo  (hdc, 1, rect.bottom-2);

            SelectObject(hdc, hLight);

            MoveToEx(hdc, 0, rect.bottom-1, NULL);
            LineTo  (hdc, rect.right-1, rect.bottom-1);
            LineTo  (hdc, rect.right-1, 0 );

      // HORIZONTAL DRAW
      if(UGC->type==TYPE_HORIZ)
      {

            // prepare progress bar
            float delta = (float)((rect.right-rect.left)-1)/100.0f;
            int amt     = UGC->value;
            int draw = (int)(amt*delta);

            // handle extremities
            if(amt==100)   draw = ((rect.right-rect.left)-1);
            if(amt==0)     draw = rect.left+1;
            if(draw<=2) draw=2;


            // blit out unused to background
            if(amt!=100)
            {

               HGDIOBJ hOldPen = SelectObject(hdc, hPT);
               HGDIOBJ hOldBrush = SelectObject(hdc, hProgressTerm);
               Rectangle(hdc,draw,2,rect.right-1,rect.bottom-2);
			   SelectObject(hdc, hOldPen);
			   SelectObject(hdc, hOldBrush);
          }

            // draw progress bar
            if(amt>0)
            {
               HGDIOBJ hOldPen = SelectObject(hdc, hPP);
               HGDIOBJ hOldBrush = SelectObject(hdc, hProgress);
               Rectangle(hdc,2,2,draw,rect.bottom-2);
			   SelectObject(hdc, hOldPen);
			   SelectObject(hdc, hOldBrush);
            }
      }
      // VERTICAL DRAW
      if(UGC->type==TYPE_VERT)
      {

            // prepare progress bar
            float delta = (float)((rect.bottom-rect.top)-4)/100.0f;
            int amt     = UGC->value;
            int draw = (int)(amt*delta);

            // handle extremities
            if(amt==100)   draw = ((rect.bottom-rect.top)-4);
            if(amt==0)     draw = 0;//rect.bottom-2;

            
            // blit out unused to background
            if(amt!=100)
            {
               HGDIOBJ hOldPen = SelectObject(hdc, hPT);
               HGDIOBJ hOldBrush = SelectObject(hdc, hProgressTerm);
               Rectangle(hdc,2,rect.top+2,rect.right-2,(rect.bottom-2)-draw);
			   SelectObject(hdc, hOldPen);
			   SelectObject(hdc, hOldBrush);
            }

            // draw progress bar
            if(amt>0)
            {
               HGDIOBJ hOldPen = SelectObject(hdc, hPP);
               HGDIOBJ hOldBrush = SelectObject(hdc, hProgress);
               Rectangle(hdc,2,rect.bottom-2,rect.right-2,(rect.bottom-2)-draw);
			   SelectObject(hdc, hOldPen);
			   SelectObject(hdc, hOldBrush);
            }
      }

            DeleteObject(hLight);
            DeleteObject(hDark);
            DeleteObject(hBlack);
            DeleteObject(hPP);
            DeleteObject(hPT);
            DeleteObject(hProgress);
            DeleteObject(hProgressTerm);

            // end paint cycle
            EndPaint( hWnd, &ps );
            return 0;
         }

   }

   return TRUE;
}