forgotten commit. disabled until egl is adapted.
[AROS-Contrib.git] / gfx / lunapaint / src / app / palette_editor.c
blob82182aaa071751c17f023f0f99a28b1183938f75
1 /****************************************************************************
2 * *
3 * palette_editor.c -- Lunapaint, *
4 * http://developer.berlios.de/projects/lunapaintami/ *
5 * Copyright (C) 2006, 2007, Hogne Titlestad <hogga@sub-ether.org> *
6 * Copyright (C) 2009-2011 LunaPaint Development Team *
7 * *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the Free Software Foundation, *
20 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21 * *
22 ****************************************************************************/
23 #include <SDI_hook.h>
24 #include "palette_editor.h"
26 Object *paletteWindow;
27 Object *paletteRect;
28 Object *palSlideR;
29 Object *palSlideG;
30 Object *palSlideB;
31 Object *palColRect;
32 Object *palBtnUse;
33 Object *palBtnSave;
34 Object *palBtnLoad;
35 Object *palStrFileSave;
37 // Action buttons
38 Object *palBtnCopy;
39 Object *palBtnSwap;
40 Object *palBtnSpread;
41 Object *palBtnReverse;
42 Object *palBtnClear;
43 Object *palBtnPaste;
45 unsigned int tempCopiedColor;
46 BOOL tempCopiedColorExists;
48 struct Hook rgbslider_hook;
49 struct Hook paletteSave_hook;
50 struct Hook paletteLoad_hook;
51 struct Hook paletteClose_hook;
55 Call the function that opens a palette file requestor and
56 save on the resulting file...
59 HOOKPROTONHNO(paletteSave_func, ULONG, int *param)
61 savePalette ( );
62 return ( IPTR )NULL;
66 We do this when we close the palette window
69 HOOKPROTONHNO(paletteClose_func, ULONG, int *param)
71 set ( paletteWindow, MUIA_Window_Open, FALSE );
72 DoMethod ( tbxAreaPalette, MUIM_Draw );
73 return ( IPTR )NULL;
77 Call the function that opens a palette file requestor and
78 load the resulting file...
81 HOOKPROTONHNO (paletteLoad_func, ULONG, int *param)
83 loadPalette ( );
84 tbxPaletteRedraw ( );
86 return ( IPTR )NULL;
89 To this every time a slider RGB moves...
91 HOOKPROTONHNO(rgbslider_func, ULONG, int *param)
94 // Set current selected color
96 int R = XGET ( palSlideR, MUIA_Numeric_Value );
97 int G = XGET ( palSlideG, MUIA_Numeric_Value );
98 int B = XGET ( palSlideB, MUIA_Numeric_Value );
100 if ( currColor >= 0 && currColor < 256 )
101 globalPalette[ currColor ] = RGBtoPaletteColor ( R, G, B );
103 updateColorPreview ( ); PaletteRedraw ( currColor );
105 return 0;
110 Dispatcher for our palette area
113 BOOPSI_DISPATCHER(IPTR, PaletteArea, cl, obj, msg)
115 switch ( msg->MethodID )
117 case MUIM_Draw:
118 return ( IPTR )PaletteRedraw ( -1 );
120 case MUIM_HandleInput:
121 return ( IPTR )PaletteEvents ( cl, obj, ( struct MUIP_HandleInput* )msg );
123 case MUIM_Setup:
125 if ( 1 )
127 // Update slider positions when the window is initialized
128 struct rgbData colors = paletteColorToRGB ( globalPalette[ currColor ] );
129 set ( palSlideR, MUIA_Numeric_Value, colors.r );
130 set ( palSlideG, MUIA_Numeric_Value, colors.g );
131 set ( palSlideB, MUIA_Numeric_Value, colors.b );
133 MUI_RequestIDCMP( obj, IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE | IDCMP_RAWKEY );
134 return DoSuperMethodA ( cl, obj, msg );
136 case MUIM_Luna_Palette_Copy:
137 return ( IPTR )PaletteActions ( MUIM_Luna_Palette_Copy );
139 case MUIM_Luna_Palette_Paste:
140 return ( IPTR )PaletteActions ( MUIM_Luna_Palette_Paste );
142 case MUIM_Luna_Palette_Swap:
143 return ( IPTR )PaletteActions ( MUIM_Luna_Palette_Swap );
145 case MUIM_Luna_Palette_Reverse:
146 return ( IPTR )PaletteActions ( MUIM_Luna_Palette_Reverse );
148 case MUIM_Luna_Palette_Spread:
149 return ( IPTR )PaletteActions ( MUIM_Luna_Palette_Spread );
151 case MUIM_Luna_Palette_Clear:
152 return ( IPTR )PaletteActions ( MUIM_Luna_Palette_Clear );
154 /* Tool stuff (should be in a dispatcher in the toolbox! */
156 case MUIM_Luna_SetTool_Draw:
157 if ( globalCurrentTool != LUNA_TOOL_CLIPBRUSH )
159 globalBrushMode = 0; // normal drawing mode
160 DoMethod ( tbxAreaPalette, MUIM_Luna_Canvas_AlterBrushShape );
162 globalCurrentTool = LUNA_TOOL_BRUSH;
163 setToolbarActive ( );
164 return 0;
166 case MUIM_Luna_SetTool_Fill:
168 // Make a small brush now
169 globalCurrentTool = LUNA_TOOL_FILL;
170 setToolbarActive ( );
171 return 0;
173 case MUIM_Luna_SetTool_Line:
174 globalCurrentTool = LUNA_TOOL_LINE;
175 setToolbarActive ( );
176 return 0;
178 case MUIM_Luna_SetTool_Rectangle:
179 globalCurrentTool = LUNA_TOOL_RECTANGLE;
180 setToolbarActive ( );
181 return 0;
183 case MUIM_Luna_SetTool_Circle:
184 globalCurrentTool = LUNA_TOOL_CIRCLE;
185 setToolbarActive ( );
186 return 0;
188 case MUIM_Luna_SetTool_ClipBrush:
189 globalCurrentTool = LUNA_TOOL_CLIPBRUSH;
190 globalBrushMode = 1; // clipbrush mode
191 setToolbarActive ( );
192 return 0;
194 case MUIM_Luna_SetTool_Colorpicker:
195 globalCurrentTool = LUNA_TOOL_COLORPICKER;
196 setToolbarActive ( );
197 return 0;
199 case MUIM_Luna_ExecuteRevert:
200 checkMenuEvents ( 595 );
201 return 0;
203 /* End tool stuff */
206 default:
207 return DoSuperMethodA ( cl, obj, msg );
209 return ( IPTR )0;
211 BOOPSI_DISPATCHER_END
213 IPTR PaletteRedraw ( int colorIndex )
215 BOOL WeAreOpen = FALSE; get ( paletteWindow, MUIA_Window_Open, &WeAreOpen );
216 if ( !WeAreOpen ) return ( IPTR )NULL;
218 int Y = XGET ( paletteRect, MUIA_TopEdge );
219 int X = XGET ( paletteRect, MUIA_LeftEdge );
220 int W = XGET ( paletteRect, MUIA_Width );
221 int H = XGET ( paletteRect, MUIA_Height );
223 ULONG *tempBuf = AllocVec ( W * H * 4, MEMF_ANY );
225 double xslice = ( ( double )W / 16 );
226 double yslice = ( ( double )H / 16 );
227 double targetx = xslice * ( currColor % 16 );
228 double targety = yslice * ( currColor / 16 );
230 int y = 0; for ( ; y < H; y++ )
232 int x = 0; for ( ; x < W; x++ )
234 int inX = ( double )x / W * 16;
235 int inY = ( double )y / H * 16;
236 int index = inY * 16 + inX;
237 char check = ( y + x ) % 2;
239 if (
240 index == currColor &&
242 x == ( int )targetx || x == ( int )( targetx + xslice - 1 ) ||
243 y == ( int )targety || y == ( int )( targety + yslice - 1 )
244 ) &&
245 check == 0
248 tempBuf[ y * W + x ] = 0xFFFFFF;
250 else
251 tempBuf[ y * W + x ] = globalPalette[ index ];
255 if ( globalBrushMode == 0 ) makeToolBrush ( );
257 // Plot all colors on screen
258 if ( colorIndex == -1 )
260 WritePixelArray (
261 tempBuf, 0, 0, 4 * W, _rp ( paletteRect ), X, Y, W, H, RECTFMT_RGBA
264 else
265 // Write only the selected color on screen
266 // and the previous selected color
268 // Draw over previous color
269 int targetx = ( prevColor % 16 ) * xslice;
270 int targety = ( prevColor / 16 ) * yslice;
271 WritePixelArray (
272 tempBuf, targetx, targety, 4 * W,
273 _rp ( paletteRect ), targetx + X, targety + Y, ( int )xslice, ( int )yslice,
274 RECTFMT_RGBA
276 // Current color
277 targetx = ( currColor % 16 ) * xslice;
278 targety = ( currColor / 16 ) * yslice;
279 WritePixelArray (
280 tempBuf, targetx, targety, 4 * W,
281 _rp ( paletteRect ), targetx + X, targety + Y, ( int )xslice, ( int )yslice,
282 RECTFMT_RGBA
286 FreeVec ( tempBuf );
288 updateColorPreview ( );
290 return ( IPTR )NULL;
293 IPTR PaletteEvents ( Class *CLASS, Object *self, struct MUIP_HandleInput *msg )
295 if ( msg->imsg )
297 switch ( msg->imsg->Class )
299 case IDCMP_MOUSEBUTTONS:
300 if ( msg->imsg->Code == SELECTDOWN )
302 // Set a color based on click in palette
303 int mousex, mousey, topedge=0, leftedge=0, wi=0, he=0;
304 double slicex, slicey;
305 get ( paletteRect, MUIA_TopEdge, &topedge );
306 get ( paletteRect, MUIA_LeftEdge, &leftedge );
307 get ( paletteRect, MUIA_Width, &wi );
308 get ( paletteRect, MUIA_Height, &he );
309 slicex = ( ( double )wi / 16 );
310 slicey = ( ( double )he / 16 );
311 mousex = ( int )msg->imsg->MouseX - leftedge;
312 mousey = ( int )msg->imsg->MouseY - topedge;
314 // Only regard things happening in the palette area
315 // widget itself
316 if ( mousex >= 0 && mousey >= 0 && mousex < wi && mousey < he )
318 int indexX = ( int )( ( double )mousex / slicex );
319 int indexY = ( int )( ( double )mousey / slicey );
320 int index = ( unsigned int )( ( indexY * 16 ) + indexX );
321 if ( index >= 0 && index < 256 )
323 prevColor = currColor;
324 currColor = ( unsigned int )( ( indexY * 16 ) + indexX );
325 globalColor = globalPalette[ currColor ];
326 DoMethod ( tbxAreaPalette, MUIM_Draw );
329 // Update slider positions
330 struct rgbData colors = paletteColorToRGB ( globalPalette[ currColor ] );
331 set ( palSlideR, MUIA_Numeric_Value, colors.r );
332 set ( palSlideG, MUIA_Numeric_Value, colors.g );
333 set ( palSlideB, MUIA_Numeric_Value, colors.b );
336 break;
337 default:
338 break;
341 return ( IPTR )NULL;
344 IPTR PaletteActions ( ULONG action )
346 switch ( action )
348 case MUIM_Luna_Palette_Copy:
349 tempCopiedColor = *( globalPalette + currColor );
350 tempCopiedColorExists = TRUE;
351 break;
353 case MUIM_Luna_Palette_Paste:
355 if ( tempCopiedColorExists )
357 // Paste copied color
358 *( globalPalette + currColor ) = tempCopiedColor;
359 // Update slider positions
360 struct rgbData colors = paletteColorToRGB ( *( globalPalette + currColor ) );
361 set ( palSlideR, MUIA_Numeric_Value, colors.r );
362 set ( palSlideG, MUIA_Numeric_Value, colors.g );
363 set ( palSlideB, MUIA_Numeric_Value, colors.b );
366 break;
368 case MUIM_Luna_Palette_Swap:
370 // Swap two colors
371 if ( prevColor != currColor )
373 unsigned int tempcol = *( globalPalette + prevColor );
374 *( globalPalette + prevColor ) = *( globalPalette + currColor );
375 *( globalPalette + currColor ) = tempcol;
376 // Update slider positions
377 struct rgbData colors = paletteColorToRGB ( *( globalPalette + currColor ) );
378 set ( palSlideR, MUIA_Numeric_Value, colors.r );
379 set ( palSlideG, MUIA_Numeric_Value, colors.g );
380 set ( palSlideB, MUIA_Numeric_Value, colors.b );
381 // Redraw everything
382 PaletteRedraw ( -1 );
385 break;
387 case MUIM_Luna_Palette_Reverse:
389 if ( currColor != prevColor )
391 unsigned int firstCol = ( currColor > prevColor ) ? prevColor : currColor;
392 unsigned int lastCol = ( currColor > prevColor ) ? currColor : prevColor;
393 int span = ( int )lastCol - ( int )firstCol + 1;
394 unsigned int *temp = AllocVec ( 4 * span, MEMF_ANY );
395 // Copy the present order
396 unsigned int i = 0; for ( ; i < span; i++ )
398 temp[ i ] = globalPalette[ firstCol + i ];
400 // Place the reverse order
401 for ( i = 0; i < span; i++ )
403 globalPalette[ lastCol - i ] = temp[ i ];
406 FreeVec ( temp );
408 // Update slider positions
409 struct rgbData colors = paletteColorToRGB ( *( globalPalette + currColor ) );
410 set ( palSlideR, MUIA_Numeric_Value, colors.r );
411 set ( palSlideG, MUIA_Numeric_Value, colors.g );
412 set ( palSlideB, MUIA_Numeric_Value, colors.b );
413 // Redraw everything
414 PaletteRedraw ( -1 );
417 break;
419 case MUIM_Luna_Palette_Spread:
420 if ( currColor != prevColor )
422 unsigned int firstCol = ( currColor > prevColor ) ? prevColor : currColor;
423 unsigned int lastCol = ( currColor > prevColor ) ? currColor : prevColor;
424 struct rgbData source = paletteColorToRGB ( *( globalPalette + firstCol ) );
425 struct rgbData dest = paletteColorToRGB ( *( globalPalette + lastCol ) );
426 int span = lastCol - firstCol;
427 unsigned int i; for ( i = 1; i < span; i++ )
429 struct rgbData result;
430 int dr = ( int )dest.r;
431 int dg = ( int )dest.g;
432 int db = ( int )dest.b;
433 int sr = ( int )source.r;
434 int sg = ( int )source.g;
435 int sb = ( int )source.b;
436 result.r = ( unsigned int )( sr - ( ( double )( sr - dr ) * ( ( double )i / span ) ) );
437 result.g = ( unsigned int )( sg - ( ( double )( sg - dg ) * ( ( double )i / span ) ) );
438 result.b = ( unsigned int )( sb - ( ( double )( sb - db ) * ( ( double )i / span ) ) );
439 *( globalPalette + firstCol + i ) = RGBtoPaletteColor ( result.r, result.g, result.b );
441 // Redraw everything
442 PaletteRedraw ( -1 );
444 break;
446 case MUIM_Luna_Palette_Clear:
447 if ( 1 )
449 // Clear all colors in palette with current color
450 unsigned int tempColor = *( globalPalette + currColor );
451 unsigned int a = 0; for ( a = 0; a < 256; a++ )
452 *( globalPalette + a ) = tempColor;
453 // Update slider positions
454 struct rgbData colors = paletteColorToRGB ( *( globalPalette + currColor ) );
455 set ( palSlideR, MUIA_Numeric_Value, colors.r );
456 set ( palSlideG, MUIA_Numeric_Value, colors.g );
457 set ( palSlideB, MUIA_Numeric_Value, colors.b );
458 // Redraw everything
459 PaletteRedraw ( -1 );
461 break;
463 default:
464 break;
466 return ( IPTR )NULL;
469 void updateColorPreview ( )
471 // Update only color preview if we have an open window!
473 BOOL state = FALSE;
475 get ( paletteWindow, MUIA_Window_Open, &state );
477 if ( state == TRUE )
479 int R=0, G=0, B=0, W=0, H=0, TE=0, LE=0;
481 get ( palSlideR, MUIA_Numeric_Value, &R );
482 get ( palSlideG, MUIA_Numeric_Value, &G );
483 get ( palSlideB, MUIA_Numeric_Value, &B );
484 get ( palColRect, MUIA_TopEdge, &TE );
485 get ( palColRect, MUIA_LeftEdge, &LE );
486 get ( palColRect, MUIA_Width, &W );
487 get ( palColRect, MUIA_Height, &H );
489 ULONG *tempBuf = AllocVec ( 4 * ( W * H ), MEMF_ANY );
490 unsigned int tempCol = RGBtoPaletteColor ( R, G, B );
492 int Y = 0; for ( ; Y < H; Y++ )
494 int X = 0; for ( ; X < W; X++ )
495 tempBuf[ ( W * Y ) + X ] = tempCol;
497 WritePixelArray (
498 tempBuf, 0, 0, W * 4, _rp ( palColRect ),
499 LE, TE, W, H, RECTFMT_RGBA
501 FreeVec ( tempBuf );
505 void Init_PaletteWindow ( )
507 struct MUI_CustomClass *mcc =
508 MUI_CreateCustomClass (
509 NULL, MUIC_Rectangle, NULL,
511 &PaletteArea
514 paletteWindow = WindowObject,
515 MUIA_Window_Title, __(MSG_PALETTE_WIN),
516 MUIA_Window_SizeGadget, FALSE,
517 MUIA_Window_Screen, ( IPTR )lunaPubScreen,
518 MUIA_Window_ID, MAKE_ID('L','P','P','W'),
519 WindowContents, ( IPTR )VGroup,
520 Child, ( IPTR )GroupObject,
521 MUIA_Frame, MUIV_Frame_Group,
522 Child, ( IPTR )HGroup,
523 Child, ( IPTR )VGroup,
524 Child, ( IPTR )HGroup,
525 Child, ( IPTR )VGroup,
526 Child, ( IPTR )( palBtnCopy = SimpleButton ( __(MSG_PALETTE_COPY) )),
527 Child, ( IPTR )( palBtnPaste = SimpleButton ( __(MSG_PALETTE_PASTE) )),
528 Child, ( IPTR )( palBtnClear = SimpleButton ( __(MSG_PALETTE_CLEAR) )),
529 End,
530 Child, ( IPTR )VGroup,
531 Child, ( IPTR )( palBtnReverse = SimpleButton ( __(MSG_PALETTE_REVERSE) )),
532 Child, ( IPTR )( palBtnSwap = SimpleButton ( __(MSG_PALETTE_SWAP) )),
533 Child, ( IPTR )( palBtnSpread = SimpleButton ( __(MSG_PALETTE_SPREAD) )),
534 End,
535 End,
536 Child, ( IPTR )VGroup,
537 Child, ( IPTR )RectangleObject,
538 MUIA_Frame, MUIV_Frame_None,
539 MUIA_FixHeight, 10,
540 MUIA_Rectangle_HBar, TRUE,
541 End,
542 Child, ( IPTR )StringObject,
543 MUIA_String_MaxLen, 8,
544 MUIA_String_Format, MUIV_String_Format_Center,
545 MUIA_Frame, MUIV_Frame_String,
546 End,
547 Child, ( IPTR )SimpleButton ( __(MSG_PALETTE_WEB) ),
548 End,
549 End,
550 Child, ( IPTR )VGroup,
551 Child, ( IPTR )HGroup,
552 Child, ( IPTR )GroupObject,
553 MUIA_Frame, MUIV_Frame_Group,
554 Child, ( IPTR )( palColRect = RectangleObject,
555 MUIA_FixHeight, 15,
556 End ),
557 End,
558 End,
559 Child, ( IPTR )HGroup,
560 Child, ( IPTR )( palSlideR = SliderObject,
561 MUIA_Slider_Horiz, FALSE,
562 MUIA_Numeric_Min, 0,
563 MUIA_Numeric_Max, 255,
564 MUIA_Numeric_Value, 0,
565 End ),
566 Child, ( IPTR )( palSlideG = SliderObject,
567 MUIA_Slider_Horiz, FALSE,
568 MUIA_Numeric_Min, 0,
569 MUIA_Numeric_Max, 255,
570 MUIA_Numeric_Value, 0,
571 End ),
572 Child, ( IPTR )( palSlideB = SliderObject,
573 MUIA_Slider_Horiz, FALSE,
574 MUIA_Numeric_Min, 0,
575 MUIA_Numeric_Max, 255,
576 MUIA_Numeric_Value, 0,
577 End ),
578 End,
579 End,
580 End,
581 Child, ( IPTR )VGroup,
582 Child, ( IPTR )RectangleObject,
583 MUIA_Frame, MUIV_Frame_None,
584 MUIA_FixHeight, 10,
585 MUIA_Rectangle_HBar, TRUE,
586 End,
587 Child, ( IPTR )GroupObject,
588 MUIA_Frame, MUIV_Frame_Group,
589 Child, ( IPTR )( paletteRect = NewObject (
590 mcc->mcc_Class, NULL,
591 MUIA_FixWidth, 256,
592 MUIA_FixHeight, 128,
593 TAG_DONE
594 ) ),
595 End,
596 End,
597 Child, HGroup,
598 Child, ( IPTR )( palBtnLoad = SimpleButton ( __(MSG_PALETTE_LOAD) ) ),
599 Child, ( IPTR )( palBtnSave = SimpleButton ( __(MSG_PALETTE_SAVE) ) ),
600 Child, ( IPTR )( palBtnUse = SimpleButton ( __(MSG_PALETTE__USE) )),
601 End,
602 End,
603 End,
604 End;
607 void Init_PaletteMethods ( )
609 // Setup hooks
610 MakeStaticHook(rgbslider_hook, &rgbslider_func);
611 MakeStaticHook(paletteLoad_hook, &paletteLoad_func);
612 MakeStaticHook(paletteSave_hook, &paletteSave_func);
613 MakeStaticHook(paletteClose_hook, &paletteClose_func);
615 // Set initial slider positions
616 struct rgbData colors = paletteColorToRGB ( globalPalette[ currColor ] );
617 set ( palSlideR, MUIA_Numeric_Value, colors.r );
618 set ( palSlideG, MUIA_Numeric_Value, colors.g );
619 set ( palSlideB, MUIA_Numeric_Value, colors.b );
621 DoMethod (
622 palSlideR, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime,
623 palSlideR, 3, MUIM_CallHook, &rgbslider_hook, MUIV_TriggerValue
625 DoMethod (
626 palSlideG, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime,
627 palSlideG, 3, MUIM_CallHook, &rgbslider_hook, MUIV_TriggerValue
629 DoMethod (
630 palSlideB, MUIM_Notify, MUIA_Numeric_Value, MUIV_EveryTime,
631 palSlideB, 3, MUIM_CallHook, &rgbslider_hook, MUIV_TriggerValue
633 DoMethod (
634 palBtnUse, MUIM_Notify,
635 MUIA_Pressed, FALSE,
636 paletteWindow, 3, MUIM_CallHook, &paletteClose_hook
638 DoMethod (
639 paletteWindow, MUIM_Notify,
640 MUIA_Window_CloseRequest, TRUE,
641 paletteWindow, 3, MUIM_CallHook, &paletteClose_hook
644 // Action buttons
645 DoMethod (
646 palBtnCopy, MUIM_Notify,
647 MUIA_Pressed, FALSE,
648 paletteRect, 1, MUIM_Luna_Palette_Copy
650 DoMethod (
651 palBtnPaste, MUIM_Notify,
652 MUIA_Pressed, FALSE,
653 paletteRect, 1, MUIM_Luna_Palette_Paste
655 DoMethod (
656 palBtnSpread, MUIM_Notify,
657 MUIA_Pressed, FALSE,
658 paletteRect, 1, MUIM_Luna_Palette_Spread
660 DoMethod (
661 palBtnSwap, MUIM_Notify,
662 MUIA_Pressed, FALSE,
663 paletteRect, 1, MUIM_Luna_Palette_Swap
665 DoMethod (
666 palBtnReverse, MUIM_Notify,
667 MUIA_Pressed, FALSE,
668 paletteRect, 1, MUIM_Luna_Palette_Reverse
670 DoMethod (
671 palBtnClear, MUIM_Notify,
672 MUIA_Pressed, FALSE,
673 paletteRect, 1, MUIM_Luna_Palette_Clear
676 // Load/Save
677 DoMethod (
678 palBtnSave, MUIM_Notify, MUIA_Pressed, FALSE,
679 palBtnSave, 3, MUIM_CallHook, &paletteSave_hook, MUIV_TriggerValue
681 DoMethod (
682 palBtnLoad, MUIM_Notify, MUIA_Pressed, FALSE,
683 palBtnLoad, 3, MUIM_CallHook, &paletteLoad_hook, MUIV_TriggerValue
687 ULONG savePalette ( )
689 // We have a filename!!
690 char *filename = getFilename ( );
691 if ( filename != NULL )
693 // The aros way!
694 BPTR myfile;
695 if ( ( myfile = Open ( filename, MODE_NEWFILE ) ) != BNULL )
697 Write ( myfile, globalPalette, 4 * 256 );
698 Close ( myfile );
700 else printf ( "Failed to write palette..\n" );
701 FreeVec ( filename );
703 return 0;
706 ULONG loadPalette ( )
708 // We have a filename!!
709 char *filename = getFilename ( );
710 if ( filename != NULL )
712 // The aros way!
713 BPTR myfile;
714 if ( ( myfile = Open ( filename, MODE_OLDFILE ) ) != BNULL )
716 Read ( myfile, globalPalette, 4 * 256 );
717 Close ( myfile );
719 else printf ( "Failed to load palette..\n" );
720 FreeVec ( filename );
722 return 0;