Browse Source

Rgba developing

master
blobt 5 years ago
parent
commit
70b92b818e
  1. 63
      CMakeLists.txt
  2. 15
      build.sh
  3. 16
      src/CMakeFiles/CMakeDirectoryInformation.cmake
  4. 1
      src/CMakeFiles/progress.marks
  5. 21
      src/CMakeFiles/test.dir/DependInfo.cmake
  6. 113
      src/CMakeFiles/test.dir/build.make
  7. 10
      src/CMakeFiles/test.dir/cmake_clean.cmake
  8. 2
      src/CMakeFiles/test.dir/depend.make
  9. 10
      src/CMakeFiles/test.dir/flags.make
  10. 1
      src/CMakeFiles/test.dir/link.txt
  11. 3
      src/CMakeFiles/test.dir/progress.make
  12. 6
      src/CMakeLists.txt
  13. 180
      src/Makefile
  14. 25
      src/Rgba.cc
  15. 29
      src/Rgba.h
  16. 39
      src/cmake_install.cmake
  17. 64
      src/gtktest.cc
  18. 9
      src/test.cc
  19. 68
      src/timer.cc

63
CMakeLists.txt

@ -1,60 +1,19 @@
cmake_minimum_required(VERSION 2.6)
cmake_minimum_required (VERSION 3.10)
project(3dbase CXX)
project(3dbase)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE "Debug")
endif()
set(CXX_FLAGS
-g
-DVALGRIND
-DMUDUO_STD_STRING
-DCHECK_PTHREAD_RETURN_VALUE
-D_FILE_OFFSET_BITS=64
-Wall
-Wextra
-Werror
-Wconversion
-Wno-unused-parameter
-Wold-style-cast
-Woverloaded-virtual
-Wpointer-arith
-Wshadow
-Wwrite-strings
-march=native
-MMD
-std=c++11
-Wnarrowing
-rdynamic
)
if(CMAKE_BUILD_BITS EQUAL 32)
list(APPEND CXX_FLAGS "-m32")
endif()
string(REPLACE ";" " " CMAKE_CXX_FLAGS "${CXX_FLAGS}")
set(CMAKE_CXX_COMPILER "g++")
set(CMAKE_CXX_FLAGS_DEBUG "-O0")
set(CMAKE_CXX_FLAGS_RELEASE "-O2 -finline-limit=1000 -DNDEBUG")
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin)
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
find_package(Boost REQUIRED)
find_library(BOOSTTEST_LIBRARY NAMES boost_unit_test_framework)
find_library(BOOSTPO_LIBRARY NAMES boost_program_options)
find_path(TCMALLOC_INCLUDE_DIR google/heap-profiler.h)
find_library(TCMALLOC_LIBRARY NAMES tcmalloc_and_profiler)
if(TCMALLOC_INCLUDE_DIR AND TCMALLOC_LIBRARY)
message(STATUS "found tcmalloc")
else()
message(STATUS "not found tcmalloc")
endif()
include_directories(${Boost_INCLUDE_DIRS})
include_directories(${PROJECT_SOURCE_DIR})
string(TOUPPER ${CMAKE_BUILD_TYPE} BUILD_TYPE)
message(STATUS "CXX_FLAGS = " ${CMAKE_CXX_FLAGS} " " ${CMAKE_CXX_FLAGS_${BUILD_TYPE}})
find_package(PkgConfig REQUIRED)
pkg_check_modules(GTK2 REQUIRED gtk+-2.0)
message(STATUS "----- GTK2_INCLUDE_DIRS: ${GTK2_INCLUDE_DIRS}")
message(STATUS "----- GKT2_LIBRARIES: ${GTK2_LIBRARIES}")
message(STATUS "----- GTK2_LINK_LIBRARIES: ${GTK2_LINK_LIBRARIES}")
include_directories(${GTK2_INCLUDE_DIRS})
link_directories(${GTK2_LIBRARY_DIRS})
list(APPEND FC_DEP_LIBS ${GTK2_LIBRARIES})
add_subdirectory(src)

15
build.sh

