shithub: map

ref: c6a16dc58a2cb3152cd0b08b81fbf85df713280b
dir: /map.c/

View raw version
#include <u.h>
#include <libc.h>
#include <draw.h>
#include <event.h>
#include <nate/nate.h>
#include <nate/n_window.h>
#include <nate/n_hbox.h>
#include <nate/n_vbox.h>
#include <nate/n_box.h>
#include <nate/n_label.h>
#include <nate/n_button.h>
#include <nate/n_image.h>
#include "dat.h"
#include "fns.h"

NWindow *mainwindow;
NImage *nimage;

Image *testimage;

void
inittestimage(void)
{
	Image *r, *g;
	testimage = allocimage(display, Rect(0, 0, 100, 100), screen->chan, 1, DWhite);
	r = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, DRed);
	g = allocimage(display, Rect(0, 0, 1, 1), screen->chan, 1, DGreen);
	draw(testimage, Rect(0, 0, 50, 50), r, nil, ZP);
	draw(testimage, Rect(50, 50, 100, 100), g, nil, ZP);
	freeimage(r);
	freeimage(g);
}

void
eresized(int new)
{
	if (new && getwindow(display, Refnone) < 0)
		sysfatal("%r");
	
	nateredraw(1);
}

int
exitclicked(Mouse, Nelem *el, void*)
{
	exits(nil);
}

void
main(int argc, char **argv)
{
	Event ev;
	int z = 0;
	char *url;
	
	if (initdraw(nil, nil, "map") < 0)
		sysfatal("%r");
	
	einit(Emouse);
	nateinit();
	
	inittestimage();
	
	NAssign(NWindow, &mainwindow, New_Window(nil))
	->MakeRoot()
	->Slot(
		New_VBox(nil)
		->Slot(
			New_HBox("menu")
			->SizeToContent(1)
			->Slot(
				New_Button(nil)
				->SizeToContent(1)
				->Border(1, display->black)
				->Label("Exit")
				->OnClick(exitclicked, nil)
			)
			->Slot(
				New_Button(nil)
				->SizeToContent(1)
				->Label("Test")
				->Border(1, display->black)
			)
		)
		->Slot(
			New_Box(nil)
			->Border(1, display->black)
			->Size(Pt(200, 300))
			->Slot(
				NAssign(NImage, &nimage, New_Image("map"))
				->Image(testimage)
			)
		)
		->Slot(
			New_Box(nil)
			->Border(1, display->black)
			->Size(Pt(500, 30))
			->Slot(
				New_Label(nil)
				->Label("Status Line")
			)
		)
	);
	
	nateredraw(1);
	
	for (;;) {
		switch (event(&ev)) {
		case Emouse:
			if (ev.mouse.buttons & 4)
				exits(nil);
			else
				natemouseevent(ev.mouse);
			break;
		}
	}
	
	GPos loc = getlocation();
	GBundle bundle = getbundle(loc, z);
	GProvider *prov = getprovider();
	
	url = prov->formaturl(bundle);
	print("%s\n", url);
}