~ctwm/ctwm/trunk

« back to all changes in this revision

Viewing changes to util.c

  • Committer: Matthew Fuller
  • Date: 2016-07-25 06:49:48 UTC
  • mto: This revision was merged to the branch mainline in revision 505.
  • Revision ID: fullermd@over-yonder.net-20160725064948-own2esfq6ovjsksr
Start moving generalized drawing funcs into their own file by pulling
Draw3DBorder() out of util.c.

Show diffs side-by-side

added added

removed removed

Lines of Context:
101
101
#include "resize.h"
102
102
#include "image.h"
103
103
#include "decorations.h"
 
104
#include "drawing.h"
104
105
 
105
106
 
106
107
/***********************************************************************
855
856
 
856
857
 
857
858
 
858
 
#define FBGC(gc, fix_fore, fix_back)\
859
 
    Gcv.foreground = fix_fore;\
860
 
    Gcv.background = fix_back;\
861
 
    XChangeGC(dpy, gc, GCForeground|GCBackground,&Gcv)
862
 
 
863
 
void
864
 
Draw3DBorder(Window w, int x, int y, int width, int height, int bw,
865
 
             ColorPair cp, int state, bool fill, bool forcebw)
866
 
{
867
 
        int           i;
868
 
        XGCValues     gcv;
869
 
        unsigned long gcm;
870
 
 
871
 
        if((width < 1) || (height < 1)) {
872
 
                return;
873
 
        }
874
 
        if(Scr->Monochrome != COLOR) {
875
 
                if(fill) {
876
 
                        gcm = GCFillStyle;
877
 
                        gcv.fill_style = FillOpaqueStippled;
878
 
                        XChangeGC(dpy, Scr->BorderGC, gcm, &gcv);
879
 
                        XFillRectangle(dpy, w, Scr->BorderGC, x, y, width, height);
880
 
                }
881
 
                gcm  = 0;
882
 
                gcm |= GCLineStyle;
883
 
                gcv.line_style = (state == on) ? LineSolid : LineDoubleDash;
884
 
                gcm |= GCFillStyle;
885
 
                gcv.fill_style = FillSolid;
886
 
                XChangeGC(dpy, Scr->BorderGC, gcm, &gcv);
887
 
                for(i = 0; i < bw; i++) {
888
 
                        XDrawLine(dpy, w, Scr->BorderGC, x,                 y + i,
889
 
                                  x + width - i - 1, y + i);
890
 
                        XDrawLine(dpy, w, Scr->BorderGC, x + i,                  y,
891
 
                                  x + i, y + height - i - 1);
892
 
                }
893
 
 
894
 
                gcm  = 0;
895
 
                gcm |= GCLineStyle;
896
 
                gcv.line_style = (state == on) ? LineDoubleDash : LineSolid;
897
 
                gcm |= GCFillStyle;
898
 
                gcv.fill_style = FillSolid;
899
 
                XChangeGC(dpy, Scr->BorderGC, gcm, &gcv);
900
 
                for(i = 0; i < bw; i++) {
901
 
                        XDrawLine(dpy, w, Scr->BorderGC, x + width - i - 1,          y + i,
902
 
                                  x + width - i - 1, y + height - 1);
903
 
                        XDrawLine(dpy, w, Scr->BorderGC, x + i,         y + height - i - 1,
904
 
                                  x + width - 1, y + height - i - 1);
905
 
                }
906
 
                return;
907
 
        }
908
 
 
909
 
        if(fill) {
910
 
                FBGC(Scr->BorderGC, cp.back, cp.fore);
911
 
                XFillRectangle(dpy, w, Scr->BorderGC, x, y, width, height);
912
 
        }
913
 
        if(Scr->BeNiceToColormap) {
914
 
                int dashoffset = 0;
915
 
 
916
 
                gcm  = 0;
917
 
                gcm |= GCLineStyle;
918
 
                gcv.line_style = (forcebw) ? LineSolid : LineDoubleDash;
919
 
                gcm |= GCBackground;
920
 
                gcv.background = cp.back;
921
 
                XChangeGC(dpy, Scr->BorderGC, gcm, &gcv);
922
 
 
923
 
                if(state == on) {
924
 
                        XSetForeground(dpy, Scr->BorderGC, Scr->Black);
925
 
                }
926
 
                else {
927
 
                        XSetForeground(dpy, Scr->BorderGC, Scr->White);
928
 
                }
929
 
                for(i = 0; i < bw; i++) {
930
 
                        XDrawLine(dpy, w, Scr->BorderGC, x + i,     y + dashoffset,
931
 
                                  x + i, y + height - i - 1);
932
 
                        XDrawLine(dpy, w, Scr->BorderGC, x + dashoffset,    y + i,
933
 
                                  x + width - i - 1, y + i);
934
 
                        dashoffset = 1 - dashoffset;
935
 
                }
936
 
                XSetForeground(dpy, Scr->BorderGC, ((state == on) ? Scr->White : Scr->Black));
937
 
                for(i = 0; i < bw; i++) {
938
 
                        XDrawLine(dpy, w, Scr->BorderGC, x + i,         y + height - i - 1,
939
 
                                  x + width - 1, y + height - i - 1);
940
 
                        XDrawLine(dpy, w, Scr->BorderGC, x + width - i - 1,          y + i,
941
 
                                  x + width - i - 1, y + height - 1);
942
 
                }
943
 
                return;
944
 
        }
945
 
        if(state == on) {
946
 
                FBGC(Scr->BorderGC, cp.shadd, cp.shadc);
947
 
        }
948
 
        else             {
949
 
                FBGC(Scr->BorderGC, cp.shadc, cp.shadd);
950
 
        }
951
 
        for(i = 0; i < bw; i++) {
952
 
                XDrawLine(dpy, w, Scr->BorderGC, x,                 y + i,
953
 
                          x + width - i - 1, y + i);
954
 
                XDrawLine(dpy, w, Scr->BorderGC, x + i,                  y,
955
 
                          x + i, y + height - i - 1);
956
 
        }
957
 
 
958
 
        if(state == on) {
959
 
                FBGC(Scr->BorderGC, cp.shadc, cp.shadd);
960
 
        }
961
 
        else             {
962
 
                FBGC(Scr->BorderGC, cp.shadd, cp.shadc);
963
 
        }
964
 
        for(i = 0; i < bw; i++) {
965
 
                XDrawLine(dpy, w, Scr->BorderGC, x + width - i - 1,          y + i,
966
 
                          x + width - i - 1, y + height - 1);
967
 
                XDrawLine(dpy, w, Scr->BorderGC, x + i,         y + height - i - 1,
968
 
                          x + width - 1, y + height - i - 1);
969
 
        }
970
 
        return;
971
 
}
972
 
 
973
 
#undef FBGC
974
 
 
975
 
 
976
859
void PaintIcon(TwmWindow *tmp_win)
977
860
{
978
861
        int         width, twidth, mwidth, len, x;