Commit d01d19ca authored by teknopaul's avatar teknopaul
Browse files

initial vesion

parents
*.o
*.deb
deploy/root/
cairoruler
control
.bzr/
.bzrignore
#include <gtk/gtk.h>
/*
define the colurs for the components
*/
// ruler dimentions
int C_R_BORDER_WIDTH;
int C_R_TICK_BIG;
int C_R_TICK_LITTLE;
// rulers colour
gdouble C_R_COLOUR_RULER_R;
gdouble C_R_COLOUR_RULER_G;
gdouble C_R_COLOUR_RULER_B;
gdouble C_R_COLOUR_RULER_A;
gdouble C_R_GRADIENT_EXTENT;
// rulers lines
gdouble C_R_COLOUR_TICK_R;
gdouble C_R_COLOUR_TICK_G;
gdouble C_R_COLOUR_TICK_B;
gdouble C_R_COLOUR_TICK_A;
gdouble C_R_RULER_FONT_SIZE;
// marker lines
gdouble C_R_COLOUR_LINE_R;
gdouble C_R_COLOUR_LINE_G;
gdouble C_R_COLOUR_LINE_B;
gdouble C_R_COLOUR_LINE_A;
// overlay box
gdouble C_R_COLOUR_BOX_R;
gdouble C_R_COLOUR_BOX_G;
gdouble C_R_COLOUR_BOX_B;
gdouble C_R_COLOUR_BOX_A;
gdouble C_R_FONT_SIZE;
// positions boxes
gdouble C_R_TEXT_BOX_A;
void initDefaultColours();
void initDefaultColours()
{
// ruler dimentions
C_R_BORDER_WIDTH = 50;
C_R_TICK_BIG = 50;
C_R_TICK_LITTLE = 50;
// rulers colour
C_R_COLOUR_RULER_R = 1.0;
C_R_COLOUR_RULER_G = 0.2;
C_R_COLOUR_RULER_B = 0.2;
C_R_COLOUR_RULER_A = 0.5;
C_R_GRADIENT_EXTENT = 0.2;
// rulers lines
C_R_COLOUR_TICK_R = 1.0;
C_R_COLOUR_TICK_G = 1.0;
C_R_COLOUR_TICK_B = 1.0;
C_R_COLOUR_TICK_A = 0.7;
C_R_RULER_FONT_SIZE = 12.0;
// marker lines
C_R_COLOUR_LINE_R = 1.0;
C_R_COLOUR_LINE_G = 0.2;
C_R_COLOUR_LINE_B = 0.2;
C_R_COLOUR_LINE_A = 0.7;
// overlay box
C_R_COLOUR_BOX_R = 1.0;
C_R_COLOUR_BOX_G = 0.1;
C_R_COLOUR_BOX_B = 0.1;
C_R_COLOUR_BOX_A = 0.2;
C_R_FONT_SIZE = 23.5;
// positions boxes
C_R_TEXT_BOX_A = 0.5;
}
/*
define the colurs for the components
*/
#ifndef CAIRO_RULER_COLOURS_H
#define CAIRO_RULER_COLOURS_H
// ruler dimentions
int C_R_BORDER_WIDTH;
int C_R_TICK_BIG;
int C_R_TICK_LITTLE;
// rulers colour
gdouble C_R_COLOUR_RULER_R;
gdouble C_R_COLOUR_RULER_G;
gdouble C_R_COLOUR_RULER_B;
gdouble C_R_COLOUR_RULER_A;
gdouble C_R_GRADIENT_EXTENT;
// rulers lines
gdouble C_R_COLOUR_TICK_R;
gdouble C_R_COLOUR_TICK_G;
gdouble C_R_COLOUR_TICK_B;
gdouble C_R_COLOUR_TICK_A;
gdouble C_R_RULER_FONT_SIZE;
// marker lines
gdouble C_R_COLOUR_LINE_R;
gdouble C_R_COLOUR_LINE_G;
gdouble C_R_COLOUR_LINE_B;
gdouble C_R_COLOUR_LINE_A;
// overlay box
gdouble C_R_COLOUR_BOX_R;
gdouble C_R_COLOUR_BOX_G;
gdouble C_R_COLOUR_BOX_B;
gdouble C_R_COLOUR_BOX_A;
gdouble C_R_FONT_SIZE;
// positions boxes
gdouble C_R_TEXT_BOX_A;
void initDefaultColours();
#endif /* CAIRO_RULER_COLOURS_H */
#!/bin/bash -e
#
# Compiler script, oh for make but that is a bit above me right now
#
# requires libgtk2.0-dev
#
#
cd $(dirname $0)
opts="-Wall -Werror"
#
# first compile the files with the -c flag so linking is not attmepted
# N.B. the --libs-only-L flag so we don't get -lblah attempt to link
# and a ton of warnings
#
/usr/bin/gcc $opts -c keybindings.c `pkg-config --cflags --libs-only-L gtk+-2.0`
/usr/bin/gcc $opts -c transparent.c `pkg-config --cflags --libs-only-L gtk+-2.0`
/usr/bin/gcc $opts -c cairorulercolours.c `pkg-config --cflags --libs-only-L gtk+-2.0`
# Linking is done just by specifying a list of .o output files for gcc with no flags
/usr/bin/gcc $opts transparent.o keybindings.o cairorulercolours.o -o cairoruler `pkg-config --cflags --libs gtk+-2.0`
rm *.o
# easy when you know how, but for some reason keybindings.c can not have static functions
Package: cairoruler
Version: @PACKAGE_VERSION@
Section:
Priority: optional
Architecture: all
Essential: no
Depends:
Pre-Depends:
Recommends:
Suggests:
Installed-Size: @SIZE@
Maintainer: teknopaul [teknopaul@tp23.org]
Conflicts:
Replaces:
Provides: cairoruler
Description: A screen ruler using GTK and Cairo
#!/bin/sh
#
# rm all the data
#
#!/bin/bash -e
#
# Build the .deb package
# Files to be build into the .deb should be build to ../deploy/root before calling this script (or edit it). e.g. cp --archive src/* ../deploy/root/opt/myproj/
#
test `id -u` == "0" || (echo "Run as root" && exit 1) # requires bash -e
#
# The package name
#
NAME=cairoruler
ARCH=`uname -m`
#
# Select the files to include
#
cd `dirname $0`/..
PROJECT_ROOT=`pwd`
#
# Copy files e.g. cp --archive src/* ${PROJECT_ROOT}/deploy/root/opt/$NAME/
#
mkdir -p ${PROJECT_ROOT}/deploy/root/usr/local/bin
cp help.png cairoruler ${PROJECT_ROOT}/deploy/root/usr/local/bin
FILES=${PROJECT_ROOT}/deploy/root
#
# Create a temporary build directory
#
TMP_DIR=/tmp/${NAME}_debbuild
rm -rf ${TMP_DIR}
mkdir -p ${TMP_DIR}
. ./version
sed -e "s/@PACKAGE_VERSION@/${VERSION}/" ${PROJECT_ROOT}/deploy/DEBIAN/control.in > ${PROJECT_ROOT}/deploy/DEBIAN/control
cp --archive -R ${FILES}/* ${TMP_DIR}/
SIZE=$(du -sk ${TMP_DIR} | cut -f 1)
sed -i -e "s/@SIZE@/${SIZE}/" ${PROJECT_ROOT}/deploy/DEBIAN/control
cp --archive -R ${PROJECT_ROOT}/deploy/DEBIAN ${TMP_DIR}/
#
# Setup the installation package ownership here if it needs root
#
#chown root.root ${TMP_DIR}/root/*
chown root.root ${TMP_DIR}/usr/local/bin/*
#chown root.root \
# ${TMP_DIR}/root \
# ${TMP_DIR}/home \
# ${TMP_DIR}/usr/bin ${TMP_DIR}/usr \
#
# Build the .deb
#
dpkg-deb --build ${TMP_DIR} ${NAME}-${VERSION}-1.${ARCH}.deb
test -f ${NAME}-${VERSION}-1.${ARCH}.deb
echo "built ${NAME}-${VERSION}-1.${ARCH}.deb"
#include <gtk/gtk.h>
#include <gdk/gdkscreen.h>
#include <cairo.h>
#include <stdio.h>
#include <stdlib.h>
void show_help(cairo_t* cr) {
int w, h;
cairo_surface_t *image;
image = cairo_image_surface_create_from_png ("help.png");
w = cairo_image_surface_get_width (image);
h = cairo_image_surface_get_height (image);
cairo_set_source_surface (cr, image, 0, 0);
cairo_paint (cr);
cairo_surface_destroy (image);
}
\ No newline at end of file
help.png

54.3 KB

#include <gtk/gtk.h>
#include <gdk/gdkscreen.h>
#include <stdio.h>
#include <stdlib.h>
#include "transparent.h"
#include "cairorulercolours.h"
/*
void output(char* text)
{
fprintf(stdout, text);
}
*/
void do_exit()
{
exit(0);
}
/*
recieves
typedef struct {
GdkEventType type;
GdkWindow *window;
gint8 send_event;
guint32 time;
guint state;
guint keyval;
gint length;
gchar *string;
guint16 hardware_keycode;
guint8 group;
guint is_modifier : 1;
} GdkEventKey;
F1 = help
Esc = exit
Ctrl + C = copy to clipboard as "X x Y"
Ctrl + V = move to parsing clipboard as "X x Y"
Ctrl + E = edit format
Enter = center
M = minimise
P = Pointer
X = Crosshair
C = Cursor
Up = ruler up 10
Down 0 ruler down 10
PageUp = to top
+ more opaque
- more transparent
*/
void do_keypressed(GtkWindow *win, GdkEventKey *event, gpointer user_data)
{
//fprintf(stdout, "hardware_keycode = %d\n", event->hardware_keycode);
//fprintf(stdout, "keyval = %d\n", event->keyval);
if(event->hardware_keycode == 9) {
// escape
do_exit();
}
else if(event->hardware_keycode == 67) {
// F1
show_help();
}
else if(event->hardware_keycode == 36) {
// Enter
GtkWidget *window = get_main_window();
GdkScreen *screen = gtk_widget_get_screen(GTK_WIDGET(window));
screen_width = gdk_screen_get_width(screen);
screen_height = gdk_screen_get_height(screen);
gdk_window_move_resize(window->window, 0, 0, screen_width, screen_height);
GtkWidget *xwindow = get_crosshair_window();
GdkScreen *xscreen = gtk_widget_get_screen(GTK_WIDGET(xwindow));
gdk_window_move_resize(xwindow->window, 0, 0, gdk_screen_get_width(xscreen), gdk_screen_get_height(xscreen));
ruler_top();
}
else if(event->hardware_keycode == 58) {
// M Minimize
// keycode = 109
// hmmm needs two presses and then you can't get the windows back since you loose the keybindings
/*
if( gdk_window_is_visible(event->window) ) {
gdk_window_hide(event->window);
}
else {
gdk_window_show(event->window);
}
*/
}
else if(event->hardware_keycode == 33) {
// P = Pointer
// keycode = 112
}
else if(event->hardware_keycode == 53) {
// X = Crosshair
// keycode = 120
GtkWidget * xwindow = get_crosshair_window();
if( gdk_window_is_visible(xwindow->window) ) {
gdk_window_hide(xwindow->window);
}
else {
gdk_window_show(xwindow->window);
}
}
else if(event->hardware_keycode == 54) {
// C = Cursor
// keycode = 99
}
else if(event->hardware_keycode == 104) {
// Down
ruler_down();
}
else if(event->hardware_keycode == 98) {
// Up
ruler_up();
}
else if(event->hardware_keycode == 99) {
// PageUp
ruler_top();
}
else if(event->hardware_keycode == 35) {
// + more opaque
C_R_COLOUR_RULER_A += 0.1;
C_R_TEXT_BOX_A += 0.1;
repaint();
}
else if(event->hardware_keycode == 61) {
// - less opaque
C_R_COLOUR_RULER_A -= 0.1;
C_R_TEXT_BOX_A -= 0.1;
repaint();
}
}
#ifndef CAIRO_RULER_KEYBINDINGS_H
#define CAIRO_RULER_KEYBINDINGS_H
void output(char* text);
void do_keypressed(GtkWindow *window, GdkEventKey *event, gpointer user_data);
#endif /* CAIRO_RULER_KEYBINDINGS_H */
#include <cairo.h>
int
main (int argc, char *argv[])
{
cairo_surface_t *surface;
cairo_t *cr;
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 240, 80);
cr = cairo_create (surface);
cairo_select_font_face (cr, "serif", CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_BOLD);
cairo_set_font_size (cr, 32.0);
cairo_set_source_rgb (cr, 0.0, 0.0, 1.0);
cairo_move_to (cr, 10.0, 50.0);
cairo_show_text (cr, "Hello, world");
cairo_destroy (cr);
cairo_surface_write_to_png (surface, "hello.png");
cairo_surface_destroy (surface);
return 0;
}
This diff is collapsed.
#ifndef CAIRO_RULER_TRANSPARENT_H
#define CAIRO_RULER_TRANSPARENT_H
GtkWidget *get_crosshair_window();
GtkWidget *get_main_window();
void ruler_down();
void ruler_up();
void ruler_top();
void repaint();
void show_help();
int screen_width, screen_height;
#endif /* CAIRO_RULER_TRANSPARENT_H */
VERSION=0.1
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment