-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
104 lines (81 loc) · 2.44 KB
/
Copy pathmain.cpp
File metadata and controls
104 lines (81 loc) · 2.44 KB
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
/*
* File: main.cpp
* Author: feiyu
*
* Created on February 7, 2016, 1:43 AM
*/
#include <assert.h>
#include <stdio.h>
#include <iostream>
#include <X11/Xlib.h>
#include <cairo/cairo.h>
#include <cairo/cairo-xlib.h>
#include "Config.h"
#include "notSoEasyGL.h"
#include "mEventDispatcher.h"
#include "WidgetButton.h"
#include "WidgetTextbox.h"
#define M_PI 3.1415
int width, height;
void draw(cairo_t *cr) {
//std::cout << "DrawGUI" << std::endl;
double x = 25.6, /* parameters like cairo_rectangle */
y = 25.6, width = 204.8, height = 204.8, aspect = 1.0, /* aspect ratio */
corner_radius = height / 10.0; /* and corner curvature radius */
double radius = corner_radius / aspect;
double degrees = M_PI / 180.0;
cairo_new_sub_path(cr);
cairo_arc(cr, x + width - radius, y + radius, radius, -90 * degrees,
0 * degrees);
cairo_arc(cr, x + width - radius, y + height - radius, radius, 0 * degrees,
90 * degrees);
cairo_arc(cr, x + radius, y + height - radius, radius, 90 * degrees,
180 * degrees);
cairo_arc(cr, x + radius, y + radius, radius, 180 * degrees, 270 * degrees);
cairo_close_path(cr);
cairo_set_source_rgb(cr, 0.5, 0.5, 1);
cairo_fill_preserve(cr);
cairo_set_source_rgba(cr, 0.5, 0, 0, 0.5);
cairo_set_line_width(cr, 10.0);
cairo_stroke(cr);
}
void draw2(cairo_t *cr) {
cairo_set_source_rgb(cr, 0.2, 0.3, 0.8);
cairo_rectangle(cr, 10, 10, 30, 30);
cairo_fill(cr);
cairo_translate(cr, 20, 20);
cairo_set_source_rgb(cr, 0.8, 0.3, 0.2);
cairo_rectangle(cr, 0, 0, 30, 30);
cairo_fill(cr);
cairo_translate(cr, 30, 30);
cairo_set_source_rgb(cr, 0.8, 0.8, 0.2);
cairo_rectangle(cr, 0, 0, 30, 30);
cairo_fill(cr);
cairo_translate(cr, 40, 40);
cairo_set_source_rgb(cr, 0.3, 0.8, 0.8);
cairo_rectangle(cr, 0, 0, 30, 30);
cairo_fill(cr);
}
void ondrag(Button* b, int x, int y) {
b->setTLPosition(x, y);
}
int winWidth, winHeight;
int main() {
initGUISys(1280, 960);
mWindow win;
win.addGUIComponent(new GUIComponentBase(0, 0));
Button *zeroButton = new Button(400, 400, 500, 460);
Textbox *textbox = new Textbox(1, 1);
//zeroButton->regOnDraw(draw2);
win.addGUIComponent(zeroButton);
//win.addGUIComponent(textbox);
win.registerDrawGuiFunc(draw);
win.showWindow();
win.startEventLoop();
return 0;
}