~ubuntu-branches/ubuntu/trusty/grafx2/trusty

« back to all changes in this revision

Viewing changes to brush.c

  • Committer: Bazaar Package Importer
  • Author(s): Gürkan Sengün
  • Date: 2009-09-21 14:24:19 UTC
  • mfrom: (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20090921142419-lhpqq102buior0ol
Tags: 2.1-1
New upstream version.

Show diffs side-by-side

added added

removed removed

Lines of Context:
123
123
  int position;
124
124
  byte * temp;
125
125
 
126
 
  if (!(is_preview && Mouse_K)) // Si bouton enfonc� & preview > pas de dessin
 
126
  if (is_preview==0 || Mouse_K==0) // pas de curseur si on est en preview et 
 
127
                                     // en train de cliquer
127
128
  switch (Paintbrush_shape)
128
129
  {
129
130
    case PAINTBRUSH_SHAPE_POINT : // !!! TOUJOURS EN PREVIEW !!!
151
152
      end_counter_x=start_x_counter+width;
152
153
      end_counter_y=start_y_counter+height;
153
154
 
154
 
      if (is_preview)
 
155
      if (is_preview != 0)
155
156
      {
156
157
        if ( (width>0) && (height>0) )
157
158
          Display_brush_color(
165
166
                Brush_width
166
167
          );
167
168
 
168
 
        if (Main_magnifier_mode)
 
169
        if (Main_magnifier_mode != 0)
169
170
        {
170
171
          Compute_clipped_dimensions_zoom(&start_x,&start_y,&width,
171
172
                &height
196
197
      }
197
198
      else
198
199
      {
199
 
        if ((Smear_mode) && (Shade_table==Shade_table_left))
 
200
        if ((Smear_mode != 0) && (Shade_table==Shade_table_left))
200
201
        {
201
 
          if (Smear_start)
 
202
          if (Smear_start != 0)
202
203
          {
203
204
            if ((width>0) && (height>0))
204
205
            {
275
276
      start_y_counter=start_y-(y-Brush_offset_Y);
276
277
      end_counter_x=start_x_counter+width;
277
278
      end_counter_y=start_y_counter+height;
278
 
      if (is_preview)
 
279
      if (is_preview != 0)
279
280
      {
280
281
        if ( (width>0) && (height>0) )
281
282
          Display_brush_mono(start_x-Main_offset_X,
285
286
                             Back_color,Fore_color,
286
287
                             Brush_width);
287
288
 
288
 
        if (Main_magnifier_mode)
 
289
        if (Main_magnifier_mode != 0)
289
290
        {
290
291
          Compute_clipped_dimensions_zoom(&start_x,&start_y,&width,&height);
291
292
          start_x_counter=start_x-(x-Brush_offset_X);
314
315
      }
315
316
      else
316
317
      {
317
 
        if ((Smear_mode) && (Shade_table==Shade_table_left))
 
318
        if ((Smear_mode != 0) && (Shade_table==Shade_table_left))
318
319
        {
319
 
          if (Smear_start)
 
320
          if (Smear_start != 0)
320
321
          {
321
322
            if ((width>0) && (height>0))
322
323
            {
377
378
      start_y_counter=start_y-(y-Paintbrush_offset_Y);
378
379
      end_counter_x=start_x_counter+width;
379
380
      end_counter_y=start_y_counter+height;
380
 
      if (is_preview)
 
381
      if (is_preview != 0)
381
382
      {
382
383
        temp=Brush;
383
384
        Brush=Paintbrush_sprite;
390
391
                             0,Fore_color,
391
392
                             MAX_PAINTBRUSH_SIZE);
392
393
 
393
 
        if (Main_magnifier_mode)
 
394
        if (Main_magnifier_mode != 0)
394
395
        {
395
396
          Compute_clipped_dimensions_zoom(&start_x,&start_y,&width,&height);
396
397
          start_x_counter=start_x-(x-Paintbrush_offset_X);
419
420
      }
420
421
      else
421
422
      {
422
 
        if ((Smear_mode) && (Shade_table==Shade_table_left))
 
423
        if ((Smear_mode != 0) && (Shade_table==Shade_table_left))
423
424
        {
424
 
          if (Smear_start)
 
425
          if (Smear_start != 0)
425
426
          {
426
427
            if ((width>0) && (height>0))
427
428
            {
444
445
              {
445
446
                temp_color=Read_pixel_from_current_screen(x_pos,y_pos);
446
447
                position=(counter_y*Smear_brush_width)+counter_x;
447
 
                if ( (Paintbrush_sprite[(MAX_PAINTBRUSH_SIZE*counter_y)+counter_x]) // Le pinceau sert de masque pour dire quels pixels on doit traiter dans le rectangle
448
 
                  && (counter_y<Smear_max_Y) && (counter_x<Smear_max_X)          // On clippe l'effet smear entre Smear_Min et Smear_Max
449
 
                  && (counter_y>=Smear_min_Y) && (counter_x>=Smear_min_X) )
450
 
                  Display_pixel(x_pos,y_pos,Smear_brush[position]);
 
448
                if ( (Paintbrush_sprite[(MAX_PAINTBRUSH_SIZE*counter_y)+counter_x] != 0) 
 
449
                    // Le pinceau sert de masque pour dire quels pixels on doit traiter dans le rectangle
 
450
                    && (counter_y<Smear_max_Y) && (counter_x<Smear_max_X)
 
451
                    && (counter_y>=Smear_min_Y) && (counter_x>=Smear_min_X)
 
452
                    // On clippe l'effet smear entre Smear_Min et Smear_Max
 
453
                )
 
454
                    Display_pixel(x_pos,y_pos,Smear_brush[position]);
451
455
                Smear_brush[position]=temp_color;
452
456
              }
453
457
              Update_part_of_screen(start_x, start_y, width, height);
464
468
          for (y_pos=start_y,counter_y=start_y_counter;counter_y<end_counter_y;y_pos++,counter_y++)
465
469
            for (x_pos=start_x,counter_x=start_x_counter;counter_x<end_counter_x;x_pos++,counter_x++)
466
470
            {
467
 
              if (Paintbrush_sprite[(MAX_PAINTBRUSH_SIZE*counter_y)+counter_x])
 
471
              if (Paintbrush_sprite[(MAX_PAINTBRUSH_SIZE*counter_y)+counter_x] != 0)
468
472
                Display_pixel(x_pos,y_pos,color);
469
473
            }
470
474
          Update_part_of_screen(start_x,start_y,width,height);
473
477
  }
474
478
}
475
479
 
 
480
///
 
481
/// Changes the Brush size, discarding its previous content.
 
482
/// @return 0 OK, 1 Failed
 
483
byte Realloc_brush(word new_brush_width, word new_brush_height)
 
484
{
 
485
  byte return_code=0;
 
486
  
 
487
  if ( (((long)Brush_height)*Brush_width) !=
 
488
       (((long)new_brush_height)*new_brush_width) )
 
489
  {
 
490
    free(Brush);
 
491
    Brush=(byte *)malloc(((long)new_brush_height)*new_brush_width);
 
492
    if (Brush == NULL)
 
493
    {
 
494
      Error(0);
 
495
      return_code=1;
 
496
  
 
497
      Brush=(byte *)malloc(1*1);
 
498
      if(Brush == NULL)
 
499
      {
 
500
          Error(ERROR_MEMORY);
 
501
          exit(ERROR_MEMORY);
 
502
      }
 
503
      new_brush_height=new_brush_width=1;
 
504
      *Brush=Fore_color;
 
505
    }
 
506
  }
 
507
  Brush_width=new_brush_width;
 
508
  Brush_height=new_brush_height;
 
509
  
 
510
  free(Smear_brush);
 
511
  Smear_brush_width=(Brush_width>MAX_PAINTBRUSH_SIZE)?Brush_width:MAX_PAINTBRUSH_SIZE;
 
512
  Smear_brush_height=(Brush_height>MAX_PAINTBRUSH_SIZE)?Brush_height:MAX_PAINTBRUSH_SIZE;
 
513
  Smear_brush=(byte *)malloc(((long)Smear_brush_height)*Smear_brush_width);
 
514
  
 
515
  if (Smear_brush == NULL) // Failed to allocate the smear brush
 
516
  {
 
517
    Error(0);
 
518
    return_code=1;
 
519
  
 
520
    free(Brush);
 
521
    Brush=(byte *)malloc(1*1);
 
522
    if(Brush == NULL)
 
523
    {
 
524
      Error(ERROR_MEMORY);
 
525
      exit(ERROR_MEMORY);
 
526
    }
 
527
    Brush_height=1;
 
528
    Brush_width=1;
 
529
  
 
530
    Smear_brush=(byte *)malloc(MAX_PAINTBRUSH_SIZE*MAX_PAINTBRUSH_SIZE);
 
531
    if(Smear_brush == NULL)
 
532
    {
 
533
      Error(ERROR_MEMORY);
 
534
      exit(ERROR_MEMORY);
 
535
    }
 
536
    Smear_brush_height=MAX_PAINTBRUSH_SIZE;
 
537
    Smear_brush_width=MAX_PAINTBRUSH_SIZE;
 
538
  }
 
539
  return return_code;
 
540
}
 
541
 
 
542
 
476
543
// -- Effacer le pinceau -- //
477
544
//
478
545
void Hide_paintbrush(short x,short y)
495
562
  //short counter_x; // Position X (dans la brosse/pinceau) en cours
496
563
        //d'affichage
497
564
  //short counter_y; // Position Y (dans la brosse/pinceau) en cours d'affichage
498
 
  short end_counter_x; // Position X ou s'arr�te l'affichade de la brosse/pinceau
499
 
  short end_counter_y; // Position Y ou s'arr�te l'affichade de la brosse/pinceau
 
565
  short end_counter_x; // Position X ou s'arr�te l'affichage de la brosse/pinceau
 
566
  short end_counter_y; // Position Y ou s'arr�te l'affichage de la brosse/pinceau
500
567
  byte * temp;
501
568
 
502
 
  if (!Mouse_K)
 
569
  if (Mouse_K == 0)
503
570
  switch (Paintbrush_shape)
504
571
  {
505
572
    case PAINTBRUSH_SHAPE_POINT :
531
598
                    width,height,Back_color,
532
599
                    Main_image_width);
533
600
 
534
 
      if (Main_magnifier_mode)
 
601
      if (Main_magnifier_mode != 0)
535
602
      {
536
603
        Compute_clipped_dimensions_zoom(&start_x,&start_y,&width,&height);
537
604
        start_x_counter=start_x;
577
644
                    Main_image_width);
578
645
      }
579
646
 
580
 
      if (Main_magnifier_mode)
 
647
      if (Main_magnifier_mode != 0)
581
648
      {
582
649
        Compute_clipped_dimensions_zoom(&start_x,&start_y,&width,&height);
583
650
        start_x_counter=start_x;
651
718
    if (start_y+new_brush_height>Main_image_height)
652
719
      new_brush_height=Main_image_height-start_y;
653
720
 
654
 
    if ( (((long)Brush_height)*Brush_width) !=
655
 
         (((long)new_brush_height)*new_brush_width) )
656
 
    {
657
 
      free(Brush);
658
 
      Brush=(byte *)malloc(((long)new_brush_height)*new_brush_width);
659
 
      if (!Brush)
660
 
      {
661
 
        Error(0);
662
 
 
663
 
        Brush=(byte *)malloc(1*1);
664
 
        new_brush_height=new_brush_width=1;
665
 
        *Brush=Fore_color;
666
 
      }
667
 
    }
668
 
    Brush_width=new_brush_width;
669
 
    Brush_height=new_brush_height;
670
 
 
671
 
    free(Smear_brush);
672
 
    Smear_brush_width=(Brush_width>MAX_PAINTBRUSH_SIZE)?Brush_width:MAX_PAINTBRUSH_SIZE;
673
 
    Smear_brush_height=(Brush_height>MAX_PAINTBRUSH_SIZE)?Brush_height:MAX_PAINTBRUSH_SIZE;
674
 
    Smear_brush=(byte *)malloc(((long)Smear_brush_height)*Smear_brush_width);
675
 
 
676
 
    if (!Smear_brush) // On ne peut m�me pas allouer la brosse du smear!
677
 
    {
678
 
      Error(0);
679
 
 
680
 
      free(Brush);
681
 
      Brush=(byte *)malloc(1*1);
682
 
      Brush_height=1;
683
 
      Brush_width=1;
684
 
 
685
 
      Smear_brush=(byte *)malloc(MAX_PAINTBRUSH_SIZE*MAX_PAINTBRUSH_SIZE);
686
 
      Smear_brush_height=MAX_PAINTBRUSH_SIZE;
687
 
      Smear_brush_width=MAX_PAINTBRUSH_SIZE;
688
 
    }
 
721
    Realloc_brush(new_brush_width, new_brush_height);
689
722
 
690
723
    Copy_image_to_brush(start_x,start_y,Brush_width,Brush_height,Main_image_width);
691
724
 
692
725
    // On regarde s'il faut effacer quelque chose:
693
 
    if (clear)
 
726
    if (clear != 0)
694
727
    {
695
728
      for (y_pos=start_y;y_pos<start_y+Brush_height;y_pos++)
696
729
        for (x_pos=start_x;x_pos<start_x+Brush_width;x_pos++)
716
749
  new_brush=(byte *)malloc(((long)Brush_height)*Brush_width);
717
750
  if (new_brush)
718
751
  {
719
 
    Rotate_90_deg_lowlevel(Brush,new_brush,Brush_width,Brush_height);
 
752
    Rotate_90_deg_lowlevel(Brush,/*@out@*/ new_brush,Brush_width,Brush_height);
720
753
    free(Brush);
721
754
    Brush=new_brush;
722
755
 
767
800
  //       conversion puisque elles n'existent pas dans la brosse, donc elles
768
801
  //       ne seront pas utilis�es par Remap_brush_LOWLEVEL.
769
802
  for (color=0;color<=255;color++)
770
 
    if (used[color])
 
803
    if (used[color] != 0)
771
804
      used[color]=Best_color(Spare_palette[color].R,Spare_palette[color].G,Spare_palette[color].B);
772
805
 
773
806
  //   Il reste une couleur non calcul�e dans la table qu'il faut mettre �
808
841
 
809
842
    // On copie la brosse courante dans la nouvelle
810
843
    Copy_part_of_image_to_another(Brush, // source
811
 
                                             0, 0,
812
 
                                             Brush_width,
813
 
                                             Brush_height,
814
 
                                             Brush_width,
815
 
                                             new_brush, // Destination
816
 
                                             1, 1,
817
 
                                             width);
 
844
        0, 0, Brush_width, Brush_height, Brush_width,
 
845
        new_brush, // Destination
 
846
        1, 1, width);
818
847
 
819
848
    // On intervertit la nouvelle et l'ancienne brosse:
820
849
    temp=Brush;
835
864
        {
836
865
          if (temp[((y_pos-1)*width)+x_pos-1]==Back_color)
837
866
          {
838
 
            if (state)
 
867
            if (state != 0)
839
868
            {
840
869
              Pixel_in_brush(x_pos,y_pos,Fore_color);
841
870
              state=0;
842
871
            }
843
872
          }
844
 
          else
 
873
          else if (state == 0)
845
874
          {
846
 
            if (!state)
847
 
            {
848
 
              Pixel_in_brush(x_pos-1,y_pos,Fore_color);
849
 
              state=1;
850
 
            }
 
875
            Pixel_in_brush(x_pos-1,y_pos,Fore_color);
 
876
            state=1;
851
877
          }
852
878
        }
853
879
        // Cas du dernier pixel � droite de la ligne
854
 
        if (state)
 
880
        if (state != 0)
855
881
          Pixel_in_brush(x_pos,y_pos,Fore_color);
856
882
      }
857
883
 
863
889
        {
864
890
          if (temp[((y_pos-1)*width)+x_pos-1]==Back_color)
865
891
          {
866
 
            if (state)
 
892
            if (state != 0)
867
893
            {
868
894
              Pixel_in_brush(x_pos,y_pos,Fore_color);
869
895
              state=0;
870
896
            }
871
897
          }
872
 
          else
 
898
          else if (state == 0)
873
899
          {
874
 
            if (!state)
875
 
            {
876
900
              Pixel_in_brush(x_pos,y_pos-1,Fore_color);
877
901
              state=1;
878
 
            }
879
902
          }
880
903
        }
881
904
        // Cas du dernier pixel en bas de la colonne
882
 
        if (state)
 
905
        if (state != 0)
883
906
          Pixel_in_brush(x_pos,y_pos,Fore_color);
884
907
      }
885
908
    }
903
926
 
904
927
void Nibble_brush(void)
905
928
{
906
 
  long /*Pos,*/x_pos,y_pos;
 
929
  long x_pos,y_pos;
907
930
  byte state;
908
931
  byte * new_brush;
909
932
  byte * temp;
946
969
        {
947
970
          if (temp[((y_pos+1)*width)+x_pos+1]==Back_color)
948
971
          {
949
 
            if (state)
 
972
            if (state != 0)
950
973
            {
951
974
              if (x_pos>0)
952
975
                Pixel_in_brush(x_pos-1,y_pos,Back_color);
955
978
          }
956
979
          else
957
980
          {
958
 
            if (!state)
 
981
            if (state == 0)
959
982
            {
960
983
              Pixel_in_brush(x_pos,y_pos,Back_color);
961
984
              state=1;
984
1007
          }
985
1008
          else
986
1009
          {
987
 
            if (!state)
 
1010
            if (state == 0)
988
1011
            {
989
1012
              Pixel_in_brush(x_pos,y_pos,Back_color);
990
1013
              state=1;
1021
1044
  short start_y=Limit_bottom+1;
1022
1045
  short end_x=Limit_left-1;
1023
1046
  short end_y=Limit_top-1;
1024
 
  short temp;
 
1047
  unsigned short temp;
1025
1048
  short x_pos;
1026
1049
  short y_pos;
1027
1050
  word  new_brush_width;
1029
1052
 
1030
1053
 
1031
1054
  // On recherche les bornes de la brosse:
1032
 
  for (temp=0; temp<vertices; temp++)
 
1055
  for (temp=0; temp<2*vertices; temp+=2)
1033
1056
  {
1034
 
    x_pos=points[temp<<1];
1035
 
    y_pos=points[(temp<<1)+1];
 
1057
    x_pos=points[temp];
 
1058
    y_pos=points[temp+1];
1036
1059
    if (x_pos<start_x)
1037
1060
      start_x=x_pos;
1038
1061
    if (x_pos>end_x)
1079
1102
        Error(0);
1080
1103
 
1081
1104
        Brush=(byte *)malloc(1*1);
 
1105
        if(Brush==NULL) Error(ERROR_MEMORY);
1082
1106
        new_brush_height=new_brush_width=1;
1083
1107
        *Brush=Fore_color;
1084
1108
      }
1097
1121
 
1098
1122
      free(Brush);
1099
1123
      Brush=(byte *)malloc(1*1);
 
1124
      if(Brush==NULL) Error(ERROR_MEMORY);
1100
1125
      Brush_height=1;
1101
1126
      Brush_width=1;
1102
1127