@ -4,18 +4,9 @@ set -x
SOURCE_DIR=`pwd`
BUILD_DIR=${BUILD_DIR:-./build}
BUILD_TYPE=${BUILD_TYPE:-release}
INSTALL_DIR=${INSTALL_DIR:-../${BUILD_TYPE}-install}
BUILD_NO_EXAMPLES=${BUILD_NO_EXAMPLES:-0}
mkdir -p $BUILD_DIR/$BUILD_TYPE \
&& cd $BUILD_DIR/$BUILD_TYPE \
&& cmake \
-DCMAKE_BUILD_TYPE=$BUILD_TYPE \
-DCMAKE_INSTALL_PREFIX=$INSTALL_DIR \
-DCMAKE_BUILD_NO_EXAMPLES=$BUILD_NO_EXAMPLES \
$SOURCE_DIR \
mkdir -p $BUILD_DIR \
&& cd $BUILD_DIR \
&& cmake $SOURCE_DIR \
&& make $*
# cd $SOURCE_DIR && doxygen

16
src/CMakeFiles/CMakeDirectoryInformation.cmake

@ -1,16 +0,0 @@
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.10
# Relative path conversion top directories.
set(CMAKE_RELATIVE_PATH_TOP_SOURCE "/home/blobt/Documents/dev/cpp/3dbase")
set(CMAKE_RELATIVE_PATH_TOP_BINARY "/home/blobt/Documents/dev/cpp/3dbase")
# Force unix paths in dependencies.
set(CMAKE_FORCE_UNIX_PATHS 1)
# The C and CXX include file regular expressions for this directory.
set(CMAKE_C_INCLUDE_REGEX_SCAN "^.*$")
set(CMAKE_C_INCLUDE_REGEX_COMPLAIN "^$")
set(CMAKE_CXX_INCLUDE_REGEX_SCAN ${CMAKE_C_INCLUDE_REGEX_SCAN})
set(CMAKE_CXX_INCLUDE_REGEX_COMPLAIN ${CMAKE_C_INCLUDE_REGEX_COMPLAIN})

1
src/CMakeFiles/progress.marks

@ -1 +0,0 @@
2

21
src/CMakeFiles/test.dir/DependInfo.cmake

@ -1,21 +0,0 @@
# The set of languages for which implicit dependencies are needed:
set(CMAKE_DEPENDS_LANGUAGES
"CXX"
)
# The set of files for implicit dependencies of each language:
set(CMAKE_DEPENDS_CHECK_CXX
"/home/blobt/Documents/dev/cpp/3dbase/src/test.cc" "/home/blobt/Documents/dev/cpp/3dbase/src/CMakeFiles/test.dir/test.cc.o"
)
set(CMAKE_CXX_COMPILER_ID "GNU")
# The include file search paths:
set(CMAKE_CXX_TARGET_INCLUDE_PATH
"."
)
# Targets to which this target links.
set(CMAKE_TARGET_LINKED_INFO_FILES
)
# Fortran module output directory.
set(CMAKE_Fortran_TARGET_MODULE_DIR "")

113
src/CMakeFiles/test.dir/build.make

