Add gtk116
This commit is contained in:
parent
27504922e9
commit
b4fdde68b7
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools"
|
||||
}
|
|
@ -0,0 +1,62 @@
|
|||
set(CMAKE_CXX_STANDARD 17)
|
||||
cmake_minimum_required(VERSION 3.0.0)
|
||||
project(gtk116 VERSION 1.0.0)
|
||||
|
||||
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../GCR_CMake/macros)
|
||||
include(GlibCompileResourcesSupport)
|
||||
|
||||
include(CTest)
|
||||
enable_testing()
|
||||
|
||||
set(CPACK_PROJECT_NAME ${PROJECT_NAME})
|
||||
set(CPACK_PROJECT_VERSION ${PROJECT_VERSION})
|
||||
|
||||
include(CPack)
|
||||
include_directories(.)
|
||||
include_directories(..)
|
||||
|
||||
find_package (PkgConfig REQUIRED)
|
||||
pkg_check_modules (GTKMM3 REQUIRED gtkmm-3.0)
|
||||
include_directories (${GTKMM3_INCLUDE_DIRS})
|
||||
link_directories (${GTKMM3_LIBRARY_DIRS})
|
||||
|
||||
#Compile Resource
|
||||
|
||||
# set(RESOURCE_LIST
|
||||
# gnome-fs-directory.png
|
||||
# gnome-fs-regular.png
|
||||
# icons/24x24/actions/view-grid-symbolic.png
|
||||
# icons/24x24/actions/view-list-symbolic.png
|
||||
# icons/48x48/actions/dialog-error.png)
|
||||
|
||||
# compile_gresources(RESOURCE_FILE
|
||||
# XML_OUT
|
||||
# TYPE EMBED_C
|
||||
# RESOURCES ${RESOURCE_LIST}
|
||||
# PREFIX "/org/gtk/daleclack"
|
||||
# SOURCE_DIR ${PROJECT_SOURCE_DIR}/../default_res)
|
||||
|
||||
# Add a custom target to the makefile. Now make builds our resource file.
|
||||
# It depends on the output RESOURCE_FILE.
|
||||
# add_custom_target(resource ALL DEPENDS ${RESOURCE_FILE})
|
||||
|
||||
#For win32 platform,use rc resource and .ico icon
|
||||
if(WIN32)
|
||||
SET(CMAKE_RC_COMPILER x86_64-w64-mingw32-windres)
|
||||
set(app_WINRC ../icon.rc)
|
||||
set_property(SOURCE ../icon.rc APPEND PROPERTY
|
||||
OBJECT_DEPENDS ${PROJECT_SOURCE_DIR}/../icon.ico
|
||||
)
|
||||
add_executable(${PROJECT_NAME} WIN32 ${app_WINRC} src/main.cc src/MyWin.cc)
|
||||
else()
|
||||
add_executable(${PROJECT_NAME} src/main.cc src/MyWin.cc)
|
||||
|
||||
endif(WIN32)
|
||||
|
||||
#Add command to generate .gitignore
|
||||
add_custom_command(TARGET ${PROJECT_NAME}
|
||||
COMMAND echo \"*\" > ${CMAKE_BINARY_DIR}/.gitignore
|
||||
COMMAND echo \"**/*\" > ${CMAKE_BINARY_DIR}/.hgignore)
|
||||
|
||||
SET (CMAKE_EXTRA_CXX_FLAGS ${GTKMM3_CFLAGS_OTHER})
|
||||
target_link_libraries (${PROJECT_NAME} ${GTKMM3_LIBRARIES} -lpthread)
|
|
@ -0,0 +1,52 @@
|
|||
#include "MyWin.hh"
|
||||
#include <iostream>
|
||||
#include "winpe.xpm"
|
||||
|
||||
MyWin::MyWin(){
|
||||
set_icon_name("org.gtk.daleclack");
|
||||
background.set_size_request(640,360);
|
||||
|
||||
//Create a pixbuf
|
||||
pixbuf = Gdk::Pixbuf::create_from_xpm_data(winpe);
|
||||
sized = pixbuf->scale_simple(640,360,Gdk::INTERP_BILINEAR);
|
||||
|
||||
//Set image
|
||||
gtk_image_set_from_pixbuf(background.gobj(),sized->gobj());
|
||||
get_pixel_color(320,180);
|
||||
add(background);
|
||||
show_all_children();
|
||||
pixbuf.reset();
|
||||
}
|
||||
|
||||
void MyWin::get_pixel_color(int x,int y){
|
||||
//Get Image data
|
||||
int red=0,green=0,blue=0,alpha=0;
|
||||
int n_channels = sized->get_n_channels();
|
||||
int rowstride = sized->get_rowstride(); //Rows
|
||||
|
||||
//Get Pixel data
|
||||
guint8 * pixels = sized->get_pixels();
|
||||
|
||||
//Get Color at specified location
|
||||
for(int i = x-2; i <= x+2; i++){
|
||||
for(int j = y-2; j <= y+2; j++){
|
||||
guchar * p = pixels + y * rowstride + x * n_channels;
|
||||
red += p[0];
|
||||
green += p[1];
|
||||
blue += p[2];
|
||||
if(sized->get_has_alpha()){
|
||||
alpha += p[4];
|
||||
}else{
|
||||
alpha += 255;
|
||||
}
|
||||
}
|
||||
}
|
||||
red/=25;blue/=25;green/=25;alpha/=25;
|
||||
|
||||
//OutPut the color rgba set
|
||||
if(pixbuf->get_has_alpha()){
|
||||
std::cout<<red<<" "<<green<<" "<<blue<<" "<<alpha<<std::endl;
|
||||
}else{
|
||||
std::cout<<red<<" "<<green<<" "<<blue<<" "<<alpha<<std::endl;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
#pragma once
|
||||
|
||||
#include <gtkmm.h>
|
||||
|
||||
class MyWin : public Gtk::Window{
|
||||
public:
|
||||
MyWin();
|
||||
private:
|
||||
//Child Widgets
|
||||
Gtk::Image background;
|
||||
Glib::RefPtr<Gdk::Pixbuf> pixbuf;
|
||||
Glib::RefPtr<Gdk::Pixbuf> sized;
|
||||
//Signal Handlers
|
||||
void get_pixel_color(int x,int y);
|
||||
};
|
|
@ -0,0 +1,7 @@
|
|||
#include "MyWin.hh"
|
||||
|
||||
int main(int argc,char ** argv){
|
||||
auto app = Gtk::Application::create(argc,argv,"org.gtk.daleclack");
|
||||
MyWin window;
|
||||
return app->run(window);
|
||||
}
|
Loading…
Reference in New Issue