Commit 16676609 authored by Francois Techene's avatar Francois Techene

Initial implementation

parent 4923d859
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
width="16"
height="16"
version="1.1"
id="svg8"
sodipodi:docname="dice-symbolic.svg"
inkscape:version="1.0.1 (3bc2e813f5, 2020-09-07)">
<metadata
id="metadata14">
<rdf:RDF>
<cc:Work
rdf:about="">
<dc:format>image/svg+xml</dc:format>
<dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
</cc:Work>
</rdf:RDF>
</metadata>
<defs
id="defs12" />
<sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="640"
inkscape:window-height="480"
id="namedview10"
showgrid="false"
inkscape:zoom="25.684162"
inkscape:cx="22.784079"
inkscape:cy="16.552873"
inkscape:current-layer="svg8" />
<path
d="M 3.5,1 A 2.506,2.506 0 0 0 1,3.5 v 9 C 1,13.876 2.124,15 3.5,15 h 9 c 1.376,0 2.5,-1.124 2.5,-2.5 v -9 C 15,2.124 13.876,1 12.5,1 Z m 0,1 h 9 C 13.34,2 14,2.66 14,3.5 v 9 c 0,0.84 -0.66,1.5 -1.5,1.5 h -9 C 2.66,14 2,13.34 2,12.5 v -9 C 2,2.66 2.66,2 3.5,2 Z"
style="color:#000000;font-weight:400;line-height:normal;font-variant-ligatures:normal;font-variant-position:normal;font-variant-caps:normal;font-variant-numeric:normal;font-variant-alternates:normal;font-feature-settings:normal;text-indent:0;text-align:start;text-decoration:none;text-decoration-line:none;text-decoration-style:solid;text-decoration-color:#000000;text-transform:none;text-orientation:mixed;shape-padding:0;isolation:auto;mix-blend-mode:normal;fill:#474747;marker:none;fill-opacity:1"
font-family="sans-serif"
white-space="normal"
overflow="visible"
id="path2" />
<g
id="g1013"
transform="translate(0.02268124,0.09885132)">
<circle
style="fill:#474747;fill-opacity:1;stroke:none;stroke-width:0.604374;stroke-linecap:square;stroke-opacity:1"
id="path883"
cx="4.8555965"
cy="4.7782478"
r="1.2434648" />
<circle
style="fill:#474747;fill-opacity:1;stroke:none;stroke-width:0.604374;stroke-linecap:square;stroke-opacity:1"
id="path883-3"
cx="11.099041"
cy="4.7782478"
r="1.2434648" />
<circle
style="fill:#474747;fill-opacity:1;stroke:none;stroke-width:0.604374;stroke-linecap:square;stroke-opacity:1"
id="path883-6"
cx="4.8555965"
cy="11.02405"
r="1.2434646" />
<circle
style="fill:#474747;fill-opacity:1;stroke:none;stroke-width:0.604374;stroke-linecap:square;stroke-opacity:1"
id="path883-3-7"
cx="11.099041"
cy="11.02405"
r="1.2434646" />
</g>
</svg>
......@@ -45,8 +45,8 @@ on_activate (GtkApplication *app)
if (window == NULL)
window = g_object_new (RANDOMIZER_TYPE_WINDOW,
"application", app,
"default-width", 600,
"default-height", 300,
NULL,
NULL,
NULL);
/* Ask the window manager/compositor to present the window. */
......
......@@ -25,10 +25,51 @@ struct _RandomizerWindow
/* Template widgets */
HdyViewSwitcherTitle *switcher_title;
GtkLabel *boolean_label;
GtkLabel *dice_label;
};
G_DEFINE_TYPE (RandomizerWindow, randomizer_window, HDY_TYPE_WINDOW)
static int
get_randomized_number_with_range (int lower,
int upper)
{
int num = (rand() %(upper - lower + 1)) + lower;
return num;
}
static void
boolean_randomize_clicked_cb (GtkButton *btn,
RandomizerWindow *self)
{
int num = get_randomized_number_with_range(0,1);
if (num == 0) {
gtk_label_set_text(self->boolean_label, "No");
}
else {
gtk_label_set_text(self->boolean_label, "Yes");
}
}
static void
dice_randomize_clicked_cb (GtkButton *btn,
RandomizerWindow *self)
{
int num = get_randomized_number_with_range(1,6);
char str[1];
sprintf(str, "%d", num);
gtk_label_set_text(self->dice_label, str);
}
static void
randomizer_window_class_init (RandomizerWindowClass *klass)
{
......@@ -36,7 +77,10 @@ randomizer_window_class_init (RandomizerWindowClass *klass)
gtk_widget_class_set_template_from_resource (widget_class, "/sm/puri/Randomizer/randomizer-window.ui");
gtk_widget_class_bind_template_child (widget_class, RandomizerWindow, switcher_title);
//gtk_widget_class_bind_template_child (widget_class, RandomizerWindow, label);
gtk_widget_class_bind_template_child (widget_class, RandomizerWindow, boolean_label);
gtk_widget_class_bind_template_child (widget_class, RandomizerWindow, dice_label);
gtk_widget_class_bind_template_callback (widget_class, boolean_randomize_clicked_cb);
gtk_widget_class_bind_template_callback (widget_class, dice_randomize_clicked_cb);
}
static void
......
......@@ -4,7 +4,7 @@
<requires lib="libhandy" version="0.0"/>
<template class="RandomizerWindow" parent="HdyWindow">
<property name="default-width">600</property>
<property name="default-height">300</property>
<property name="default-height">600</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
......@@ -32,12 +32,56 @@
<property name="visible">True</property>
<property name="can_focus">False</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin">24</property>
<property name="label" translatable="yes">Yes or No ?</property>
</object>
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="vexpand">True</property>
<property name="hexpand">True</property>
<property name="spacing">24</property>
<child>
<object class="GtkLabel" id="boolean_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes"></property>
<property name="justify">center</property>
<property name="wrap">True</property>
<property name="opacity">0.5</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="scale" value="2"/>
</attributes>
</object>
</child>
<child>
<object class="GtkLabel" id="boolean_description_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Yes or No ?</property>
<property name="justify">center</property>
<property name="wrap">True</property>
<property name="opacity">0.5</property>
<attributes>
<attribute name="weight" value="normal"/>
<attribute name="scale" value="1"/>
</attributes>
</object>
</child>
<child>
<object class="GtkButton">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Decide</property>
<property name="use-underline">True</property>
<signal name="clicked" handler="boolean_randomize_clicked_cb" swapped="no"/>
<style>
<class name="suggested-action"/>
</style>
</object>
</child>
</object>
<packing>
<property name="name">page1</property>
<property name="title" translatable="yes">Yes/No</property>
......@@ -45,16 +89,47 @@
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin">24</property>
<property name="label" translatable="yes">Generate a random number</property>
</object>
<object class="GtkBox">
<property name="visible">True</property>
<property name="orientation">vertical</property>
<property name="can_focus">False</property>
<property name="halign">center</property>
<property name="valign">center</property>
<property name="vexpand">True</property>
<property name="hexpand">True</property>
<property name="spacing">24</property>
<child>
<object class="GtkLabel" id="dice_label">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes"></property>
<property name="justify">center</property>
<property name="wrap">True</property>
<property name="opacity">0.5</property>
<attributes>
<attribute name="weight" value="bold"/>
<attribute name="scale" value="2"/>
</attributes>
</object>
</child>
<child>
<object class="GtkButton">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Throw the dice</property>
<property name="use-underline">True</property>
<signal name="clicked" handler="dice_randomize_clicked_cb" swapped="no"/>
<style>
<class name="suggested-action"/>
</style>
</object>
</child>
</object>
<packing>
<property name="name">page2</property>
<property name="title" translatable="yes">Number</property>
<property name="icon_name">numbers-symbolic</property>
<property name="title" translatable="yes">Dice</property>
<property name="icon_name">dice-symbolic</property>
<property name="position">1</property>
</packing>
</child>
......
......@@ -3,6 +3,7 @@
<gresource prefix="/sm/puri/Randomizer">
<file preprocess="xml-stripblanks">randomizer-window.ui</file>
<file preprocess="xml-stripblanks">icons/checkbox-checked-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/dice-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/numbers-symbolic.svg</file>
</gresource>
</gresources>
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