@ -1,113 +0,0 @@
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.10
# Delete rule output on recipe failure.
.DELETE_ON_ERROR:
#=============================================================================
# Special targets provided by cmake.
# Disable implicit rules so canonical targets will work.
.SUFFIXES:
# Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES =
.SUFFIXES: .hpux_make_needs_suffix_list
# Suppress display of executed commands.
$(VERBOSE).SILENT:
# A target that is always out of date.
cmake_force:
.PHONY : cmake_force
#=============================================================================
# Set environment variables for the build.
# The shell in which to execute make rules.
SHELL = /bin/sh
# The CMake executable.
CMAKE_COMMAND = /usr/bin/cmake
# The command to remove a file.
RM = /usr/bin/cmake -E remove -f
# Escaping for special characters.
EQUALS = =
# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /home/blobt/Documents/dev/cpp/3dbase
# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /home/blobt/Documents/dev/cpp/3dbase
# Include any dependencies generated for this target.
include src/CMakeFiles/test.dir/depend.make
# Include the progress variables for this target.
include src/CMakeFiles/test.dir/progress.make
# Include the compile flags for this target's objects.
include src/CMakeFiles/test.dir/flags.make
src/CMakeFiles/test.dir/test.cc.o: src/CMakeFiles/test.dir/flags.make
src/CMakeFiles/test.dir/test.cc.o: src/test.cc
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --progress-dir=/home/blobt/Documents/dev/cpp/3dbase/CMakeFiles --progress-num=$(CMAKE_PROGRESS_1) "Building CXX object src/CMakeFiles/test.dir/test.cc.o"
cd /home/blobt/Documents/dev/cpp/3dbase/src && g++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -o CMakeFiles/test.dir/test.cc.o -c /home/blobt/Documents/dev/cpp/3dbase/src/test.cc
src/CMakeFiles/test.dir/test.cc.i: cmake_force
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Preprocessing CXX source to CMakeFiles/test.dir/test.cc.i"
cd /home/blobt/Documents/dev/cpp/3dbase/src && g++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -E /home/blobt/Documents/dev/cpp/3dbase/src/test.cc > CMakeFiles/test.dir/test.cc.i
src/CMakeFiles/test.dir/test.cc.s: cmake_force
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green "Compiling CXX source to assembly CMakeFiles/test.dir/test.cc.s"
cd /home/blobt/Documents/dev/cpp/3dbase/src && g++ $(CXX_DEFINES) $(CXX_INCLUDES) $(CXX_FLAGS) -S /home/blobt/Documents/dev/cpp/3dbase/src/test.cc -o CMakeFiles/test.dir/test.cc.s
src/CMakeFiles/test.dir/test.cc.o.requires:
.PHONY : src/CMakeFiles/test.dir/test.cc.o.requires
src/CMakeFiles/test.dir/test.cc.o.provides: src/CMakeFiles/test.dir/test.cc.o.requires
$(MAKE) -f src/CMakeFiles/test.dir/build.make src/CMakeFiles/test.dir/test.cc.o.provides.build
.PHONY : src/CMakeFiles/test.dir/test.cc.o.provides
src/CMakeFiles/test.dir/test.cc.o.provides.build: src/CMakeFiles/test.dir/test.cc.o
# Object files for target test
test_OBJECTS = \
"CMakeFiles/test.dir/test.cc.o"
# External object files for target test
test_EXTERNAL_OBJECTS =
bin/test: src/CMakeFiles/test.dir/test.cc.o
bin/test: src/CMakeFiles/test.dir/build.make
bin/test: src/CMakeFiles/test.dir/link.txt
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --green --bold --progress-dir=/home/blobt/Documents/dev/cpp/3dbase/CMakeFiles --progress-num=$(CMAKE_PROGRESS_2) "Linking CXX executable ../bin/test"
cd /home/blobt/Documents/dev/cpp/3dbase/src && $(CMAKE_COMMAND) -E cmake_link_script CMakeFiles/test.dir/link.txt --verbose=$(VERBOSE)
# Rule to build all files generated by this target.
src/CMakeFiles/test.dir/build: bin/test
.PHONY : src/CMakeFiles/test.dir/build
src/CMakeFiles/test.dir/requires: src/CMakeFiles/test.dir/test.cc.o.requires
.PHONY : src/CMakeFiles/test.dir/requires
src/CMakeFiles/test.dir/clean:
cd /home/blobt/Documents/dev/cpp/3dbase/src && $(CMAKE_COMMAND) -P CMakeFiles/test.dir/cmake_clean.cmake
.PHONY : src/CMakeFiles/test.dir/clean
src/CMakeFiles/test.dir/depend:
cd /home/blobt/Documents/dev/cpp/3dbase && $(CMAKE_COMMAND) -E cmake_depends "Unix Makefiles" /home/blobt/Documents/dev/cpp/3dbase /home/blobt/Documents/dev/cpp/3dbase/src /home/blobt/Documents/dev/cpp/3dbase /home/blobt/Documents/dev/cpp/3dbase/src /home/blobt/Documents/dev/cpp/3dbase/src/CMakeFiles/test.dir/DependInfo.cmake --color=$(COLOR)
.PHONY : src/CMakeFiles/test.dir/depend

10
src/CMakeFiles/test.dir/cmake_clean.cmake

@ -1,10 +0,0 @@
file(REMOVE_RECURSE
"CMakeFiles/test.dir/test.cc.o"
"../bin/test.pdb"
"../bin/test"
)
# Per-language clean rules from dependency scanning.
foreach(lang CXX)
include(CMakeFiles/test.dir/cmake_clean_${lang}.cmake OPTIONAL)
endforeach()

2
src/CMakeFiles/test.dir/depend.make

@ -1,2 +0,0 @@
# Empty dependencies file for test.
# This may be replaced when dependencies are built.

10
src/CMakeFiles/test.dir/flags.make

