Hint added.
[AROS.git] / workbench / prefs / Editor / SampleEd.c
blob564b43c2849950215161cef6e8da9be222037da6
1 /***************************************************************
2 **** SampleEd.c: Show an sample editor in JanoPrefs. ****
3 **** Free software under GNU license, started on 18/11/2000 ****
4 **** © T.Pierron, C.Guillaume. ****
5 ***************************************************************/
7 /** Share the rendering routines of this module **/
8 #include <libraries/gadtools.h>
9 #include "Project.c"
10 #include <graphics/clip.h>
11 #include <graphics/layers.h>
13 #include <proto/layers.h>
15 #include "Sample.h"
16 #include "Jed.h"
18 struct gv gui;
19 struct pens pen = {0,1,3,2,3,1,2,1,3,2,0,1};
21 struct TagItem BoxTags[] = { /* Draws a recessed box */
22 {GT_VisualInfo,0},
23 {GTBB_Recessed,TRUE},
24 {TAG_DONE}
27 UBYTE *SampleText[] = {LINE1, LINE2, LINE3, LINE4, LINE5};
29 extern struct RastPort RPT;
32 ** Used to remove a clipping region installed by clipWindow() or
33 ** clipWindowToBorders(), disposing of the installed region and
34 ** reinstalling the region removed. RKM source.
36 void unclipWindow(struct Window *win)
38 struct Region *old_region;
40 /* Remove any old region by installing a NULL region,
41 ** then dispose of the old region if one was installed.
43 if (NULL != (old_region = (void *) InstallClipRegion(win->WLayer, NULL)))
44 DisposeRegion(old_region);
48 ** Clip a window to a specified rectangle (given by upper left and
49 ** lower right corner.) the removed region is returned so that it
50 ** may be re-installed later. RKM source.
52 struct Region *clipWindow(struct Window *win, LONG minX, LONG minY, LONG maxX, LONG maxY)
54 struct Region *new_region;
55 struct Rectangle my_rectangle;
57 /* set up the limits for the clip */
58 my_rectangle.MinX = minX;
59 my_rectangle.MinY = minY;
60 my_rectangle.MaxX = maxX;
61 my_rectangle.MaxY = maxY;
63 /* get a new region and OR in the limits. */
64 if (NULL != (new_region = (void *) NewRegion()))
66 if (FALSE == OrRectRegion(new_region, &my_rectangle))
68 DisposeRegion(new_region);
69 new_region = NULL;
73 /* Install the new region, and return any existing region.
74 ** If the above allocation and region processing failed, then
75 ** new_region will be NULL and no clip region will be installed.
77 return (struct Region *) InstallClipRegion(win->WLayer, new_region);
80 /*** Simple project creation ***/
81 PROJECT *new_project(PROJECT *ins, PREFS *prefs)
83 PROJECT *new;
84 if(( new = (void *) AllocVec(sizeof(*new), MEMF_PUBLIC | MEMF_CLEAR) ))
86 if(ins) ins->next = new, new->prev = ins;
88 /* NbProject & first herited from project.c */
89 NbProject++;
90 if(NbProject == 1) first = new;
92 return new;
95 /*** Init size & pos of sample, depending fonts sizes ***/
96 void init_sample(struct Window *wnd, PREFS *p, WORD top)
98 struct DrawInfo *di;
99 PROJECT *new;
101 gui.left = 11;
102 gui.oldtop = top+1;
103 gui.right = wnd->Width+(EXTEND_RIG-10);
104 gui.bottom = top+SAMPLE_HEI;
105 gui.xsize = p->txtfont->tf_XSize;
106 BoxTags[0].ti_Data = (IPTR) Vi;
108 /* Find out drawing information */
109 if(( di = (void *) GetScreenDrawInfo(Scr) ))
111 WORD *offset = &p->pen.bg, *dst;
113 /* Get a copy of the correct pens for the screen */
114 for(dst=(UWORD *)&pen; (char *)dst < (char *)&pen+sizeof(pen); offset++)
115 *dst++ = (*offset <= 0 ? -(*offset)-1 : di->dri_Pens[ *offset ]);
116 /* printf("pen %d = %d\n",dst-(WORD *)&pen, dst[-1]); */
118 FreeScreenDrawInfo(Scr,di);
121 if(first == NULL)
122 if((new = new_project(NULL, &prefs))) {
123 new->name = "sorrow";
124 new->labsize = 6;
125 if((new = new_project(new, &prefs))) {
126 new->name = "JEd.c";
127 new->labsize = 5;
128 if((new = new_project(new, &prefs)))
129 new->name = "No title",
130 new->labsize = 8;
135 /*** (Re)draw the sample editor ***/
136 void render_sample( struct Window *wnd, UBYTE what )
138 struct RastPort *RP = wnd->RPort;
140 /* Draw a recessed bevel box arround this sample */
141 DrawBevelBoxA(RP,gui.left-1,gui.oldtop-1,gui.right-gui.left+(3-EXTEND_RIG),SAMPLE_HEI+2,BoxTags);
142 clipWindow(wnd,gui.left,gui.oldtop,gui.right-EXTEND_RIG,gui.bottom);
144 /* If font size changed */
145 gui.ysize = prefs.txtfont->tf_YSize;
146 gui.topcurs = prefs.txtfont->tf_Baseline + (
147 gui.top = gui.oldtop+prefs.scrfont->tf_YSize+6);
149 if( what & EDIT_GUI )
150 /* Show factice project bar */
151 SetFont(&RPT,prefs.scrfont), reshape_panel(first->next);
153 if( what & EDIT_AREA )
155 /* Show a sample selected text in the fake editor */
156 SetFont(RP,prefs.txtfont);
157 SetAPen(RP,pen.bg); Move(RP,gui.left,gui.top-1); Draw(RP,gui.right,gui.top-1);
158 SetABPenDrMd(RP,pen.fg,pen.bg,JAM2);
159 Move(RP,gui.left,gui.topcurs);
160 Text(RP,SampleText[0],15);
161 SetABPenDrMd(RP,pen.fgfill,pen.bgfill,JAM2);
162 Text(RP,SampleText[0]+15,44);
163 Move(RP,gui.left,RP->cp_y+gui.ysize); Text(RP,SampleText[1],59);
164 Move(RP,gui.left,RP->cp_y+gui.ysize); Text(RP,SampleText[2],20);
166 SetABPenDrMd(RP,pen.fg,pen.bg,JAM2);
167 Text(RP,SampleText[2]+20,39);
168 Move(RP,gui.left,RP->cp_y+gui.ysize); Text(RP,SampleText[3],59);
169 Move(RP,gui.left,RP->cp_y+gui.ysize); Text(RP,SampleText[4],59);
171 unclipWindow(wnd);
174 /*** Free allocated things here ***/
175 void free_sample()
177 PROJECT *next;
178 for(; first; next=first->next,FreeVec(first),first=next);