From BlenderWiki

Jump to: navigation, search
Note: This is an archived version of the Blender Developer Wiki. The current and active wiki is available on wiki.blender.org.
These are just notes, some examples of how things work.

I want to mess about with the GUI, ive picked the UV/Image Editor because its basic, kinda.

"UV.PNG"

The root C source code for most of this is in "source\blender\editors\space_image\".

The root source file is space_image.c.

Open it up, scroll to the bottom, you will probably find the setup function.

void ED_spacetype_image(void){
	..
}

This code sets the callback functions for each region for the UV editor.

Header
Main Window
Buttons
Scope
Properties

When they are set, stacked to list, registered to the spacetype:

	/* allocate ARegionType */
	art=MEM_callocN(sizeof(ARegionType), "spacetype image region");
	
	/* region setup */
	art->	regionid	= RGN_TYPE_HEADER;
	art->	prefsizey	= HEADERY;
	art->	keymapflag	= ED_KEYMAP_UI|ED_KEYMAP_VIEW2D|ED_KEYMAP_FRAMES|ED_KEYMAP_HEADER;
	art->	listener	= image_header_area_listener;
	art->	init		= image_header_area_init;
	art->	draw		= image_header_area_draw;
	
	/* stack into list */
	BLI_addhead(&st->regiontypes, art);
	
	/* register spacetype */
	BKE_spacetype_register(st);

Blender will process the regions via the list.

Scroll up and you will find some code for the UV editor, callbacks, operators, register stuff.

..

Lets mess about with draw code, Properties region, Display panel buttons, [Outline][Dash][Black][White].

Display.PNG

This draws the uv mesh in different styles based on the active button.

The draw code for the uv mesh is in "source\blender\editors\uvedit\uvedit_draw.c".

static void draw_uvs(SpaceImage *sima, Scene *scene, Object *obedit){
	..
}

Look for the code that draws the UV mesh edges/lines based on the active button. 2.56 looks like this:

	/* 4. draw edges */

	if(sima->flag & SI_SMOOTH_UV) {
		glEnable(GL_LINE_SMOOTH);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	}
	
	switch(sima->dt_uv) {
 		case SI_UVDT_DASH:
			..
		case SI_UVDT_BLACK: /* black/white */
		case SI_UVDT_WHITE:

			// set gl color, black or white

			if(sima->dt_uv==SI_UVDT_WHITE) glColor3f(1.0f, 1.0f, 1.0f);
			else glColor3f(0.0f, 0.0f, 0.0f);

			// loop list, uv faces

			for(efa= em->faces.first; efa; efa= efa->next) {
				tf= (MTFace *)efa->tmp.p; /* visible faces cached */

				if(tf) {

					// gl line loop, point to point, quad or triangle, black or white.

					glBegin(GL_LINE_LOOP);
						glVertex2fv(tf->uv[0]);
						glVertex2fv(tf->uv[1]);
						glVertex2fv(tf->uv[2]);
						if(efa->v4) glVertex2fv(tf->uv[3]);
					glEnd();
				}
			}
			break;
		case SI_UVDT_OUTLINE:
			..
	}

These keywords were passed to the draw function.

SpaceImage *sima	// data space image
Scene *scene		// data scene
Object *obedit		// data object
sima->dt_uv		// draw type, Outline, Dash, Black, White