summaryrefslogtreecommitdiff
path: root/app/wlib/test/draw.c
blob: 795044a4de6b1b1630d05491a7b0d6b4104c9cca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82

#include <stdio.h>
#include "wlib.h"


#define TRUE	(1)
#define FALSE	(0)

wFont_p font;
wDraw_p draw1;
wDrawColor black;
static wPos_t origX, origY, oldX, oldY;

void box( double x0, double y0, double x1, double y1, wDrawOpts opts )
{
    wDrawLine( draw1, x0, y0, x1, y0, 0, wDrawLineSolid,
	   black, opts );
    wDrawLine( draw1, x1, y0, x1, y1, 0, wDrawLineSolid,
	   black, opts );
    wDrawLine( draw1, x1, y1, x0, y1, 0, wDrawLineSolid,
	   black, opts );
    wDrawLine( draw1, x0, y1, x0, y0, 0, wDrawLineSolid,
	   black, opts );
}

void doDraw( wAction_t action, wPos_t x, wPos_t y )
{
    char str[2];
    switch (action & 0xFF) {
    case wActionLDown:
	origX = oldX = x;
	origY = oldY = y;
	box( origX, origY, oldX, oldY, wDrawOptTemp );
	break;
    case wActionLDrag:
	box( origX, origY, oldX, oldY, wDrawOptTemp );
	oldX = x; oldY = y;
	box( origX, origY, oldX, oldY, wDrawOptTemp );
	break;
    case wActionLUp:
	break;
    case wActionText:
	str[0] = (char)((action>>8)&0xFF);
	str[1] = 0;
	wDrawString( draw1, oldX, oldY, 0, str, font, 24, black, 0 );
	break;
    }
}

void doRedraw( wDraw_p bd, void * data, wPos_t x, wPos_t y )
{
	box( origX, origY, oldX, oldY, 0 );
}

void winProc(
	wWin_p win,
	winProcEvent ev,
	void * data )
{
    wPos_t w, h;
    switch( ev ) {
    case wResize_e:
	wWinGetSize( win, &w, &h );
	wDrawSetSize( draw1, w, h );
	break;
    default:
	break;
    }
}


wWin_p wMain( int argc, char * argv[] )
{

    wWin_p mainW;

    mainW = wWinMainCreate( "Fred", 2, 2, "Help", "Main", "Main", F_AUTOSIZE|F_MENUBAR, winProc, NULL );
    font = wStandardFont( F_TIMES, FALSE, FALSE );
    black = wDrawFindColor(0);
    draw1 = wDrawCreate( mainW, 2, 2, NULL, 0, 300, 200, NULL, doRedraw, doDraw );
    return mainW;
}