@ -1,10 +0,0 @@
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.10
# compile CXX with g++
CXX_FLAGS = -g -DVALGRIND -DMUDUO_STD_STRING -DCHECK_PTHREAD_RETURN_VALUE -D_FILE_OFFSET_BITS=64 -Wall -Wextra -Werror -Wconversion -Wno-unused-parameter -Wold-style-cast -Woverloaded-virtual -Wpointer-arith -Wshadow -Wwrite-strings -march=native -MMD -std=c++11 -Wnarrowing -rdynamic -O2 -finline-limit=1000 -DNDEBUG
CXX_DEFINES =
CXX_INCLUDES = -I/home/blobt/Documents/dev/cpp/3dbase

1
src/CMakeFiles/test.dir/link.txt

@ -1 +0,0 @@
g++ -g -DVALGRIND -DMUDUO_STD_STRING -DCHECK_PTHREAD_RETURN_VALUE -D_FILE_OFFSET_BITS=64 -Wall -Wextra -Werror -Wconversion -Wno-unused-parameter -Wold-style-cast -Woverloaded-virtual -Wpointer-arith -Wshadow -Wwrite-strings -march=native -MMD -std=c++11 -Wnarrowing -rdynamic -O2 -finline-limit=1000 -DNDEBUG -rdynamic CMakeFiles/test.dir/test.cc.o -o ../bin/test

3
src/CMakeFiles/test.dir/progress.make

@ -1,3 +0,0 @@
CMAKE_PROGRESS_1 = 1
CMAKE_PROGRESS_2 = 2

6
src/CMakeLists.txt

@ -1 +1,5 @@
add_executable(test test.cc)
add_executable(gtktest gtktest.cc Rgba.cc)
target_link_libraries (gtktest ${FC_DEP_LIBS})
add_executable(timer timer.cc)
target_link_libraries (timer ${FC_DEP_LIBS})

180
src/Makefile

