From 3293661948372b7a0d505fea3f8c79349c82718c Mon Sep 17 00:00:00 2001 From: daleclack Date: Fri, 19 Nov 2021 20:06:45 +0800 Subject: [PATCH] Update gtk116 --- Gtkmm3/gtk116_imagedata/src/MyWin.cc | 29 +++++++++++++++++++------ Gtkmm3/gtk116_imagedata/src/MyWin.hh | 2 +- cpp/algorithms/problem5.cpp | 28 ++++++++++++++++++++++++ cpp/algorithms/problem6.cpp | 32 ++++++++++++++++++++++++++++ 4 files changed, 83 insertions(+), 8 deletions(-) create mode 100644 cpp/algorithms/problem6.cpp diff --git a/Gtkmm3/gtk116_imagedata/src/MyWin.cc b/Gtkmm3/gtk116_imagedata/src/MyWin.cc index d485276..18fb86f 100644 --- a/Gtkmm3/gtk116_imagedata/src/MyWin.cc +++ b/Gtkmm3/gtk116_imagedata/src/MyWin.cc @@ -1,5 +1,6 @@ #include "MyWin.hh" #include +#include #include "image_types.hh" #include "winpe.xpm" @@ -9,7 +10,8 @@ hbox(Gtk::ORIENTATION_HORIZONTAL,5), btnbox(Gtk::ORIENTATION_VERTICAL,5), label_pos("(640,480)"), label_rgba("rgba(255,255,255,255)"), -label_test("Color Settings And Position info") +label_test("Color Settings And Position info"), +label_color_str("#00000000") { set_icon_name("org.gtk.daleclack"); background.set_size_request(640,480); @@ -38,11 +40,13 @@ label_test("Color Settings And Position info") //Add Color and Image Button color_btn.set_use_alpha(); + color_btn.set_halign(Gtk::ALIGN_CENTER); btnbox.pack_start(label_test,Gtk::PACK_SHRINK); btnbox.pack_start(label_pos,Gtk::PACK_SHRINK); btnbox.pack_start(label_rgba,Gtk::PACK_SHRINK); - btnbox.pack_start(color_btn,Gtk::PACK_SHRINK); - btnbox.pack_start(btn_back,Gtk::PACK_SHRINK); + btnbox.pack_start(label_color_str,Gtk::PACK_SHRINK); + btnbox.pack_start(color_btn); + btnbox.pack_start(btn_back); btnbox.set_valign(Gtk::ALIGN_CENTER); //Add Widgets and show all @@ -60,6 +64,7 @@ void MyWin::get_pixel_color(int x,int y){ int red=0,green=0,blue=0,alpha=0; int n_channels = sized->get_n_channels(); int rowstride = sized->get_rowstride(); //Rows + Glib::ustring color_str; //Get Pixel data guint8 * pixels = sized->get_pixels(); @@ -80,16 +85,26 @@ void MyWin::get_pixel_color(int x,int y){ } //Set Color to rgba - color_set.set_red(red/25.0/255.0); - color_set.set_blue(blue/25.0/255.0); - color_set.set_green(green/25.0/255.0); - color_set.set_alpha(alpha/25.0/255.0); + red/=25;blue/=25;green/=25;alpha/=25; + color_set.set_red(red/255.0); + color_set.set_blue(blue/255.0); + color_set.set_green(green/255.0); + color_set.set_alpha(alpha/255.0); //Get Color set as a string label_rgba.set_label(color_set.to_string()); //OutPut the color rgba set color_btn.set_rgba(color_set); + + //OutPut color Set as a Color Code + //If the image has a alpha value, use RGBA Code, else use RGB Code + if(sized->get_has_alpha()){ + color_str = Glib::ustring(g_strdup_printf("#%02X%02X%02X%02X",red,blue,green,alpha)); + }else{ + color_str = Glib::ustring(g_strdup_printf("#%02X%02X%02X",red,blue,green)); + } + label_color_str.set_label(color_str); } void MyWin::gesture_pressed(int n_press,double x,double y){ diff --git a/Gtkmm3/gtk116_imagedata/src/MyWin.hh b/Gtkmm3/gtk116_imagedata/src/MyWin.hh index 67bab07..706565f 100644 --- a/Gtkmm3/gtk116_imagedata/src/MyWin.hh +++ b/Gtkmm3/gtk116_imagedata/src/MyWin.hh @@ -11,7 +11,7 @@ class MyWin : public Gtk::Window{ Gtk::Button btn_back; Gtk::Image background; Gtk::Box hbox,btnbox; - Gtk::Label label_pos,label_rgba,label_test; + Gtk::Label label_pos,label_rgba,label_test,label_color_str; Gtk::ColorButton color_btn; Gtk::DrawingArea draw_area; Glib::RefPtr pixbuf; diff --git a/cpp/algorithms/problem5.cpp b/cpp/algorithms/problem5.cpp index d1adcf5..57c872c 100644 --- a/cpp/algorithms/problem5.cpp +++ b/cpp/algorithms/problem5.cpp @@ -6,6 +6,34 @@ int main(int argc,char ** argv){ while (scanf("%d",&score)!=EOF) { /* code */ + if(score > 100 || score < 0){ + printf("Score is error!\n"); + continue; + } + switch (score/10) + { + case 10: + case 9: + printf("A\n"); + break; + case 8: + printf("B\n"); + break; + case 7: + printf("C\n"); + break; + case 6: + printf("D\n"); + break; + case 5: + case 4: + case 3: + case 2: + case 1: + case 0: + printf("E\n"); + break; + } } return 0; } \ No newline at end of file diff --git a/cpp/algorithms/problem6.cpp b/cpp/algorithms/problem6.cpp new file mode 100644 index 0000000..5d54236 --- /dev/null +++ b/cpp/algorithms/problem6.cpp @@ -0,0 +1,32 @@ +//http://acm.hdu.edu.cn/showproblem.php?pid=2004 +#include + +int main(int argc,char ** argv){ + int year,month,day,sum_day=0; + while (scanf("%d/%d/%d",&year,&month,&day)!=EOF) + { + switch(month){ + case 1: + sum_day+=31; + break; + case 2: + if(month%4 == 0 && month%100 != 0){ + sum_day += 60; + }else{ + sum_day += 59; + } + break; + case 3: + case 4: + case 5: + case 6: + case 7: + case 8: + case 9: + case 10: + case 11: + case 12: + } + } + return 0; +} \ No newline at end of file