Example #1
0
static PF_Err
DrawEvent(	
	PF_InData		*in_data,
	PF_OutData		*out_data,
	PF_ParamDef		*params[],
	PF_LayerDef		*output,
	PF_EventExtra	*event_extra)
{
	PF_Err			err		=	PF_Err_NONE;
	
	AEGP_SuiteHandler suites(in_data->pica_basicP);
	

	event_extra->evt_out_flags = 0;
	

	if (!(event_extra->evt_in_flags & PF_EI_DONT_DRAW) && params[EXTRACT_DATA]->u.arb_d.value != NULL)
	{
		if(PF_EA_CONTROL == event_extra->effect_win.area)
		{
			ArbitraryData *arb_data = (ArbitraryData *)PF_LOCK_HANDLE(params[EXTRACT_DATA]->u.arb_d.value);
			ExtractStatus *extract_status = (ExtractStatus *)PF_LOCK_HANDLE(in_data->sequence_data);
		
		#define MAX_MESSAGE_LEN 127
			A_char	red_message[MAX_MESSAGE_LEN],
					green_message[MAX_MESSAGE_LEN],
					blue_message[MAX_MESSAGE_LEN],
					alpha_message[MAX_MESSAGE_LEN];
					
			A_char	*channel_message[4] = {	red_message,
											green_message,
											blue_message,
											alpha_message };
			
			ChannelStatus *channel_status[4] = {	&extract_status->red,
													&extract_status->green,
													&extract_status->blue,
													&extract_status->alpha };
												
			ChannelData *channel_data[4] = {	&arb_data->red,
												&arb_data->green,
												&arb_data->blue,
												&arb_data->alpha };
		
			// set up the messages
			for(int i=0; i<4; i++)
			{
				if(channel_data[i]->action == DO_COPY)
				{
					strcpy(channel_message[i], "(copy)");
				}
				else if(channel_data[i]->action == DO_EXTRACT)
				{
					// start with the name
					strcpy(channel_message[i], channel_data[i]->name);
					
					// process status returned from Render()
					if(channel_status[i]->status == STATUS_NOT_FOUND)
					{
						strcat(channel_message[i], " (not found)");
					}
					else if(channel_status[i]->status == STATUS_NO_CHANNELS)
					{
						strcat(channel_message[i], " (none available)");
					}
					else if(channel_status[i]->status == STATUS_ERROR)
					{
						strcat(channel_message[i], " (error)");
					}
					// can't change params during draw, need a click
					//else if(channel_status[i]->status == STATUS_INDEX_CHANGE)
					//{
					//	channel_data[i]->index = channel_status[i]->index;
					//	params[EXTRACT_DATA]->uu.change_flags = PF_ChangeFlag_CHANGED_VALUE;
					//}
				}
			}
			
			PF_Rect control_rect = event_extra->effect_win.current_frame;
			
			
#if PF_AE_PLUG_IN_VERSION < PF_AE100_PLUG_IN_VERSION

		// old-school Carbon/Win32 drawing code

		#ifdef WIN_ENV
			void*			dp = (*(event_extra->contextH))->cgrafptr;
			HDC				ecw_hdc	=	0;
			PF_GET_CGRAF_DATA(dp, PF_CGrafData_HDC, (void **)&ecw_hdc);
			PF_Point		pen;
		#endif

			PF_App_Color	pf_bg_color;
			suites.AppSuite()->PF_AppGetBgColor(&pf_bg_color);
			
		#ifdef MAC_ENV
			RGBColor titleColor, itemColor;
			RGBColor		bg_color;
	
			bg_color.red	=	pf_bg_color.red;
			bg_color.green	=	pf_bg_color.green;
			bg_color.blue	=	pf_bg_color.blue;
			
			RGBBackColor(&bg_color);
		
			EraseRect(&control_rect);
			
			GetForeColor(&itemColor);
			
			titleColor.red   = TITLE_COMP(itemColor.red);
			titleColor.green = TITLE_COMP(itemColor.green);
			titleColor.blue  = TITLE_COMP(itemColor.blue);
				
			RGBForeColor(&titleColor);
		#endif

		#ifdef MAC_ENV
		#define DRAW_STRING(STRING)	DrawText(STRING, 0, strlen(STRING));
		#define MOVE_TO(H, V)		MoveTo( (H), (V) );
		#else
		#define DRAW_STRING(STRING) \
			do{ \
				WCHAR u_string[100]; \
				UTF8toUTF16(STRING, (utf16_char *)u_string, 99); \
				TextOut(ecw_hdc, pen.h, pen.v, u_string, strlen(STRING)); \
			}while(0);
		#define MOVE_TO(H, V)		MoveToEx(ecw_hdc, (H), (V), NULL); pen.h = (H); pen.v = (V);
		#endif

		
#else // PF_AE_PLUG_IN_VERSION >= PF_AE100_PLUG_IN_VERSION

			// new-school Drawbot drawing code
			
			DRAWBOT_DrawRef			drawbot_ref = NULL;
			suites.PFEffectCustomUISuite()->PF_GetDrawingReference(event_extra->contextH, &drawbot_ref);
			
			DRAWBOT_SupplierRef		supplier_ref = NULL;
			DRAWBOT_SurfaceRef		surface_ref = NULL;

			suites.DBDrawbotSuite()->GetSupplier(drawbot_ref, &supplier_ref);
			suites.DBDrawbotSuite()->GetSurface(drawbot_ref, &surface_ref);
				
			DRAWBOT_ColorRGBA title_color = {0.8f, 0.8f, 0.8f, 1.0f};
			DRAWBOT_ColorRGBA item_color = title_color;
			
			item_color.red *= (1.0 - kUI_TITLE_COLOR_SCALEDOWN);
			item_color.green *= (1.0 - kUI_TITLE_COLOR_SCALEDOWN);
			item_color.blue *= (1.0 - kUI_TITLE_COLOR_SCALEDOWN);
			
			DRAWBOT_BrushP title_brushP(suites.DBSupplierSuite(), supplier_ref, &title_color);
			DRAWBOT_BrushP item_brushP(suites.DBSupplierSuite(), supplier_ref, &item_color);
			
			float default_font_sizeF = 0.0;
			suites.DBSupplierSuite()->GetDefaultFontSize(supplier_ref, &default_font_sizeF);
			
			DRAWBOT_FontP fontP(suites.DBSupplierSuite(), supplier_ref, default_font_sizeF);
			
			DRAWBOT_PointF32 text_origin = {0.f, 0.f};
			
			DRAWBOT_BrushP *current_brush = &title_brushP;
			
		#define MOVE_TO(H, V) \
			text_origin.x = (H) + 0.5f; \
			text_origin.y = (V) + 0.5f;
		
		#define DRAW_STRING(STRING) \
			do{ \
				DRAWBOT_UTF16Char u_str[100]; \
				UTF8toUTF16(STRING, u_str, 99); \
				suites.DBSurfaceSuite()->DrawString(surface_ref, current_brush->Get(), fontP.Get(), u_str, \
						&text_origin, kDRAWBOT_TextAlignment_Default, kDRAWBOT_TextTruncation_None, 0.0f); \
			}while(0);
			
#endif //PF_AE_PLUG_IN_VERSION >= PF_AE100_PLUG_IN_VERSION


			// Property Headings
			MOVE_TO(RIGHT_STATUS(control_rect.left), DOWN_PLACE(INFO_RED, control_rect.top) );
			DRAW_STRING("Red");
			
			MOVE_TO(RIGHT_STATUS(control_rect.left), DOWN_PLACE(INFO_GREEN, control_rect.top) );
			DRAW_STRING("Green");

			MOVE_TO(RIGHT_STATUS(control_rect.left), DOWN_PLACE(INFO_BLUE, control_rect.top) );
			DRAW_STRING("Blue");

			MOVE_TO(RIGHT_STATUS(control_rect.left), DOWN_PLACE(INFO_ALPHA, control_rect.top) );
			DRAW_STRING("Alpha");
			
			//Property Items
			PF_Point prop_origin;
			prop_origin.v = control_rect.top;
			
	#if PF_AE_PLUG_IN_VERSION < PF_AE100_PLUG_IN_VERSION
		#ifdef MAC_ENV
			RGBForeColor(&itemColor);
			prop_origin.h = control_rect.left + TextWidth("Alpha", 0, strlen("Alpha"));
		#else
			SIZE text_dim = {15, 8};
			GetTextExtentPoint(ecw_hdc, TEXT("Alpha"), strlen("Alpha"), &text_dim);
			prop_origin.h = control_rect.left + text_dim.cx;
		#endif
	#else
			current_brush = &item_brushP;
			prop_origin.h = control_rect.left + 50;
	#endif
			
			MOVE_TO(RIGHT_PROP(prop_origin.h), DOWN_PLACE(INFO_RED, prop_origin.v) );
			DRAW_STRING(red_message);
			
			MOVE_TO(RIGHT_PROP(prop_origin.h), DOWN_PLACE(INFO_GREEN, prop_origin.v) );
			DRAW_STRING(green_message);

			MOVE_TO(RIGHT_PROP(prop_origin.h), DOWN_PLACE(INFO_BLUE, prop_origin.v) );
			DRAW_STRING(blue_message);

			MOVE_TO(RIGHT_PROP(prop_origin.h), DOWN_PLACE(INFO_ALPHA, prop_origin.v) );
			DRAW_STRING(alpha_message);
			

			event_extra->evt_out_flags = PF_EO_HANDLED_EVENT;

			PF_UNLOCK_HANDLE(params[EXTRACT_DATA]->u.arb_d.value);
			PF_UNLOCK_HANDLE(in_data->sequence_data);
		}
	}

	return err;
}
Example #2
0
static void
ShowAlert(const char *title,
	  const char *ignore, const char *restart, const char *quit,
	  const char *fmt, va_list args)
{
   char                text[4096], buf1[64], buf2[64], buf3[64];
   Window              win, b1 = 0, b2 = 0, b3 = 0, root;
   Display            *dd;
   int                 wid, hih, w, h, i, k, mask;
   XGCValues           gcv;
   GC                  gc;
   unsigned int        len;
   XEvent              ev;
   XSetWindowAttributes att;
   XRectangle          rect1, rect2;
   char                colorful;
   unsigned long       cols[5];
   XColor              xcl;
   Colormap            cmap;
   int                 cnum, fh, x, y, ww, hh, bw, bh;
   char               *str1, *str2, *str3, *p;
   KeyCode             keycode;
   int                 button;
   char              **missing_charset_list_return, *def_string_return;
   int                 missing_charset_count_return;
   XFontStruct       **font_struct_list_return;
   char              **font_name_list_return;

#if 0
   /* Don't play sound here (maybe if not forked/in signal handler - later) */
   SoundPlay(SOUND_ALERT);
#endif

   if (!fmt)
      return;

   Evsnprintf(text, sizeof(text), fmt, args);

   /*
    * We may get here from obscure places like an X-error or signal handler
    * and things seem to work properly only if we do a new XOpenDisplay().
    */
   dd = XOpenDisplay(NULL);
   if (!dd)
     {
	fprintf(stderr, "%s\n", text);
	fflush(stderr);
	return;
     }

   button = 0;

   if (!title)
      title = _("Enlightenment Error");
   str1 = AlertButtonText(1, buf1, sizeof(buf1), ignore);
   str2 = AlertButtonText(2, buf2, sizeof(buf2), restart);
   str3 = AlertButtonText(3, buf3, sizeof(buf3), quit);

   cnum = 0;
   colorful = 0;
   cols[0] = cols[1] = cols[2] = cols[3] = cols[4] = 0;
   cmap = DefaultColormap(dd, DefaultScreen(dd));
   if (DefaultDepth(dd, DefaultScreen(dd)) > 4)
     {
	ExSetColor(&xcl, 220, 220, 220);
	if (!XAllocColor(dd, cmap, &xcl))
	   goto CN;
	cols[cnum++] = xcl.pixel;
	ExSetColor(&xcl, 160, 160, 160);
	if (!XAllocColor(dd, cmap, &xcl))
	   goto CN;
	cols[cnum++] = xcl.pixel;
	ExSetColor(&xcl, 100, 100, 100);
	if (!XAllocColor(dd, cmap, &xcl))
	   goto CN;
	cols[cnum++] = xcl.pixel;
	ExSetColor(&xcl, 0, 0, 0);
	if (!XAllocColor(dd, cmap, &xcl))
	   goto CN;
	cols[cnum++] = xcl.pixel;
	ExSetColor(&xcl, 255, 255, 255);
	if (!XAllocColor(dd, cmap, &xcl))
	   goto CN;
	cols[cnum++] = xcl.pixel;
	colorful = 1;
     }
 CN:

   if (colorful)
      att.background_pixel = cols[1];
   else
      att.background_pixel = BlackPixel(dd, DefaultScreen(dd));
   if (colorful)
      att.border_pixel = cols[3];
   else
      att.border_pixel = WhitePixel(dd, DefaultScreen(dd));
   att.backing_store = Always;
   att.save_under = True;
   att.override_redirect = True;
   mask = CWBackPixel | CWBorderPixel | CWOverrideRedirect | CWSaveUnder |
      CWBackingStore;

#if USE_COMPOSITE_OVERLAY_WINDOW
   /*
    * Intended workings:
    * Composite extension not enabled (or COW not available?)
    * - fall back to root
    * Composite extension enabled
    * - use COW whether or not compositing is enabled, window mode too
    */
   root = XCompositeGetOverlayWindow(dd, DefaultRootWindow(dd));
   if (root == None)
#endif
     {
	root = DefaultRootWindow(dd);
     }
   win = XCreateWindow(dd, root, -100, -100, 1, 1, 0,
		       CopyFromParent, InputOutput, CopyFromParent, mask, &att);

   gc = XCreateGC(dd, win, 0, &gcv);
   if (colorful)
      XSetForeground(dd, gc, cols[3]);
   else
      XSetForeground(dd, gc, att.border_pixel);

   xfs = XCreateFontSet(dd, "fixed",
			&missing_charset_list_return,
			&missing_charset_count_return, &def_string_return);
   if (!xfs)
      goto done;

   if (missing_charset_list_return)
      XFreeStringList(missing_charset_list_return);

   k = XFontsOfFontSet(xfs, &font_struct_list_return, &font_name_list_return);
   fh = 0;
   for (i = 0; i < k; i++)
     {
	h = font_struct_list_return[i]->ascent +
	   font_struct_list_return[i]->descent;
	if (fh < h)
	   fh = h;
     }

   XSelectInput(dd, win, ExposureMask);
   XMapWindow(dd, win);

   XGrabServer(dd);

   XGrabPointer(dd, win, False, ButtonPressMask | ButtonReleaseMask,
		GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
   XGrabKeyboard(dd, win, False, GrabModeAsync, GrabModeAsync, CurrentTime);
   XSetInputFocus(dd, win, RevertToPointerRoot, CurrentTime);

   XSync(dd, False);

   wid = DisplayWidth(dd, DefaultScreen(dd));
   hih = DisplayHeight(dd, DefaultScreen(dd));
   ww = (wid >= 600) ? 600 : (wid / 40) * 40;
   hh = (hih >= 440) ? 440 : (hih / 40) * 40;

   for (i = 40; i < ww; i += 40)
     {
	w = i;
	h = (i * hh) / ww;
	x = (wid - w) >> 1;
	y = (hih - h) >> 1;
	XMoveResizeWindow(dd, win, x, y, w, h);
	DRAW_BOX_OUT(dd, gc, win, 0, 0, w, h);
	XSync(dd, False);
	SleepUs(20000);
     }
   x = (wid - ww) >> 1;
   y = (hih - hh) >> 1;
   XMoveResizeWindow(dd, win, x, y, ww, hh);
   XSync(dd, False);

   bw = 0;
   if (str1)
     {
	ExTextExtents(xfs, str1, strlen(str1), &rect1, &rect2);
	bw = (rect2.width > bw) ? rect2.width : bw;
     }
   if (str2)
     {
	ExTextExtents(xfs, str2, strlen(str2), &rect1, &rect2);
	bw = (rect2.width > bw) ? rect2.width : bw;
     }
   if (str3)
     {
	ExTextExtents(xfs, str3, strlen(str3), &rect1, &rect2);
	bw = (rect2.width > bw) ? rect2.width : bw;
     }
   bw += 20;
   bh = fh + 10;

#define BX(i) (5 + (((ww - bw - 10) * (i)) / 2))
#define BY    (hh - bh - 5)

   if (str1)
     {
	b1 = XCreateWindow(dd, win, BX(0), BY, bw, bh, 0, CopyFromParent,
			   InputOutput, CopyFromParent, mask, &att);
	XMapWindow(dd, b1);
     }
   if (str2)
     {
	b2 = XCreateWindow(dd, win, BX(1), BY, bw, bh, 0, CopyFromParent,
			   InputOutput, CopyFromParent, mask, &att);
	XMapWindow(dd, b2);
     }
   if (str3)
     {
	b3 = XCreateWindow(dd, win, BX(2), BY, bw, bh, 0, CopyFromParent,
			   InputOutput, CopyFromParent, mask, &att);
	XMapWindow(dd, b3);
     }
   XSync(dd, False);

   button = 0;
   for (; button == 0;)
     {
	XNextEvent(dd, &ev);
	switch (ev.type)
	  {
	  case KeyPress:
	     keycode = XKeysymToKeycode(dd, XK_F1);
	     if (keycode == ev.xkey.keycode)
	       {
		  DRAW_BOX_IN(dd, gc, b1, 0, 0, bw, bh);
		  XSync(dd, False);
		  SleepUs(500000);
		  DRAW_BOX_OUT(dd, gc, b1, 0, 0, bw, bh);
		  button = 1;
		  goto do_sync;
	       }
	     keycode = XKeysymToKeycode(dd, XK_F2);
	     if (keycode == ev.xkey.keycode)
	       {
		  DRAW_BOX_IN(dd, gc, b2, 0, 0, bw, bh);
		  XSync(dd, False);
		  SleepUs(500000);
		  DRAW_BOX_OUT(dd, gc, b2, 0, 0, bw, bh);
		  button = 2;
		  goto do_sync;
	       }
	     keycode = XKeysymToKeycode(dd, XK_F3);
	     if (keycode == ev.xkey.keycode)
	       {
		  DRAW_BOX_IN(dd, gc, b3, 0, 0, bw, bh);
		  XSync(dd, False);
		  SleepUs(500000);
		  DRAW_BOX_OUT(dd, gc, b3, 0, 0, bw, bh);
		  button = 3;
		  goto do_sync;
	       }
	     break;

	  case ButtonPress:
	     if (!(ev.xbutton.y >= BY && ev.xbutton.y < BY + bh))
		break;

	     x = BX(0);
	     if (b1 && ev.xbutton.x >= x && ev.xbutton.x < x + bw)
	       {
		  DRAW_BOX_IN(dd, gc, b1, 0, 0, bw, bh);
		  goto do_sync;
	       }
	     x = BX(1);
	     if (b2 && ev.xbutton.x >= x && ev.xbutton.x < x + bw)
	       {
		  DRAW_BOX_IN(dd, gc, b2, 0, 0, bw, bh);
		  goto do_sync;
	       }
	     x = BX(2);
	     if (b3 && ev.xbutton.x >= x && ev.xbutton.x < x + bw)
	       {
		  DRAW_BOX_IN(dd, gc, b3, 0, 0, bw, bh);
		  goto do_sync;
	       }
	     break;

	  case ButtonRelease:
	     if (!(ev.xbutton.y >= BY && ev.xbutton.y < BY + bh))
		break;

	     x = BX(0);
	     if (b1 && ev.xbutton.x >= x && ev.xbutton.x < x + bw)
	       {
		  DRAW_BOX_OUT(dd, gc, b1, 0, 0, bw, bh);
		  button = 1;
		  goto do_sync;
	       }
	     x = BX(1);
	     if (b2 && ev.xbutton.x >= x && ev.xbutton.x < x + bw)
	       {
		  DRAW_BOX_OUT(dd, gc, b2, 0, 0, bw, bh);
		  button = 2;
		  goto do_sync;
	       }
	     x = BX(2);
	     if (b3 && ev.xbutton.x >= x && ev.xbutton.x < x + bw)
	       {
		  DRAW_BOX_OUT(dd, gc, b3, 0, 0, bw, bh);
		  button = 3;
		  goto do_sync;
	       }
	     break;

	  case Expose:
	     /* Flush all other Expose events */
	     while (XCheckTypedWindowEvent(dd, ev.xexpose.window, Expose, &ev))
		;

	     ExTextExtents(xfs, title, strlen(title), &rect1, &rect2);
	     w = rect2.width;

	     DRAW_HEADER(dd, gc, win, (ww - w) / 2, 5 - rect2.y, title);
	     DRAW_BOX_OUT(dd, gc, win, 0, 0, ww, bh);
	     DRAW_BOX_OUT(dd, gc, win, 0, bh - 1, ww, hh - fh - fh - 30 + 2);
	     DRAW_BOX_OUT(dd, gc, win, 0, hh - fh - 20, ww, fh + 20);
	     k = bh;
	     for (p = text;; p += len + 1)
	       {
		  len = strcspn(p, "\n");
		  DRAW_STRING(dd, gc, win, 6, 6 + k + fh, p, len);
		  k += fh + 2;
		  if (p[len] == '\0')
		     break;
	       }
	     if (str1)
	       {
		  ExTextExtents(xfs, str1, strlen(str1), &rect1, &rect2);
		  w = rect2.width;
		  DRAW_HEADER(dd, gc, b1, (bw - w) / 2, 5 - rect2.y, str1);
		  DRAW_BOX_OUT(dd, gc, b1, 0, 0, bw, bh);
		  DRAW_THIN_BOX_IN(dd, gc, win,
				   BX(0) - 2, BY - 2, bw + 4, bh + 4);
	       }
	     if (str2)
	       {
		  ExTextExtents(xfs, str2, strlen(str2), &rect1, &rect2);
		  w = rect2.width;
		  DRAW_HEADER(dd, gc, b2, (bw - w) / 2, 5 - rect2.y, str2);
		  DRAW_BOX_OUT(dd, gc, b2, 0, 0, bw, bh);
		  DRAW_THIN_BOX_IN(dd, gc, win,
				   BX(1) - 2, BY - 2, bw + 4, bh + 4);
	       }
	     if (str3)
	       {
		  ExTextExtents(xfs, str3, strlen(str3), &rect1, &rect2);
		  w = rect2.width;
		  DRAW_HEADER(dd, gc, b3, (bw - w) / 2, 5 - rect2.y, str3);
		  DRAW_BOX_OUT(dd, gc, b3, 0, 0, bw, bh);
		  DRAW_THIN_BOX_IN(dd, gc, win,
				   BX(2) - 2, BY - 2, bw + 4, bh + 4);
	       }
	   do_sync:
	     XSync(dd, False);
	     break;

	  default:
	     break;
	  }
     }

   XFreeFontSet(dd, xfs);
 done:
   XUngrabServer(dd);
   XDestroyWindow(dd, win);
   XFreeGC(dd, gc);
   if (cnum > 0)
      XFreeColors(dd, cmap, cols, cnum, 0);
   XCloseDisplay(dd);

   switch (button)
     {
     default:
     case 1:
	break;
     case 2:
	SessionExit(EEXIT_RESTART, NULL);
	break;
     case 3:
	SessionExit(EEXIT_EXIT, NULL);
	break;
     }
}