@ -1,180 +0,0 @@
# CMAKE generated file: DO NOT EDIT!
# Generated by "Unix Makefiles" Generator, CMake Version 3.10
# Default target executed when no arguments are given to make.
default_target: all
.PHONY : default_target
# Allow only one "make -f Makefile2" at a time, but pass parallelism.
.NOTPARALLEL:
#=============================================================================
# Special targets provided by cmake.
# Disable implicit rules so canonical targets will work.
.SUFFIXES:
# Remove some rules from gmake that .SUFFIXES does not remove.
SUFFIXES =
.SUFFIXES: .hpux_make_needs_suffix_list
# Suppress display of executed commands.
$(VERBOSE).SILENT:
# A target that is always out of date.
cmake_force:
.PHONY : cmake_force
#=============================================================================
# Set environment variables for the build.
# The shell in which to execute make rules.
SHELL = /bin/sh
# The CMake executable.
CMAKE_COMMAND = /usr/bin/cmake
# The command to remove a file.
RM = /usr/bin/cmake -E remove -f
# Escaping for special characters.
EQUALS = =
# The top-level source directory on which CMake was run.
CMAKE_SOURCE_DIR = /home/blobt/Documents/dev/cpp/3dbase
# The top-level build directory on which CMake was run.
CMAKE_BINARY_DIR = /home/blobt/Documents/dev/cpp/3dbase
#=============================================================================
# Targets provided globally by CMake.
# Special rule for the target rebuild_cache
rebuild_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running CMake to regenerate build system..."
/usr/bin/cmake -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR)
.PHONY : rebuild_cache
# Special rule for the target rebuild_cache
rebuild_cache/fast: rebuild_cache
.PHONY : rebuild_cache/fast
# Special rule for the target edit_cache
edit_cache:
@$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "No interactive CMake dialog available..."
/usr/bin/cmake -E echo No\ interactive\ CMake\ dialog\ available.
.PHONY : edit_cache
# Special rule for the target edit_cache
edit_cache/fast: edit_cache
.PHONY : edit_cache/fast
# The main all target
all: cmake_check_build_system
cd /home/blobt/Documents/dev/cpp/3dbase && $(CMAKE_COMMAND) -E cmake_progress_start /home/blobt/Documents/dev/cpp/3dbase/CMakeFiles /home/blobt/Documents/dev/cpp/3dbase/src/CMakeFiles/progress.marks
cd /home/blobt/Documents/dev/cpp/3dbase && $(MAKE) -f CMakeFiles/Makefile2 src/all
$(CMAKE_COMMAND) -E cmake_progress_start /home/blobt/Documents/dev/cpp/3dbase/CMakeFiles 0
.PHONY : all
# The main clean target
clean:
cd /home/blobt/Documents/dev/cpp/3dbase && $(MAKE) -f CMakeFiles/Makefile2 src/clean
.PHONY : clean
# The main clean target
clean/fast: clean
.PHONY : clean/fast
# Prepare targets for installation.
preinstall: all
cd /home/blobt/Documents/dev/cpp/3dbase && $(MAKE) -f CMakeFiles/Makefile2 src/preinstall
.PHONY : preinstall
# Prepare targets for installation.
preinstall/fast:
cd /home/blobt/Documents/dev/cpp/3dbase && $(MAKE) -f CMakeFiles/Makefile2 src/preinstall
.PHONY : preinstall/fast
# clear depends
depend:
cd /home/blobt/Documents/dev/cpp/3dbase && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 1
.PHONY : depend
# Convenience name for target.
src/CMakeFiles/test.dir/rule:
cd /home/blobt/Documents/dev/cpp/3dbase && $(MAKE) -f CMakeFiles/Makefile2 src/CMakeFiles/test.dir/rule
.PHONY : src/CMakeFiles/test.dir/rule
# Convenience name for target.
test: src/CMakeFiles/test.dir/rule
.PHONY : test
# fast build rule for target.
test/fast:
cd /home/blobt/Documents/dev/cpp/3dbase && $(MAKE) -f src/CMakeFiles/test.dir/build.make src/CMakeFiles/test.dir/build
.PHONY : test/fast
test.o: test.cc.o
.PHONY : test.o
# target to build an object file
test.cc.o:
cd /home/blobt/Documents/dev/cpp/3dbase && $(MAKE) -f src/CMakeFiles/test.dir/build.make src/CMakeFiles/test.dir/test.cc.o
.PHONY : test.cc.o
test.i: test.cc.i
.PHONY : test.i
# target to preprocess a source file
test.cc.i:
cd /home/blobt/Documents/dev/cpp/3dbase && $(MAKE) -f src/CMakeFiles/test.dir/build.make src/CMakeFiles/test.dir/test.cc.i
.PHONY : test.cc.i
test.s: test.cc.s
.PHONY : test.s
# target to generate assembly for a file
test.cc.s:
cd /home/blobt/Documents/dev/cpp/3dbase && $(MAKE) -f src/CMakeFiles/test.dir/build.make src/CMakeFiles/test.dir/test.cc.s
.PHONY : test.cc.s
# Help Target
help:
@echo "The following are some of the valid targets for this Makefile:"
@echo "... all (the default if no target is provided)"
@echo "... clean"
@echo "... depend"
@echo "... rebuild_cache"
@echo "... test"
@echo "... edit_cache"
@echo "... test.o"
@echo "... test.i"
@echo "... test.s"
.PHONY : help
#=============================================================================
# Special targets to cleanup operation of make.
# Special rule to run CMake to check the build system integrity.
# No rule that depends on this can have commands that come from listfiles
# because they might be regenerated.
cmake_check_build_system:
cd /home/blobt/Documents/dev/cpp/3dbase && $(CMAKE_COMMAND) -H$(CMAKE_SOURCE_DIR) -B$(CMAKE_BINARY_DIR) --check-build-system CMakeFiles/Makefile.cmake 0
.PHONY : cmake_check_build_system

25
src/Rgba.cc

@ -0,0 +1,25 @@
/*
* 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: Rgba.cc
* Author: Blobt
*
* Created on January 22, 2020, 9:14 PM
*/
#include "Rgba.h"
Rgba::Rgba() {
_r = 255;
_g = 255;
_b = 255;
_a = 255;
}
Rgba::~Rgba() {
}

29
src/Rgba.h

@ -0,0 +1,29 @@
/*
* 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: Rgba.h
* Author: Blobt
*
* Created on January 22, 2020, 9:14 PM
*/
#ifndef RGBA_H
#define RGBA_H
class Rgba {
public:
Rgba();
~Rgba();
private:
unsigned char _r;
unsigned char _g;
unsigned char _b;
unsigned char _a;
};
#endif /* RGBA_H */

39
src/cmake_install.cmake

