mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Split up profile frame generation into its own file.
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
3aa54e206a
commit
8e95ded57b
5 changed files with 72 additions and 43 deletions
9
Makefile
9
Makefile
|
@ -1,8 +1,10 @@
|
||||||
CC=gcc
|
CC=gcc
|
||||||
CFLAGS=-Wall -Wno-pointer-sign -g
|
CFLAGS=-Wall -Wno-pointer-sign -g
|
||||||
|
|
||||||
parse: main.o parse.o
|
OBJS=main.o profile.o parse.o
|
||||||
$(CC) $(LDLAGS) -o parse main.o parse.o `xml2-config --libs` \
|
|
||||||
|
parse: $(OBJS)
|
||||||
|
$(CC) $(LDLAGS) -o parse $(OBJS) `xml2-config --libs` \
|
||||||
`pkg-config --libs gtk+-2.0`
|
`pkg-config --libs gtk+-2.0`
|
||||||
|
|
||||||
parse.o: parse.c dive.h
|
parse.o: parse.c dive.h
|
||||||
|
@ -10,3 +12,6 @@ parse.o: parse.c dive.h
|
||||||
|
|
||||||
main.o: main.c dive.h
|
main.o: main.c dive.h
|
||||||
$(CC) $(CFLAGS) `pkg-config --cflags gtk+-2.0` -c main.c
|
$(CC) $(CFLAGS) `pkg-config --cflags gtk+-2.0` -c main.c
|
||||||
|
|
||||||
|
profile.o: profile.c dive.h
|
||||||
|
$(CC) $(CFLAGS) `pkg-config --cflags gtk+-2.0` -c profile.c
|
||||||
|
|
10
display.h
Normal file
10
display.h
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
#ifndef DISPLAY_H
|
||||||
|
#define DISPLAY_H
|
||||||
|
|
||||||
|
#include <gtk/gtk.h>
|
||||||
|
#include <gdk/gdk.h>
|
||||||
|
#include <cairo.h>
|
||||||
|
|
||||||
|
extern GtkWidget *dive_profile_frame(void);
|
||||||
|
|
||||||
|
#endif
|
4
dive.h
4
dive.h
|
@ -121,7 +121,7 @@ struct dive_table {
|
||||||
|
|
||||||
extern struct dive_table dive_table;
|
extern struct dive_table dive_table;
|
||||||
|
|
||||||
void parse_xml_init(void);
|
extern void parse_xml_init(void);
|
||||||
void parse_xml_file(const char *filename);
|
extern void parse_xml_file(const char *filename);
|
||||||
|
|
||||||
#endif /* DIVE_H */
|
#endif /* DIVE_H */
|
||||||
|
|
42
main.c
42
main.c
|
@ -1,11 +1,9 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <gtk/gtk.h>
|
|
||||||
#include <gdk/gdk.h>
|
|
||||||
#include <cairo.h>
|
|
||||||
|
|
||||||
#include "dive.h"
|
#include "dive.h"
|
||||||
|
#include "display.h"
|
||||||
|
|
||||||
static void show_dive(int nr, struct dive *dive)
|
static void show_dive(int nr, struct dive *dive)
|
||||||
{
|
{
|
||||||
|
@ -96,35 +94,6 @@ static GtkTreeModel *fill_dive_list(void)
|
||||||
return GTK_TREE_MODEL(store);
|
return GTK_TREE_MODEL(store);
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data)
|
|
||||||
{
|
|
||||||
struct dive *dive = dive_table.dives[0];
|
|
||||||
cairo_t *cr;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
cr = gdk_cairo_create(widget->window);
|
|
||||||
cairo_set_source_rgb(cr, 0, 0, 0);
|
|
||||||
gdk_cairo_rectangle(cr, &event->area);
|
|
||||||
cairo_fill(cr);
|
|
||||||
|
|
||||||
cairo_set_line_width(cr, 3);
|
|
||||||
cairo_set_source_rgb(cr, 1, 1, 1);
|
|
||||||
|
|
||||||
if (dive->samples) {
|
|
||||||
struct sample *sample = dive->sample;
|
|
||||||
cairo_move_to(cr, sample->time.seconds / 5, to_feet(sample->depth) * 3);
|
|
||||||
for (i = 1; i < dive->samples; i++) {
|
|
||||||
sample++;
|
|
||||||
cairo_line_to(cr, sample->time.seconds / 5, to_feet(sample->depth) * 3);
|
|
||||||
}
|
|
||||||
cairo_stroke(cr);
|
|
||||||
}
|
|
||||||
|
|
||||||
cairo_destroy(cr);
|
|
||||||
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static GtkWidget *create_dive_list(void)
|
static GtkWidget *create_dive_list(void)
|
||||||
{
|
{
|
||||||
GtkWidget *list;
|
GtkWidget *list;
|
||||||
|
@ -151,7 +120,6 @@ int main(int argc, char **argv)
|
||||||
GtkWidget *vbox;
|
GtkWidget *vbox;
|
||||||
GtkWidget *scrolled_window;
|
GtkWidget *scrolled_window;
|
||||||
GtkWidget *frame;
|
GtkWidget *frame;
|
||||||
GtkWidget *da;
|
|
||||||
|
|
||||||
parse_xml_init();
|
parse_xml_init();
|
||||||
|
|
||||||
|
@ -186,13 +154,9 @@ int main(int argc, char **argv)
|
||||||
gtk_widget_show(scrolled_window);
|
gtk_widget_show(scrolled_window);
|
||||||
|
|
||||||
/* Frame for dive profile */
|
/* Frame for dive profile */
|
||||||
frame = gtk_frame_new("Dive profile");
|
frame = dive_profile_frame();
|
||||||
|
|
||||||
gtk_container_add(GTK_CONTAINER(vbox), frame);
|
gtk_container_add(GTK_CONTAINER(vbox), frame);
|
||||||
gtk_widget_show(frame);
|
|
||||||
da = gtk_drawing_area_new();
|
|
||||||
gtk_widget_set_size_request(da, 450, 350);
|
|
||||||
gtk_container_add(GTK_CONTAINER(frame), da);
|
|
||||||
g_signal_connect(da, "expose_event", G_CALLBACK(expose_event), NULL);
|
|
||||||
|
|
||||||
/* Create the atual divelist */
|
/* Create the atual divelist */
|
||||||
divelist = create_dive_list();
|
divelist = create_dive_list();
|
||||||
|
|
50
profile.c
Normal file
50
profile.c
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <time.h>
|
||||||
|
|
||||||
|
#include "dive.h"
|
||||||
|
#include "display.h"
|
||||||
|
|
||||||
|
static gboolean expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer data)
|
||||||
|
{
|
||||||
|
struct dive *dive = dive_table.dives[0];
|
||||||
|
cairo_t *cr;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
cr = gdk_cairo_create(widget->window);
|
||||||
|
cairo_set_source_rgb(cr, 0, 0, 0);
|
||||||
|
gdk_cairo_rectangle(cr, &event->area);
|
||||||
|
cairo_fill(cr);
|
||||||
|
|
||||||
|
cairo_set_line_width(cr, 3);
|
||||||
|
cairo_set_source_rgb(cr, 1, 1, 1);
|
||||||
|
|
||||||
|
if (dive->samples) {
|
||||||
|
struct sample *sample = dive->sample;
|
||||||
|
cairo_move_to(cr, sample->time.seconds / 5, to_feet(sample->depth) * 3);
|
||||||
|
for (i = 1; i < dive->samples; i++) {
|
||||||
|
sample++;
|
||||||
|
cairo_line_to(cr, sample->time.seconds / 5, to_feet(sample->depth) * 3);
|
||||||
|
}
|
||||||
|
cairo_stroke(cr);
|
||||||
|
}
|
||||||
|
|
||||||
|
cairo_destroy(cr);
|
||||||
|
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
|
GtkWidget *dive_profile_frame(void)
|
||||||
|
{
|
||||||
|
GtkWidget *frame;
|
||||||
|
GtkWidget *da;
|
||||||
|
|
||||||
|
frame = gtk_frame_new("Dive profile");
|
||||||
|
gtk_widget_show(frame);
|
||||||
|
da = gtk_drawing_area_new();
|
||||||
|
gtk_widget_set_size_request(da, 450, 350);
|
||||||
|
g_signal_connect(da, "expose_event", G_CALLBACK(expose_event), NULL);
|
||||||
|
gtk_container_add(GTK_CONTAINER(frame), da);
|
||||||
|
|
||||||
|
return frame;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue