Fixed binary search: no more infinite loops when vendor is unknown.
[tangerine.git] / workbench / libs / muimaster / classes / imageadjust.c
blob2aa8e11ae768ee0e634eac7d764b1ae8a35ea19b
1 /*
2 Copyright © 2002-2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #define MUIMASTER_YES_INLINE_STDARG
8 #include <stdio.h>
9 #include <stdlib.h>
11 #include <graphics/gfx.h>
12 #include <graphics/view.h>
13 #include <clib/alib_protos.h>
15 #include <proto/dos.h>
16 #include <proto/exec.h>
17 #include <proto/graphics.h>
18 #include <proto/utility.h>
19 #include <proto/intuition.h>
20 #include <proto/muimaster.h>
22 #include <string.h>
24 /* #define MYDEBUG 1 */
25 #include "debug.h"
27 #include "imspec_intern.h"
28 #include "mui.h"
29 #include "muimaster_intern.h"
30 #include "support.h"
31 #include "support_classes.h"
32 #include "imageadjust_private.h"
34 extern struct Library *MUIMasterBase;
36 STATIC STRPTR StrDupPooled(APTR pool, CONST_STRPTR str)
38 char *newstr;
39 if (!str) return NULL;
40 newstr = AllocPooled(pool,strlen(str)+1);
41 if (newstr) strcpy(newstr,str);
42 return newstr;
45 static void Bitmap_Function(struct Hook *hook, Object *obj, APTR msg)
47 struct Imageadjust_DATA *data = *(struct Imageadjust_DATA **)msg;
48 char buf[255];
49 STRPTR name;
51 get(data->bitmap_string, MUIA_String_Contents, &name);
52 if (name && strlen(name) > 0)
54 snprintf(buf, 255, "5:%s", name);
55 set(data->bitmap_image, MUIA_Imagedisplay_Spec, (IPTR)buf);
60 static void Gradient_Function(struct Hook *hook, Object *obj, APTR msg)
62 struct Imageadjust_DATA *data = *(struct Imageadjust_DATA **)msg;
63 struct MUI_RGBcolor *start_rgb;
64 struct MUI_RGBcolor *end_rgb;
65 LONG angle = XGET(data->gradient_angle_slider, MUIA_Numeric_Value);
66 LONG is_tiled = XGET(data->gradient_type_cycle, MUIA_Cycle_Active);
68 start_rgb = (struct MUI_RGBcolor*)XGET(data->gradient_start_poppen,
69 MUIA_Pendisplay_RGBcolor);
70 end_rgb = (struct MUI_RGBcolor*)XGET(data->gradient_end_poppen,
71 MUIA_Pendisplay_RGBcolor);
73 snprintf(data->gradient_imagespec,sizeof(data->gradient_imagespec),
74 "%s:%d,%08x,%08x,%08x-%08x,%08x,%08x",
75 is_tiled ? "8" : "7",
76 angle,
77 start_rgb->red,start_rgb->green,start_rgb->blue,
78 end_rgb->red,end_rgb->green,end_rgb->blue);
80 set(data->gradient_imagedisplay, MUIA_Imagedisplay_Spec, data->gradient_imagespec);
83 static void GradientSwap_Function(struct Hook *hook, Object *obj, APTR msg)
85 struct Imageadjust_DATA *data = *(struct Imageadjust_DATA **)msg;
86 struct MUI_RGBcolor *start_rgb;
87 struct MUI_RGBcolor *end_rgb;
88 struct MUI_RGBcolor tmp;
90 start_rgb = (struct MUI_RGBcolor*)XGET(data->gradient_start_poppen,
91 MUIA_Pendisplay_RGBcolor);
92 end_rgb = (struct MUI_RGBcolor*)XGET(data->gradient_end_poppen,
93 MUIA_Pendisplay_RGBcolor);
95 tmp = *start_rgb;
96 set(data->gradient_start_poppen, MUIA_Pendisplay_RGBcolor, (IPTR)end_rgb);
97 set(data->gradient_end_poppen, MUIA_Pendisplay_RGBcolor, (IPTR)&tmp);
98 Gradient_Function(NULL,obj,&data);
102 static VOID Pattern_Select_Function(struct Hook *hook, Object *obj, void **msg)
104 struct Imageadjust_DATA *data = (struct Imageadjust_DATA *)hook->h_Data;
105 int new_selected = (int)msg[0];
107 if (data->last_pattern_selected != -1)
108 set(data->pattern_image[data->last_pattern_selected],MUIA_Selected,FALSE);
109 data->last_pattern_selected = new_selected;
113 static VOID Vector_Select_Function(struct Hook *hook, Object *obj, void **msg)
115 struct Imageadjust_DATA *data = (struct Imageadjust_DATA *)hook->h_Data;
116 int new_selected = (int)msg[0];
118 if (data->last_vector_selected != -1)
119 set(data->vector_image[data->last_vector_selected],MUIA_Selected,FALSE);
120 data->last_vector_selected = new_selected;
124 struct ExternalListEntry {
125 STRPTR reldir;
126 ULONG dirlen;
127 STRPTR filename;
128 ULONG namelen;
129 LONG type;
132 static void Imageadjust_External_Display(struct Hook *h, char **strings,
133 struct ExternalListEntry *entry)
135 static char buf[256];
137 if (entry->filename)
139 int len;
140 *strings = buf;
141 snprintf(buf, 256, "%s", FilePart(entry->filename));
142 buf[255] = 0;
143 len = strlen(buf);
144 if (len > 4 && !strcmp(buf + len - 4, ".mf0"))
145 buf[len - 4] = 0;
146 else if (len > 4 && !strcmp(buf + len - 4, ".mb0"))
147 buf[len - 4] = 0;
148 else if (len > 4 && !strcmp(buf + len - 4, ".mbr"))
149 buf[len - 4] = 0;
150 else if (len > 6 && !strcmp(buf + len - 6, ".image"))
151 buf[len - 6] = 0;
155 static struct ExternalListEntry *
156 Imageadjust_External_Construct(struct Hook *h,
157 APTR pool,
158 struct ExternalListEntry *ele)
160 struct ExternalListEntry *entry = NULL;
162 if (NULL == ele)
163 return NULL;
165 if (NULL != ele->filename)
167 entry = AllocPooled(pool, sizeof(struct ExternalListEntry));
168 if (NULL != entry)
170 *entry = *ele;
171 entry->filename = StrDupPooled(pool, entry->filename);
172 entry->reldir = StrDupPooled(pool, entry->reldir);
173 return entry;
176 return NULL;
179 static void Imageadjust_External_Destruct(struct Hook *h, APTR pool,
180 struct ExternalListEntry *entry)
182 if (entry != NULL)
184 if (entry->filename != NULL)
185 FreePooled(pool, entry->filename, entry->namelen + 1);
186 if (entry->reldir != NULL)
187 FreePooled(pool, entry->reldir, entry->dirlen + 1);
188 FreePooled(pool, entry, sizeof(struct ExternalListEntry));
193 /**************************************************************************
194 Adds a directory to the list
195 **************************************************************************/
196 static int AddDirectory(Object *list, STRPTR dir, LONG parent)
198 BPTR lock = Lock(dir,ACCESS_READ);
199 struct ExAllControl *eac;
200 struct ExAllData *ead, *EAData;
201 LONG more;
202 int dir_len = strlen(dir);
203 if (!lock) return 0;
205 //bug("AddDirectory: locked %s\n", dir);
207 eac = (struct ExAllControl*)AllocDosObject(DOS_EXALLCONTROL, NULL);
208 if (!eac)
210 UnLock(lock);
211 return 0;
214 EAData = AllocVec(1024, 0);
215 if (!EAData)
217 FreeDosObject(DOS_EXALLCONTROL, eac);
218 UnLock(lock);
219 return 0;
222 eac->eac_LastKey = 0;
226 //DoMethod(_app(list), MUIM_Application_InputBuffered);
228 more = ExAll(lock, EAData, 1024, ED_TYPE, eac);
229 if ((!more) && (IoErr() != ERROR_NO_MORE_ENTRIES)) break;
230 if (eac->eac_Entries == 0) continue;
232 ead = EAData;
235 size_t namelen = strlen(ead->ed_Name);
236 int len = dir_len + namelen + 10;
237 char *buf;
239 //DoMethod(_app(list), MUIM_Application_InputBuffered);
241 buf = AllocVec(len,0);
242 if (buf)
244 LONG num;
245 int is_directory;
246 BOOL add_me = TRUE;
248 if (ead->ed_Type > 0)
250 is_directory = 1;
251 if (ead->ed_Type == ST_SOFTLINK)
253 /* TODO: Special handling */
255 } else is_directory = 0;
257 strcpy(buf, dir);
258 AddPart(buf, ead->ed_Name, len);
260 if (!is_directory && namelen > 4
261 && !strcmp(ead->ed_Name + namelen - 4, ".mf1"))
262 add_me = FALSE;
263 if (!is_directory && namelen > 4
264 && !strcmp(ead->ed_Name + namelen - 4, ".mb1"))
265 add_me = FALSE;
267 if (add_me)
269 struct ExternalListEntry ele;
270 //bug("AddDirectory: adding image %s\n", buf);
273 ele.reldir = dir + strlen(IMSPEC_EXTERNAL_PREFIX);
274 ele.dirlen = strlen(ele.reldir);
275 ele.filename = ead->ed_Name;
276 ele.namelen = strlen(ele.filename);
277 ele.type = ead->ed_Type;
279 if (! is_directory)
281 num = DoMethod(list, MUIM_List_InsertSingle,
282 (IPTR)&ele,
283 MUIV_List_Insert_Bottom);
286 #warning "FIXME: where does num's value come from here?"
287 if (num != -1 && is_directory)
289 AddDirectory(list, buf, num);
291 FreeVec(buf);
293 ead = ead->ed_Next;
294 } while (ead);
295 } while (more);
297 FreeVec(EAData);
298 FreeDosObject(DOS_EXALLCONTROL, eac);
299 UnLock(lock);
300 return 1;
305 /**************************************************************************
307 **************************************************************************/
308 STATIC VOID Imageadjust_SetImagespec(Object *obj, struct Imageadjust_DATA *data, char *spec)
310 char *s;
311 if (!spec) spec = "0:128";
313 s = (char*)spec;
315 switch (*s)
317 case '0':
319 LONG pat;
320 StrToLong(s+2,&pat);
321 pat -= MUII_BACKGROUND;
323 if (pat >= 0 && pat < 18)
325 set(data->pattern_image[pat],MUIA_Selected,TRUE);
326 set(obj,MUIA_Group_ActivePage,0);
329 break;
331 case '1':
333 LONG vect;
334 StrToLong(s+2,&vect);
336 if (vect >= 0 && vect < 24)
338 set(data->vector_image[vect],MUIA_Selected,TRUE);
339 set(obj,MUIA_Group_ActivePage,1);
343 break;
345 case '2':
346 switch(data->adjust_type)
348 case MUIV_Imageadjust_Type_All:
349 case MUIV_Imageadjust_Type_Image:
350 nfset(obj, MUIA_Group_ActivePage, 2);
351 break;
352 case MUIV_Imageadjust_Type_Background:
353 nfset(obj, MUIA_Group_ActivePage, 1);
354 break;
355 default:
356 nfset(obj, MUIA_Group_ActivePage, 0);
357 break;
359 D(bug("imageadjust: setting color to %s\n", s));
360 set(data->color_group, MUIA_Penadjust_Spec, (IPTR)s+2);
361 break;
363 case '3':
364 case '4':
366 struct ExternalListEntry *entry;
367 LONG entries;
368 int i;
370 set(obj, MUIA_Group_ActivePage, 3);
372 get(data->external_list, MUIA_List_Entries, &entries);
373 for (i = 0; i < entries; i++)
375 DoMethod(data->external_list, MUIM_List_GetEntry, i,
376 (IPTR)&entry);
377 if (entry != NULL
378 && entry->reldir != NULL
379 && entry->filename != NULL)
381 STRPTR file = FilePart(s+2);
382 //bug("entry->reldir = %s, s + 2 = %s, len=%d\n",
383 //entry->reldir, s + 2, strlen(s + 2) - strlen(file) - 1);
384 if (!strncmp(entry->reldir, s + 2,
385 strlen(s + 2) - strlen(file) - 1))
387 //bug("entry->filename = %s, file = %s\n",
388 //entry->filename, file);
389 if (!strcmp(entry->filename, file))
391 set(data->external_list, MUIA_List_Active, i);
392 break;
398 break;
400 case '5':
401 set(data->bitmap_string,MUIA_String_Contents,(IPTR)s+2);
402 Bitmap_Function(NULL, obj, &data);
403 if (data->adjust_type == MUIV_Imageadjust_Type_All)
404 set(obj,MUIA_Group_ActivePage,4);
405 else
406 set(obj,MUIA_Group_ActivePage,2);
407 break;
409 case '6':
411 LONG img;
412 StrToLong(s+2,&img);
414 break;
416 case '7':
417 case '8':
419 struct MUI_ImageSpec_intern spec;
420 if (zune_gradient_string_to_intern(s+2,&spec))
422 struct MUI_RGBcolor col;
423 col.red = spec.u.gradient.start_rgb[0]*0x01010101;
424 col.green = spec.u.gradient.start_rgb[1]*0x01010101;
425 col.blue = spec.u.gradient.start_rgb[2]*0x01010101;
427 nnset(data->gradient_start_poppen, MUIA_Pendisplay_RGBcolor, &col);
429 col.red = spec.u.gradient.end_rgb[0]*0x01010101;
430 col.green = spec.u.gradient.end_rgb[1]*0x01010101;
431 col.blue = spec.u.gradient.end_rgb[2]*0x01010101;
433 nnset(data->gradient_end_poppen, MUIA_Pendisplay_RGBcolor, &col);
435 nnset(data->gradient_angle_slider, MUIA_Numeric_Value, spec.u.gradient.angle);
437 set(data->gradient_type_cycle, MUIA_Cycle_Active, *s == '7' ? 0 : 1);
440 Gradient_Function(NULL,obj,&data);
441 if (data->adjust_type == MUIV_Imageadjust_Type_All)
442 set(obj,MUIA_Group_ActivePage,5);
443 else
444 set(obj,MUIA_Group_ActivePage,3);
446 break;
450 IPTR Imageadjust__OM_NEW(struct IClass *cl, Object *obj, struct opSet *msg)
452 struct Imageadjust_DATA *data;
453 struct TagItem *tag;
454 const struct TagItem *tags;
455 static const char * const labels_all[] = {"Pattern", "Vector", "Color", "External", "Bitmap", "Gradient", NULL};
456 static const char * const labels_image[] = {"Pattern", "Vector", "Color", "External", NULL};
457 static const char * const labels_bg[] = {"Pattern", "Color", "Bitmap", "Gradient", NULL};
458 static const char * const labels_color[] = {"Color", NULL};
459 static const char * const gradient_type_entries[] = {"Scaled", "Tiled", NULL};
461 Object *pattern_group = NULL;
462 Object *vector_group = NULL;
463 Object *external_list = NULL;
464 Object *bitmap_string = NULL;
465 Object *bitmap_image = NULL;
466 Object *bitmap_popasl = NULL;
467 Object *gradient_imagedisplay = NULL;
468 Object *gradient_start_poppen = NULL;
469 Object *gradient_end_poppen = NULL;
470 Object *gradient_angle_slider = NULL;
471 Object *gradient_type_cycle = NULL;
472 Object *gradient_horiz_button = NULL;
473 Object *gradient_vert_button = NULL;
474 Object *gradient_swap_button = NULL;
475 char *spec = NULL;
476 LONG i;
477 LONG adjust_type;
478 Object *color_group = NULL;
479 Object *external_group = NULL;
480 Object *bitmap_group = NULL;
481 Object *gradient_group = NULL;
483 adjust_type = GetTagData(MUIA_Imageadjust_Type, MUIV_Imageadjust_Type_All,
484 msg->ops_AttrList);
486 color_group = MUI_NewObject(MUIC_Penadjust, TAG_DONE);
488 if (adjust_type == MUIV_Imageadjust_Type_All ||
489 adjust_type == MUIV_Imageadjust_Type_Image)
491 external_group = (Object *)ListviewObject,
492 MUIA_Listview_List, (IPTR)(external_list = (Object *)ListObject,
493 InputListFrame,
494 MUIA_List_ConstructHook, MUIV_List_ConstructHook_String,
495 MUIA_List_DestructHook, MUIV_List_DestructHook_String,
496 End),
497 End;
500 if (adjust_type == MUIV_Imageadjust_Type_All ||
501 adjust_type == MUIV_Imageadjust_Type_Background)
503 bitmap_group = (Object *)VGroup,
504 Child, (IPTR)(bitmap_image = (Object *)ImagedisplayObject,
505 TextFrame,
506 InnerSpacing(0,0),
507 MUIA_Imagedisplay_FreeHoriz, TRUE,
508 MUIA_Imagedisplay_FreeVert, TRUE,
509 MUIA_Dropable, FALSE,
510 End),
511 Child, (IPTR)(bitmap_popasl = (Object *)PopaslObject,
512 MUIA_Popstring_String, (IPTR)(bitmap_string = (Object *)StringObject,
513 StringFrame,
514 MUIA_CycleChain, 1,
515 End),
516 MUIA_Popstring_Button, (IPTR)PopButton(MUII_PopFile),
517 End),
518 End;
520 gradient_group = (Object *)ColGroup(2),
521 Child, (IPTR)FreeLabel("Type:"),
522 Child, (IPTR)(gradient_type_cycle = MUI_MakeObject(MUIO_Cycle,
523 (IPTR)"Type:", (IPTR)gradient_type_entries)),
524 Child, (IPTR)FreeLabel("Angle:"),
525 Child, (IPTR)VGroup,
526 Child, (IPTR)HGroup,
527 MUIA_Group_SameWidth, TRUE,
528 Child, (IPTR)(gradient_horiz_button = (Object *)TextObject,
529 ButtonFrame,
530 MUIA_Background, MUII_ButtonBack,
531 MUIA_InputMode, MUIV_InputMode_RelVerify,
532 MUIA_Text_PreParse, (IPTR)"\33c",
533 MUIA_Text_Contents, (IPTR)"Vertical",
534 End),
535 Child, (IPTR)(gradient_vert_button = (Object *)TextObject,
536 ButtonFrame,
537 MUIA_Background, MUII_ButtonBack,
538 MUIA_InputMode, MUIV_InputMode_RelVerify,
539 MUIA_Text_PreParse, (IPTR)"\33c",
540 MUIA_Text_Contents, (IPTR)"Horizontal",
541 End),
542 End,
543 Child, (IPTR)(gradient_angle_slider = (Object *)SliderObject,
544 MUIA_Group_Horiz, TRUE,
545 MUIA_Numeric_Min, 0,
546 MUIA_Numeric_Max, 179,
547 End),
548 End,
549 Child, (IPTR)FreeLabel("Colors:"),
550 Child, (IPTR)HGroup,
551 Child, (IPTR)(gradient_start_poppen = (Object *)PoppenObject,
552 MUIA_Window_Title, (IPTR) "Start pen",
553 MUIA_Pendisplay_Spec, (IPTR) "rbbbbbbbb,bbbbbbbb,bbbbbbbb", End),
554 Child, (IPTR)VCenter((gradient_swap_button = (Object *)TextObject,
555 ButtonFrame,
556 MUIA_Background, MUII_ButtonBack,
557 MUIA_InputMode, MUIV_InputMode_RelVerify,
558 MUIA_Text_Contents, (IPTR)"<->",
559 MUIA_Weight, 0,
560 End)),
561 Child, (IPTR)(gradient_end_poppen = (Object *)PoppenObject,
562 MUIA_Window_Title, (IPTR) "End pen",
563 MUIA_Pendisplay_Spec, (IPTR)"r55555555,55555555,55555555", End),
564 End,
565 Child, (IPTR)FreeLabel("Preview:"),
566 Child, (IPTR)(gradient_imagedisplay = (Object *)ImagedisplayObject,
567 TextFrame,
568 InnerSpacing(0,0),
569 MUIA_Imagedisplay_FreeHoriz, TRUE,
570 MUIA_Imagedisplay_FreeVert, TRUE,
571 MUIA_Dropable, FALSE,
572 End),
573 End;
576 switch (adjust_type)
578 case MUIV_Imageadjust_Type_All:
579 obj = (Object *)DoSuperNewTags(cl, obj, NULL,
580 MUIA_Register_Titles, (IPTR)labels_all,
581 Child, (IPTR)HCenter((pattern_group = (Object *)ColGroup(6), End)),
582 Child, (IPTR)HCenter((vector_group = (Object *)ColGroup(6), End)),
583 Child, (IPTR)color_group,
584 Child, (IPTR)external_group,
585 Child, (IPTR)bitmap_group,
586 Child, (IPTR)gradient_group,
587 TAG_MORE, (IPTR)msg->ops_AttrList);
588 break;
589 case MUIV_Imageadjust_Type_Background:
590 obj = (Object *)DoSuperNewTags(cl, obj, NULL,
591 MUIA_Register_Titles, (IPTR)labels_bg,
592 Child, (IPTR)HCenter((pattern_group = (Object *)ColGroup(6), End)),
593 Child, (IPTR)color_group,
594 Child, (IPTR)bitmap_group,
595 Child, (IPTR)gradient_group,
596 TAG_MORE, (IPTR)msg->ops_AttrList);
597 break;
598 case MUIV_Imageadjust_Type_Image:
599 obj = (Object *)DoSuperNewTags(cl, obj, NULL,
600 MUIA_Register_Titles, (IPTR)labels_image,
601 Child, (IPTR)HCenter((pattern_group = (Object *)ColGroup(6), End)),
602 Child, (IPTR)HCenter((vector_group = (Object *)ColGroup(6), End)),
603 Child, (IPTR)color_group,
604 Child, (IPTR)external_group,
605 TAG_MORE, (IPTR)msg->ops_AttrList);
606 break;
607 case MUIV_Imageadjust_Type_Pen:
608 obj = (Object *)DoSuperNewTags(cl, obj, NULL,
609 MUIA_Register_Titles, (IPTR)labels_color,
610 Child, (IPTR)color_group,
611 TAG_MORE, (IPTR)msg->ops_AttrList);
612 break;
615 if (!obj) return FALSE;
617 data = INST_DATA(cl, obj);
618 data->adjust_type = adjust_type;
619 data->color_group = color_group;
620 data->originator = (APTR)GetTagData(MUIA_Imageadjust_Originator, 0, msg->ops_AttrList);
622 if (adjust_type != MUIV_Imageadjust_Type_Pen)
624 data->last_pattern_selected = -1;
625 data->pattern_select_hook.h_Data = data;
626 data->pattern_select_hook.h_Entry = HookEntry;
627 data->pattern_select_hook.h_SubEntry = (HOOKFUNC)Pattern_Select_Function;
629 for (i=0;i<18;i++)
631 data->pattern_image[i] = (Object *)ImageObject,
632 ButtonFrame,
633 MUIA_CycleChain, 1,
634 InnerSpacing(4,4),
635 MUIA_Image_Spec, i + MUII_BACKGROUND,
636 MUIA_InputMode, MUIV_InputMode_Immediate,
637 MUIA_Image_FreeHoriz, TRUE,
638 MUIA_Image_FreeVert, TRUE,
639 MUIA_FixWidth, 16,
640 MUIA_FixHeight, 16,
641 End;
643 if (data->pattern_image[i])
645 DoMethod(pattern_group,OM_ADDMEMBER,(IPTR)data->pattern_image[i]);
646 DoMethod(data->pattern_image[i],MUIM_Notify,MUIA_Selected,TRUE,(IPTR)obj,3,MUIM_CallHook,(IPTR)&data->pattern_select_hook,i);
650 if (adjust_type != MUIV_Imageadjust_Type_Background)
652 data->last_vector_selected = -1;
653 data->vector_select_hook.h_Data = data;
654 data->vector_select_hook.h_Entry = HookEntry;
655 data->vector_select_hook.h_SubEntry = (HOOKFUNC)Vector_Select_Function;
657 for (i=0;i<24;i++)
659 char spec[10];
661 snprintf(spec, sizeof(spec), "1:%d", i);
662 data->vector_image[i] = (Object *)ImageObject,
663 ButtonFrame,
664 InnerSpacing(4,4),
665 MUIA_CycleChain, 1,
666 MUIA_Image_Spec, (IPTR)spec,
667 MUIA_InputMode, MUIV_InputMode_Immediate,
668 MUIA_Weight, 0,
669 End;
671 if (data->vector_image[i])
673 DoMethod(vector_group,OM_ADDMEMBER,(IPTR)data->vector_image[i]);
674 DoMethod(data->vector_image[i],MUIM_Notify,MUIA_Selected,TRUE,(IPTR)obj,3,MUIM_CallHook,(IPTR)&data->vector_select_hook,i);
677 } /* if (adjust_type != MUIV_Imageadjust_Type_Background) */
679 if (adjust_type != MUIV_Imageadjust_Type_Image)
681 data->bitmap_string = bitmap_string;
682 data->bitmap_image = bitmap_image;
683 data->bitmap_hook.h_Entry = HookEntry;
684 data->bitmap_hook.h_SubEntry = (HOOKFUNC)Bitmap_Function;
685 DoMethod(bitmap_popasl, MUIM_Notify, MUIA_Popasl_Active, FALSE,
686 (IPTR)obj, 3, MUIM_CallHook, (IPTR)&data->bitmap_hook, (IPTR)data);
687 DoMethod(bitmap_string, MUIM_Notify, MUIA_String_Acknowledge, MUIV_EveryTime,
688 (IPTR)obj, 3, MUIM_CallHook, (IPTR)&data->bitmap_hook, (IPTR)data);
690 } /* if (adjust_type != MUIV_Imageadjust_Type_Pen) */
692 if (gradient_imagedisplay)
694 data->gradient_imagedisplay = gradient_imagedisplay;
695 data->gradient_start_poppen = gradient_start_poppen;
696 data->gradient_end_poppen = gradient_end_poppen;
697 data->gradient_angle_slider = gradient_angle_slider;
698 data->gradient_type_cycle = gradient_type_cycle;
699 data->gradient_vert_button = gradient_vert_button;
700 data->gradient_horiz_button = gradient_horiz_button;
701 data->gradient_swap_button = gradient_swap_button;
703 DoMethod(gradient_vert_button, MUIM_Notify, MUIA_Pressed, FALSE,
704 (IPTR)gradient_angle_slider, 3, MUIM_Set, MUIA_Numeric_Value, 90);
705 DoMethod(gradient_horiz_button, MUIM_Notify, MUIA_Pressed, FALSE,
706 (IPTR)gradient_angle_slider, 3, MUIM_Set, MUIA_Numeric_Value, 0);
708 data->gradient_swap_hook.h_Entry = HookEntry;
709 data->gradient_swap_hook.h_SubEntry = (HOOKFUNC)GradientSwap_Function;
710 DoMethod(gradient_swap_button, MUIM_Notify, MUIA_Pressed, FALSE,
711 (IPTR)obj, 3, MUIM_CallHook, (IPTR)&data->gradient_swap_hook, (IPTR)data);
713 data->gradient_hook.h_Entry = HookEntry;
714 data->gradient_hook.h_SubEntry = (HOOKFUNC)Gradient_Function;
715 DoMethod(gradient_start_poppen, MUIM_Notify, MUIA_Pendisplay_Spec, MUIV_EveryTime,
716 (IPTR)obj, 3, MUIM_CallHook, (IPTR)&data->gradient_hook, (IPTR)data);
717 DoMethod(gradient_end_poppen, MUIM_Notify, MUIA_Pendisplay_Spec, MUIV_EveryTime,
718 (IPTR)obj, 3, MUIM_CallHook, (IPTR)&data->gradient_hook, (IPTR)data);
719 DoMethod(gradient_angle_slider, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime,
720 (IPTR)obj, 3, MUIM_CallHook, (IPTR)&data->gradient_hook, (IPTR)data);
721 DoMethod(gradient_type_cycle, MUIM_Notify, MUIA_Cycle_Active, MUIV_EveryTime,
722 (IPTR)obj, 3, MUIM_CallHook, (IPTR)&data->gradient_hook, (IPTR)data);
724 /* Set the gradient image to correct values */
725 Gradient_Function(NULL,obj,&data);
727 } /* if (gradient_imagedisplay) */
729 /* parse initial taglist */
730 for (tags = msg->ops_AttrList; (tag = NextTagItem(&tags)); )
732 switch (tag->ti_Tag)
734 case MUIA_Imageadjust_Spec:
735 spec = (char*)tag->ti_Data;
736 break;
740 if (adjust_type != MUIV_Imageadjust_Type_Background &&
741 adjust_type != MUIV_Imageadjust_Type_Pen)
743 data->external_list = external_list;
744 data->external_display_hook.h_Entry = HookEntry;
745 data->external_display_hook.h_SubEntry = (HOOKFUNC)Imageadjust_External_Display;
746 set(data->external_list, MUIA_List_DisplayHook, (IPTR)&data->external_display_hook);
748 data->external_construct_hook.h_Entry = HookEntry;
749 data->external_construct_hook.h_SubEntry = (HOOKFUNC)Imageadjust_External_Construct;
750 set(data->external_list, MUIA_List_ConstructHook, (IPTR)&data->external_construct_hook);
752 data->external_destruct_hook.h_Entry = HookEntry;
753 data->external_destruct_hook.h_SubEntry = (HOOKFUNC)Imageadjust_External_Destruct;
754 set(data->external_list, MUIA_List_DestructHook, (IPTR)&data->external_destruct_hook);
756 /* Because we have many childs, we disable the forwarding of the notify method */
757 DoMethod(obj, MUIM_Group_DoMethodNoForward, MUIM_Notify,
758 MUIA_Group_ActivePage, 3, (IPTR)obj, 1,
759 MUIM_Imageadjust_ReadExternal);
761 if (data->originator)
762 DoMethod(data->external_list, MUIM_Notify,
763 MUIA_Listview_DoubleClick, TRUE,
764 MUIV_Notify_Application, 5, MUIM_Application_PushMethod,
765 (IPTR)data->originator, 2, MUIM_Popimage_CloseWindow, TRUE);
767 Imageadjust_SetImagespec(obj,data,spec);
768 return (IPTR)obj;
771 IPTR Imageadjust__OM_DISPOSE(struct IClass *cl, Object *obj, Msg msg)
773 struct Imageadjust_DATA *data = INST_DATA(cl, obj);
775 if (data->imagespec) FreeVec(data->imagespec);
777 DoSuperMethodA(cl,obj,msg);
778 return 0;
781 IPTR Imageadjust__OM_SET(struct IClass *cl, Object *obj, struct opSet *msg)
783 const struct TagItem *tags;
784 struct TagItem *tag;
785 struct Imageadjust_DATA *data = INST_DATA(cl, obj);
787 for (tags = msg->ops_AttrList; (tag = NextTagItem(&tags)); )
789 switch (tag->ti_Tag)
791 case MUIA_Imageadjust_Spec:
792 Imageadjust_SetImagespec(obj,data,(char*)tag->ti_Data);
793 break;
797 return DoSuperMethodA(cl,obj,(Msg)msg);
800 IPTR Imageadjust__OM_GET(struct IClass *cl, Object *obj, struct opGet *msg)
802 struct Imageadjust_DATA *data = INST_DATA(cl, obj);
803 struct pages {
804 LONG type;
805 LONG pos[6];
808 const static struct pages pages_per_type[] =
810 { MUIV_Imageadjust_Type_Pen, { 2, -1, -1, -1, -1, -1} },
811 { MUIV_Imageadjust_Type_Background, { 0, 2, 4, 5, -1, -1} },
812 { MUIV_Imageadjust_Type_Image, { 0, 1, 2, 3, -1, -1} },
813 { MUIV_Imageadjust_Type_All, { 0, 1, 2, 3, 4, 5} },
816 switch (msg->opg_AttrID)
818 case MUIA_Imageadjust_Spec:
820 int i;
822 LONG act;
823 if (data->imagespec)
825 FreeVec(data->imagespec);
826 data->imagespec = NULL;
829 get(obj, MUIA_Group_ActivePage, &act);
831 for (i = 0; i < 4; i++)
833 if (pages_per_type[i].type == data->adjust_type)
834 break;
837 act = pages_per_type[i].pos[act];
839 switch (act)
841 case 0: /* Pattern */
842 if ((data->imagespec = AllocVec(40,0)))
844 if (data->last_pattern_selected != -1)
845 snprintf(data->imagespec, 40, "0:%d",
846 data->last_pattern_selected+128);
847 else
848 strcpy(data->imagespec,"0:128");
850 break;
852 case 1:
853 if ((data->imagespec = AllocVec(20,0)))
855 if (data->last_vector_selected != -1)
856 snprintf(data->imagespec, 20, "1:%d",
857 data->last_vector_selected);
858 else
859 strcpy(data->imagespec,"0:128");
861 break;
863 case 2:
865 struct MUI_PenSpec *penspec;
867 get(data->color_group, MUIA_Penadjust_Spec, &penspec);
868 if (penspec)
870 LONG len;
871 D(bug("imageadjust: penspec = %s\n", penspec));
872 len = strlen((STRPTR)penspec) + 3;
873 if ((data->imagespec = AllocVec(len, 0)))
874 snprintf(data->imagespec, len, "2:%s", penspec->ps_buf);
877 break;
879 case 3: /* External */
881 struct ExternalListEntry *entry;
883 DoMethod(data->external_list, MUIM_List_GetEntry,
884 MUIV_List_GetEntry_Active, (IPTR)&entry);
885 if (entry != NULL && entry->filename != NULL&& entry->reldir != NULL)
887 LONG len;
888 len = 2 + strlen(entry->reldir) + 1 + strlen(entry->filename) + 1;
889 if ((data->imagespec = AllocVec(len, 0)))
891 snprintf(data->imagespec, len, "3:%s/%s",
892 entry->reldir, entry->filename);
893 D(bug("Imageadjust_OM_GET: imspec=%s\n", data->imagespec));
897 break;
899 case 4: /* Bitmap */
901 char *str;
902 get(data->bitmap_string,MUIA_String_Contents,&str);
903 if (str)
905 LONG len;
906 len = strlen(str) + 10;
907 if ((data->imagespec = AllocVec(len, 0)))
908 snprintf(data->imagespec, len, "5:%s", str);
911 break;
913 case 5: /* Gradient */
914 data->imagespec = StrDup(data->gradient_imagespec);
915 break;
917 if (data->imagespec) *msg->opg_Storage = (ULONG)data->imagespec;
918 else *msg->opg_Storage = (ULONG)"0:128";
920 return TRUE;
923 return (DoSuperMethodA(cl, obj, (Msg) msg));
926 IPTR Imageadjust__MUIM_Imageadjust_ReadExternal(struct IClass *cl, Object *obj, Msg msg)
928 struct Imageadjust_DATA *data = INST_DATA(cl, obj);
930 DoMethod(data->external_list, MUIM_List_Clear);
931 set(data->external_list, MUIA_List_Quiet, TRUE);
932 AddDirectory(data->external_list, IMSPEC_EXTERNAL_PREFIX, -1);
933 set(data->external_list, MUIA_List_Quiet, FALSE);
934 return 0;
937 #if 0
938 IPTR Imageadjust__MUIM_Imageadjust_ExternalSelected(struct IClass *cl, Object *obj, Msg msg)
940 struct Imageadjust_DATA *data = INST_DATA(cl, obj);
942 if (data->originator)
943 DoMethod(_app(obj), MUIM_Application_PushMethod, data->originator, 2,
944 MUIM_Popimage_CloseWindow, TRUE);
945 return 0;
947 #endif
949 #if ZUNE_BUILTIN_IMAGEADJUST
950 BOOPSI_DISPATCHER(IPTR, Imageadjust_Dispatcher, cl, obj, msg)
952 switch (msg->MethodID)
954 case OM_NEW:
955 return Imageadjust__OM_NEW(cl, obj, (struct opSet *)msg);
957 case OM_DISPOSE:
958 return Imageadjust__OM_DISPOSE(cl,obj,(APTR)msg);
960 case OM_SET:
961 return Imageadjust__OM_SET(cl, obj, (struct opSet *)msg);
963 case OM_GET:
964 return Imageadjust__OM_GET(cl,obj,(APTR)msg);
966 case MUIM_Imageadjust_ReadExternal:
967 return Imageadjust__MUIM_Imageadjust_ReadExternal(cl,obj,(APTR)msg);
969 //case MUIM_Imageadjust_ExternalSelected:
970 //return Imageadjust__MUIM_Imageadjust_ExternalSelected(cl,obj,(APTR)msg);
972 default:
973 return DoSuperMethodA(cl, obj, msg);
976 BOOPSI_DISPATCHER_END
978 const struct __MUIBuiltinClass _MUI_Imageadjust_desc =
980 MUIC_Imageadjust,
981 MUIC_Register,
982 sizeof(struct Imageadjust_DATA),
983 (void*)Imageadjust_Dispatcher
985 #endif /* ZUNE_BUILTIN_IMAGEADJUST */