@ -1,39 +0,0 @@
# Install script for directory: /home/blobt/Documents/dev/cpp/3dbase/src
# Set the install prefix
if(NOT DEFINED CMAKE_INSTALL_PREFIX)
set(CMAKE_INSTALL_PREFIX "/home/blobt/Documents/dev/cpp/3dbase/build/release-install")
endif()
string(REGEX REPLACE "/$" "" CMAKE_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
# Set the install configuration name.
if(NOT DEFINED CMAKE_INSTALL_CONFIG_NAME)
if(BUILD_TYPE)
string(REGEX REPLACE "^[^A-Za-z0-9_]+" ""
CMAKE_INSTALL_CONFIG_NAME "${BUILD_TYPE}")
else()
set(CMAKE_INSTALL_CONFIG_NAME "release")
endif()
message(STATUS "Install configuration: \"${CMAKE_INSTALL_CONFIG_NAME}\"")
endif()
# Set the component getting installed.
if(NOT CMAKE_INSTALL_COMPONENT)
if(COMPONENT)
message(STATUS "Install component: \"${COMPONENT}\"")
set(CMAKE_INSTALL_COMPONENT "${COMPONENT}")
else()
set(CMAKE_INSTALL_COMPONENT)
endif()
endif()
# Install shared libraries without execute permission?
if(NOT DEFINED CMAKE_INSTALL_SO_NO_EXE)
set(CMAKE_INSTALL_SO_NO_EXE "1")
endif()
# Is this installation the result of a crosscompile?
if(NOT DEFINED CMAKE_CROSSCOMPILING)
set(CMAKE_CROSSCOMPILING "FALSE")
endif()

64
src/gtktest.cc

@ -0,0 +1,64 @@
#include <iostream>
#include <cairo.h>
#include <gtk/gtk.h>
#include "Rgba.h"
using namespace std;
gint height = 500;
gint width = 500;
unsigned char* makeBitmap() {
unsigned char* data = new unsigned char[width * height * 4];
for (int i = 0; i < width * height * 4; i++) {
data[i] = rand() % 255;
}
return data;
}
void render(GtkWidget *widget) {
//允许窗口可以绘图
gtk_widget_set_app_paintable(widget, TRUE);
gtk_widget_realize(widget);
gtk_widget_queue_draw(widget);
//模拟一张图片
unsigned char* data = makeBitmap();
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_data(data, GDK_COLORSPACE_RGB, TRUE, 8, width, height, width * 4, NULL, NULL);
GdkPixmap *pixmap = NULL;
gdk_pixbuf_render_pixmap_and_mask(pixbuf, &pixmap, NULL, 128);
gdk_window_set_back_pixmap(widget->window, pixmap, FALSE);
g_object_unref(pixbuf);
g_object_unref(pixmap);
delete data;
}
int main(int argc, char* argv[]) {
gtk_init(&argc, &argv);
//创建窗口
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_widget_set_size_request(window, width, height);
gtk_window_set_title(GTK_WINDOW(window), "Gtk testing");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER_ALWAYS);
//窗口关闭时候,关闭程序
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
//设置渲染
g_signal_connect(window, "expose-event", G_CALLBACK(render), window);
gtk_widget_show_all(window);
gtk_main();
return 0;
}

9
src/test.cc

@ -1,9 +0,0 @@
#include <iostream>
using namespace std;
int main(){
cout << "Hello" << endl;
return 0;
}

68
src/timer.cc

@ -0,0 +1,68 @@
#include <cairo.h>
#include <gtk/gtk.h>
gchar buf[256];
gboolean on_expose_event(GtkWidget *widget,
GdkEventExpose *event,
gpointer data) {
cairo_t *cr;
cr = gdk_cairo_create(widget->window);
cairo_move_to(cr, 30, 30);
cairo_set_font_size(cr, 15);
cairo_show_text(cr, buf);
cairo_destroy(cr);
return FALSE;
}
gboolean time_handler(GtkWidget *widget) {
if (widget->window == NULL) return FALSE;
GDateTime *now = g_date_time_new_now_local();
gchar *my_time = g_date_time_format(now, "%H:%M:%S");
sprintf(buf, "%s", my_time);
g_free(my_time);
g_date_time_unref(now);
gtk_widget_queue_draw(widget);
return TRUE;
}
int main(int argc, char *argv[]) {
GtkWidget *window;
GtkWidget *darea;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
darea = gtk_drawing_area_new();
gtk_container_add(GTK_CONTAINER(window), darea);
g_signal_connect(darea, "expose-event",
G_CALLBACK(on_expose_event), NULL);
g_signal_connect(window, "destroy",
G_CALLBACK(gtk_main_quit), NULL);
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 300, 200);
gtk_window_set_title(GTK_WINDOW(window), "Timer");
g_timeout_add(1000, (GSourceFunc) time_handler, (gpointer) window);
gtk_widget_show_all(window);
time_handler(window);
gtk_main();
return 0;
}
Loading…
Cancel
Save